lib/client public_html/js

Aleksander Machniak machniak at kolabsys.com
Fri Oct 5 11:30:20 CEST 2012


 lib/client/kolab_client_task_settings.php |    1 
 public_html/js/kolab_admin.js             |   35 ++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 9 deletions(-)

New commits:
commit f68e47fe538b2c8c45b0e8a2aa894ab59400a357
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Oct 5 11:29:55 2012 +0200

    Disable optional flag for required attributes

diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
index 87a03ab..bd3ea99 100644
--- a/lib/client/kolab_client_task_settings.php
+++ b/lib/client/kolab_client_task_settings.php
@@ -717,6 +717,7 @@ class kolab_client_task_settings extends kolab_client_task
             'name' => array(
                 'type' => kolab_form::INPUT_SELECT,
                 'options' => $attributes,
+                'onchange' => 'kadm.type_attr_name_change(this)',
             ),
             'type' => array(
                 'type' => kolab_form::INPUT_SELECT,
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index b6c9a72..b7b16c9 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1793,20 +1793,22 @@ function kolab_admin()
     $('input[name="attr_data"]').val(attr ? data.data : '');
     $('input[name="attr_maxcount"]').val(data.maxcount ? data.maxcount : '');
     $('textarea[name="attr_options"]').val(data.values ? data.values.join("\n") : '');
-    this.form_element_update({name: 'attr_options'});
-
     $('span', name_select.parent()).remove();
-    this.type_attr_type_change('select[name="attr_type"]');
-    this.type_attr_value_change('select[name="attr_value"]');
 
     if (attr) {
       name_select.hide().val(attr);
-      $('<span></span>').text(this.env.attributes[attr] ? this.env.attributes[attr] : attr).appendTo(name_select.parent());
+      $('<span></span>').text(this.env.attributes[attr] ? this.env.attributes[attr] : attr)
+        .appendTo(name_select.parent());
       return;
     }
+    else {
+      this.type_attr_select_init();
+      name_select.show();
+    }
 
-    this.type_attr_select_init();
-    name_select.show();
+    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"]');
   };
 
   // Initialize attribute name selector
@@ -1822,13 +1824,28 @@ function kolab_admin()
     options.not(':disabled').first().attr('selected', true);
   };
 
+  // Update attribute form on attribute name change
+  this.type_attr_name_change = function(elem)
+  {
+    this.type_attr_value_change('select[name="attr_value"]');
+  };
+
   // Update attribute form on value type change
   this.type_attr_value_change = function(elem)
   {
-    var type = $(elem).val();
+    var type = $(elem).val(),
+      optional = $('#attr_form_row_optional'),
+      select = $('select[name="attr_name"]').val(),
+      attr_name = this.env.attributes[select],
+      // only non-static and non-required attributes can be marked as optional
+      opt = type != 'static' && $.inArray(attr_name, this.env.attributes_required) == -1;
+
     $('input[name="attr_data"]')[type != 'normal' ? 'show' : 'hide']();
-    $('#attr_form_row_optional')[type != 'static' ? 'show' : 'hide']();
     $('#attr_form_row_readonly')[type != 'static' ? 'show' : 'hide']();
+    optional[opt ? 'show' : 'hide']();
+
+    if (!opt)
+      $('input', optional).attr('checked', false);
   };
 
   // Update attribute form on type change





More information about the commits mailing list