3 commits - doc/kolab_wap.sql lib/api lib/kolab_client_task.php public_html/js

Aleksander Machniak machniak at kolabsys.com
Tue Apr 15 15:32:27 CEST 2014


 doc/kolab_wap.sql                        |    2 -
 lib/api/kolab_api_service_form_value.php |   20 ++++++++----
 lib/kolab_client_task.php                |   14 ++++++--
 public_html/js/kolab_admin.js            |   50 ++++++++++++++++++++++---------
 4 files changed, 62 insertions(+), 24 deletions(-)

New commits:
commit eaca5181d46f5176b2215885a2dd611667d36b07
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Tue Apr 15 15:31:53 2014 +0200

    Added user autocompletion in imap acl widget

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index e013285..f5e7ca5 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -1323,19 +1323,27 @@ class kolab_api_service_form_value extends kolab_api_service
 
         $data['attributes'] = array('displayname', 'mail');
 
-        $service = $this->controller->get_service('users');
-        $result  = $service->users_list(null, $data);
-        $list    = $result['list'];
+        $service    = $this->controller->get_service('users');
+        $result     = $service->users_list(null, $data);
+        $list       = $result['list'];
+        $result     = array();
+        $result_key = $postdata['result_key'] ?: 'entrydn';
 
         // convert to key=>value array
         foreach ($list as $idx => $value) {
-            $list[$idx] = $value['displayname'];
+            $ret = $value['displayname'];
             if (!empty($value['mail'])) {
-                $list[$idx] .= ' <' . $value['mail'] . '>';
+                $ret .= ' <' . $value['mail'] . '>';
             }
+
+            if ($result_key != 'entrydn') {
+                $idx = $value[$result_key];
+            }
+
+            $result[$idx] = $ret;
         }
 
-        return $list;
+        return $result;
     }
 
     private function _list_options_resources($postdata, $attribs = array())
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index d7167c4..c7a803b 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -473,6 +473,17 @@ function kolab_admin()
 
   this.ac_init = function(obj, props)
   {
+    if (props && props.form) {
+      if (i = $('[name="type_id"]', props.form).val())
+        props.type_id = i;
+      if (i = $('[name="object_type"]', props.form).val())
+        props.object_type = i;
+      if (i = $('[name="id"]', props.form).val())
+        props.id = i;
+
+      delete props['form'];
+    }
+
     obj.keydown(function(e) { return kadm.ac_keydown(e, props); })
       .attr('autocomplete', 'off');
   };
@@ -877,14 +888,11 @@ function kolab_admin()
         }, -1);
 
         // Initialize autocompletion
-        var props = {attribute: form_element.name, oninsert: this.form_element_oninsert};
-        if (i = $('[name="type_id"]', form).val())
-          props.type_id = i;
-        if (i = $('[name="object_type"]', form).val())
-          props.object_type = i;
-        if (i = $('[name="id"]', form).val())
-          props.id = i;
-        this.ac_init(elem, props);
+        this.ac_init(elem, {
+          form: form,
+          attribute: form_element.name,
+          oninsert: this.form_element_oninsert
+        });
 
         elem.appendTo(area);
         area.addClass('autocomplete');
@@ -1886,7 +1894,7 @@ function kolab_admin()
     this.trigger_event('form-load', 'acl-form');
 
     // reset form elements
-    subject_select.val(acl.subject).change();
+    subject_select.val(acl.subject.match(/^(anyone|anonymous)$/i) ? acl.subject : 'user').change();
     subject_input.val(subject_select.val() == 'user' ? acl.subject : '');
     epoch_input.val(this.unix_to_date(acl.epoch, true));
     epoch_input.datetimepicker({
@@ -1900,6 +1908,15 @@ function kolab_admin()
       $('input[value="' + this + '"]', rights_div).prop('checked', v == 'custom' && acl.rights && acl.rights.indexOf(this) > -1);
     });
 
+    // Initialize autocompletion
+    this.ac_init(subject_input, {
+      action: 'form_value.list_options',
+      attribute: 'owner',
+      result_key: 'mail',
+      oninsert: function(key, val) { $(this.ac_input).val(key); },
+      form: $('textarea[name="' + this.acl_dialog_name + '"]').parents('form')
+    });
+
     return dialog.show();
   };
 


