Simplify popup dialogs creation

pull/5388/head
Aleksander Machniak 8 years ago
parent 5801f6fb18
commit 9e3263acbe

@ -3650,26 +3650,16 @@ function rcube_webmail()
// list recipients with missing keys // list recipients with missing keys
if (!isvalid && missing_keys.length) { if (!isvalid && missing_keys.length) {
// display dialog with missing keys // display dialog with missing keys
ref.show_popup_dialog( ref.simple_dialog(
ref.get_label('nopubkeyfor').replace('$email', missing_keys.join(', ')) + ref.get_label('nopubkeyfor').replace('$email', missing_keys.join(', ')) +
'<p>' + ref.get_label('searchpubkeyservers') + '</p>', '<p>' + ref.get_label('searchpubkeyservers') + '</p>',
ref.get_label('encryptedsendialog'), 'encryptedsendialog',
[{ function() {
text: ref.get_label('search'),
'class': 'mainaction',
click: function() {
var $dialog = $(this);
ref.mailvelope_search_pubkeys(missing_keys, function() { ref.mailvelope_search_pubkeys(missing_keys, function() {
$dialog.dialog('close') return true; // close dialog
}); });
}
}, },
{ {button: 'search'}
text: ref.get_label('cancel'),
click: function(){
$(this).dialog('close');
}
}]
); );
return false; return false;
} }
@ -4173,21 +4163,11 @@ function rcube_webmail()
// the message has been sent but not saved, ask the user what to do // the message has been sent but not saved, ask the user what to do
if (!saveonly && this.env.is_sent) { if (!saveonly && this.env.is_sent) {
return this.show_popup_dialog(this.get_label('messageissent'), '', return this.simple_dialog(this.get_label('messageissent'), '',
[{ function() {
text: this.get_label('save'),
'class': 'mainaction',
click: function() {
ref.submit_messageform(false, true); ref.submit_messageform(false, true);
$(this).dialog('close'); return true;
}
},
{
text: this.get_label('cancel'),
click: function() {
$(this).dialog('close');
} }
}]
); );
} }
@ -4941,21 +4921,14 @@ function rcube_webmail()
var input = $('<input>').attr({type: 'text', size: 50}).val(attachment.name), var input = $('<input>').attr({type: 'text', size: 50}).val(attachment.name),
content = $('<label>').text(this.get_label('namex')).append(input); content = $('<label>').text(this.get_label('namex')).append(input);
this.show_popup_dialog(content, this.get_label('attachmentrename'), this.simple_dialog(content, 'attachmentrename', function() {
[{
text: this.get_label('save'),
'class': 'mainaction',
click: function() {
var name; var name;
if ((name = input.val()) && name != attachment.name) { if ((name = input.val()) && name != attachment.name) {
ref.http_post('rename-attachment', {_id: ref.env.compose_id, _file: id, _name: name}, ref.http_post('rename-attachment', {_id: ref.env.compose_id, _file: id, _name: name},
ref.set_busy(true, 'loading')); ref.set_busy(true, 'loading'));
return true;
} }
},
$(this).dialog('close');
}
}],
{open: function() { input.select(); }} {open: function() { input.select(); }}
); );
}; };
@ -6017,22 +5990,15 @@ function rcube_webmail()
var input = $('<input>').attr('type', 'text'), var input = $('<input>').attr('type', 'text'),
content = $('<label>').text(this.get_label('namex')).append(input); content = $('<label>').text(this.get_label('namex')).append(input);
this.show_popup_dialog(content, this.get_label('newgroup'), this.simple_dialog(content, 'newgroup',
[{ function() {
text: this.get_label('save'),
'class': 'mainaction',
click: function() {
var name; var name;
if (name = input.val()) { if (name = input.val()) {
ref.http_post('group-create', {_source: ref.env.source, _name: name}, ref.http_post('group-create', {_source: ref.env.source, _name: name},
ref.set_busy(true, 'loading')); ref.set_busy(true, 'loading'));
return true;
} }
});
$(this).dialog('close');
}
}]
);
}; };
// group rename dialog // group rename dialog
@ -6045,21 +6011,15 @@ function rcube_webmail()
input = $('<input>').attr('type', 'text').val(group_name), input = $('<input>').attr('type', 'text').val(group_name),
content = $('<label>').text(this.get_label('namex')).append(input); content = $('<label>').text(this.get_label('namex')).append(input);
this.show_popup_dialog(content, this.get_label('grouprename'), this.simple_dialog(content, 'grouprename',
[{ function() {
text: this.get_label('save'),
'class': 'mainaction',
click: function() {
var name; var name;
if ((name = input.val()) && name != group_name) { if ((name = input.val()) && name != group_name) {
ref.http_post('group-rename', {_source: ref.env.source, _gid: ref.env.group, _name: name}, ref.http_post('group-rename', {_source: ref.env.source, _gid: ref.env.group, _name: name},
ref.set_busy(true, 'loading')); ref.set_busy(true, 'loading'));
return true;
} }
},
$(this).dialog('close');
}
}],
{open: function() { input.select(); }} {open: function() { input.select(); }}
); );
}; };
@ -6409,21 +6369,15 @@ function rcube_webmail()
var input = $('<input>').attr('type', 'text'), var input = $('<input>').attr('type', 'text'),
content = $('<label>').text(this.get_label('namex')).append(input); content = $('<label>').text(this.get_label('namex')).append(input);
this.show_popup_dialog(content, this.get_label('searchsave'), this.simple_dialog(content, 'searchsave',
[{ function() {
text: this.get_label('save'),
'class': 'mainaction',
click: function() {
var name; var name;
if (name = input.val()) { if (name = input.val()) {
ref.http_post('search-create', {_search: ref.env.search_request, _name: name}, ref.http_post('search-create', {_search: ref.env.search_request, _name: name},
ref.set_busy(true, 'loading')); ref.set_busy(true, 'loading'));
return true;
} }
$(this).dialog('close');
} }
}]
); );
}; };
@ -7437,6 +7391,28 @@ function rcube_webmail()
return popup; return popup;
}; };
// show_popup_dialog() wrapper for simple dialogs with Save and Cancel buttons
this.simple_dialog = function(content, title, button_func, options)
{
var title = this.get_label(title),
buttons = [{
text: this.get_label((options || {}).button || 'save'),
'class': 'mainaction',
click: function() {
if (button_func())
$(this).dialog('close');
}
},
{
text: ref.get_label('cancel'),
click: function() {
$(this).dialog('close');
}
}];
return this.show_popup_dialog(content, title, buttons, options);
};
// enable/disable buttons for page shifting // enable/disable buttons for page shifting
this.set_page_buttons = function() this.set_page_buttons = function()
{ {

Loading…
Cancel
Save