|
|
@ -16,11 +16,15 @@ let vueImage = new Vue({
|
|
|
|
images: [],
|
|
|
|
images: [],
|
|
|
|
uploadSucceeded: false,
|
|
|
|
uploadSucceeded: false,
|
|
|
|
postUploadChecks: 0,
|
|
|
|
postUploadChecks: 0,
|
|
|
|
|
|
|
|
renameImageShow: false,
|
|
|
|
|
|
|
|
renameImageId: '',
|
|
|
|
|
|
|
|
renameImageFilename: '',
|
|
|
|
deleteImageShow: false,
|
|
|
|
deleteImageShow: false,
|
|
|
|
deleteImageId: 0,
|
|
|
|
deleteImageId: '',
|
|
|
|
deleteImageFilename: ''
|
|
|
|
deleteImageFilename: ''
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
|
|
|
|
open: () => {
|
|
|
|
open: () => {
|
|
|
|
mdeModalOpenState = true;
|
|
|
|
mdeModalOpenState = true;
|
|
|
|
$('#modal-editor-image').slideDown();
|
|
|
|
$('#modal-editor-image').slideDown();
|
|
|
@ -30,6 +34,17 @@ let vueImage = new Vue({
|
|
|
|
mdeModalOpenState = false;
|
|
|
|
mdeModalOpenState = false;
|
|
|
|
$('#modal-editor-image').slideUp();
|
|
|
|
$('#modal-editor-image').slideUp();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
// INSERT IMAGE
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectImage: (imageId) => {
|
|
|
|
|
|
|
|
vueImage.currentImage = imageId;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
selectAlignment: (align) => {
|
|
|
|
|
|
|
|
vueImage.currentAlign = align;
|
|
|
|
|
|
|
|
},
|
|
|
|
insertImage: (ev) => {
|
|
|
|
insertImage: (ev) => {
|
|
|
|
|
|
|
|
|
|
|
|
if(mde.codemirror.doc.somethingSelected()) {
|
|
|
|
if(mde.codemirror.doc.somethingSelected()) {
|
|
|
@ -57,6 +72,11 @@ let vueImage = new Vue({
|
|
|
|
vueImage.cancel();
|
|
|
|
vueImage.cancel();
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
// NEW FOLDER
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
newFolder: (ev) => {
|
|
|
|
newFolder: (ev) => {
|
|
|
|
vueImage.newFolderName = '';
|
|
|
|
vueImage.newFolderName = '';
|
|
|
|
vueImage.newFolderError = false;
|
|
|
|
vueImage.newFolderError = false;
|
|
|
@ -90,6 +110,11 @@ let vueImage = new Vue({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
// FETCH FROM URL
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
fetchFromUrl: (ev) => {
|
|
|
|
fetchFromUrl: (ev) => {
|
|
|
|
vueImage.fetchFromUrlURL = '';
|
|
|
|
vueImage.fetchFromUrlURL = '';
|
|
|
|
vueImage.fetchFromUrlShow = true;
|
|
|
|
vueImage.fetchFromUrlShow = true;
|
|
|
@ -107,7 +132,7 @@ let vueImage = new Vue({
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
socket.emit('uploadsFetchFileFromURL', { folder: vueImage.currentFolder, fetchUrl: vueImage.fetchFromUrlURL }, (data) => {
|
|
|
|
socket.emit('uploadsFetchFileFromURL', { folder: vueImage.currentFolder, fetchUrl: vueImage.fetchFromUrlURL }, (data) => {
|
|
|
|
if(data.ok) {
|
|
|
|
if(data.ok) {
|
|
|
|
vueImage.waitUploadComplete();
|
|
|
|
vueImage.waitChangeComplete(vueImage.images.length, true);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
alerts.pushError('Upload error', data.msg);
|
|
|
|
alerts.pushError('Upload error', data.msg);
|
|
|
@ -117,22 +142,92 @@ let vueImage = new Vue({
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// -------------------------------------------
|
|
|
|
* Select a folder
|
|
|
|
// RENAME IMAGE
|
|
|
|
*
|
|
|
|
// -------------------------------------------
|
|
|
|
* @param {string} fldName The folder name
|
|
|
|
|
|
|
|
* @return {Void} Void
|
|
|
|
renameImage: () => {
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
let c = _.find(vueImage.images, ['_id', vueImage.renameImageId ]);
|
|
|
|
|
|
|
|
vueImage.renameImageFilename = c.basename || '';
|
|
|
|
|
|
|
|
vueImage.renameImageShow = true;
|
|
|
|
|
|
|
|
_.delay(() => {
|
|
|
|
|
|
|
|
$('#txt-editor-renameimage').focus();
|
|
|
|
|
|
|
|
_.defer(() => { $('#txt-editor-renameimage').select(); });
|
|
|
|
|
|
|
|
}, 400);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
renameImageDiscard: () => {
|
|
|
|
|
|
|
|
vueImage.renameImageShow = false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
renameImageGo: () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vueImage.renameImageDiscard();
|
|
|
|
|
|
|
|
vueImage.isLoadingText = 'Renaming image...';
|
|
|
|
|
|
|
|
vueImage.isLoading = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
|
|
|
|
socket.emit('uploadsRenameFile', { uid: vueImage.renameImageId, folder: vueImage.currentFolder, filename: vueImage.renameImageFilename }, (data) => {
|
|
|
|
|
|
|
|
if(data.ok) {
|
|
|
|
|
|
|
|
vueImage.waitChangeComplete(vueImage.images.length, false);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
|
|
|
|
alerts.pushError('Rename error', data.msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
// MOVE IMAGE
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
moveImage: (uid, fld) => {
|
|
|
|
|
|
|
|
vueImage.isLoadingText = 'Moving image...';
|
|
|
|
|
|
|
|
vueImage.isLoading = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
|
|
|
|
socket.emit('uploadsMoveFile', { uid: uid, folder: fld }, (data) => {
|
|
|
|
|
|
|
|
if(data.ok) {
|
|
|
|
|
|
|
|
vueImage.loadImages();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
|
|
|
|
alerts.pushError('Rename error', data.msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
// DELETE IMAGE
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deleteImageWarn: (show) => {
|
|
|
|
|
|
|
|
if(show) {
|
|
|
|
|
|
|
|
let c = _.find(vueImage.images, ['_id', vueImage.deleteImageId ]);
|
|
|
|
|
|
|
|
vueImage.deleteImageFilename = c.filename || 'this image';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vueImage.deleteImageShow = show;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteImageGo: () => {
|
|
|
|
|
|
|
|
vueImage.deleteImageWarn(false);
|
|
|
|
|
|
|
|
vueImage.isLoadingText = 'Deleting image...';
|
|
|
|
|
|
|
|
vueImage.isLoading = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
|
|
|
|
socket.emit('uploadsDeleteFile', { uid: vueImage.deleteImageId }, (data) => {
|
|
|
|
|
|
|
|
vueImage.loadImages();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
// LOAD FROM REMOTE
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
selectFolder: (fldName) => {
|
|
|
|
selectFolder: (fldName) => {
|
|
|
|
vueImage.currentFolder = fldName;
|
|
|
|
vueImage.currentFolder = fldName;
|
|
|
|
vueImage.loadImages();
|
|
|
|
vueImage.loadImages();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Refresh folder list and load images from root
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return {Void} Void
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
refreshFolders: () => {
|
|
|
|
refreshFolders: () => {
|
|
|
|
vueImage.isLoadingText = 'Fetching folders list...';
|
|
|
|
vueImage.isLoadingText = 'Fetching folders list...';
|
|
|
|
vueImage.isLoading = true;
|
|
|
|
vueImage.isLoading = true;
|
|
|
@ -146,58 +241,66 @@ let vueImage = new Vue({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Loads images in selected folder
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return {Void} Void
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
loadImages: (silent) => {
|
|
|
|
loadImages: (silent) => {
|
|
|
|
if(!silent) {
|
|
|
|
if(!silent) {
|
|
|
|
vueImage.isLoadingText = 'Fetching images...';
|
|
|
|
vueImage.isLoadingText = 'Fetching images...';
|
|
|
|
vueImage.isLoading = true;
|
|
|
|
vueImage.isLoading = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
|
|
|
|
socket.emit('uploadsGetImages', { folder: vueImage.currentFolder }, (data) => {
|
|
|
|
|
|
|
|
vueImage.images = data;
|
|
|
|
|
|
|
|
if(!silent) {
|
|
|
|
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vueImage.attachContextMenus();
|
|
|
|
|
|
|
|
resolve(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
waitChangeComplete: (oldAmount, expectChange) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expectChange = (_.isBoolean(expectChange)) ? expectChange : true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vueImage.postUploadChecks++;
|
|
|
|
|
|
|
|
vueImage.isLoadingText = 'Processing...';
|
|
|
|
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
socket.emit('uploadsGetImages', { folder: vueImage.currentFolder }, (data) => {
|
|
|
|
vueImage.loadImages(true).then(() => {
|
|
|
|
vueImage.images = data;
|
|
|
|
if((vueImage.images.length !== oldAmount) === expectChange) {
|
|
|
|
if(!silent) {
|
|
|
|
vueImage.postUploadChecks = 0;
|
|
|
|
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
|
|
|
|
} else if(vueImage.postUploadChecks > 5) {
|
|
|
|
|
|
|
|
vueImage.postUploadChecks = 0;
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
|
|
|
|
alerts.pushError('Unable to fetch updated listing', 'Try again later');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_.delay(() => {
|
|
|
|
|
|
|
|
vueImage.waitChangeComplete(oldAmount, expectChange);
|
|
|
|
|
|
|
|
}, 1500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vueImage.attachContextMenus();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Select an image
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param {String} imageId The image identifier
|
|
|
|
|
|
|
|
* @return {Void} Void
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
selectImage: (imageId) => {
|
|
|
|
|
|
|
|
vueImage.currentImage = imageId;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Set image alignment
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param {String} align The alignment
|
|
|
|
|
|
|
|
* @return {Void} Void
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
selectAlignment: (align) => {
|
|
|
|
|
|
|
|
vueImage.currentAlign = align;
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// -------------------------------------------
|
|
|
|
* Attach right-click context menus to images and folders
|
|
|
|
// IMAGE CONTEXT MENU
|
|
|
|
*
|
|
|
|
// -------------------------------------------
|
|
|
|
* @return {Void} Void
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
attachContextMenus: () => {
|
|
|
|
attachContextMenus: () => {
|
|
|
|
|
|
|
|
|
|
|
|
let moveFolders = _.map(vueImage.folders, (f) => {
|
|
|
|
let moveFolders = _.map(vueImage.folders, (f) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
name: (f !== '') ? f : '/ (root)',
|
|
|
|
name: (f !== '') ? f : '/ (root)',
|
|
|
|
icon: 'fa-folder'
|
|
|
|
icon: 'fa-folder',
|
|
|
|
|
|
|
|
callback: (key, opt) => {
|
|
|
|
|
|
|
|
let moveImageId = _.toString($(opt.$trigger).data('uid'));
|
|
|
|
|
|
|
|
let moveImageDestFolder = _.nth(vueImage.folders, key);
|
|
|
|
|
|
|
|
vueImage.moveImage(moveImageId, moveImageDestFolder);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -221,7 +324,8 @@ let vueImage = new Vue({
|
|
|
|
name: "Rename",
|
|
|
|
name: "Rename",
|
|
|
|
icon: "fa-edit",
|
|
|
|
icon: "fa-edit",
|
|
|
|
callback: (key, opt) => {
|
|
|
|
callback: (key, opt) => {
|
|
|
|
alert("Clicked on " + key);
|
|
|
|
vueImage.renameImageId = _.toString(opt.$trigger[0].dataset.uid);
|
|
|
|
|
|
|
|
vueImage.renameImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
move: {
|
|
|
|
move: {
|
|
|
@ -233,60 +337,12 @@ let vueImage = new Vue({
|
|
|
|
name: "Delete",
|
|
|
|
name: "Delete",
|
|
|
|
icon: "fa-trash",
|
|
|
|
icon: "fa-trash",
|
|
|
|
callback: (key, opt) => {
|
|
|
|
callback: (key, opt) => {
|
|
|
|
vueImage.deleteImageId = _.toString($(opt.$trigger).data('uid'));
|
|
|
|
vueImage.deleteImageId = _.toString(opt.$trigger[0].dataset.uid);
|
|
|
|
vueImage.deleteImageWarn(true);
|
|
|
|
vueImage.deleteImageWarn(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deleteImageWarn: (show) => {
|
|
|
|
|
|
|
|
if(show) {
|
|
|
|
|
|
|
|
let c = _.find(vueImage.images, ['_id', vueImage.deleteImageId ]);
|
|
|
|
|
|
|
|
if(c) {
|
|
|
|
|
|
|
|
vueImage.deleteImageFilename = c.filename;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
vueImage.deleteImageFilename = 'this image';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vueImage.deleteImageShow = show;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deleteImageGo: () => {
|
|
|
|
|
|
|
|
vueImage.deleteImageWarn(false);
|
|
|
|
|
|
|
|
vueImage.isLoadingText = 'Deleting image...';
|
|
|
|
|
|
|
|
vueImage.isLoading = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
|
|
|
|
socket.emit('uploadsDeleteFile', { uid: vueImage.deleteImageId }, (data) => {
|
|
|
|
|
|
|
|
vueImage.loadImages();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
waitUploadComplete: () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vueImage.postUploadChecks++;
|
|
|
|
|
|
|
|
vueImage.isLoadingText = 'Processing...';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let currentUplAmount = vueImage.images.length;
|
|
|
|
|
|
|
|
vueImage.loadImages(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
|
|
|
|
_.delay(() => {
|
|
|
|
|
|
|
|
if(currentUplAmount !== vueImage.images.length) {
|
|
|
|
|
|
|
|
vueImage.postUploadChecks = 0;
|
|
|
|
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
|
|
|
|
} else if(vueImage.postUploadChecks > 5) {
|
|
|
|
|
|
|
|
vueImage.postUploadChecks = 0;
|
|
|
|
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
|
|
|
|
alerts.pushError('Unable to fetch new listing', 'Try again later');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
vueImage.waitUploadComplete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -294,6 +350,8 @@ let vueImage = new Vue({
|
|
|
|
|
|
|
|
|
|
|
|
$('#btn-editor-uploadimage input').on('change', (ev) => {
|
|
|
|
$('#btn-editor-uploadimage input').on('change', (ev) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let curImageAmount = vueImage.images.length;
|
|
|
|
|
|
|
|
|
|
|
|
$(ev.currentTarget).simpleUpload("/uploads/img", {
|
|
|
|
$(ev.currentTarget).simpleUpload("/uploads/img", {
|
|
|
|
|
|
|
|
|
|
|
|
name: 'imgfile',
|
|
|
|
name: 'imgfile',
|
|
|
@ -346,7 +404,7 @@ $('#btn-editor-uploadimage input').on('change', (ev) => {
|
|
|
|
|
|
|
|
|
|
|
|
finish: () => {
|
|
|
|
finish: () => {
|
|
|
|
if(vueImage.uploadSucceeded) {
|
|
|
|
if(vueImage.uploadSucceeded) {
|
|
|
|
vueImage.waitUploadComplete();
|
|
|
|
vueImage.waitChangeComplete(curImageAmount, true);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
vueImage.isLoading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|