+ this.env.filtersets[id] = o.name;
+ list.insert_row(row.get(0));
+
+ // move row into its position on the list
+ if (o.index != list.rowcount-1) {
+ row.detach();
+ var elem = $('tr:visible', list.list).get(o.index);
+ row.insertBefore(elem);
+ }
+
+ list.select(id);
+
+ break;
+ }
+
+ this.set_busy(false);
+};
+
+// load filter frame
+rcube_webmail.prototype.load_managesieveframe = function(id)
+{
+ var has_id = typeof(id) != 'undefined' && id != null;
+ this.enable_command('plugin.managesieve-act', 'plugin.managesieve-del', has_id);
+
+ if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
+ target = window.frames[this.env.contentframe];
+ var msgid = this.set_busy(true, 'loading');
+ target.location.href = this.env.comm_path+'&_action=plugin.managesieve&_framed=1'
+ +(id ? '&_fid='+id : '')+'&_unlock='+msgid;
+ }
+};
+
+// load filter frame
+rcube_webmail.prototype.managesieve_dragstart = function(list)
+{
+ var id = this.filters_list.get_single_selection();
+
+ this.drag_active = true;
+ this.drag_filter = id;
+};
+
+rcube_webmail.prototype.managesieve_dragend = function(e)
+{
+ if (this.drag_active) {
+ if (this.drag_filter_target) {
+ var lock = this.set_busy(true, 'loading');
+
+ this.show_contentframe(false);
+ this.http_post('plugin.managesieve', '_act=move&_fid='+this.drag_filter
+ +'&_to='+this.drag_filter_target, lock);
+ }
+ this.drag_active = false;
+ }
+};
+
+rcube_webmail.prototype.managesieve_focus_filter = function(row)
+{
+ var id = row.id.replace(/^rcmrow/, '');
+ if (this.drag_active && id != this.drag_filter) {
+ this.drag_filter_target = id;
+ $(row.obj).addClass(id < this.drag_filter ? 'filtermoveup' : 'filtermovedown');
+ }
+};
+
+rcube_webmail.prototype.managesieve_unfocus_filter = function(row)
+{
+ if (this.drag_active) {
+ $(row.obj).removeClass('filtermoveup filtermovedown');
+ this.drag_filter_target = null;
+ }
+};
+
+/*********************************************************/
+/********* Filter Form methods *********/
+/*********************************************************/
+
+// Form submition
+rcube_webmail.prototype.managesieve_save = function()
+{
+ if (parent.rcmail && parent.rcmail.filters_list && this.gui_objects.sieveform.name != 'filtersetform') {
+ var id = parent.rcmail.filters_list.get_single_selection();
+ if (id != null)
+ this.gui_objects.sieveform.elements['_fid'].value = parent.rcmail.filters_list.rows[id].uid;
+ }
+ this.gui_objects.sieveform.submit();
+};
+
+// Operations on filters form
+rcube_webmail.prototype.managesieve_ruleadd = function(id)
+{
+ this.http_post('plugin.managesieve', '_act=ruleadd&_rid='+id);
+};
+
+rcube_webmail.prototype.managesieve_rulefill = function(content, id, after)
+{
+ if (content != '') {
+ // create new element
+ var div = document.getElementById('rules'),
+ row = document.createElement('div');
+
+ this.managesieve_insertrow(div, row, after);
+ // fill row after inserting (for IE)
+ row.setAttribute('id', 'rulerow'+id);
+ row.className = 'rulerow';
+ row.innerHTML = content;
+
+ this.managesieve_formbuttons(div);
+ }
+};
+
+rcube_webmail.prototype.managesieve_ruledel = function(id)
+{
+ if ($('#ruledel'+id).hasClass('disabled'))
+ return;
+
+ if (confirm(this.get_label('managesieve.ruledeleteconfirm'))) {
+ var row = document.getElementById('rulerow'+id);
+ row.parentNode.removeChild(row);
+ this.managesieve_formbuttons(document.getElementById('rules'));
+ }
+};
+
+rcube_webmail.prototype.managesieve_actionadd = function(id)
+{
+ this.http_post('plugin.managesieve', '_act=actionadd&_aid='+id);
+};
+
+rcube_webmail.prototype.managesieve_actionfill = function(content, id, after)
+{
+ if (content != '') {
+ var div = document.getElementById('actions'),
+ row = document.createElement('div');
+
+ this.managesieve_insertrow(div, row, after);
+ // fill row after inserting (for IE)
+ row.className = 'actionrow';
+ row.setAttribute('id', 'actionrow'+id);
+ row.innerHTML = content;
+
+ this.managesieve_formbuttons(div);
+ }
+};
+
+rcube_webmail.prototype.managesieve_actiondel = function(id)
+{
+ if ($('#actiondel'+id).hasClass('disabled'))
+ return;
+
+ if (confirm(this.get_label('managesieve.actiondeleteconfirm'))) {
+ var row = document.getElementById('actionrow'+id);
+ row.parentNode.removeChild(row);
+ this.managesieve_formbuttons(document.getElementById('actions'));
+ }
+};
+
+// insert rule/action row in specified place on the list
+rcube_webmail.prototype.managesieve_insertrow = function(div, row, after)
+{
+ for (var i=0; i<div.childNodes.length; i++) {
+ if (div.childNodes[i].id == (div.id == 'rules' ? 'rulerow' : 'actionrow') + after)
+ break;
+ }
+
+ if (div.childNodes[i+1])
+ div.insertBefore(row, div.childNodes[i+1]);
+ else
+ div.appendChild(row);
+};
+
+// update Delete buttons status
+rcube_webmail.prototype.managesieve_formbuttons = function(div)
+{
+ var i, button, buttons = [];
+
+ // count and get buttons
+ for (i=0; i<div.childNodes.length; i++) {
+ if (div.id == 'rules' && div.childNodes[i].id) {
+ if (/rulerow/.test(div.childNodes[i].id))
+ buttons.push('ruledel' + div.childNodes[i].id.replace(/rulerow/, ''));
+ }
+ else if (div.childNodes[i].id) {
+ if (/actionrow/.test(div.childNodes[i].id))
+ buttons.push( 'actiondel' + div.childNodes[i].id.replace(/actionrow/, ''));