4 commits - lib/kolab_client_task.php lib/kolab_html.php public_html/js public_html/skins

Aleksander Machniak machniak at kolabsys.com
Thu Apr 5 15:56:35 CEST 2012


 lib/kolab_client_task.php           |  167 +++++++++---------------------------
 lib/kolab_html.php                  |    4 
 public_html/js/kolab_admin.js       |   97 +++++++++++---------
 public_html/skins/default/style.css |   10 +-
 4 files changed, 103 insertions(+), 175 deletions(-)

New commits:
commit c45fd3ba976832fe6de86fc1c462b1e1fcdba92a
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Thu Apr 5 15:55:59 2012 +0200

    Fix clicking delete button on last listelement row

diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 554b22d..da01cd7 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -830,7 +830,7 @@ function kolab_admin()
 
     if (data.readonly)
       input.addClass('readonly');
-    else if (ac)
+    if (ac)
       input.addClass('autocomplete');
 
     // attach element creation event
@@ -854,7 +854,7 @@ function kolab_admin()
           l = $('input[name^="' + name + '"]', form),
           key = $(this).data('key');
 
-        if (ac || l.length > 1)
+        if (l.length > 1 || $('input[name="' + name + '"]', form).attr('data-autocomplete'))
           span.remove();
         else
           $('input', span).val('').focus();


commit 3bf36317189cc78ccae7aa2e58bb42da6f696eb1
Merge: bbed551 de8fdf8
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Thu Apr 5 15:45:32 2012 +0200

    Merge branch 'master' of ssh://git.kolab.org/git/kolab-wap

diff --cc lib/kolab_client_task.php
index 23ad468,2bb819b..0bbef04
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@@ -762,8 -762,9 +762,8 @@@ class kolab_client_tas
              }
  
              $field['name'] = $idx;
-             $fields[$idx] = $this->form_element_type($field);
+             $fields[$idx] = $this->form_element_type($field, $data);
              $fields[$idx]['readonly'] = true;
 -            $fields[$idx]['disabled'] = true;
  
              $extra_fields[$idx] = true;
  


commit bbed55197fd29f45c89beb932438b9a339041c70
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Thu Apr 5 15:43:58 2012 +0200

    Fix UI widgets to properly handle readonly/disabled state

diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 5d183d9..554b22d 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -733,7 +733,7 @@ function kolab_admin()
   // Replaces form element with smart element
   this.form_element_wrapper = function(form_element)
   {
-    var i, j = 0, len = 0, elem, e = $(form_element),
+    var i, j = 0, elem, e = $(form_element),
       list = this.env.assoc_fields[form_element.name],
       disabled = e.attr('disabled'),
       readonly = e.attr('readonly'),
@@ -744,47 +744,58 @@ function kolab_admin()
     e.hide();
 
     if (!list) {
-      if (form_element.value) {
-        list = form_element.value.split("\n");
-        len = list.length;
-        list = $.extend({}, list);
-      }
-      else if (!autocomplete)
+      if (form_element.value)
+        list = $.extend({}, form_element.value.split("\n"));
+      else if (!autocomplete || disabled || readonly)
         list = {0: ''};
     }
 
-    // add autocompletion input
-    if (!disabled && !readonly && autocomplete) {
-      elem = this.form_list_element(form_element.form, {
-        maxlength: maxlength,
-        autocomplete: autocomplete,
-        disabled: !len && (disabled || readonly),
-        element: e
-      }, -1);
-
-      elem.appendTo(area);
-      this.ac_init(elem, {attribute: form_element.name, oninsert: this.form_element_oninsert});
-    }
+    // Create simple list for readonly/disabled
+    if (disabled || readonly) {
+      area.addClass('readonly');
 
-    // add input rows
-    for (i in list) {
-      elem = this.form_list_element(form_element.form, {
-        value: list[i],
-        key: i,
-        disabled: disabled,
-        readonly: readonly,
-        maxlength: maxlength,
-        autocomplete: autocomplete,
-        element: e
-      }, j++);
-
-      elem.appendTo(area);
+      // add simple input rows
+      for (i in list) {
+        elem = $('<input>');
+        elem.attr({
+          value: list[i],
+          disabled: disabled,
+          readonly: readonly,
+          name: form_element.name + '[' + (j++) + ']'
+          })
+        elem = $('<span class="listelement">').append(elem);
+        elem.appendTo(area);
+      }
     }
+    // extended widget with add/remove buttons and/or autocompletion
+    else {
+      // add autocompletion input
+      if (autocomplete) {
+        elem = this.form_list_element(form_element.form, {
+          maxlength: maxlength,
+          autocomplete: autocomplete,
+          element: e
+        }, -1);
+
+        elem.appendTo(area);
+        this.ac_init(elem, {attribute: form_element.name, oninsert: this.form_element_oninsert});
+
+        area.addClass('autocomplete');
+      }
 
-    if (disabled)
-      area.addClass('readonly');
-    if (autocomplete)
-      area.addClass('autocomplete');
+      // add input rows
+      for (i in list) {
+        elem = this.form_list_element(form_element.form, {
+          value: list[i],
+          key: i,
+          maxlength: maxlength,
+          autocomplete: autocomplete,
+          element: e
+        }, j++);
+
+        elem.appendTo(area);
+      }
+    }
 
     area.appendTo(form_element.parentNode);
   };
@@ -797,9 +808,8 @@ function kolab_admin()
       orig = data.element
       ac = data.autocomplete;
 
-    data.name = data.name || orig.attr('name') + '[' + idx + ']';
-    data.disabled = data.disabled || (ac && idx >= 0);
-    data.readonly = data.readonly || (ac && idx >= 0);
+    data.name = (orig ? orig.attr('name') : data.name) + '[' + idx + ']';
+    data.readonly = (ac && idx >= 0);
 
     // remove internal attributes
     delete data['element'];
@@ -820,13 +830,9 @@ function kolab_admin()
 
     if (data.readonly)
       input.addClass('readonly');
-
-    if (ac && idx == -1)
+    else if (ac)
       input.addClass('autocomplete');
 
-    if (data.disabled && !ac)
-      return elem;
-
     // attach element creation event
     if (!ac)
       $('span[class="add"]', elem).click(function() {
@@ -1071,6 +1077,7 @@ function kolab_admin()
       this.form_value_error('userpassword2');
       return;
     }
+    delete data['userpassword2'];
 
     if (!this.check_required_fields(data)) {
       this.display_message('form.required.empty', 'error');
diff --git a/public_html/skins/default/style.css b/public_html/skins/default/style.css
index eaa0d38..a3cd8c0 100644
--- a/public_html/skins/default/style.css
+++ b/public_html/skins/default/style.css
@@ -551,6 +551,11 @@ span.listelement input {
   height: 19px;
 }
 
+span.listarea.disabled span.listelement input,
+span.listarea.readonly span.listelement input {
+  width: 370px;  
+}
+
 span.listelement input:focus {
   outline: none;
 }
@@ -614,11 +619,6 @@ span.listarea.autocomplete span.listelement input.autocomplete {
   color: black;
 }
 
-span.listarea.disabled span.listelement span.actions,
-span.listarea.readonly span.listelement span.actions {
-  opacity: .5;
-}
-
 .autocomplete > span.listelement input {
   /* FIXME: it should be 348px, but when listarea has scroller, input jumps below action buttons */
   width: 332px;


commit 3187daec959427302e07f31b0189338b62fc6967
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Thu Apr 5 14:06:52 2012 +0200

    Simplify effective rights checks in the form generator
    Hide Submit button if all form fields are readonly (no rights)

diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 8dc2f34..23ad468 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -764,7 +764,6 @@ class kolab_client_task
             $field['name'] = $idx;
             $fields[$idx] = $this->form_element_type($field);
             $fields[$idx]['readonly'] = true;
-            $fields[$idx]['disabled'] = true;
 
             $extra_fields[$idx] = true;
 
@@ -799,9 +798,8 @@ class kolab_client_task
             else {
                 unset($extra_fields[$idx]);
             }
-//            $fields[$idx]['required'] = true;
+
             $fields[$idx]['readonly'] = false;
-            $fields[$idx]['disabled'] = false;
 
             // Attach on-change events to some fields, to update
             // auto-generated field values
@@ -811,6 +809,34 @@ class kolab_client_task
             }
         }
 
+        // Get the rights on the entry and attribute level
+        $result = $this->api->get("user.effective_rights", array($name => $data['id']));
+        $attribute_rights = $result->get('attributeLevelRights');
+        $entry_rights     = $result->get('entryLevelRights');
+
+        $data['effective_rights'] = array(
+            'attribute' => $attribute_rights,
+            'entry'     => $entry_rights,
+        );
+
+        foreach ($fields as $idx => $field) {
+            if (!array_key_exists($idx, $attribute_rights)) {
+                // If the entry level rights contain 'add' and 'delete', well, you're an admin
+                if (in_array('add', $entry_rights) && in_array('delete', $entry_rights)) {
+                    $fields[$idx]['readonly'] = false;
+                }
+                else {
+                    $fields[$idx]['readonly'] = true;
+                }
+            }
+            else {
+                // No entry level rights, check on attribute level
+                if (!in_array('write', $attribute_rights[$idx])) {
+                    $fields[$idx]['readonly'] = true;
+                }
+            }
+        }
+
         // Register list of auto-generated fields
         $this->output->set_env('auto_fields', $auto_fields);
         // Register list of disabled fields
@@ -898,16 +924,12 @@ class kolab_client_task
      * @param array  $sections   List of form sections
      * @param array  $fields     Fields list (from self::form_prepare())
      * @param array  $fields_map Fields map (used for sorting and sections assignment)
-     * @param array  $data       Object data
+     * @param array  $data       Object data (with effective rights, see form_prepare())
      *
      * @return kolab_form HTML Form object
      */
     protected function form_create($name, $attribs, $sections, $fields, $fields_map, $data, $add_mode)
     {
-        // Get the rights on the entry and attribute level
-        $effective_rights = $this->api->get("user.effective_rights", array($name => $data['id']))->get();
-        //console($effective_rights);
-
         // Assign sections to fields
         foreach ($fields as $idx => $field) {
             if (!$field['section']) {
@@ -932,6 +954,7 @@ class kolab_client_task
         $form = new kolab_form($attribs);
         $assoc_fields = array();
         $req_fields   = array();
+        $writeable    = 0;
 
         $auto_fields = $this->output->get_env('auto_fields');
         //console("\$auto_fields", $auto_fields);
@@ -966,7 +989,6 @@ class kolab_client_task
                         $field['value'] = implode("\n", $field['value']);
                     }
                 }
-
 /*
                 if (!empty($field['suffix'])) {
                     $field['suffix'] = kolab_html::escape($this->translate($field['suffix']));
@@ -995,117 +1017,14 @@ class kolab_client_task
                     $field['name'] = $idx;
                 }
 
-                //console("before authz: " . $field['name'], $field);
-
-                // Only edit those fields that actually have merit
-                if (array_key_exists('disabled', $field) || array_key_exists('readonly', $field)) {
-                    if (!array_key_exists($field['name'], $effective_rights['attributeLevelRights'])) {
-                        //console("No explicit rights on attribute " . $field['name']);
-                        // If the entry level rights contain 'add' and 'delete', well, you're an admin
-                        if (
-                                in_array('add', $effective_rights['entryLevelRights']) &&
-                                in_array('delete', $effective_rights['entryLevelRights'])
-                            ) {
-
-                            //console("Overriding any permissions for field " . $field['name'] . ", simply because we have the access to delete and add back the entry.");
-                            if (array_key_exists('disabled', $field) && $field['disabled']) {
-                                //console("overriding disabled state on " . $field['name']);
-                                $field['disabled'] = false;
-                            }
-
-                            if (array_key_exists('readonly', $field) && $field['readonly']) {
-                                //console("overriding readonly state on " . $field['name']);
-                                $field['readonly'] = false;
-                            }
-
-                        } else {
-                            //console("no explicit write permissions on " . $field['name'] . ", disabling");
-                            if (array_key_exists('disabled', $field) && $field['disabled']) {
-                                //console("overriding disabled state on " . $field['name']);
-                                $field['disabled'] = false;
-                            }
-                            if (array_key_exists('readonly', $field) && !$field['readonly']) {
-                                //console("overriding readonly state on " . $field['name']);
-                                $field['readonly'] = true;
-                            }
-                        }
-                    } else {
-                        //console("Explicit rights on attribute " . $field['name'] . " found");
-                        if (!in_array('write', $effective_rights['attributeLevelRights'][$field['name']])) {
-                            //console("no write permissions on " . $field['name'] . ", marking read-only");
-/*                            if (array_key_exists('disabled', $field) && !$field['disabled']) {
-                                //console("overriding disabled state on " . $field['name']);
-                                $field['disabled'] = true;
-                            }
-*/
-                            if (array_key_exists('readonly', $field) && !$field['readonly']) {
-                                //console("overriding readonly state on " . $field['name']);
-                                $field['readonly'] = true;
-                            }
-                        } else {
-                            //console("explicit write permissions on " . $field['name']);
-
-                            if (array_key_exists('disabled', $field) && $field['disabled']) {
-                                //console("overriding disabled state on " . $field['name']);
-                                $field['disabled'] = false;
-                            }
-                            if (array_key_exists('readonly', $field) && $field['readonly']) {
-                                //console("overriding readonly state on " . $field['name']);
-                                $field['readonly'] = false;
-                            }
-                        }
-
+                if (empty($field['readonly']) && empty($field['disabled'])) {
+                    // count writeable fields
+                    if ($field['type'] && $field['type'] != kolab_form::INPUT_HIDDEN) {
+                        $writeable++;
                     }
-
-                    // Some fields are special, such as the 'userpassword2' field.
-                    switch ($field['name']) {
-                        case "type_id":
-                            $field['disabled'] = false;
-                            break;
-                        case "userpassword2":
-                            if (
-                                    in_array('add', $effective_rights['entryLevelRights']) &&
-                                    in_array('delete', $effective_rights['entryLevelRights'])
-                                ) {
-                                $field['disabled'] = false;
-                                $field['readonly'] = false;
-                            } elseif (!array_key_exists('userpassword', $effective_rights['attributeLevelRights'])) {
-                                $field['disabled'] = true;
-                                $field['readonly'] = true;
-                            } elseif (!in_array('write', $effective_rights['attributeLevelRights']['userpassword'])) {
-                                $field['disabled'] = true;
-                                $field['readonly'] = true;
-                            } else {
-                                $field['disabled'] = false;
-                                $field['readonly'] = false;
-                            }
-
-                            break;
-                        default:
-                            break;
+                    if (!empty($field['required'])) {
+                        $req_fields[] = $idx;
                     }
-
-                    // Other fields are generated by policy, and should therefore not be editable.
-                    if (array_key_exists($field['name'], $auto_fields)) {
-/*
-                        // Not sure what to do here - if it's not disabled but an auto-generated
-                        // field... perhaps we need to mark it as read-only or optional
-                        if (array_key_exists('disabled', $field) && !$field['disabled']) {
-                            console("overriding disabled state on " . $field['name'] . ", as the field contains an automatically generated value");
-                            $field['disabled'] = true;
-                        }
-*/
-                        if (array_key_exists('readonly', $field) && !$field['readonly']) {
-                            //console("overriding readonly state on " . $field['name'] . ", as the field contains an automatically generated value");
-                            $field['readonly'] = true;
-                        }
-                    }
-                }
-
-                //console("after authz " . $field['name'], $field);
-
-                if (!empty($field['required']) && empty($field['readonly']) && empty($field['disabled'])) {
-                    $req_fields[] = $idx;
                 }
 
                 $form->add_element($field);
@@ -1116,12 +1035,14 @@ class kolab_client_task
             $form->activate_section($data['section']);
         }
 
-        $form->add_button(array(
-            'value'   => kolab_html::escape($this->translate('submit.button')),
-            'onclick' => "kadm.{$name}_save()",
-        ));
+        if ($writeable) {
+            $form->add_button(array(
+                'value'   => kolab_html::escape($this->translate('submit.button')),
+                'onclick' => "kadm.{$name}_save()",
+            ));
+        }
 
-        if (!empty($data['id']) && in_array('delete', $effective_rights['entryLevelRights'])) {
+        if (!empty($data['id']) && in_array('delete', $data['effective_rights']['entry'])) {
             $id = $data['id'];
             $form->add_button(array(
                 'value'   => kolab_html::escape($this->translate('delete.button')),
diff --git a/lib/kolab_html.php b/lib/kolab_html.php
index 385b0ad..b1b4653 100644
--- a/lib/kolab_html.php
+++ b/lib/kolab_html.php
@@ -38,8 +38,8 @@ class kolab_html
     public static $textarea_attribs = array('cols', 'rows', 'disabled', 'name', 'readonly', 'tabindex');
     public static $input_attribs  = array('checked', 'disabled', 'name', 'readonly', 'tabindex',
         'type', 'size', 'maxlength', 'value', 'autofocus');
-    public static $select_attribs = array('multiple', 'name', 'size', 'disabled', 'autofocus');
-    public static $option_attribs = array('selected', 'value', 'disabled');
+    public static $select_attribs = array('multiple', 'name', 'size', 'disabled', 'readonly', 'autofocus');
+    public static $option_attribs = array('selected', 'value', 'disabled', 'readonly');
     public static $a_attribs      = array('href', 'name', 'rel', 'tabindex', 'target');
     public static $form_attribs   = array('action', 'enctype', 'method', 'name', 'target');
     public static $label_attribs  = array('for');





More information about the commits mailing list