lib/api lib/client lib/locale public_html/js public_html/skins

Aleksander Machniak machniak at kolabsys.com
Fri Sep 20 14:02:54 CEST 2013


 lib/api/kolab_api_service_form_value.php  |   27 +++++++++++++++++--------
 lib/client/kolab_client_task_settings.php |   32 ++++++++++++++++++++++++------
 lib/locale/en_US.php                      |    4 +++
 public_html/js/kolab_admin.js             |   12 +++++++----
 public_html/skins/default/ui.js           |    9 ++++++++
 5 files changed, 66 insertions(+), 18 deletions(-)

New commits:
commit 69ef0de8ffd1460ebba165fc7210034b3235a791
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Sep 20 14:01:42 2013 +0200

    Add possibility to set 'validate' flag for form_fields in object type definition

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index ce72173..1e4b044 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -28,6 +28,10 @@
  */
 class kolab_api_service_form_value extends kolab_api_service
 {
+    const VALIDATE_DEFAULT = 'default';
+    const VALIDATE_BASIC   = 'basic';
+    const VALIDATE_NONE    = 'none';
+
 
     /**
      * Returns service capabilities.
@@ -223,14 +227,21 @@ class kolab_api_service_form_value extends kolab_api_service
                 }
             }
 
-            if ($attribs['form_fields'][$attr_name]['validate'] === false) {
+            $validate = $attribs['form_fields'][$attr_name]['validate'];
+
+            // deprecated value: false = VALIDATE_NONE
+            if ($validate === false) {
+                $validate = self::VALIDATE_NONE;
+            }
+
+            if ($validate == self::VALIDATE_NONE) {
                 $result[$attr_name] = $attr_value;
             }
             else if ($attribs['form_fields'][$attr_name]['optional'] && $attr_value === '') {
                 $result[$attr_name] = $attr_value;
             }
             else {
-                $result[$attr_name] = $this->{$method_name}($attr_value, $postdata);
+                $result[$attr_name] = $this->{$method_name}($attr_value, $postdata, $validate);
             }
         }
 
@@ -1079,7 +1090,7 @@ class kolab_api_service_form_value extends kolab_api_service
         return $options;
     }
 
-    private function validate_alias($value)
+    private function validate_alias($value, $postdata = null, $validation_type = null)
     {
         $auth = Auth::get_instance();
         $conf = Conf::get_instance();
@@ -1103,7 +1114,7 @@ class kolab_api_service_form_value extends kolab_api_service
 
     }
 
-    private function validate_associateddomain($value)
+    private function validate_associateddomain($value, $postdata = array(), $validation_type = null)
     {
         return $value;
 
@@ -1119,7 +1130,7 @@ class kolab_api_service_form_value extends kolab_api_service
         return $value;
     }
 
-    private function validate_astaccountrealmedpassword($value, $postdata)
+    private function validate_astaccountrealmedpassword($value, $postdata = array(), $validation_type = null)
     {
         if (!array_key_exists('userpassword', $postdata) || empty($postdata['userpassword'])) {
             return $value;
@@ -1136,7 +1147,7 @@ class kolab_api_service_form_value extends kolab_api_service
         return md5($str);
     }
 
-    private function validate_mail($value)
+    private function validate_mail($value, $postdata = array(), $validation_type = null)
     {
         $auth = Auth::get_instance();
         $conf = Conf::get_instance();
@@ -1159,7 +1170,7 @@ class kolab_api_service_form_value extends kolab_api_service
         }
     }
 
-    private function validate_mailquota($value)
+    private function validate_mailquota($value, $postdata = array(), $validation_type = null)
     {
         // convert MB/GB into KB
         if (preg_match('/^([0-9]+)\s*(KB|MB|GB)$/i', $value, $m)) {
@@ -1173,7 +1184,7 @@ class kolab_api_service_form_value extends kolab_api_service
         return (int) $value;
     }
 
-    private function validate_mailalternateaddress($value)
+    private function validate_mailalternateaddress($value, $postdata = array(), $validation_type = null)
     {
         $auth = Auth::get_instance();
         $conf = Conf::get_instance();
diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
index 2ec463d..019b417 100644
--- a/lib/client/kolab_client_task_settings.php
+++ b/lib/client/kolab_client_task_settings.php
@@ -584,8 +584,8 @@ class kolab_client_task_settings extends kolab_client_task
             'optional' => array(
                 'body'  => $this->translate('attribute.optional'),
             ),
-            'value' => array(
-                'body'  => $this->translate('attribute.value'),
+            'validate' => array(
+                'body'  => $this->translate('attribute.validate'),
             ),
         );
 
@@ -624,6 +624,7 @@ class kolab_client_task_settings extends kolab_client_task
             $type         = $data['attributes']['form_fields'][$attr]['type'];
             $optional     = $data['attributes']['form_fields'][$attr]['optional'];
             $autocomplete = $data['attributes']['form_fields'][$attr]['autocomplete'];
+            $validate     = $data['attributes']['form_fields'][$attr]['validate'];
             $valtype      = 'normal';
             $value        = '';
 
@@ -639,13 +640,18 @@ class kolab_client_task_settings extends kolab_client_task
             }
             else if (isset($data['attributes']['auto_form_fields'][$attr])) {
                 $valtype = 'auto';
+
                 if (is_array($data['attributes']['auto_form_fields'][$attr]['data'])) {
                     $_data = implode(',', $data['attributes']['auto_form_fields'][$attr]['data']);
                 }
                 else {
                     $_data = '';
                 }
-                $value = $this->translate('attribute.value.auto') . ': ' . kolab_html::escape($_data);
+
+                $value = $this->translate('attribute.value.auto');
+                if (!empty($_data)) {
+                    $value . ': ' . kolab_html::escape($_data);
+                }
 
                 if (empty($data['attributes']['form_fields'][$attr])) {
                     $valtype = 'auto-readonly';
@@ -656,15 +662,17 @@ class kolab_client_task_settings extends kolab_client_task
                 }
             }
 
+            $n_validate = $validate === false ? 'none' : $validate ? $validate : 'default';
+
             // set cell content
             $row['name']['body']     = !empty($available[$attr]) ? $available[$attr] : $attr;
             $row['type']['body']     = !empty($type) ? $type : 'text';
-            $row['value']['body']    = $value;
             $row['readonly']['body'] = $valtype == 'auto-readonly' ? $yes : $no;
             $row['optional']['body'] = $optional ? $yes : $no;
+            $row['validate']['body'] = $this->translate('attribute.validate.' . $n_validate);
 
             if (!empty($row['actions'])) {
-                $row['actions']['body']  = '';
+                $row['actions']['body'] = '';
 
                 if (in_array('delete', $rights)) {
                     $row['actions']['body'] .= kolab_html::a(array(
@@ -681,6 +689,7 @@ class kolab_client_task_settings extends kolab_client_task
 
             $rows[] = array(
                 'id'    => 'attr_table_row_' . $attr,
+                'title' => $value,
                 'cells' => $row,
             );
 
@@ -689,6 +698,7 @@ class kolab_client_task_settings extends kolab_client_task
                 'type'     => !empty($type) ? $type : 'text',
                 'valtype'  => $valtype,
                 'optional' => $optional,
+                'validate' => $n_validate,
                 'maxcount' => $data['attributes']['form_fields'][$attr]['maxcount'],
                 'data'     => $_data,
                 'values'   => $data['attributes']['form_fields'][$attr]['values'],
@@ -716,7 +726,9 @@ class kolab_client_task_settings extends kolab_client_task
         $this->output->set_env('yes_label', $yes);
         $this->output->set_env('no_label', $no);
         $this->output->add_translation('attribute.value.auto', 'attribute.value.static',
-            'attribute.key.invalid', 'attribute.required.error');
+            'attribute.key.invalid', 'attribute.required.error',
+            'attribute.validate.default', 'attribute.validate.basic', 'attribute.validate.none'
+        );
 
         // Add attribute link
         if (in_array('write', $rights)) {
@@ -765,6 +777,14 @@ class kolab_client_task_settings extends kolab_client_task
                 ),
                 'onchange' => 'kadm.type_attr_value_change(this)',
             ),
+            'validate' => array(
+                'type' => kolab_form::INPUT_SELECT,
+                'options' => array(
+                    'default'  => $this->translate('attribute.validate.default'),
+                    'basic'    => $this->translate('attribute.validate.basic'),
+                    'none'     => $this->translate('attribute.validate.none'),
+                ),
+            ),
             'optional' => array(
                 'type'  => kolab_form::INPUT_CHECKBOX,
                 'value' => 1,
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index f10451a..390f150 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -24,6 +24,10 @@ $LANG['attribute.value.static'] = 'Static';
 $LANG['attribute.options'] = 'Options';
 $LANG['attribute.key.invalid'] = 'Type key contains forbidden characters!';
 $LANG['attribute.required.error'] = 'Required attributes missing in attributes list ($1)!';
+$LANG['attribute.validate'] = ' Validation';
+$LANG['attribute.validate.default'] = 'default';
+$LANG['attribute.validate.none'] = 'none';
+$LANG['attribute.validate.basic'] = 'basic';
 
 $LANG['button.cancel'] = 'Cancel';
 $LANG['button.delete'] = 'Delete';
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 2433c10..983ae8c 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1810,6 +1810,8 @@ function kolab_admin()
         data.optional = true;
       if (attr.maxcount)
         data.maxcount = attr.maxcount;
+      if (attr.validate != 'default')
+        data.validate = attr.validate;
 
       if (attr.valtype == 'normal' || attr.valtype == 'auto')
         request.attributes.form_fields[i] = data;
@@ -1928,7 +1930,7 @@ function kolab_admin()
   // Saves attribute form, create/update attribute row
   this.type_attr_save = function()
   {
-    var attr, row, value = '', data = {},
+    var attr, row, data = {},
       form_data = this.serialize_form('#'+this.env.form_id),
       name_select = $('select[name="attr_name"]');
 
@@ -1936,6 +1938,7 @@ function kolab_admin()
     data.type = form_data.attr_type;
     data.valtype = form_data.attr_value;
     data.optional = form_data.attr_optional;
+    data.validate = form_data.attr_validate;
     data.data = data.valtype != 'normal' ? form_data.attr_data : null;
     data.maxcount = data.type == 'list' || data.type == 'list-autocomplete' ? form_data.attr_maxcount : 0;
     data.values = data.type == 'select' || data.type == 'multiselect' ? form_data.attr_options : [];
@@ -1944,7 +1947,7 @@ function kolab_admin()
       // new attribute
       attr = name_select.val();
       row = $('<tr><td class="name"></td><td class="type"></td><td class="readonly"></td>'
-        +'<td class="optional"></td><td class="value"></td><td class="actions">'
+        +'<td class="optional"></td><td class="validate"></td><td class="actions">'
         +'<a class="button delete" title="delete" onclick="kadm.type_attr_delete(\''+attr+'\')" href="#delete"></a>'
         +'<a class="button edit" title="edit" onclick="kadm.type_attr_edit(\''+attr+'\')" href="#edit"></a></td></tr>')
         .attr('id', 'attr_table_row_' + attr).appendTo('#type_attr_table > tbody');
@@ -1956,7 +1959,7 @@ function kolab_admin()
     }
 
     if (data.valtype != 'normal') {
-      value = this.t('attribute.value.' + (data.valtype == 'static' ? 'static' : 'auto')) + ': ' + data.data;
+      row.attr('title', this.t('attribute.value.' + (data.valtype == 'static' ? 'static' : 'auto')) + ': ' + data.data);
     }
 
     // Update table row
@@ -1964,7 +1967,7 @@ function kolab_admin()
     $('td.type', row).text(data.type);
     $('td.readonly', row).text(data.valtype == 'auto-readonly' ? this.env.yes_label : this.env.no_label);
     $('td.optional', row).text(data.optional ? this.env.yes_label : this.env.no_label);
-    $('td.value', row).text(value);
+    $('td.validate', row).text(this.t('attribute.validate.' + data.validate));
 
     // Update env data
     this.env.attr_table[attr] = data;
@@ -1986,6 +1989,7 @@ function kolab_admin()
 
     $('select[name="attr_type"]').val(type);
     $('select[name="attr_value"]').val(attr ? data.valtype : 'normal');
+    $('select[name="attr_validate"]').val(attr ? data.validate : '');
     $('input[name="attr_optional"]').attr('checked', attr ? data.optional : false);
     $('input[name="attr_data"]').val(attr ? data.data : '');
     $('input[name="attr_maxcount"]').val(data.maxcount ? data.maxcount : '');
diff --git a/public_html/skins/default/ui.js b/public_html/skins/default/ui.js
index ac56bc7..11b513d 100644
--- a/public_html/skins/default/ui.js
+++ b/public_html/skins/default/ui.js
@@ -145,6 +145,15 @@ function form_load(id)
 {
   if (id != 'search-form')
     init_tabs(id);
+
+  if (id == 'type-form') {
+    // add double-click event on attributes list
+    $('#type_attr_table tbody').on('dblclick', 'tr:not("#type_attr_form")', function() {
+      var button = $('a.button.edit', this);
+      if (button.length)
+        button.click();
+    });
+  }
 };
 
 // UI resize handler




More information about the commits mailing list