]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/components/image-manager.vue
Added mulit image-type compatability to manager & app and added scaled image selection
[bookstack] / resources / assets / js / components / image-manager.vue
index bb691760b92ae654feec8caef1f62772bce873ee..c47fee184dac95ae79696dbe19e823a997d10528 100644 (file)
             }
         },
 
+        props: {
+            imageType: {
+                type: String,
+                required: true
+            },
+            resizeWidth: {
+                type: String
+            },
+            resizeHeight: {
+                type: String
+            },
+            resizeCrop: {
+                type: Boolean
+            }
+        },
+
         created: function () {
             window.ImageManager = this;
         },
         methods: {
             fetchData: function () {
                 var _this = this;
-                this.$http.get('/images/gallery/all/' + _this.page, function (data) {
+                this.$http.get('/images/' + _this.imageType + '/all/' + _this.page, function (data) {
                     _this.images = _this.images.concat(data.images);
                     _this.hasMore = data.hasMore;
                     _this.page++;
             setupDropZone: function () {
                 var _this = this;
                 var dropZone = new Dropzone(_this.$els.dropZone, {
-                    url: '/images/gallery/upload',
+                    url: '/images/' + _this.imageType + '/upload',
                     init: function () {
                         var dz = this;
                         this.on("sending", function (file, xhr, data) {
                 });
             },
 
+            returnCallback: function (image) {
+                var _this = this;
+                var isResized = _this.resizeWidth && _this.resizeHeight;
+
+                if (!isResized) {
+                    _this.callback(image);
+                    return;
+                }
+
+                var cropped = _this.resizeCrop ? 'true' : 'false';
+                var requestString = '/images/thumb/' + image.id + '/' + _this.resizeWidth + '/' + _this.resizeHeight + '/' + cropped;
+                _this.$http.get(requestString, function(data) {
+                    image.thumbs.custom = data.url;
+                    _this.callback(image);
+                });
+
+            },
+
             imageClick: function (image) {
                 var dblClickTime = 380;
                 var cTime = (new Date()).getTime();
                 if (this.cClickTime !== 0 && timeDiff < dblClickTime && this.selectedImage === image) {
                     // DoubleClick
                     if (this.callback) {
-                        this.callback(image);
+                        this.returnCallback(image);
                     }
                     this.hide();
                 } else {
 
             selectButtonClick: function () {
                 if (this.callback) {
-                    this.callback(this.selectedImage);
+                    this.returnCallback(this.selectedImage);
                 }
                 this.hide();
             },