Dialogs: Cleanup.
This commit is contained in:
parent
a0b79f5649
commit
2f91606e35
|
@ -23,6 +23,11 @@
|
||||||
* this class to ease the usage of jquery dialogs
|
* this class to ease the usage of jquery dialogs
|
||||||
*/
|
*/
|
||||||
var OCdialogs = {
|
var OCdialogs = {
|
||||||
|
// dialog button types
|
||||||
|
YES_NO_BUTTONS: 70,
|
||||||
|
OK_BUTTONS: 71,
|
||||||
|
// used to name each dialog
|
||||||
|
dialogs_counter: 0,
|
||||||
/**
|
/**
|
||||||
* displays alert dialog
|
* displays alert dialog
|
||||||
* @param text content of dialog
|
* @param text content of dialog
|
||||||
|
@ -31,7 +36,7 @@ var OCdialogs = {
|
||||||
* @param modal make the dialog modal
|
* @param modal make the dialog modal
|
||||||
*/
|
*/
|
||||||
alert:function(text, title, callback, modal) {
|
alert:function(text, title, callback, modal) {
|
||||||
OCdialogs.message(text, title, 'alert', OCdialogs.OK_BUTTON, callback, modal);
|
this.message(text, title, 'alert', OCdialogs.OK_BUTTON, callback, modal);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* displays info dialog
|
* displays info dialog
|
||||||
|
@ -41,7 +46,7 @@ var OCdialogs = {
|
||||||
* @param modal make the dialog modal
|
* @param modal make the dialog modal
|
||||||
*/
|
*/
|
||||||
info:function(text, title, callback, modal) {
|
info:function(text, title, callback, modal) {
|
||||||
OCdialogs.message(text, title, 'info', OCdialogs.OK_BUTTON, callback, modal);
|
this.message(text, title, 'info', OCdialogs.OK_BUTTON, callback, modal);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* displays confirmation dialog
|
* displays confirmation dialog
|
||||||
|
@ -51,81 +56,7 @@ var OCdialogs = {
|
||||||
* @param modal make the dialog modal
|
* @param modal make the dialog modal
|
||||||
*/
|
*/
|
||||||
confirm:function(text, title, callback, modal) {
|
confirm:function(text, title, callback, modal) {
|
||||||
OCdialogs.message(text, title, 'notice', OCdialogs.YES_NO_BUTTONS, callback, modal);
|
this.message(text, title, 'notice', OCdialogs.YES_NO_BUTTONS, callback, modal);
|
||||||
},
|
|
||||||
/**
|
|
||||||
* prompt for user input
|
|
||||||
* @param text content of dialog
|
|
||||||
* @param title dialog title
|
|
||||||
* @param callback which will be triggered when user presses OK (input text will be passed to callback)
|
|
||||||
* @param modal make the dialog modal
|
|
||||||
*/
|
|
||||||
prompt:function(text, title, default_value, callback, modal) {
|
|
||||||
var input = '<input type="text" id="oc-dialog-prompt-input" value="' + escapeHTML(default_value) + '" style="width:90%">';
|
|
||||||
var content = '<p><span class="ui-icon ui-icon-pencil"></span>' + escapeHTML(text) + ':<br/>' + input + '</p>';
|
|
||||||
OCdialogs.message(content, title, 'prompt', OCdialogs.OK_BUTTON, callback, modal);
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* prompt user for input with custom form
|
|
||||||
* fields should be passed in following format: [{text:'prompt text', name:'return name', type:'input type', value: 'default value'},...]
|
|
||||||
* example:
|
|
||||||
* var fields=[{text:'Test', name:'test', type:'select', options:[{text:'hello1',value:1},{text:'hello2',value:2}] }];
|
|
||||||
* @param fields to display
|
|
||||||
* @param title dialog title
|
|
||||||
* @param callback which will be triggered when user presses OK (user answers will be passed to callback in following format: [{name:'return name', value: 'user value'},...])
|
|
||||||
* @param modal make the dialog modal
|
|
||||||
*/
|
|
||||||
form:function(fields, title, callback, modal) {
|
|
||||||
var content = '<table>';
|
|
||||||
$.each(fields, function(index, field){
|
|
||||||
content += '<tr><td>' + escapeHTML(field.text) + '</td><td>';
|
|
||||||
var type = field.type;
|
|
||||||
|
|
||||||
if (type === 'text' || type === 'checkbox' || type === 'password') {
|
|
||||||
content += '<input type="' + type + '" name="' + field.name + '"';
|
|
||||||
if (type === 'checkbox' && field.value === true) {
|
|
||||||
content += ' checked="checked"';
|
|
||||||
} else if (type === 'text' || type === 'password' && val.value) {
|
|
||||||
content += ' value="' + escapeHTML(field.value) + '"';
|
|
||||||
}
|
|
||||||
content += '>';
|
|
||||||
} else if (type === 'select') {
|
|
||||||
content += '<select name="' + escapeHTML(field.name) + '"';
|
|
||||||
if (field.value !== undefined) {
|
|
||||||
content += ' value="' + escapeHTML(field.value) + '"';
|
|
||||||
}
|
|
||||||
content += '>';
|
|
||||||
$.each(field.options, function(index, field_option){
|
|
||||||
content += '<option value="' + escapeHTML(field_option.value) + '">' + escapeHTML(field_option.text) + '</option>';
|
|
||||||
});
|
|
||||||
content += '</select>';
|
|
||||||
}
|
|
||||||
content += '</td></tr>';
|
|
||||||
|
|
||||||
});
|
|
||||||
content += '</table>';
|
|
||||||
|
|
||||||
var dialog_name = 'oc-dialog-' + OCdialogs.dialogs_counter + '-content';
|
|
||||||
var dialog_id = '#' + dialog_name;
|
|
||||||
var dialog_div = '<div id="' + dialog_name + '" title="' + escapeHTML(title) + '">' + content + '</div>';
|
|
||||||
if (modal === undefined) { modal = false };
|
|
||||||
$('body').append(dialog_div);
|
|
||||||
var buttonlist = [{
|
|
||||||
text: t('core', 'Ok'),
|
|
||||||
click: function(){ OCdialogs.form_ok_handler(callback, dialog_id); }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t('core', 'Cancel'),
|
|
||||||
click: function(){ $(dialog_id).dialog('close'); }
|
|
||||||
}];
|
|
||||||
var dialog_height = ( $('tr', dialog_div).length + 1 ) * 30 + 120;
|
|
||||||
$(dialog_id).dialog({
|
|
||||||
width: (4/9) * $(document).width(),
|
|
||||||
height: dialog_height,
|
|
||||||
modal: modal,
|
|
||||||
buttons: buttonlist
|
|
||||||
});
|
|
||||||
OCdialogs.dialogs_counter++;
|
|
||||||
},
|
},
|
||||||
_getFilePickerTemplate: function() {
|
_getFilePickerTemplate: function() {
|
||||||
var defer = $.Deferred();
|
var defer = $.Deferred();
|
||||||
|
@ -231,6 +162,7 @@ var OCdialogs = {
|
||||||
}];
|
}];
|
||||||
|
|
||||||
self.$filePicker.dialog({
|
self.$filePicker.dialog({
|
||||||
|
closeOnEscape: true,
|
||||||
width: (4/9)*$(document).width(),
|
width: (4/9)*$(document).width(),
|
||||||
height: 420,
|
height: 420,
|
||||||
modal: modal,
|
modal: modal,
|
||||||
|
@ -304,6 +236,7 @@ var OCdialogs = {
|
||||||
};
|
};
|
||||||
|
|
||||||
$(dialog_id).dialog({
|
$(dialog_id).dialog({
|
||||||
|
closeOnEscape: true,
|
||||||
modal: modal,
|
modal: modal,
|
||||||
buttons: buttonlist
|
buttons: buttonlist
|
||||||
});
|
});
|
||||||
|
@ -313,12 +246,6 @@ var OCdialogs = {
|
||||||
alert(t('core', 'Error loading file picker template'));
|
alert(t('core', 'Error loading file picker template'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// dialog button types
|
|
||||||
YES_NO_BUTTONS: 70,
|
|
||||||
OK_BUTTONS: 71,
|
|
||||||
// used to name each dialog
|
|
||||||
dialogs_counter: 0,
|
|
||||||
|
|
||||||
determineValue: function(element) {
|
determineValue: function(element) {
|
||||||
if ( $(element).attr('type') === 'checkbox' ) {
|
if ( $(element).attr('type') === 'checkbox' ) {
|
||||||
return element.checked;
|
return element.checked;
|
||||||
|
@ -362,7 +289,7 @@ var OCdialogs = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.fillTreeList();
|
self.fillSlug();
|
||||||
var sorted = dirs.concat(others);
|
var sorted = dirs.concat(others);
|
||||||
|
|
||||||
$.each(sorted, function(idx, entry) {
|
$.each(sorted, function(idx, entry) {
|
||||||
|
@ -382,16 +309,13 @@ var OCdialogs = {
|
||||||
/**
|
/**
|
||||||
* fills the tree list with directories
|
* fills the tree list with directories
|
||||||
*/
|
*/
|
||||||
fillTreeList: function() {
|
fillSlug: function() {
|
||||||
this.$dirTree.empty();
|
this.$dirTree.empty();
|
||||||
var self = this
|
var self = this
|
||||||
var path = this.$filePicker.data('path');
|
var path = this.$filePicker.data('path');
|
||||||
if(!path) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var $template = $('<span data-dir="{dir}">{name}</span>');
|
var $template = $('<span data-dir="{dir}">{name}</span>');
|
||||||
|
if(path) {
|
||||||
var paths = path.split('/');
|
var paths = path.split('/');
|
||||||
//paths.pop();
|
|
||||||
$.each(paths, function(index, dir) {
|
$.each(paths, function(index, dir) {
|
||||||
var dir = paths.pop();
|
var dir = paths.pop();
|
||||||
if(dir === '') {
|
if(dir === '') {
|
||||||
|
@ -402,7 +326,8 @@ var OCdialogs = {
|
||||||
name: dir
|
name: dir
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
self.$dirTree.prepend($template.octemplate({
|
}
|
||||||
|
this.$dirTree.prepend($template.octemplate({
|
||||||
dir: '',
|
dir: '',
|
||||||
name: '/'
|
name: '/'
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue