2 commits - lib/client lib/kolab_form.php public_html/js public_html/skins

Aleksander Machniak machniak at kolabsys.com
Fri Feb 24 13:59:10 CET 2012


 lib/client/kolab_client_task_user.php |   34 ++++++++++++++++++++++++----------
 lib/kolab_form.php                    |   17 +++++++++++++++--
 public_html/js/kolab_admin.js         |   13 ++++++++++++-
 public_html/skins/default/ui.js       |    6 +++++-
 4 files changed, 56 insertions(+), 14 deletions(-)

New commits:
commit 7caad906bb40ea7f4e73c0aa53b44caff00e33db
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Feb 24 13:55:59 2012 +0100

    Functionality related to user-type change

diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index 17ba129..7b21aef 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -180,7 +180,8 @@ class kolab_client_task_user extends kolab_client_task
      */
     public function action_add()
     {
-        $output = $this->user_form(null, null);
+        $data   = $this->get_input('data', 'POST');
+        $output = $this->user_form(null, $data, true);
 
         $this->output->set_object('taskcontent', $output);
     }
@@ -194,8 +195,8 @@ class kolab_client_task_user extends kolab_client_task
         $form      = new kolab_form($attribs);
         $utypes    = (array) $this->user_types();
         $form_id   = $attribs['id'];
+        $add_mode  = empty($data['user']);
         $accttypes = array();
-        $new       = $data === null;
 
         foreach ($utypes as $idx => $elem) {
             $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']);
@@ -322,7 +323,7 @@ class kolab_client_task_user extends kolab_client_task
                         'description' => 'user.password.desc',
                         'type'        => kolab_form::INPUT_TEXT,
                         'maxlength'   => 50,
-                        'required'    => $new ? true : false,
+                        'required'    => $add_mode ? true : false,
                         'system'      => true,
                     ),
                     'userpassword2' => array(
@@ -330,7 +331,7 @@ class kolab_client_task_user extends kolab_client_task
                         'description' => 'user.password-confirm.desc',
                         'type'        => kolab_form::INPUT_TEXT,
                         'maxlength'   => 50,
-                        'required'    => $new ? true : false,
+                        'required'    => $add_mode ? true : false,
                         'system'      => true,
                     ),
                     'kolabhomeserver' => array(
@@ -345,6 +346,8 @@ class kolab_client_task_user extends kolab_client_task
                         'description' => 'user.type.desc',
                         'type'        => kolab_form::INPUT_SELECT,
                         'options'     => $accttypes,
+                        'system'      => $add_mode ? true : false,
+                        'onchange'    => "kadm.user_save(true, 'system')",
                     ),
                 ),
             ),
@@ -462,19 +465,26 @@ class kolab_client_task_user extends kolab_client_task
             );
         }
 
-        // New user form
-        if ($new) {
-            // Pre-populate password fields
-            $pass = $this->api->get('form_value.generate_userpassword');
-            $data['userpassword'] = $data['userpassword2'] = $pass->get('userpassword');
+        // Create mode
+        if ($add_mode) {
+            if (empty($data['userpassword'])) {
+                // Pre-populate password fields
+                $pass = $this->api->get('form_value.generate_userpassword');
+                $data['userpassword'] = $data['userpassword2'] = $pass->get('userpassword');
+            }
 
             // Page title
             $title = $this->translate('user.add');
         }
+        // Edit mode
         else {
             $title = $data['displayname'];
+
             // remove password
             $data['userpassword'] = '';
+
+            // Remove user type selector
+            unset($fields['system']['fields']['user_type_id']);
         }
 
         // Parse elements and add them to the form object
@@ -537,7 +547,7 @@ class kolab_client_task_user extends kolab_client_task
             'onclick' => "kadm.user_save()",
         ));
 
-        if (!$new) {
+        if (!$add_mode) {
             $user = $data['user'];
             $form->add_button(array(
                 'value'   => kolab_html::escape($this->translate('delete.button')),
@@ -545,6 +555,10 @@ class kolab_client_task_user extends kolab_client_task
             ));
         }
 
+        if (!empty($data['section'])) {
+            $form->activate_section($data['section']);
+        }
+
         return $form->output();
     }
 
diff --git a/lib/kolab_form.php b/lib/kolab_form.php
index ce0acc7..2e087f0 100644
--- a/lib/kolab_form.php
+++ b/lib/kolab_form.php
@@ -42,6 +42,7 @@ class kolab_form
     private $sections = array();
     private $buttons  = array();
     private $title;
+    private $active_section;
 
 
     /**
@@ -65,6 +66,17 @@ class kolab_form
         $this->sections[$index] = $legend;
     }
 
+
+    /**
+     * Activate form section.
+     *
+     * @param string $index   Section internal index
+     */
+    public function activate_section($index)
+    {
+        $this->active_section = $index;
+    }
+
     /**
      * Adds form element definition.
      *
@@ -123,8 +135,9 @@ class kolab_form
 
                 if (!empty($rows)) {
                     $content .= "\n" . kolab_html::fieldset(array(
-                        'legend' => $set,
-                        'content' => kolab_html::table(array('body' => $rows, 'class' => 'form'))
+                        'legend'  => $set,
+                        'content' => kolab_html::table(array('body' => $rows, 'class' => 'form')),
+                        'class'   => $this->active_section == $set_idx ? 'active' : '',
                     ));
                 }
             }
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 7e4839e..29801ef 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -531,10 +531,16 @@ function kolab_admin()
     this.command('user.list', {page: page});
   };
 
-  this.user_save = function()
+  this.user_save = function(reload, section)
   {
     var data = this.serialize_form('#'+this.env.form_id);
 
+    if (reload) {
+      data.section = section;
+      this.http_post('user.add', {data: data});
+      return;
+    }
+
     this.form_error_clear();
 
     // check password
diff --git a/public_html/skins/default/ui.js b/public_html/skins/default/ui.js
index 9a1b433..c55fb54 100644
--- a/public_html/skins/default/ui.js
+++ b/public_html/skins/default/ui.js
@@ -76,7 +76,11 @@ function init_tabs(id, current)
   if (!fs.length)
     return;
 
-  current = current ? current : 0;
+  // find active fieldset
+  if (!current) {
+    current = 0;
+    fs.each(function(idx) { if ($(this).hasClass('active')) { current = idx; return false; } });
+  }
 
   // first hide not selected tabs
   fs.each(function(idx) { if (idx != current) $(this).hide(); });


commit d0b98e875358a700e2837f8517d2fb6a6f9b9508
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Feb 24 12:12:28 2012 +0100

    Logout on invalid-session (403) response from the API

diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index f2271ba..7e4839e 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -355,6 +355,11 @@ function kolab_admin()
     if (!response || response.status != 'OK') {
       var msg = response && response.reason ? response.reason : this.t('servererror');
       this.display_message(msg, 'error');
+
+      // Logout on invalid-session error
+      if (response.code == 403)
+        this.main_logout();
+
       return false;
     }
 





More information about the commits mailing list