From 3ebac0167bf20104fb7a2a55934765117760264c Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Mon, 18 Aug 2014 03:53:18 -0400
Subject: [PATCH] Only add zen-mode text labels in compose step

---
 plugins/acl/acl.js |  103 ++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/plugins/acl/acl.js b/plugins/acl/acl.js
index aa9e06d..e59ac72 100644
--- a/plugins/acl/acl.js
+++ b/plugins/acl/acl.js
@@ -11,23 +11,29 @@
             rcmail.acl_list_init();
             // enable autocomplete on user input
             if (rcmail.env.acl_users_source) {
-                rcmail.init_address_input_events($('#acluser'), {action:'settings/plugin.acl-autocomplete'});
+                var inst = rcmail.is_framed() ? parent.rcmail : rcmail;
+                inst.init_address_input_events($('#acluser'), {action:'settings/plugin.acl-autocomplete'});
+
+                // pass config settings and localized texts to autocomplete context
+                inst.set_env({ autocomplete_max:rcmail.env.autocomplete_max, autocomplete_min_length:rcmail.env.autocomplete_min_length });
+                inst.add_label('autocompletechars', rcmail.labels.autocompletechars);
+                inst.add_label('autocompletemore', rcmail.labels.autocompletemore);
+
                 // fix inserted value
-                rcmail.addEventListener('autocomplete_insert', function(e) {
+                inst.addEventListener('autocomplete_insert', function(e) {
                     if (e.field.id != 'acluser')
                         return;
 
-                    var value = e.insert;
-                    // get UID from the entry value
-                    if (value.match(/\s*\(([^)]+)\)[, ]*$/))
-                        value = RegExp.$1;
-                    e.field.value = value;
+                    e.field.value = e.insert.replace(/[ ,;]+$/, '');
                 });
             }
         }
 
         rcmail.enable_command('acl-create', 'acl-save', 'acl-cancel', 'acl-mode-switch', true);
         rcmail.enable_command('acl-delete', 'acl-edit', false);
+
+        if (rcmail.env.acl_advanced)
+            $('#acl-switch').addClass('selected');
     });
 }
 