commit 1427f5ff20b9a35b6ba854d1e4c4c0b505470e4b
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Tue Apr 15 14:32:16 2014 +0200

    Enable acl field for shared folders

diff --git a/doc/kolab_wap.sql b/doc/kolab_wap.sql
index ad23987..9a6c13d 100644
--- a/doc/kolab_wap.sql
+++ b/doc/kolab_wap.sql
@@ -174,7 +174,7 @@ CREATE TABLE `sharedfolder_types` (
 
 LOCK TABLES `sharedfolder_types` WRITE;
 /*!40000 ALTER TABLE `sharedfolder_types` DISABLE KEYS */;
-INSERT INTO `sharedfolder_types` VALUES (1,'addressbook','Shared Address Book','A shared address book','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"contact\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"cn\":[]}}'),(2,'calendar','Shared Calendar','A shared calendar','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"event\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"cn\":[]}}'),(3,'journal','Shared Journal','A shared journal','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"journal\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"cn\":[]}}'),(4,'task','Shared Tasks','A shared tasks folder','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"task\"],\"objectclass\":[\"top\",\"kolabsharedfolder\"]},\"form_fields\":{\"cn\":[]}}'),(5,'mail','Shared Mail Folder','A shared mail folder','{\"auto_form_fields\":[],\"fields\":{\"kolabfoldertype\":[\"mail\"],\"objectcl
 ass\":[\"top\",\"kolabsharedfolder\",\"mailrecipient\"]},\"form_fields\":{\"cn\":[],\"alias\":{\"type\":\"list\",\"optional\":true},\"kolabdelegate\":{\"type\":\"list\",\"autocomplete\":true,\"optional\":true},\"kolaballowsmtprecipient\":{\"type\":\"list\",\"optional\":true},\"kolaballowsmtpsender\":{\"type\":\"list\",\"optional\":true},\"kolabtargetfolder\":[],\"mail\":[]}}');
+INSERT INTO `sharedfolder_types` VALUES (1,'addressbook','Shared Address Book','A shared address book','{\"fields\":{\"objectclass\":[\"kolabsharedfolder\",\"top\"],\"kolabfoldertype\":\"contact\"},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]},\"auto_form_fields\":[]}'),(2,'calendar','Shared Calendar','A shared calendar','{\"fields\":{\"objectclass\":[\"kolabsharedfolder\",\"top\"],\"kolabfoldertype\":\"event\"},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]},\"auto_form_fields\":[]}'),(3,'journal','Shared Journal','A shared journal','{\"fields\":{\"objectclass\":[\"kolabsharedfolder\",\"top\"],\"kolabfoldertype\":\"journal\"},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]},\"auto_form_fields\":[]}'),(4,'task','Shared Tasks','A shared tasks folder','{\"fields\":{\"objectclass\":[\"kolabsharedfolder\",\
 "top\"],\"kolabfoldertype\":\"task\"},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrs\"},\"cn\":[]},\"auto_form_fields\":[]}'),(5,'mail','Shared Mail Folder','A shared mail folder','{\"fields\":{\"objectclass\":[\"kolabsharedfolder\",\"mailrecipient\",\"top\"],\"kolabfoldertype\":\"mail\"},\"form_fields\":{\"acl\":{\"type\":\"imap_acl\",\"optional\":true,\"default\":\"anyone, lrsp\"},\"alias\":{\"type\":\"list\",\"optional\":true},\"cn\":[],\"kolaballowsmtprecipient\":{\"type\":\"list\",\"optional\":true},\"kolaballowsmtpsender\":{\"type\":\"list\",\"optional\":true},\"kolabdelegate\":{\"type\":\"list\",\"autocomplete\":true,\"optional\":true},\"kolabtargetfolder\":[],\"mail\":[]},\"auto_form_fields\":[]}');
 /*!40000 ALTER TABLE `sharedfolder_types` ENABLE KEYS */;
 UNLOCK TABLES;
 


commit 7fb0da4c53097d9b5c39df3bd8d90eb1abea8793
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Tue Apr 15 14:24:55 2014 +0200

    Support default value for imap_acl fields, fix handling defaults on object type change

diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 370ad64..f1c5fb3 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -900,6 +900,7 @@ class kolab_client_task
         case 'imap_acl':
             $result['type']      = kolab_form::INPUT_TEXTAREA;
             $result['data-type'] = 'acl';
+            $result['default']   = $field['default'];
 
             $this->output->add_translation('aci.new', 'aci.edit', 'aci.remove',
                 'button.ok', 'button.cancel',
@@ -1265,9 +1266,11 @@ class kolab_client_task
         }
 
         $form = new kolab_form($attribs);
-        $assoc_fields = array();
-        $req_fields   = array();
-        $writeable    = 0;
+
+        $default_values = array();
+        $assoc_fields   = array();
+        $req_fields     = array();
+        $writeable      = 0;
 
         $auto_fields = $this->output->get_env('auto_fields');
 
@@ -1312,7 +1315,9 @@ class kolab_client_task
                     $field['value'] = $value;
                 }
                 else if ($add_mode && !isset($field['value']) && isset($field['default'])) {
-                    $field['value'] = $field['default'];
+                    $field['value']       = $field['default'];
+                    $default_values[$idx] = $field['default'];
+
                     unset($field['default']);
                 }
 
@@ -1392,6 +1397,7 @@ class kolab_client_task
         $ac_min_len = $this->config_get('autocomplete_min_length', 1, Conf::INT);
 
         $this->output->set_env('form_id', $attribs['id']);
+        $this->output->set_env('default_values', $default_values);
         $this->output->set_env('assoc_fields', $assoc_fields);
         $this->output->set_env('required_fields', $req_fields);
         $this->output->set_env('autocomplete_min_length', $ac_min_len);
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 7178c97..d7167c4 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -30,6 +30,7 @@ function kolab_admin()
   this.request_timeout = 300;
   this.message_time = 3000;
   this.events = {};
+  this.attr_default_rx = /^(text|select|imap_acl)/;
 
   // set jQuery ajax options
   $.ajaxSetup({
@@ -2633,7 +2634,7 @@ function kolab_admin()
       if (attr.validate != 'default')
         data.validate = attr.validate;
 
-      if (attr['default'] && attr.valtype == 'normal' && attr.type.match(/^(text|select)/))
+      if (attr['default'] && attr.valtype == 'normal' && attr.type.match(this.attr_default_rx))
         data['default'] = attr['default'];
 
       if (attr.valtype == 'normal' || attr.valtype == 'auto')
@@ -2728,6 +2729,12 @@ function kolab_admin()
       action = data.id ? 'edit' : 'add';
 
     if (reload) {
+      // remove unchanged defaults
+      $.each(this.env.default_values || [], function(i, v) {
+        if (v == data[i])
+          delete data[i];
+      });
+
       data.section = section;
       this.http_post(type + '.' + action, {data: data});
       return false;
@@ -2826,7 +2833,7 @@ function kolab_admin()
       row.attr('title', this.t('attribute.value.' + (data.valtype == 'static' ? 'static' : 'auto')) + ': ' + data.data);
     }
 
-    if (form_data.attr_default && data.valtype == 'normal' && data.type.match(/^(text|select)/)) {
+    if (form_data.attr_default && data.valtype == 'normal' && data.type.match(this.attr_default_rx)) {
       data['default'] = form_data.attr_default;
     }
 
@@ -2912,7 +2919,7 @@ function kolab_admin()
 
     $('input[name="attr_data"]')[type != 'normal' ? 'show' : 'hide']();
     $('#attr_form_row_readonly')[type != 'static' ? 'show' : 'hide']();
-    $('#attr_form_row_default')[type == 'normal' && field_type.match(/^(text|select)/) ? 'show' : 'hide']();
+    $('#attr_form_row_default')[type == 'normal' && field_type.match(this.attr_default_rx) ? 'show' : 'hide']();
     optional[opt ? 'show' : 'hide']();
 
     if (!opt)
@@ -2927,7 +2934,7 @@ function kolab_admin()
 
     $('#attr_form_row_maxcount')[type == 'list' || type == 'list-autocomplete' ? 'show' : 'hide']();
     $('#attr_form_row_options')[type == 'select' || type == 'multiselect' ? 'show' : 'hide']();
-    $('#attr_form_row_default')[val_type == 'normal' && type.match(/^(text|select)/) ? 'show' : 'hide']();
+    $('#attr_form_row_default')[val_type == 'normal' && type.match(this.attr_default_rx) ? 'show' : 'hide']();
   };
 
   // Update attributes list on object classes change




More information about the commits mailing list