diff --git a/js/src/dialogs/userbrowser.js b/js/src/dialogs/userbrowser.js
index 7624a0250..4f70a2086 100644
--- a/js/src/dialogs/userbrowser.js
+++ b/js/src/dialogs/userbrowser.js
@@ -7,7 +7,7 @@ class UserBrowserDialog {
this.mainView = mainView;
const self = this;
-
+
// set up the OK button and the enter button
$('#userbrowserok').click(function(event) {
self.#shareSelected();
diff --git a/js/src/views/browser.js b/js/src/views/browser.js
index b90b4c6f8..bf4ba0cb5 100644
--- a/js/src/views/browser.js
+++ b/js/src/views/browser.js
@@ -11,207 +11,210 @@ class BrowserView {
}
// parse the query string and put it in a dictionary
-var queryDict = {};
-location.search.substr(1).split("&").
- forEach(function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]});
+const queryDict = {};
+location.search.substr(1).split('&').
+ forEach(function(item) {
+ queryDict[item.split('=')[0]] = item.split('=')[1];
+ });
function dictToURI(dict) {
- var str = [];
- for(var p in dict){
- str.push(encodeURIComponent(p) + "=" + encodeURIComponent(dict[p]));
+ const str = [];
+ for (const p in dict) {
+ str.push(encodeURIComponent(p) + '=' + encodeURIComponent(dict[p]));
}
- return str.join("&");
+ return str.join('&');
}
function set_single_selection() {
- // disable Save button
- $('#savemulti').unbind('click');
- $('#savemulti').addClass('disabled');
-
- // unselect selected files
- $('.file.selected').removeClass('selected');
-
- // update handler for file tiles
- $('.file').unbind('click');
- $('.file').click(function(event) {
- const path = $(this).data('path');
- // show "activity" overlay
- $('#overlaytext').text('Saving file...');
- $('#overlay').css("display", "block");
- // tell the server to store the file
- $.ajax({
- url: "/browser/savefromsmb",
- type: "post",
- data: { "path": path,
- "type": queryDict['type'] },
- success: function(data) {
- if(data.code) {
- alert("Error: "+data.message);
- $('#overlay').css("display", "none");
- } else {
- // hide the file browser
- parent.CKEDITOR.dialog.getCurrent().hide();
- // call the call back function
- parent.CKEDITOR.fbcallback(data.uploadurl, {'filename': data.filename, 'type': data.type});
- }
- }
- });
+ // disable Save button
+ $('#savemulti').unbind('click');
+ $('#savemulti').addClass('disabled');
+
+ // unselect selected files
+ $('.file.selected').removeClass('selected');
+
+ // update handler for file tiles
+ $('.file').unbind('click');
+ $('.file').click(function(event) {
+ const path = $(this).data('path');
+ // show "activity" overlay
+ $('#overlaytext').text('Saving file...');
+ $('#overlay').css('display', 'block');
+ // tell the server to store the file
+ $.ajax({
+ url: '/browser/savefromsmb',
+ type: 'post',
+ data: {'path': path,
+ 'type': queryDict['type']},
+ success: function(data) {
+ if (data.code) {
+ alert('Error: '+data.message);
+ $('#overlay').css('display', 'none');
+ } else {
+ // hide the file browser
+ parent.CKEDITOR.dialog.getCurrent().hide();
+ // call the call back function
+ parent.CKEDITOR.fbcallback(data.uploadurl, {'filename': data.filename, 'type': data.type});
+ }
+ },
});
+ });
}
-var files_total = 0;
-var files_left = 0;
+let files_total = 0;
+let files_left = 0;
function set_multi_selection() {
- // update handler for file tiles
- $('.file').unbind('click');
- $('.file').click(function(event) {
- $(this).toggleClass('selected');
- });
-
- // set up Save button
- $('#savemulti').removeClass('disabled');
- $('#savemulti').click(function() {
- // count files
- files_total = $('.file.selected').length;
- files_left = files_total;
- // show "activity" overlay
- $('#overlaytext').html('Saving files... (0/'+files_total+')'+
+ // update handler for file tiles
+ $('.file').unbind('click');
+ $('.file').click(function(event) {
+ $(this).toggleClass('selected');
+ });
+
+ // set up Save button
+ $('#savemulti').removeClass('disabled');
+ $('#savemulti').click(function() {
+ // count files
+ files_total = $('.file.selected').length;
+ files_left = files_total;
+ // show "activity" overlay
+ $('#overlaytext').html('Saving files... (0/'+files_total+')'+
'
');
- $('#overlay').css("display", "block");
- // save files
- $('.file.selected').each(function() {
- const path = $(this).data('path');
- // tell the server to store the file
- $.ajax({
- url: "/browser/savefromsmb",
- type: "post",
- data: { "path": path,
- "type": queryDict['type'] },
- success: function(data) {
- files_left -= 1;
- $('#filecounter').text('('+(files_total-files_left)+'/'+files_total+')');
- if(data.code) {
- $('#saveerrors').append('Error: '+data.filename+': '+data.message+'
');
- } else {
- // call the call back function
- parent.CKEDITOR.fbcallback(data.uploadurl, {'filename': data.filename, 'type': data.type});
- }
- if(!files_left && $('#saveerrors').html() == '') {
- // hide the file browser
- parent.CKEDITOR.dialog.getCurrent().hide();
- }
- }
- });
- });
+ $('#overlay').css('display', 'block');
+ // save files
+ $('.file.selected').each(function() {
+ const path = $(this).data('path');
+ // tell the server to store the file
+ $.ajax({
+ url: '/browser/savefromsmb',
+ type: 'post',
+ data: {'path': path,
+ 'type': queryDict['type']},
+ success: function(data) {
+ files_left -= 1;
+ $('#filecounter').text('('+(files_total-files_left)+'/'+files_total+')');
+ if (data.code) {
+ $('#saveerrors').append('Error: '+data.filename+': '+data.message+'
');
+ } else {
+ // call the call back function
+ parent.CKEDITOR.fbcallback(data.uploadurl, {'filename': data.filename, 'type': data.type});
+ }
+ if (!files_left && $('#saveerrors').html() == '') {
+ // hide the file browser
+ parent.CKEDITOR.dialog.getCurrent().hide();
+ }
+ },
+ });
});
+ });
}
function init_browser() {
- if(queryDict['multi'] === 'true') {
- set_multi_selection();
+ if (queryDict['multi'] === 'true') {
+ set_multi_selection();
+ } else {
+ set_single_selection();
+ }
+
+ $('#multiswitch-checkbox').click(function(event) {
+ if (this.checked) {
+ set_multi_selection();
} else {
- set_single_selection();
+ set_single_selection();
}
-
- $('#multiswitch-checkbox').click(function(event) {
- if(this.checked) {
- set_multi_selection();
+ });
+
+ // tell the upload form how to communicate with the server
+ $('#uploadform').submit(function(event) {
+ event.preventDefault();
+ const formData = new FormData(this);
+
+ // show "activity" overlay
+ $('#overlaytext').text('Uploading file...');
+ $('#overlay').css('display', 'block');
+ // send file to server
+ $.ajax({
+ url: '/browser/upload?type=img',
+ data: formData,
+ type: 'POST',
+ contentType: false,
+ processData: false,
+ success: function(data) {
+ if (data.uploaded) {
+ parent.CKEDITOR.dialog.getCurrent().hide(); // hide the file browser
+ parent.CKEDITOR.fbcallback(data.url); // call the call back
} else {
- set_single_selection();
+ alert('Error: '+data.error['message']);
+ $('#overlay').css('display', 'none');
}
+ },
+ error: function(jqXHR, textStatus, errorThrown) {
+ alert('Error when communicating with server.');
+ },
});
+ });
- // tell the upload form how to communicate with the server
- $('#uploadform').submit(function(event) {
- event.preventDefault();
- var formData = new FormData(this);
-
- // show "activity" overlay
- $('#overlaytext').text('Uploading file...');
- $('#overlay').css("display", "block");
- // send file to server
- $.ajax({
- url: '/browser/upload?type=img',
- data: formData,
- type: 'POST',
- contentType: false,
- processData: false,
- success: function(data) {
- if(data.uploaded) {
- parent.CKEDITOR.dialog.getCurrent().hide(); // hide the file browser
- parent.CKEDITOR.fbcallback(data.url); // call the call back
- } else {
- alert("Error: "+data.error['message']);
- $('#overlay').css("display", "none");
- }
- },
- error: function(jqXHR, textStatus, errorThrown) {
- alert("Error when communicating with server.");
- }
- });
- });
-
- function folderclickhandler(event) {
- if(document.getElementById('multiswitch-checkbox') !== null)
- queryDict['multi'] = document.getElementById('multiswitch-checkbox').checked;
- location.replace('/browser/'+$(this).data('url')+'?'+dictToURI(queryDict));
- event.preventDefault();
+ function folderclickhandler(event) {
+ if (document.getElementById('multiswitch-checkbox') !== null) {
+ queryDict['multi'] = document.getElementById('multiswitch-checkbox').checked;
}
+ location.replace('/browser/'+$(this).data('url')+'?'+dictToURI(queryDict));
+ event.preventDefault();
+ }
- $('.folder').click(folderclickhandler);
-
- // TODO: note that the functionality of inpectpath and inspectresource could be easily combined and the following
- // code could be reduced a lot by treating historyitem, resource and shortcut all the same way...
-
- // check for each history item if it is available
- $('.historyitem').each(function(index, element) {
- var historyitemdiv = $(this);
- $.ajax({
- url: "/browser/inspectpath",
- type: "post",
- data: { "smbpath": $(this).data('url') },
- success: function(data) {
- if(!data.code) {
- historyitemdiv.find('img').attr('src', '/static/images/folder.png');
- historyitemdiv.addClass('available'); // for CSS :hover
- // add click handler for new elements
- historyitemdiv.click(folderclickhandler);
- } else {
- historyitemdiv.find('img').attr('src', '/static/images/folder_inaccessible.png');
- }
- }
- });
+ $('.folder').click(folderclickhandler);
+
+ // TODO: note that the functionality of inpectpath and inspectresource could be easily combined and the following
+ // code could be reduced a lot by treating historyitem, resource and shortcut all the same way...
+
+ // check for each history item if it is available
+ $('.historyitem').each(function(index, element) {
+ const historyitemdiv = $(this);
+ $.ajax({
+ url: '/browser/inspectpath',
+ type: 'post',
+ data: {'smbpath': $(this).data('url')},
+ success: function(data) {
+ if (!data.code) {
+ historyitemdiv.find('img').attr('src', '/static/images/folder.png');
+ historyitemdiv.addClass('available'); // for CSS :hover
+ // add click handler for new elements
+ historyitemdiv.click(folderclickhandler);
+ } else {
+ historyitemdiv.find('img').attr('src', '/static/images/folder_inaccessible.png');
+ }
+ },
});
-
- // check for each resource if it is available and if it has a user/sample folder
- $('.resource').each(function(index, element) {
- $.ajax({
- url: "/browser/inspectresource",
- type: "post",
- data: { "sampleid": queryDict['sample'],
- "resourceid": $(this).data('id') },
- success: function(data) {
- const resourcediv = $('#resource' + data.resourceid);
- const shortcutsdiv = $('#shortcuts' + data.resourceid);
- shortcutsdiv.empty();
- if(!data.code) {
- if(data.userfolder != '') {
- shortcutsdiv.append("");
- }
- if(data.samplefolder != '') {
- shortcutsdiv.append("");
- }
- resourcediv.addClass('available'); // for CSS :hover
-
- // add click handler for new elements
- resourcediv.click(folderclickhandler);
- shortcutsdiv.children('img').click(folderclickhandler);
- } else {
- resourcediv.append(" (N/A)");
- }
- }
- })
+ });
+
+ // check for each resource if it is available and if it has a user/sample folder
+ $('.resource').each(function(index, element) {
+ $.ajax({
+ url: '/browser/inspectresource',
+ type: 'post',
+ data: {'sampleid': queryDict['sample'],
+ 'resourceid': $(this).data('id')},
+ success: function(data) {
+ const resourcediv = $('#resource' + data.resourceid);
+ const shortcutsdiv = $('#shortcuts' + data.resourceid);
+ shortcutsdiv.empty();
+ if (!data.code) {
+ if (data.userfolder != '') {
+ shortcutsdiv.append('');
+ }
+ if (data.samplefolder != '') {
+ shortcutsdiv.append('');
+ }
+ resourcediv.addClass('available'); // for CSS :hover
+
+ // add click handler for new elements
+ resourcediv.click(folderclickhandler);
+ shortcutsdiv.children('img').click(folderclickhandler);
+ } else {
+ resourcediv.append(' (N/A)');
+ }
+ },
});
+ });
}
export default BrowserView;
diff --git a/js/src/views/main/sample.js b/js/src/views/main/sample.js
index 3f0fa57ef..89a28362c 100644
--- a/js/src/views/main/sample.js
+++ b/js/src/views/main/sample.js
@@ -24,7 +24,7 @@ class SampleView extends AjaxView {
this.invertactionorder = false;
this.showparentactions = false;
}
-
+
onDocumentReady() {
const self = this;