3 commits - lib/client lib/locale public_html/js public_html/skins

Aleksander Machniak machniak at kolabsys.com
Fri Mar 16 15:10:56 CET 2012


 lib/client/kolab_client_task_group.php |  235 ++++++++++++++++++++++++++++++---
 lib/locale/en_US.php                   |   11 +
 public_html/js/kolab_admin.js          |   38 +++++
 public_html/skins/default/style.css    |    5 
 4 files changed, 271 insertions(+), 18 deletions(-)

New commits:
commit 1f0b3a7a7dac41932e425a0d27345e07be566e3e
Merge: 2b622ff 72fa65e
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Mar 16 15:10:41 2012 +0100

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



commit 2b622ff7107d11ebe374fad034beda8f0c611d2a
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Mar 16 15:09:56 2012 +0100

    Group add/edit forms

diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index 23b9eb5..3d8c876 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -170,18 +170,123 @@ class kolab_client_task_group extends kolab_client_task
         $id     = $this->get_input('id', 'POST');
         $result = $this->api->get('group.info', array('group' => $id));
         $group  = $result->get($id);
+
         $group['group'] = $id;
+        $output = $this->group_form(null, $group);
 
-        $this->output->set_object('taskcontent', print_r($group, true));
+        $this->output->set_object('taskcontent', $output);
     }
 
-    public function group_add()
+    /**
+     * Group search action.
+     */
+    public function search_form()
     {
-    
+        return '';
     }
 
-    public function search_form()
+    /**
+     * Groups adding (form) action.
+     */
+    public function action_add()
     {
-        return '';
+        $data   = $this->get_input('data', 'POST');
+        $output = $this->group_form(null, $data, true);
+
+        $this->output->set_object('taskcontent', $output);
+    }
+
+    /**
+     * Group edit/add form.
+     */
+    private function group_form($attribs, $data = array())
+    {
+        if (empty($attribs['id'])) {
+            $attribs['id'] = 'group-form';
+        }
+
+        // Form sections
+        $sections = array(
+            'system'   => 'group.system',
+            'other'    => 'group.other',
+        );
+
+        // field-to-section map and fields order
+        $fields_map = array(
+            'group_type_id'       => 'system',
+            'group_type_id_name'  => 'system',
+            'cn'                  => 'system',
+            'gidnumber'           => 'system',
+            'mail'                => 'system',
+            'uniquemember'        => 'system',
+        );
+
+        // Prepare fields
+        list($fields, $types, $type) = $this->form_prepare('group', $data);
+
+        $add_mode  = empty($data['group']);
+        $accttypes = array();
+
+        foreach ($types as $idx => $elem) {
+            $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']);
+        }
+
+        // Add user type id selector
+        $fields['group_type_id'] = array(
+            'section'  => 'system',
+            'type'     => kolab_form::INPUT_SELECT,
+            'options'  => $accttypes,
+            'onchange' => "kadm.group_save(true, 'system')",
+        );
+
+        // Hide account type selector if there's only one type
+        if (count($accttypes) < 2 || !$add_mode) {
+            $fields['group_type_id']['type'] = kolab_form::INPUT_HIDDEN;
+        }
+
+        // Create mode
+        if ($add_mode) {
+            // Page title
+            $title = $this->translate('group.add');
+        }
+        // Edit mode
+        else {
+            $title = $data['cn'];
+
+            // Add user type name
+            $fields['group_type_id_name'] = array(
+                'label'    => 'group.group_type_id',
+                'section'  => 'system',
+                'value'    => $accttypes[$type]['content'],
+            );
+        }
+
+        // Create form object and populate with fields
+        $form = $this->form_create('group', $attribs, $sections, $fields, $fields_map, $data);
+
+        $form->set_title(kolab_html::escape($title));
+
+        $this->output->add_translation('group.add.success', 'group.delete.success');
+
+        return $form->output();
+    }
+
+    /**
+     * Returns list of group types.
+     *
+     * @return array List of group types
+     */
+    public function group_types()
+    {
+        if (!isset($_SESSION['group_types'])) {
+            $result = $this->api->post('group_types.list');
+            $list   = $result->get('list');
+
+            if (is_array($list)) {
+                $_SESSION['group_types'] = $list;
+            }
+        }
+
+        return $_SESSION['group_types'];
     }
 }
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index 2e7f4a8..efd7439 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -92,6 +92,14 @@ $LANG['group.add'] = 'Add Group';
 $LANG['group.norecords'] = 'No group records found!';
 $LANG['group.list'] = 'Groups List';
 $LANG['group.list.records'] = '$1 to $2 of $3';
+$LANG['group.cn'] = 'Common name';
+$LANG['group.mail'] = 'Primary Email Address';
+$LANG['group.group_type_id'] = 'Group type';
+$LANG['group.add.success'] = 'Group created successfully.';
+$LANG['group.delete.success'] = 'Group deleted successfully.';
+$LANG['group.gidnumber'] = 'Primary group number';
+$LANG['group.system'] = 'System';
+$LANG['group.other'] = 'Other';
 
 $LANG['MB'] = 'MB';
 $LANG['days'] = 'days';


commit a1b3f65163e80ec7e8bae0dbc57b9af0980c5c5d
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Mar 16 14:31:21 2012 +0100

    Groups UI

diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index 673bd90..23b9eb5 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -30,19 +30,25 @@ class kolab_client_task_group extends kolab_client_task
         'add'  => 'group.add',
     );
 
+    /**
+     * Default action.
+     */
     public function action_default()
     {
-        $this->output->set_object('content', '');
+        $this->output->set_object('content', 'group', true);
         $this->output->set_object('task_navigation', $this->menu());
 
         $this->action_list();
     }
 
+    /**
+     * Groups list action.
+     */
     public function action_list()
     {
         $page_size = 20;
         $page      = (int) self::get_input('page', 'POST');
-        if (!$page) {
+        if (!$page || $page < 1) {
             $page = 1;
         }
 
@@ -55,35 +61,127 @@ class kolab_client_task_group extends kolab_client_task
             'page'       => $page,
         );
 
-        $result = $this->api->get('groups.list');
+/*
+        // search parameters
+        if (!empty($_POST['search'])) {
+            $search = self::get_input('search', 'POST', true);
+            $field  = self::get_input('field',  'POST');
+            $method = self::get_input('method', 'POST');
+
+            $search_request = array(
+                $field => array(
+                    'value' => $search,
+                    'type'  => $method,
+                ),
+            );
+        }
+        else if (!empty($_POST['search_request'])) {
+            $search_request = self::get_input('search_request', 'POST');
+            $search_request = @unserialize(base64_decode($search_request));
+        }
+
+        if (!empty($search_request)) {
+            $post['search']          = $search_request;
+            $post['search_operator'] = 'OR';
+        }
+*/
+        // get groups list
+        $result = $this->api->post('groups.list', null, $post);
         $count  = (int) $result->get('count');
         $result = (array) $result->get('list');
 
-        foreach ($result as $idx => $item) {
-            if (!is_array($item) || empty($item['cn'])) {
-                unset($result[$idx]);
-                continue;
+        // calculate records
+        if ($count) {
+            $start = 1 + max(0, $page - 1) * $page_size;
+            $end   = min($start + $page_size - 1, $count);
+        }
+
+        $rows = $head = $foot = array();
+        $cols = array('name');
+        $i    = 0;
+
+        // table header
+        $head[0]['cells'][] = array('class' => 'name', 'body' => $this->translate('group.list'));
+
+        // table footer (navigation)
+        if ($count) {
+            $pages = ceil($count / $page_size);
+            $prev  = max(0, $page - 1);
+            $next  = $page < $pages ? $page + 1 : 0;
+
+            $count_str = kolab_html::span(array(
+                'content' => $this->translate('group.list.records', $start, $end, $count)), true);
+            $prev = kolab_html::a(array(
+                'class' => 'prev' . ($prev ? '' : ' disabled'),
+                'href'  => '#',
+                'onclick' => $prev ? "kadm.command('group.list', {page: $prev})" : "return false",
+            ));
+            $next = kolab_html::a(array(
+                'class' => 'next' . ($next ? '' : ' disabled'),
+                'href'  => '#',
+                'onclick' => $next ? "kadm.command('group.list', {page: $next})" : "return false",
+            ));
+
+            $foot_body = kolab_html::span(array('content' => $prev . $count_str . $next));
+        }
+        $foot[0]['cells'][] = array('class' => 'listnav', 'body' => $foot_body);
+
+        // table body
+        if (!empty($result)) {
+            foreach ($result as $idx => $item) {
+                if (!is_array($item) || empty($item['cn'])) {
+                    continue;
+                }
+
+                $i++;
+                $cells = array();
+                $cells[] = array('class' => 'name', 'body' => kolab_html::escape($item['cn']),
+                    'onclick' => "kadm.command('group.info', '$idx')");
+                $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
             }
-            $result[$idx] = sprintf('<li><a href="#" onclick="kadm.command(\'group.info\', \'%s\')">%s</a></li>',
-                $idx, $item['cn']);
         }
+        else {
+            $rows[] = array('cells' => array(
+                0 => array('class' => 'empty-body', 'body' => $this->translate('group.norecords')
+            )));
+        }
+
+        $table = kolab_html::table(array(
+            'id'    => 'grouplist',
+            'class' => 'list',
+            'head'  => $head,
+            'body'  => $rows,
+            'foot'  => $foot,
+        ));
 
-        $result = '<ul id="grouplist">' . implode("\n", $result) . '</ul>';
-        $this->output->set_object('content', $result);
+        $this->output->set_env('search_request', $search_request ? base64_encode(serialize($search_request)) : null);
+        $this->output->set_env('list_page', $page);
+        $this->output->set_env('list_count', $count);
+
+        $this->watermark('taskcontent');
+        $this->output->set_object('grouplist', $table);
     }
 
+    /**
+     * Group information (form) action.
+     */
     public function action_info()
     {
-
         $id     = $this->get_input('id', 'POST');
         $result = $this->api->get('group.info', array('group' => $id));
+        $group  = $result->get($id);
+        $group['group'] = $id;
 
-        $group = $result->get($id);
-        $this->output->set_object('content', print_r($group, true));
+        $this->output->set_object('taskcontent', print_r($group, true));
     }
 
     public function group_add()
     {
     
     }
+
+    public function search_form()
+    {
+        return '';
+    }
 }
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index 49cdb79..2e7f4a8 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -89,6 +89,9 @@ $LANG['user.shell'] = 'Shell';
 $LANG['user.uidnumber'] = 'User ID number';
 
 $LANG['group.add'] = 'Add Group';
+$LANG['group.norecords'] = 'No group records found!';
+$LANG['group.list'] = 'Groups List';
+$LANG['group.list.records'] = '$1 to $2 of $3';
 
 $LANG['MB'] = 'MB';
 $LANG['days'] = 'days';
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 69bab51..5bddf5d 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -577,6 +577,44 @@ function kolab_admin()
     this.display_message('user.add.success');
     this.command('user.list', {page: this.env.list_page});
   };
