lib/client lib/locale public_html/js

Aleksander Machniak machniak at kolabsys.com
Fri Oct 5 09:29:44 CEST 2012


 lib/client/kolab_client_task_settings.php |    9 ++++----
 lib/locale/en_US.php                      |    1 
 public_html/js/kolab_admin.js             |   31 ++++++++++++++++++++++++------
 3 files changed, 31 insertions(+), 10 deletions(-)

New commits:
commit 6fd00391103bc89a4377bb37e6841cef9bc0ed5a
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Oct 5 09:29:07 2012 +0200

    Add required attributes check in object types management

diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
index f149ba0..87a03ab 100644
--- a/lib/client/kolab_client_task_settings.php
+++ b/lib/client/kolab_client_task_settings.php
@@ -695,7 +695,7 @@ 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.key.invalid', 'attribute.required.error');
 
         // Add attribute link
         $link = kolab_html::a(array(
@@ -817,12 +817,13 @@ class kolab_client_task_settings extends kolab_client_task
 
         // convert to hash array
         if (!empty($response['list'])) {
-            $attributes = array_combine(array_map('strtolower', $response['list']), $response['list']);
+            // remove objectClass
+            $attributes = array_diff($response['list'], array('objectClass'));
+            $attributes = array_combine(array_map('strtolower', $attributes), $attributes);
         }
 
         $this->output->set_env('attributes', $attributes);
-        // @TODO: check if all required attributes are used
-//        $this->output->set_env('attributes_required', $attributes['required']);
+        $this->output->set_env('attributes_required', $response['required']);
 
         return $attributes;
     }
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index 6b7606d..1810fbc 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -21,6 +21,7 @@ $LANG['attribute.value.normal'] = 'Normal';
 $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['button.cancel'] = 'Cancel';
 $LANG['button.delete'] = 'Delete';
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index fd4d3fd..b6c9a72 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1549,9 +1549,10 @@ function kolab_admin()
 
   this.type_save = function(reload, section)
   {
-    var i, attr, request = {},
+    var i, n, attr, request = {},
       data = this.serialize_form('#'+this.env.form_id),
-      action = data.id ? 'edit' : 'add';
+      action = data.id ? 'edit' : 'add',
+      required = this.env.attributes_required || [];
 
     if (reload) {
       data.section = section;
@@ -1571,6 +1572,9 @@ function kolab_admin()
       return;
     }
 
+    // remove objectClass from required attributes list
+    required = $.map(required, function(a) { return a == 'objectClass' ? null : a; });
+
     request.id = data.id;
     request.key = data.key;
     request.name = data.name;
@@ -1583,6 +1587,14 @@ function kolab_admin()
     // Build attributes array compatible with the API format
     // @TODO: use attr_table format
     for (i in this.env.attr_table) {
+      // attribute doesn't exist in specified object classes set
+      if (!(n = this.env.attributes[i]))
+        continue;
+
+      // check required attributes
+      if (required.length)
+        required = $.map(required, function(a) { return a != n ? a : null; });
+
       attr = this.env.attr_table[i];
       data = {};
 
@@ -1615,6 +1627,11 @@ function kolab_admin()
       }
     }
 
+    if (required.length) {
+      this.display_message(this.t('attribute.required.error').replace(/\$1/, required.join(',')), 'error');
+      return;
+    }
+
     this.set_busy(true, 'saving');
     this.api_post('type.' + action, request, 'type_' + action + '_response');
   };
@@ -1836,16 +1853,18 @@ function kolab_admin()
     if (!this.api_response(response))
       return;
 
-    var i, lc, list = response.result.attribute.list,
-      required = response.result.attribute.required,
+    var i, lc, list = response.result.attribute.list || [],
       select = $('select[name="attr_name"]');
 
     this.env.attributes = {};
+    this.env.attributes_required = response.result.attribute.required || [];
     select.empty();
 
     for (i in list) {
-      lc = list[i].toLowerCase()
-      this.env.attributes[list[i].toLowerCase()] = list[i];
+      if (i == 'objectClass')
+        continue;
+      lc = list[i].toLowerCase();
+      this.env.attributes[lc] = list[i];
       $('<option>').text(list[i]).val(lc).appendTo(select);
     }
   };





More information about the commits mailing list