+
+/*********************************************************/
+/********* Mail UI methods *********/
+/*********************************************************/
+
+rcube_webmail.prototype.managesieve_create = function()
+{
+ if (!rcmail.env.sieve_headers || !rcmail.env.sieve_headers.length)
+ return;
+
+ var i, html, buttons = {}, dialog = $("#sievefilterform");
+
+ // create dialog window
+ if (!dialog.length) {
+ dialog = $('<div id="sievefilterform"></div>');
+ $('body').append(dialog);
+ }
+
+ // build dialog window content
+ html = '<fieldset><legend>'+this.gettext('managesieve.usedata')+'</legend><ul>';
+ for (i in rcmail.env.sieve_headers)
+ html += '<li><input type="checkbox" name="headers[]" id="sievehdr'+i+'" value="'+i+'" checked="checked" />'
+ +'<label for="sievehdr'+i+'">'+rcmail.env.sieve_headers[i][0]+':</label> '+rcmail.env.sieve_headers[i][1]+'</li>';
+ html += '</ul></fieldset>';
+
+ dialog.html(html);
+
+ // [Next Step] button action
+ buttons[this.gettext('managesieve.nextstep')] = function () {
+ // check if there's at least one checkbox checked
+ var hdrs = $('input[name="headers[]"]:checked', dialog);
+ if (!hdrs.length) {
+ alert(rcmail.gettext('managesieve.nodata'));
+ return;
+ }
+
+ // build frame URL
+ var url = rcmail.get_task_url('mail');
+ url = rcmail.add_url(url, '_action', 'plugin.managesieve');
+ url = rcmail.add_url(url, '_framed', 1);
+
+ hdrs.map(function() {
+ var val = rcmail.env.sieve_headers[this.value];
+ url = rcmail.add_url(url, 'r['+this.value+']', val[0]+':'+val[1]);
+ });
+
+ // load form in the iframe
+ var frame = $('<iframe>').attr({src: url, frameborder: 0})
+ dialog.empty().append(frame).dialog('dialog').resize();
+
+ // Change [Next Step] button with [Save] button
+ buttons = {};
+ buttons[rcmail.gettext('save')] = function() {
+ var win = $('iframe', dialog).get(0).contentWindow;
+ win.rcmail.managesieve_save();
+ };
+ dialog.dialog('option', 'buttons', buttons);
+ };
+
+ // show dialog window
+ dialog.dialog({
+ modal: false,
+ resizable: !bw.ie6,
+ closeOnEscape: (!bw.ie6 && !bw.ie7), // disable for performance reasons
+ title: this.gettext('managesieve.newfilter'),
+ close: function() { rcmail.managesieve_dialog_close(); },
+ buttons: buttons,
+ minWidth: 600,
+ minHeight: 300,
+ height: 250
+ }).show();
+
+ this.env.managesieve_dialog = dialog;
+}
+
+rcube_webmail.prototype.managesieve_dialog_close = function()
+{
+ var dialog = this.env.managesieve_dialog;
+
+ // BUG(?): if we don't remove the iframe first, it will be reloaded
+ dialog.html('');
+ dialog.dialog('destroy').hide();
+}
+
+rcube_webmail.prototype.managesieve_dialog_resize = function(o)
+{
+ var dialog = this.env.managesieve_dialog,
+ win = $(window), form = $(o);
+ width = form.width(), height = form.height(),
+ w = win.width(), h = win.height();
+
+ dialog.dialog('option', { height: Math.min(h-20, height+120), width: Math.min(w-20, width+65) })
+ .dialog('option', 'position', ['center', 'center']); // only works in a separate call (!?)
+}