+
+  this.group_info = function(id)
+  {
+    this.http_post('group.info', {id: id});
+  };
+
+  this.group_list = function(props)
+  {
+    if (!props)
+      props = {};
+
+    if (props.search === undefined && this.env.search_request)
+      props.search_request = this.env.search_request;
+
+    this.http_post('group.list', props);
+  };
+
+  this.group_delete = function(groupid)
+  {
+    this.set_busy(true, 'deleting');
+    this.api_post('group.delete', {group: userid}, 'group_delete_response');
+  };
+
+  this.group_delete_response = function(response)
+  {
+    if (!this.api_response(response))
+      return;
+
+    var page = this.env.list_page;
+
+    // goto previous page if last user on the current page has been deleted
+    if (this.env.list_count)
+      page -= 1;
+
+    this.display_message('group.delete.success');
+    this.command('group.list', {page: page});
+  };
+
 };
 
 var kadm = new kolab_admin();
diff --git a/public_html/skins/default/style.css b/public_html/skins/default/style.css
index ba6247a..96cfa30 100644
--- a/public_html/skins/default/style.css
+++ b/public_html/skins/default/style.css
@@ -722,8 +722,9 @@ fieldset.tabbed
   vertical-align: top;
 }
 
-/**** User task elements ****/
+/**** User/Group task elements ****/
 
-#userlist table {
+#userlist table,
+#grouplist table {
   width: 100%;
 }





More information about the commits mailing list