Merge pull request #8200 from owncloud/js-cleanup-dialogs-master
javascript code cleanup + fixing syntax errors
This commit is contained in:
commit
2eeab60378
1 changed files with 168 additions and 175 deletions
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/* global OC, t */
|
||||
/* global OC, t, alert */
|
||||
|
||||
/**
|
||||
* this class to ease the usage of jquery dialogs
|
||||
|
@ -29,7 +29,7 @@ var OCdialogs = {
|
|||
YES_NO_BUTTONS: 70,
|
||||
OK_BUTTONS: 71,
|
||||
// used to name each dialog
|
||||
dialogs_counter: 0,
|
||||
dialogsCounter: 0,
|
||||
/**
|
||||
* displays alert dialog
|
||||
* @param text content of dialog
|
||||
|
@ -54,7 +54,8 @@ var OCdialogs = {
|
|||
* displays confirmation dialog
|
||||
* @param text content of dialog
|
||||
* @param title dialog title
|
||||
* @param callback which will be triggered when user presses YES or NO (true or false would be passed to callback respectively)
|
||||
* @param callback which will be triggered when user presses YES or NO
|
||||
* (true or false would be passed to callback respectively)
|
||||
* @param modal make the dialog modal
|
||||
*/
|
||||
confirm:function(text, title, callback, modal) {
|
||||
|
@ -65,21 +66,20 @@ var OCdialogs = {
|
|||
* @param title dialog title
|
||||
* @param callback which will be triggered when user presses Choose
|
||||
* @param multiselect whether it should be possible to select multiple files
|
||||
* @param mimetype_filter mimetype to filter by
|
||||
* @param mimetypeFilter mimetype to filter by
|
||||
* @param modal make the dialog modal
|
||||
*/
|
||||
filepicker:function(title, callback, multiselect, mimetype_filter, modal) {
|
||||
filepicker:function(title, callback, multiselect, mimetypeFilter, modal) {
|
||||
var self = this;
|
||||
$.when(this._getFilePickerTemplate()).then(function($tmpl) {
|
||||
var dialog_name = 'oc-dialog-filepicker-content';
|
||||
var dialog_id = '#' + dialog_name;
|
||||
var dialogName = 'oc-dialog-filepicker-content';
|
||||
if(self.$filePicker) {
|
||||
self.$filePicker.ocdialog('close');
|
||||
}
|
||||
self.$filePicker = $tmpl.octemplate({
|
||||
dialog_name: dialog_name,
|
||||
dialog_name: dialogName,
|
||||
title: title
|
||||
}).data('path', '').data('multiselect', multiselect).data('mimetype', mimetype_filter);
|
||||
}).data('path', '').data('multiselect', multiselect).data('mimetype', mimetypeFilter);
|
||||
|
||||
if (modal === undefined) {
|
||||
modal = false;
|
||||
|
@ -87,8 +87,8 @@ var OCdialogs = {
|
|||
if (multiselect === undefined) {
|
||||
multiselect = false;
|
||||
}
|
||||
if (mimetype_filter === undefined) {
|
||||
mimetype_filter = '';
|
||||
if (mimetypeFilter === undefined) {
|
||||
mimetypeFilter = '';
|
||||
}
|
||||
|
||||
$('body').append(self.$filePicker);
|
||||
|
@ -133,7 +133,7 @@ var OCdialogs = {
|
|||
height: 420,
|
||||
modal: modal,
|
||||
buttons: buttonlist,
|
||||
close: function(event, ui) {
|
||||
close: function() {
|
||||
try {
|
||||
$(this).ocdialog('destroy').remove();
|
||||
} catch(e) {}
|
||||
|
@ -156,15 +156,15 @@ var OCdialogs = {
|
|||
* Displays raw dialog
|
||||
* You better use a wrapper instead ...
|
||||
*/
|
||||
message:function(content, title, dialog_type, buttons, callback, modal) {
|
||||
message:function(content, title, dialogType, buttons, callback, modal) {
|
||||
$.when(this._getMessageTemplate()).then(function($tmpl) {
|
||||
var dialog_name = 'oc-dialog-' + OCdialogs.dialogs_counter + '-content';
|
||||
var dialog_id = '#' + dialog_name;
|
||||
var dialogName = 'oc-dialog-' + OCdialogs.dialogsCounter + '-content';
|
||||
var dialogId = '#' + dialogName;
|
||||
var $dlg = $tmpl.octemplate({
|
||||
dialog_name: dialog_name,
|
||||
dialog_name: dialogName,
|
||||
title: title,
|
||||
message: content,
|
||||
type: dialog_type
|
||||
type: dialogType
|
||||
});
|
||||
if (modal === undefined) {
|
||||
modal = false;
|
||||
|
@ -179,7 +179,7 @@ var OCdialogs = {
|
|||
if (callback !== undefined) {
|
||||
callback(true);
|
||||
}
|
||||
$(dialog_id).ocdialog('close');
|
||||
$(dialogId).ocdialog('close');
|
||||
},
|
||||
defaultButton: true
|
||||
},
|
||||
|
@ -189,13 +189,13 @@ var OCdialogs = {
|
|||
if (callback !== undefined) {
|
||||
callback(false);
|
||||
}
|
||||
$(dialog_id).ocdialog('close');
|
||||
$(dialogId).ocdialog('close');
|
||||
}
|
||||
}];
|
||||
break;
|
||||
case OCdialogs.OK_BUTTON:
|
||||
var functionToCall = function() {
|
||||
$(dialog_id).ocdialog('close');
|
||||
$(dialogId).ocdialog('close');
|
||||
if(callback !== undefined) {
|
||||
callback();
|
||||
}
|
||||
|
@ -208,12 +208,12 @@ var OCdialogs = {
|
|||
break;
|
||||
}
|
||||
|
||||
$(dialog_id).ocdialog({
|
||||
$(dialogId).ocdialog({
|
||||
closeOnEscape: true,
|
||||
modal: modal,
|
||||
buttons: buttonlist
|
||||
});
|
||||
OCdialogs.dialogs_counter++;
|
||||
OCdialogs.dialogsCounter++;
|
||||
})
|
||||
.fail(function(status, error) {
|
||||
// If the method is called while navigating away from
|
||||
|
@ -251,7 +251,7 @@ var OCdialogs = {
|
|||
image.onload = function () {
|
||||
var url = crop(image);
|
||||
deferred.resolve(url);
|
||||
}
|
||||
};
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
} else {
|
||||
|
@ -339,22 +339,22 @@ var OCdialogs = {
|
|||
//if (selection.defaultAction) {
|
||||
// controller[selection.defaultAction](data);
|
||||
//} else {
|
||||
var dialog_name = 'oc-dialog-fileexists-content';
|
||||
var dialog_id = '#' + dialog_name;
|
||||
var dialogName = 'oc-dialog-fileexists-content';
|
||||
var dialogId = '#' + dialogName;
|
||||
if (this._fileexistsshown) {
|
||||
// add conflict
|
||||
|
||||
var conflicts = $(dialog_id+ ' .conflicts');
|
||||
var conflicts = $(dialogId+ ' .conflicts');
|
||||
addConflict(conflicts, original, replacement);
|
||||
|
||||
var count = $(dialog_id+ ' .conflict').length;
|
||||
var count = $(dialogId+ ' .conflict').length;
|
||||
var title = n('core',
|
||||
'{count} file conflict',
|
||||
'{count} file conflicts',
|
||||
count,
|
||||
{count:count}
|
||||
);
|
||||
$(dialog_id).parent().children('.oc-dialog-title').text(title);
|
||||
$(dialogId).parent().children('.oc-dialog-title').text(title);
|
||||
|
||||
//recalculate dimensions
|
||||
$(window).trigger('resize');
|
||||
|
@ -365,7 +365,7 @@ var OCdialogs = {
|
|||
$.when(this._getFileExistsTemplate()).then(function($tmpl) {
|
||||
var title = t('core','One file conflict');
|
||||
var $dlg = $tmpl.octemplate({
|
||||
dialog_name: dialog_name,
|
||||
dialog_name: dialogName,
|
||||
title: title,
|
||||
type: 'fileexists',
|
||||
|
||||
|
@ -380,14 +380,14 @@ var OCdialogs = {
|
|||
var conflicts = $($dlg).find('.conflicts');
|
||||
addConflict(conflicts, original, replacement);
|
||||
|
||||
buttonlist = [{
|
||||
var buttonlist = [{
|
||||
text: t('core', 'Cancel'),
|
||||
classes: 'cancel',
|
||||
click: function(){
|
||||
if ( typeof controller.onCancel !== 'undefined') {
|
||||
controller.onCancel(data);
|
||||
}
|
||||
$(dialog_id).ocdialog('close');
|
||||
$(dialogId).ocdialog('close');
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -395,69 +395,70 @@ var OCdialogs = {
|
|||
classes: 'continue',
|
||||
click: function(){
|
||||
if ( typeof controller.onContinue !== 'undefined') {
|
||||
controller.onContinue($(dialog_id + ' .conflict'));
|
||||
controller.onContinue($(dialogId + ' .conflict'));
|
||||
}
|
||||
$(dialog_id).ocdialog('close');
|
||||
$(dialogId).ocdialog('close');
|
||||
}
|
||||
}];
|
||||
|
||||
$(dialog_id).ocdialog({
|
||||
$(dialogId).ocdialog({
|
||||
width: 500,
|
||||
closeOnEscape: true,
|
||||
modal: true,
|
||||
buttons: buttonlist,
|
||||
closeButton: null,
|
||||
close: function(event, ui) {
|
||||
close: function() {
|
||||
self._fileexistsshown = false;
|
||||
$(this).ocdialog('destroy').remove();
|
||||
}
|
||||
});
|
||||
|
||||
$(dialog_id).css('height','auto');
|
||||
$(dialogId).css('height','auto');
|
||||
|
||||
//add checkbox toggling actions
|
||||
$(dialog_id).find('.allnewfiles').on('click', function() {
|
||||
var checkboxes = $(dialog_id).find('.conflict .replacement input[type="checkbox"]');
|
||||
$(dialogId).find('.allnewfiles').on('click', function() {
|
||||
var checkboxes = $(dialogId).find('.conflict .replacement input[type="checkbox"]');
|
||||
checkboxes.prop('checked', $(this).prop('checked'));
|
||||
});
|
||||
$(dialog_id).find('.allexistingfiles').on('click', function() {
|
||||
var checkboxes = $(dialog_id).find('.conflict .original input[type="checkbox"]');
|
||||
$(dialogId).find('.allexistingfiles').on('click', function() {
|
||||
var checkboxes = $(dialogId).find('.conflict .original input[type="checkbox"]');
|
||||
checkboxes.prop('checked', $(this).prop('checked'));
|
||||
});
|
||||
$(dialog_id).find('.conflicts').on('click', '.replacement,.original', function() {
|
||||
$(dialogId).find('.conflicts').on('click', '.replacement,.original', function() {
|
||||
var checkbox = $(this).find('input[type="checkbox"]');
|
||||
checkbox.prop('checked', !checkbox.prop('checked'));
|
||||
});
|
||||
$(dialog_id).find('.conflicts').on('click', 'input[type="checkbox"]', function() {
|
||||
$(dialogId).find('.conflicts').on('click', 'input[type="checkbox"]', function() {
|
||||
var checkbox = $(this);
|
||||
checkbox.prop('checked', !checkbox.prop('checked'));
|
||||
});
|
||||
|
||||
//update counters
|
||||
$(dialog_id).on('click', '.replacement,.allnewfiles', function() {
|
||||
var count = $(dialog_id).find('.conflict .replacement input[type="checkbox"]:checked').length;
|
||||
if (count === $(dialog_id+ ' .conflict').length) {
|
||||
$(dialog_id).find('.allnewfiles').prop('checked', true);
|
||||
$(dialog_id).find('.allnewfiles + .count').text(t('core','(all selected)'));
|
||||
$(dialogId).on('click', '.replacement,.allnewfiles', function() {
|
||||
var count = $(dialogId).find('.conflict .replacement input[type="checkbox"]:checked').length;
|
||||
if (count === $(dialogId+ ' .conflict').length) {
|
||||
$(dialogId).find('.allnewfiles').prop('checked', true);
|
||||
$(dialogId).find('.allnewfiles + .count').text(t('core','(all selected)'));
|
||||
} else if (count > 0) {
|
||||
$(dialog_id).find('.allnewfiles').prop('checked', false);
|
||||
$(dialog_id).find('.allnewfiles + .count').text(t('core','({count} selected)',{count:count}));
|
||||
$(dialogId).find('.allnewfiles').prop('checked', false);
|
||||
$(dialogId).find('.allnewfiles + .count').text(t('core','({count} selected)',{count:count}));
|
||||
} else {
|
||||
$(dialog_id).find('.allnewfiles').prop('checked', false);
|
||||
$(dialog_id).find('.allnewfiles + .count').text('');
|
||||
$(dialogId).find('.allnewfiles').prop('checked', false);
|
||||
$(dialogId).find('.allnewfiles + .count').text('');
|
||||
}
|
||||
});
|
||||
$(dialog_id).on('click', '.original,.allexistingfiles', function(){
|
||||
var count = $(dialog_id).find('.conflict .original input[type="checkbox"]:checked').length;
|
||||
if (count === $(dialog_id+ ' .conflict').length) {
|
||||
$(dialog_id).find('.allexistingfiles').prop('checked', true);
|
||||
$(dialog_id).find('.allexistingfiles + .count').text(t('core','(all selected)'));
|
||||
$(dialogId).on('click', '.original,.allexistingfiles', function(){
|
||||
var count = $(dialogId).find('.conflict .original input[type="checkbox"]:checked').length;
|
||||
if (count === $(dialogId+ ' .conflict').length) {
|
||||
$(dialogId).find('.allexistingfiles').prop('checked', true);
|
||||
$(dialogId).find('.allexistingfiles + .count').text(t('core','(all selected)'));
|
||||
} else if (count > 0) {
|
||||
$(dialog_id).find('.allexistingfiles').prop('checked', false);
|
||||
$(dialog_id).find('.allexistingfiles + .count').text(t('core','({count} selected)',{count:count}));
|
||||
$(dialogId).find('.allexistingfiles').prop('checked', false);
|
||||
$(dialogId).find('.allexistingfiles + .count')
|
||||
.text(t('core','({count} selected)',{count:count}));
|
||||
} else {
|
||||
$(dialog_id).find('.allexistingfiles').prop('checked', false);
|
||||
$(dialog_id).find('.allexistingfiles + .count').text('');
|
||||
$(dialogId).find('.allexistingfiles').prop('checked', false);
|
||||
$(dialogId).find('.allexistingfiles + .count').text('');
|
||||
}
|
||||
});
|
||||
})
|
||||
|
@ -529,13 +530,6 @@ var OCdialogs = {
|
|||
}
|
||||
);
|
||||
},
|
||||
_determineValue: function(element) {
|
||||
if ( $(element).attr('type') === 'checkbox' ) {
|
||||
return element.checked;
|
||||
} else {
|
||||
return $(element).val();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* fills the filepicker with files
|
||||
|
@ -627,7 +621,6 @@ var OCdialogs = {
|
|||
this.$filelist.find('.filepicker_element_selected').removeClass('filepicker_element_selected');
|
||||
}
|
||||
$element.toggleClass('filepicker_element_selected');
|
||||
return;
|
||||
} else if ( $element.data('type') === 'dir' ) {
|
||||
this._fillFilePicker(this.$filePicker.data('path') + '/' + $element.data('entryname'));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue