2 commits - lib/client

Aleksander Machniak machniak at kolabsys.com
Tue Sep 18 14:00:57 CEST 2012


 lib/client/kolab_client_task_settings.php |  331 ++++++++++++++++++++++++++++++
 1 file changed, 331 insertions(+)

New commits:
commit c0795a6e388c23a45095b407699c457e854df65d
Merge: 1fe531f f57bdca
Author: Aleksander Machniak <alec at alec.pl>
Date:   Tue Sep 18 14:00:47 2012 +0200

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



commit 1fe531f45013787ce7ee3df8c8801d86eff5e21d
Author: Aleksander Machniak <alec at alec.pl>
Date:   Tue Sep 18 14:00:24 2012 +0200

    Add lost file

diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
new file mode 100644
index 0000000..03e0a34
--- /dev/null
+++ b/lib/client/kolab_client_task_settings.php
@@ -0,0 +1,331 @@
+<?php
+/*
+ +--------------------------------------------------------------------------+
+ | This file is part of the Kolab Web Admin Panel                           |
+ |                                                                          |
+ | Copyright (C) 2011-2012, Kolab Systems AG                                |
+ |                                                                          |
+ | This program is free software: you can redistribute it and/or modify     |
+ | it under the terms of the GNU Affero General Public License as published |
+ | by the Free Software Foundation, either version 3 of the License, or     |
+ | (at your option) any later version.                                      |
+ |                                                                          |
+ | This program is distributed in the hope that it will be useful,          |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             |
+ | GNU Affero General Public License for more details.                      |
+ |                                                                          |
+ | You should have received a copy of the GNU Affero General Public License |
+ | along with this program. If not, see <http://www.gnu.org/licenses/>      |
+ +--------------------------------------------------------------------------+
+ | Author: Aleksander Machniak <machniak at kolabsys.com>                      |
+ +--------------------------------------------------------------------------+
+*/
+
+class kolab_client_task_settings extends kolab_client_task
+{
+    protected $ajax_only = true;
+
+    protected $menu = array(
+//        'user.info'  => 'settings.info',
+        'type_list'  => 'type.list',
+    );
+
+    /**
+     * Default action.
+     */
+    public function action_default()
+    {
+        $this->output->set_object('task_navigation', $this->menu());
+//        $this->output->set_object('content', 'settings', true);
+
+        $caps = $this->get_capability('actions');
+        if (!empty($caps['user.edit']) || !empty($caps['user.info'])) {
+            $this->action_info();
+        }
+        else {
+            $this->output->command('set_watermark', 'content');
+        }
+    }
+
+    /**
+     * Returns task menu output (overrides parent's menu method).
+     *
+     * @return string HTML output
+     */
+    protected function menu()
+    {
+        $caps = $this->capabilities();
+        $menu = array();
+
+        foreach ($this->menu as $idx => $label) {
+            if (!array_key_exists($idx, (array)$caps['actions'])) {
+                continue;
+            }
+
+            if (strpos($idx, '.')) {
+                $action = $idx;
+                $class  = preg_replace('/\.[a-z_-]+$/', '', $idx);
+            }
+            else {
+                $action = $task . '.' . $idx;
+                $class  = $idx;
+            }
+
+            $menu[$idx] = sprintf('<li class="%s">'
+                .'<a href="#%s" onclick="return kadm.command(\'%s\', \'\', this)">%s</a></li>',
+                $class, $idx, $action, $this->translate($label));
+        }
+
+        return '<ul>' . implode("\n", $menu) . '</ul>';
+    }
+
+    /**
+     * User info action.
+     */
+    public function action_info()
+    {
+        // Disable for directory manager (see #1025)
+        if (preg_match('/^cn=([a-z ]+)/i', $_SESSION['user']['id'])) {
+            $this->output->command('set_watermark', 'content');
+            return;
+        }
+
+        $_POST['id'] = $_SESSION['user']['id'];
+        $user_task    = new kolab_client_task_user($this->output);
+        $user_task->action_info();
+
+        $this->output->set_object('content', $this->output->get_object('taskcontent'));
+    }
+
+    /**
+     * Groups list action.
+     */
+    public function action_types_list()
+    {
+        $page_size = 20;
+        $page      = (int) self::get_input('page', 'POST');
+        if (!$page || $page < 1) {
+            $page = 1;
+        }
+
+        // request parameters
+        $post = array(
+            'attributes' => array('cn'),
+//            'sort_order' => 'ASC',
+            'sort_by'    => 'cn',
+            'page_size'  => $page_size,
+            'page'       => $page,
+        );
+
+        // 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('types.list', null, $post);
+        $count  = (int) $result->get('count');
+        $result = (array) $result->get('list');
+
+        // 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('type.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('type.list.records', $start, $end, $count)), true);
+            $prev = kolab_html::a(array(
+                'class' => 'prev' . ($prev ? '' : ' disabled'),
+                'href'  => '#',
+                'onclick' => $prev ? "kadm.command('type.list', {page: $prev})" : "return false",
+            ));
+            $next = kolab_html::a(array(
+                'class' => 'next' . ($next ? '' : ' disabled'),
+                'href'  => '#',
+                'onclick' => $next ? "kadm.command('type.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('type.info', '$idx')");
+                $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
+            }
+        }
+        else {
+            $rows[] = array('cells' => array(
+                0 => array('class' => 'empty-body', 'body' => $this->translate('type.norecords')
+            )));
+        }
+
+        $table = kolab_html::table(array(
+            'id'    => 'typelist',
+            'class' => 'list',
+            'head'  => $head,
+            'body'  => $rows,
+            'foot'  => $foot,
+        ));
+
+        $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->output->set_object('typelist', $table);
+    }
+
+    /**
+     * Group information (form) action.
+     */
+    public function action_type_info()
+    {
+        $id     = $this->get_input('id', 'POST');
+        $result = $this->api->get('type.info', array('type' => $id));
+        $type   = $result->get();
+        $output = $this->group_form(null, $type);
+
+        $this->output->set_object('taskcontent', $output);
+    }
+
+    /**
+     * Groups adding (form) action.
+     */
+    public function action_type_add()
+    {
+        $data   = $this->get_input('data', 'POST');
+        $output = $this->type_form(null, $data, true);
+
+        $this->output->set_object('taskcontent', $output);
+    }
+
+    /**
+     * Group edit/add form.
+     */
+    private function type_form($attribs, $data = array())
+    {
+        if (empty($attribs['id'])) {
+            $attribs['id'] = 'type-form';
+        }
+
+        // Form sections
+        $sections = array(
+            'props'   => 'type.properties',
+            'attribs' => 'type.attributes',
+        );
+
+        // field-to-section map and fields order
+        $fields_map = array(
+            'type_id'       => 'props',
+            'objectclasses' => 'props',
+            'type_id_name'  => 'attribs',
+        );
+
+        // Prepare fields
+        list($fields, $types, $type) = $this->form_prepare('type', $data);
+
+        $add_mode = empty($data['id']);
+
+        // Add type id selector
+        $fields['type_id'] = array(
+            'section'  => 'props',
+            'type'     => kolab_form::INPUT_HIDDEN,
+        );
+
+        // Create mode
+        if ($add_mode) {
+            // Page title
+            $title = $this->translate('type.add');
+        }
+        // Edit mode
+        else {
+            $title = $data['cn'];
+        }
+
+        // Create form object and populate with fields
+        $form = $this->form_create('type', $attribs, $sections, $fields, $fields_map, $data, $add_mode);
+
+        $form->set_title(kolab_html::escape($title));
+
+        $this->output->add_translation('type.add.success', 'type.edit.success', 'type.delete.success');
+
+        return $form->output();
+    }
+
+    /**
+     * Users search form.
+     *
+     * @return string HTML output of the form
+     */
+    public function search_form()
+    {
+        $form = new kolab_form(array('id' => 'search-form'));
+/*
+        $form->add_section('criteria', kolab_html::escape($this->translate('search.criteria')));
+        $form->add_element(array(
+            'section' => 'criteria',
+            'label'   => $this->translate('search.field'),
+            'name'    => 'field',
+            'type'    => kolab_form::INPUT_SELECT,
+            'options' => array(
+                'cn'   => kolab_html::escape($this->translate('search.name')),
+                'mail' => kolab_html::escape($this->translate('search.email')),
+            ),
+        ));
+        $form->add_element(array(
+            'section' => 'criteria',
+            'label'   => $this->translate('search.method'),
+            'name'    => 'method',
+            'type'    => kolab_form::INPUT_SELECT,
+            'options' => array(
+                'both'   => kolab_html::escape($this->translate('search.contains')),
+                'exact'  => kolab_html::escape($this->translate('search.is')),
+                'prefix' => kolab_html::escape($this->translate('search.prefix')),
+            ),
+        ));
+*/
+        return $form->output();
+    }
+
+}





More information about the commits mailing list