Branch 'kolab-webadmin-3.1' - lib/client lib/kolab_client_task.php lib/locale public_html/js

Aleksander Machniak machniak at kolabsys.com
Wed Oct 16 15:11:18 CEST 2013


 lib/client/kolab_client_task_settings.php |    4 +++
 lib/kolab_client_task.php                 |   32 +++++++++++++++++++-----------
 lib/locale/en_US.php                      |    1 
 public_html/js/kolab_admin.js             |   27 ++++++++++++++++++-------
 4 files changed, 46 insertions(+), 18 deletions(-)

New commits:
commit 3444203fdd2c7f207673f58ff5aa3aa940882e41
Author: Aleksander Machniak <alec at alec.pl>
Date:   Wed Oct 16 15:11:09 2013 +0200

    Implement 'default' value support for form_fields of type text, text-quota and select (Request #2358)
    
    Conflicts:
    
    	lib/client/kolab_client_task_settings.php
    	public_html/js/kolab_admin.js

diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
index 2ec463d..a135153 100644
--- a/lib/client/kolab_client_task_settings.php
+++ b/lib/client/kolab_client_task_settings.php
@@ -692,6 +692,7 @@ class kolab_client_task_settings extends kolab_client_task
                 'maxcount' => $data['attributes']['form_fields'][$attr]['maxcount'],
                 'data'     => $_data,
                 'values'   => $data['attributes']['form_fields'][$attr]['values'],
+                'default'  => $data['attributes']['form_fields'][$attr]['default'],
             );
         }
 
@@ -765,6 +766,9 @@ class kolab_client_task_settings extends kolab_client_task
                 ),
                 'onchange' => 'kadm.type_attr_value_change(this)',
             ),
+            'default' => array(
+                'type' => kolab_form::INPUT_TEXT,
+            ),
             'optional' => array(
                 'type'  => kolab_form::INPUT_CHECKBOX,
                 'value' => 1,
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index f6e574c..07864ff 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -839,6 +839,7 @@ class kolab_client_task
             $result['type']    = kolab_form::INPUT_SELECT;
             $result['options'] = $opts['options'];
             $result['value']   = $opts['default'];
+            $result['default'] = $field['default'];
 
             if ($field['type'] == 'multiselect') {
                 $result['multiple'] = true;
@@ -874,14 +875,17 @@ class kolab_client_task
             break;
 
         case 'text-quota':
-            $result['type'] = kolab_form::INPUT_TEXTQUOTA;
+            $result['type']    = kolab_form::INPUT_TEXTQUOTA;
+            $result['default'] = $field['default'];
             break;
 
         default:
             $result['type'] = kolab_form::INPUT_TEXT;
+
             if (isset($field['maxlength'])) {
                 $result['maxlength'] = $field['maxlength'];
             }
+
             if ($field['type'] && $field['type'] != 'text') {
                 $result['data-type'] = $field['type'];
                 if ($field['type'] == 'ldap_url') {
@@ -892,6 +896,9 @@ class kolab_client_task
                     );
                 }
             }
+            else {
+                $result['default'] = $field['default'];
+            }
         }
 
         $result['required'] = empty($field['optional']);
@@ -1228,7 +1235,6 @@ class kolab_client_task
 
         //console("form_create() \$attribs", $attribs);
         //console("form_create() \$auto_fields", $auto_fields);
-
         //console("Going to walk through sections", $sections);
 
         // Parse elements and add them to the form object
