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