3 window.ImageManager = new Vue({
13 dependantPages: false,
17 created: function () {
19 this.fetchData(this.page);
28 fetchData: function () {
30 this.$http.get('/images/all/' + _this.page, function (data) {
31 _this.images = _this.images.concat(data.images);
32 _this.hasMore = data.hasMore;
37 setupDropZone: function () {
39 var dropZone = new Dropzone(_this.$$.dropZone, {
43 this.on("sending", function (file, xhr, data) {
44 data.append("_token", document.querySelector('meta[name=token]').getAttribute('content'));
46 this.on("success", function (file, data) {
47 _this.images.unshift(data);
48 $(file.previewElement).fadeOut(400, function () {
56 imageClick: function (image) {
57 var dblClickTime = 380;
58 var cTime = (new Date()).getTime();
59 var timeDiff = cTime - this.cClickTime;
60 if (this.cClickTime !== 0 && timeDiff < dblClickTime && this.selectedImage === image) {
67 this.selectedImage = (this.selectedImage === image) ? false : image;
68 this.dependantPages = false;
70 this.cClickTime = cTime;
73 selectButtonClick: function () {
75 this.callback(this.selectedImage);
80 show: function (callback) {
81 this.callback = callback;
82 this.$$.overlay.style.display = 'block';
85 overlayClick: function (e) {
86 if (e.target.className === 'overlay') {
92 this.$$.overlay.style.display = 'none';
95 saveImageDetails: function (e) {
98 var form = $(_this.$$.imageForm);
99 $.ajax('/images/update/' + _this.selectedImage.id, {
101 data: form.serialize()
102 }).done(function () {
103 form.showSuccess('Image name updated');
104 }).fail(function (jqXHR) {
105 form.showFailure(jqXHR.responseJSON);
109 deleteImage: function (e) {
112 _this.deleteForm.force = _this.dependantPages !== false;
113 $.ajax('/images/' + _this.selectedImage.id, {
115 data: _this.deleteForm
116 }).done(function () {
117 _this.images.splice(_this.images.indexOf(_this.selectedImage), 1);
118 _this.selectedImage = false;
119 $(_this.$$.imageTitle).showSuccess('Image Deleted');
120 }).fail(function(jqXHR, textStatus) {
122 if(jqXHR.status === 400) {
123 _this.dependantPages = jqXHR.responseJSON;