@@ -1249,28 +1255,32 @@ class kolab_client_task
                 $field['section']     = $section_idx;
 
                 if (empty($field['value']) && !empty($data[$idx])) {
-
                     //console("Using data value", $data[$idx], "for value of field $idx");
-
-                    $field['value'] = $data[$idx];
+                    $value = $data[$idx];
 
                     // Convert data for the list field with autocompletion
                     if ($field['data-type'] == kolab_form::TYPE_LIST) {
-                        if (!is_array($data[$idx])) {
+                        if (!is_array($value)) {
                             if (!empty($field['data-autocomplete'])) {
-                                $data[$idx] = array($data[$idx] => $data[$idx]);
+                                $value = array($value => $value);
                             }
                             else {
-                                $data[$idx] = (array) $data[$idx];
+                                $value = (array) $value;
                             }
                         }
 
-                        $field['value'] = !empty($field['data-autocomplete']) ? array_keys($data[$idx]) : array_values($data[$idx]);
+                        $value = !empty($field['data-autocomplete']) ? array_keys($value) : array_values($value);
                     }
 
-                    if (is_array($field['value'])) {
-                        $field['value'] = implode("\n", $field['value']);
+                    if (is_array($value)) {
+                        $value = implode("\n", $value);
                     }
+
+                    $field['value'] = $value;
+                }
+                else if ($add_mode && !isset($field['value']) && isset($field['default'])) {
+                    $field['value'] = $field['default'];
+                    unset($field['default']);
                 }
 
                 // @TODO: We assume here that all autocompletion lists are associative
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index f10451a..f54478e 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -10,6 +10,7 @@ $LANG['about.warranty'] = 'It comes with absolutely <b>no warranties</b> and is
 $LANG['add'] = 'Add';
 
 $LANG['attribute.add'] = 'Add attribute';
+$LANG['attribute.default'] = 'Default value';
 $LANG['attribute.static'] = 'Static value';
 $LANG['attribute.name'] = 'Attribute';
 $LANG['attribute.optional'] = 'Optional';
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 2433c10..9a1e776 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1811,6 +1811,9 @@ function kolab_admin()
       if (attr.maxcount)
         data.maxcount = attr.maxcount;
 
+      if (attr['default'] && attr.valtype == 'normal' && attr.type.match(/^(text|select)/))
+        data['default'] = attr['default'];
+
       if (attr.valtype == 'normal' || attr.valtype == 'auto')
         request.attributes.form_fields[i] = data;
       if (attr.valtype == 'auto' || attr.valtype == 'auto-readonly') {
@@ -1959,6 +1962,10 @@ function kolab_admin()
       value = this.t('attribute.value.' + (data.valtype == 'static' ? 'static' : 'auto')) + ': ' + data.data;
     }
 
+    if (form_data.attr_default && data.valtype == 'normal' && data.type.match(/^(text|select)/)) {
+      data['default'] = form_data.attr_default;
+    }
+
     // Update table row
     $('td.name', row).text(this.env.attributes[attr]);
     $('td.type', row).text(data.type);
@@ -1986,9 +1993,10 @@ function kolab_admin()
 
     $('select[name="attr_type"]').val(type);
     $('select[name="attr_value"]').val(attr ? data.valtype : 'normal');
+    $('input[name="attr_default"]').val(data['default'] || '');
     $('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 : '');
+    $('input[name="attr_data"]').val(data.data || '');
+    $('input[name="attr_maxcount"]').val(data.maxcount || '');
     $('textarea[name="attr_options"]').val(data.values ? data.values.join("\n") : '');
     $('span', name_select.parent()).remove();
 
@@ -2003,8 +2011,8 @@ function kolab_admin()
     }
 
     this.form_element_update({name: 'attr_options'});
-    this.type_attr_type_change('select[name="attr_type"]');
-    this.type_attr_value_change('select[name="attr_value"]');
+    this.type_attr_type_change();
+    this.type_attr_value_change();
   };
 
   // Initialize attribute name selector
@@ -2023,13 +2031,14 @@ function kolab_admin()
   // Update attribute form on attribute name change
   this.type_attr_name_change = function(elem)
   {
-    this.type_attr_value_change('select[name="attr_value"]');
+    this.type_attr_value_change();
   };
 
   // Update attribute form on value type change
   this.type_attr_value_change = function(elem)
   {
-    var type = $(elem).val(),
+    var type = $(elem || 'select[name="attr_value"]').val(),
+      field_type = $('select[name="attr_type"]').val(),
       optional = $('#attr_form_row_optional'),
       select = $('select[name="attr_name"]').val(),
       attr_name = this.env.attributes[select],
@@ -2038,6 +2047,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']();
     optional[opt ? 'show' : 'hide']();
 
     if (!opt)
@@ -2047,9 +2057,12 @@ function kolab_admin()
   // Update attribute form on type change
   this.type_attr_type_change = function(elem)
   {
-    var type = $(elem).val();
+    var type = $(elem || 'select[name="attr_type"]').val(),
+      val_type = $('select[name="attr_value"]').val();
+
     $('#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']();
   };
 
   // Update attributes list on object classes change




More information about the commits mailing list