2 commits - lib/client

Aleksander Machniak machniak at kolabsys.com
Thu Mar 15 12:22:06 CET 2012


 lib/client/kolab_client_task_user.php |   33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

New commits:
commit 300ca43680037d2247f8d0f8f57e29430746f379
Merge: 6f5eced 01ce37e
Author: Aleksander Machniak <alec at alec.pl>
Date:   Thu Mar 15 12:21:44 2012 +0100

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



commit 6f5ecedf1c2e1e84ce04630ceb94afc9b59e120a
Author: Aleksander Machniak <alec at alec.pl>
Date:   Thu Mar 15 12:21:11 2012 +0100

    Regenerate auto_form_fields values on user type change (#626)

diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index 7fadc2e..a58c091 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -257,6 +257,7 @@ class kolab_client_task_user extends kolab_client_task
         $auto_fields  = array();
         $form_fields  = array();
         $_fields      = array();
+        $auto_attribs = array();
 
         // Selected account type
         if (!empty($data['user_type_id'])) {
@@ -274,21 +275,39 @@ class kolab_client_task_user extends kolab_client_task
 
         // Mark automatically generated fields as read-only, etc.
         foreach ($auto_fields as $idx => $field) {
+            if (!is_array($field)) {
+                continue;
+            }
             // merge with field definition from
             if (isset($form_fields[$idx])) {
                 $field = array_merge($field, $form_fields[$idx]);
             }
+            // remove auto-generated value on user type change, it will be re-generated
+            else if ($add_mode) {
+                unset($data[$idx]);
+            }
 
             $_fields[$idx] = $this->form_element_type($field);
             $_fields[$idx]['section'] = isset($fields[$idx]) ? $fields[$idx] : 'other';
             $_fields[$idx]['readonly'] = true;
             $_fields[$idx]['disabled'] = true;
 
-            if (is_array($field) && !empty($field['data'])) {
+            // build auto_attribs and event_fields lists
+            $is_data = 0;
+            if (!empty($field['data'])) {
                  foreach ($field['data'] as $fd) {
                      $event_fields[$fd][] = $idx;
+                     if (isset($data[$fd])) {
+                        $is_data++;
+                     }
+                 }
+                 if (count($field['data']) == $is_data) {
+                     $auto_attribs[] = $idx;
                  }
             }
+            else {
+                $auto_attribs[] = $idx;
+            }
         }
 
         // Other fields
@@ -329,12 +348,14 @@ class kolab_client_task_user extends kolab_client_task
 
         // Create mode
         if ($add_mode) {
-            if (empty($data['userpassword'])) {
-                // Pre-populate password fields
-                $post = array('attributes' => array('userpassword'));
-                $pass = $this->api->post('form_value.generate', null, $post);
-                $data['userpassword'] = $pass->get('userpassword');
+            // (Re-|Pre-)populate auto_form_fields
+            if (!empty($auto_attribs)) {
+                $data = array_merge((array)$data, array('attributes' => $auto_attribs));
+                $resp = $this->api->post('form_value.generate', null, $data);
+                $data = array_merge((array)$data, (array)$resp->get());
             }
+
+            // copy password to password confirm field
             $data['userpassword2'] = $data['userpassword'];
 
             // Page title





More information about the commits mailing list