summaryrefslogtreecommitdiff
path: root/plugins/managesieve/managesieve.js
diff options
context:
space:
mode:
authorHugues Hiegel <root@paranoid>2014-08-05 16:46:22 +0200
committerHugues Hiegel <root@paranoid>2014-08-05 16:46:22 +0200
commit59478e06c25303a790a0840ab2ac30662c4ef781 (patch)
tree8d5e964a8f94adaef41efebb0597629f11495c42 /plugins/managesieve/managesieve.js
parent7c494b677f9e470ee0d32e62cfa8dc709f39e748 (diff)
c'est la merde..working
Diffstat (limited to 'plugins/managesieve/managesieve.js')
-rw-r--r--plugins/managesieve/managesieve.js185
1 files changed, 48 insertions, 137 deletions
diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js
index 156bce6f0..035ed7bec 100644
--- a/plugins/managesieve/managesieve.js
+++ b/plugins/managesieve/managesieve.js
@@ -55,11 +55,6 @@ if (window.rcmail) {
}
$('input[type="text"]:first', rcmail.gui_objects.sieveform).focus();
-
- // initialize smart list inputs
- $('textarea[data-type="list"]', rcmail.gui_objects.sieveform).each(function() {
- smart_field_init(this);
- });
}
else {
rcmail.enable_command('plugin.managesieve-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror);
@@ -474,11 +469,6 @@ rcube_webmail.prototype.managesieve_rulefill = function(content, id, after)
row.className = 'rulerow';
row.innerHTML = content;
- // initialize smart list inputs
- $('textarea[data-type="list"]', row).each(function() {
- smart_field_init(this);
- });
-
this.managesieve_formbuttons(div);
}
};
@@ -575,45 +565,40 @@ function rule_header_select(id)
var obj = document.getElementById('header' + id),
size = document.getElementById('rule_size' + id),
op = document.getElementById('rule_op' + id),
- header = document.getElementById('custom_header' + id + '_list'),
+ target = document.getElementById('rule_target' + id),
+ header = document.getElementById('custom_header' + id),
mod = document.getElementById('rule_mod' + id),
trans = document.getElementById('rule_trans' + id),
- comp = document.getElementById('rule_comp' + id),
- datepart = document.getElementById('rule_date_part' + id),
- dateheader = document.getElementById('rule_date_header_div' + id),
- h = obj.value;
+ comp = document.getElementById('rule_comp' + id);
- if (h == 'size') {
+ if (obj.value == 'size') {
size.style.display = 'inline';
- $.each([op, header, mod, trans, comp], function() { this.style.display = 'none'; });
+ op.style.display = 'none';
+ target.style.display = 'none';
+ header.style.display = 'none';
+ mod.style.display = 'none';
+ trans.style.display = 'none';
+ comp.style.display = 'none';
}
else {
- header.style.display = h != '...' ? 'none' : 'inline-block';
+ header.style.display = obj.value != '...' ? 'none' : 'inline';
size.style.display = 'none';
op.style.display = 'inline';
comp.style.display = '';
- mod.style.display = h == 'body' || h == 'currentdate' || h == 'date' ? 'none' : 'block';
- trans.style.display = h == 'body' ? 'block' : 'none';
+ rule_op_select(id);
+ mod.style.display = obj.value == 'body' ? 'none' : 'block';
+ trans.style.display = obj.value == 'body' ? 'block' : 'none';
}
- if (datepart)
- datepart.style.display = h == 'currentdate' || h == 'date' ? 'inline' : 'none';
- if (dateheader)
- dateheader.style.display = h == 'date' ? '' : 'none';
-
- rule_op_select(op, id, h);
- rule_mod_select(id, h);
- obj.style.width = h == '...' ? '40px' : '';
+ obj.style.width = obj.value == '...' ? '40px' : '';
};
-function rule_op_select(obj, id, header)
+function rule_op_select(id)
{
- var target = document.getElementById('rule_target' + id + '_list');
+ var obj = document.getElementById('rule_op' + id),
+ target = document.getElementById('rule_target' + id);
- if (!header)
- header = document.getElementById('header' + id).value;
-
- target.style.display = obj.value == 'exists' || obj.value == 'notexists' || header == 'size' ? 'none' : 'inline-block';
+ target.style.display = obj.value == 'exists' || obj.value == 'notexists' ? 'none' : 'inline';
};
function rule_trans_select(id)
@@ -624,19 +609,12 @@ function rule_trans_select(id)
target.style.display = obj.value != 'content' ? 'none' : 'inline';
};
-function rule_mod_select(id, header)
+function rule_mod_select(id)
{
var obj = document.getElementById('rule_mod_op' + id),
- target = document.getElementById('rule_mod_type' + id),
- index = document.getElementById('rule_index_div' + id);
-
- if (!header)
- header = document.getElementById('header' + id).value;
+ target = document.getElementById('rule_mod_type' + id);
target.style.display = obj.value != 'address' && obj.value != 'envelope' ? 'none' : 'inline';
-
- if (index)
- index.style.display = header != 'body' && header != 'currentdate' && header != 'size' && obj.value != 'envelope' ? '' : 'none';
};
function rule_join_radio(value)
@@ -661,7 +639,7 @@ function rule_adv_switch(id, elem)
function action_type_select(id)
{
var obj = document.getElementById('action_type' + id),
- v = obj.value, enabled = {},
+ enabled = {},
elems = {
mailbox: document.getElementById('action_mailbox' + id),
target: document.getElementById('action_target' + id),
@@ -672,25 +650,25 @@ function action_type_select(id)
notify: document.getElementById('action_notify' + id)
};
- if (v == 'fileinto' || v == 'fileinto_copy') {
+ if (obj.value == 'fileinto' || obj.value == 'fileinto_copy') {
enabled.mailbox = 1;
}
- else if (v == 'redirect' || v == 'redirect_copy') {
+ else if (obj.value == 'redirect' || obj.value == 'redirect_copy') {
enabled.target = 1;
}
- else if (v.match(/^reject|ereject$/)) {
+ else if (obj.value.match(/^reject|ereject$/)) {
enabled.target_area = 1;
}
- else if (v.match(/^(add|set|remove)flag$/)) {
+ else if (obj.value.match(/^(add|set|remove)flag$/)) {
enabled.flags = 1;
}
- else if (v == 'vacation') {
+ else if (obj.value == 'vacation') {
enabled.vacation = 1;
}
- else if (v == 'set') {
+ else if (obj.value == 'set') {
enabled.set = 1;
}
- else if (v == 'notify') {
+ else if (obj.value == 'notify') {
enabled.notify = 1;
}
@@ -699,72 +677,6 @@ function action_type_select(id)
}
};
-// Inititalizes smart list input
-function smart_field_init(field)
-{
- var id = field.id + '_list',
- area = $('<span class="listarea"></span>'),
- list = field.value ? field.value.split("\n") : [''];
-
- if ($('#'+id).length)
- return;
-
- // add input rows
- $.each(list, function(i, v) {
- area.append(smart_field_row(v, field.name, i, $(field).data('size')));
- });
-
- area.attr('id', id);
- field = $(field);
-
- if (field.attr('disabled'))
- area.hide();
-
- field.after(area);
-
- if (field.hasClass('error')) {
- area.addClass('error');
- rcmail.managesieve_tip_register([[id, field.data('tip')]]);
- }
-};
-
-function smart_field_row(value, name, idx, size)
-{
- // build row element content
- var input, content = '<span class="listelement">'
- + '<span class="reset"></span><input type="text"></span>',
- elem = $(content),
- attrs = {value: value, name: name + '[]'};
-
- if (size)
- attrs.size = size;
-
- input = $('input', elem).attr(attrs).keydown(function(e) {
- var input = $(this);
- // element creation event (on Enter)
- if (e.which == 13) {
- var name = input.attr('name').replace(/\[\]$/, ''),
- dt = (new Date()).getTime(),
- elem = smart_field_row('', name, dt, size);
-
- input.parent().after(elem);
- $('input', elem).focus();
- }
- });
-
- // element deletion event
- $('span[class="reset"]', elem).click(function() {
- var span = $(this.parentNode);
-
- if (span.parent().children().length > 1)
- span.remove();
- else
- $('input', span).val('').focus();
- });
-
- return elem;
-}
-
// Register onmouse(leave/enter) events for tips on specified form element
rcube_webmail.prototype.managesieve_tip_register = function(tips)
{
@@ -773,26 +685,25 @@ rcube_webmail.prototype.managesieve_tip_register = function(tips)
for (var n in tips) {
$('#'+tips[n][0])
- .data('tip', tips[n][1])
- .bind('mouseenter', function(e) {
- var elem = $(this),
- offset = elem.offset(),
- left = offset.left,
- top = offset.top - 12,
- minwidth = elem.width();
-
- if (framed) {
- offset = $((rcmail.env.task == 'mail' ? '#sievefilterform > iframe' : '#filter-box'), parent.document).offset();
- top += offset.top;
- left += offset.left;
- }
-
- tip.html(elem.data('tip'));
- top -= tip.height();
-
- tip.css({left: left, top: top, minWidth: (minwidth-2) + 'px'}).show();
- })
- .bind('mouseleave', function(e) { tip.hide(); });
+ .bind('mouseenter', {str: tips[n][1]},
+ function(e) {
+ var offset = $(this).offset(),
+ left = offset.left,
+ top = offset.top - 12,
+ minwidth = $(this).width();
+
+ if (framed) {
+ offset = $((rcmail.env.task == 'mail' ? '#sievefilterform > iframe' : '#filter-box'), parent.document).offset();
+ top += offset.top;
+ left += offset.left;
+ }
+
+ tip.html(e.data.str)
+ top -= tip.height();
+
+ tip.css({left: left, top: top, minWidth: (minwidth-2) + 'px'}).show();
+ })
+ .bind('mouseleave', function(e) { tip.hide(); });
}
};