@@ -61,14 +67,14 @@
 // Save ACL data
 rcube_webmail.prototype.acl_save = function()
 {
-    var user = $('#acluser').val(), rights = '', type;
+    var user = $('#acluser', this.acl_form).val(), rights = '', type;
 
-    $(':checkbox', this.env.acl_advanced ? $('#advancedrights') : sim_ul = $('#simplerights')).map(function() {
+    $((this.env.acl_advanced ? '#advancedrights :checkbox' : '#simplerights :checkbox'), this.acl_form).map(function() {
         if (this.checked)
             rights += this.value;
     });
 
-    if (type = $('input:checked[name=usertype]').val()) {
+    if (type = $('input:checked[name=usertype]', this.acl_form).val()) {
         if (type != 'user')
             user = type;
     }
@@ -94,7 +100,7 @@
 rcube_webmail.prototype.acl_cancel = function()
 {
     this.ksearch_blur();
-    this.acl_form.hide();
+    this.acl_popup.dialog('close');
 }
 
 // Update data after save (and hide form)
@@ -112,7 +118,7 @@
     // hide autocomplete popup
     this.ksearch_blur();
     // hide form
-    this.acl_form.hide();
+    this.acl_popup.dialog('close');
 }
 
 // Switch table display mode
@@ -129,12 +135,17 @@
 // ACL table initialization
 rcube_webmail.prototype.acl_list_init = function()
 {
+    var method = this.env.acl_advanced ? 'addClass' : 'removeClass';
+
+    $('#acl-switch')[method]('selected');
+    $(this.gui_objects.acltable)[method]('advanced');
+
     this.acl_list = new rcube_list_widget(this.gui_objects.acltable,
-        {multiselect:true, draggable:false, keyboard:true, toggleselect:true});
-    this.acl_list.addEventListener('select', function(o) { rcmail.acl_list_select(o); });
-    this.acl_list.addEventListener('dblclick', function(o) { rcmail.acl_list_dblclick(o); });
-    this.acl_list.addEventListener('keypress', function(o) { rcmail.acl_list_keypress(o); });
-    this.acl_list.init();
+        {multiselect: true, draggable: false, keyboard: true});
+    this.acl_list.addEventListener('select', function(o) { rcmail.acl_list_select(o); })
+        .addEventListener('dblclick', function(o) { rcmail.acl_list_dblclick(o); })
+        .addEventListener('keypress', function(o) { rcmail.acl_list_keypress(o); })
+        .init();
 }
 
 // ACL table row selection handler
@@ -214,16 +225,23 @@
         row = $('thead > tr', table).clone();
 
     // Update new row
-    $('td', row).map(function() {
-        var r, cl = this.className.replace(/^acl/, '');
+    $('th', row).map(function() {
+        var td = $('<td>'),
+            title = $(this).attr('title'),
+            cl = this.className.replace(/^acl/, '');
+
+        if (title)
+            td.attr('title', title);
 
         if (items && items[cl])
             cl = items[cl];
 
         if (cl == 'user')
-            $(this).text(o.username);
+            td.addClass(cl).append($('<a>').text(o.username));
         else
-            $(this).addClass(rcmail.acl_class(o.acl, cl)).text('');
+            td.addClass(this.className + ' ' + rcmail.acl_class(o.acl, cl)).text('');
+
+        $(this).replaceWith(td);
     });
 
     row.attr('id', 'rcmrow'+id);
@@ -267,10 +285,10 @@
 {
     var ul, row, td, val = '', type = 'user', li_elements, body = $('body'),
         adv_ul = $('#advancedrights'), sim_ul = $('#simplerights'),
-        name_input = $('#acluser');
+        name_input = $('#acluser'), type_list = $('#usertype');
 
     if (!this.acl_form) {
-        var fn = function () { $('input[value=user]').prop('checked', true); };
+        var fn = function () { $('input[value="user"]').prop('checked', true); };
         name_input.click(fn).keypress(fn);
     }
 
@@ -295,9 +313,8 @@
     if (id && (row = this.acl_list.rows[id])) {
         row = row.obj;
         li_elements.map(function() {
-            val = this.value;
             td = $('td.'+this.id, row);
-            if (td && td.hasClass('enabled'))
+            if (td.length && td.hasClass('enabled'))
                 this.checked = true;
         });
 
@@ -307,27 +324,43 @@
             type = id;
     }
     // mark read (lrs) rights by default
-    else
+    else {
         li_elements.filter(function() { return this.id.match(/^acl([lrs]|read)$/); }).prop('checked', true);
+    }
 
     name_input.val(val);
     $('input[value='+type+']').prop('checked', true);
 
     this.acl_id = id;
 
-    // position the form horizontally
-    var bw = body.width(), mw = this.acl_form.width();
+    var buttons = {}, me = this, body = document.body;
 
-    if (bw >= mw)
-        this.acl_form.css({left: parseInt((bw - mw)/2)+'px'});
+    buttons[this.gettext('save')] = function(e) { me.command('acl-save'); };
+    buttons[this.gettext('cancel')] = function(e) { me.command('acl-cancel'); };
 
-    // display it
-    this.acl_form.show();
+    // display it as popup
+    this.acl_popup = this.show_popup_dialog(
+        '<div style="width:480px;height:280px">&nbsp;</div>',
+        id ? this.gettext('acl.editperms') : this.gettext('acl.newuser'),
+        buttons,
+        {
+            modal: true,
+            closeOnEscape: true,
+            close: function(e, ui) {
+                (me.is_framed() ? parent.rcmail : me).ksearch_hide();
+                me.acl_form.appendTo(body).hide();
+                $(this).remove();
+                window.focus(); // focus iframe
+            }
+        }
+    );
+
+    this.acl_form.appendTo(this.acl_popup).show();
+
     if (type == 'user')
         name_input.focus();
-
-    // unfocus the list, make backspace key in name input field working
-    this.acl_list.blur();
+    else
+        $('input:checked', type_list).focus();
 }
 
 // Returns class name according to ACL comparision result

--
Gitblit v1.9.1