8 commits - lib/api lib/Auth lib/client lib/kolab_client_task.php lib/locale public_html/js public_html/skins

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Fri May 25 10:26:16 CEST 2012


 lib/Auth/LDAP.php                                 |    2 
 lib/api/kolab_api_service_form_value.php          |    4 
 lib/client/kolab_client_task_main.php             |    1 
 lib/client/kolab_client_task_resource.php         |  329 ++++++++++++++++++++++
 lib/kolab_client_task.php                         |   31 ++
 lib/locale/en_US.php                              |   17 +
 public_html/js/kolab_admin.js                     |   78 +++++
 public_html/skins/default/templates/resource.html |   17 +
 8 files changed, 475 insertions(+), 4 deletions(-)

New commits:
commit c40c756848245c66ac6306c71a66f2267914a9ed
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri May 25 09:25:59 2012 +0100

    Add resources.default task to menu

diff --git a/lib/client/kolab_client_task_main.php b/lib/client/kolab_client_task_main.php
index 09b0991..5af9754 100644
--- a/lib/client/kolab_client_task_main.php
+++ b/lib/client/kolab_client_task_main.php
@@ -27,6 +27,7 @@ class kolab_client_task_main extends kolab_client_task
     protected $menu = array(
         'user.default'      => 'menu.users',
         'group.default'     => 'menu.groups',
+        'resource.default'  => 'menu.resources',
         'domain.default'    => 'menu.domains',
         'role.default'      => 'menu.roles',
         'about.default'     => 'menu.about',


commit 3444f2cc8b4529af58124268ebe46269020f332f
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri May 25 09:25:45 2012 +0100

    Add JavaScript functions for resource management

diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 84f5384..d6f0927 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1245,6 +1245,84 @@ function kolab_admin()
     this.command('group.list', {page: this.env.list_page});
   };
 
+  this.resource_info = function(id)
+  {
+    this.http_post('resource.info', {id: id});
+  };
+
+  this.resource_list = function(props)
+  {
+    if (!props)
+      props = {};
+
+    if (props.search === undefined && this.env.search_request)
+      props.search_request = this.env.search_request;
+
+    this.http_post('resource.list', props);
+  };
+
+  this.resource_delete = function(resourceid)
+  {
+    this.set_busy(true, 'deleting');
+    this.api_post('resource.delete', {resource: resourceid}, 'resource_delete_response');
+  };
+
+  this.resource_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('resource.delete.success');
+    this.command('resource.list', {page: page});
+  };
+
+  this.resource_save = function(reload, section)
+  {
+    var data = this.serialize_form('#'+this.env.form_id),
+      action = data.id ? 'edit' : 'add';
+
+    if (reload) {
+      data.section = section;
+      this.http_post('resource.' + action, {data: data});
+      return;
+    }
+
+    this.form_error_clear();
+
+    if (!this.check_required_fields(data)) {
+      this.display_message('form.required.empty', 'error');
+      return;
+    }
+
+    this.set_busy(true, 'saving');
+    this.api_post('resource.' + action, data, 'resource_' + action + '_response');
+  };
+
+  this.resource_add_response = function(response)
+  {
+    if (!this.api_response(response))
+      return;
+
+    this.display_message('resource.add.success');
+    this.command('resource.list', {page: this.env.list_page});
+  };
+
+  this.resource_edit_response = function(response)
+  {
+    if (!this.api_response(response))
+      return;
+
+    this.display_message('resource.edit.success');
+    this.command('resource.list', {page: this.env.list_page});
+  };
+
+
   this.generate_password = function(fieldname)
   {
     this.env.password_field = fieldname;


commit 81768b237abb7dc099eca3072ffd00ce5dee87cb
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri May 25 09:25:31 2012 +0100

    Add resource management client interface smarty template

diff --git a/public_html/skins/default/templates/resource.html b/public_html/skins/default/templates/resource.html
new file mode 100644
index 0000000..b2adf2f
--- /dev/null
+++ b/public_html/skins/default/templates/resource.html
@@ -0,0 +1,17 @@
+<div id="toc" class="resource">
+    <div id="search">
+        <div class="searchinput">
+            <input type="text" id="searchinput" name="search" value="{$engine->translate('search')}" />
+            <script type="text/javascript">search_init('resource')</script>
+            <span class="searchactions">
+                <span id="search-details" title="{$engine->translate('search.criteria')}" onclick="search_details()"></span>
+                <span id="search-reset" title="{$engine->translate('search.reset')}" onclick="search_reset()"></span>
+            </span>
+        </div>
+        <div class="searchdetails">{$engine->search_form()}</div>
+    </div>
+    <div id="resourcelist"></div>
+</div>
+<div class="vsplitter"> </div>
+<div id="taskcontent" class="resource"></div>
+<div class="clear"></div>


commit 044500826704ad7ff55034e123049e96dbb1517f
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri May 25 09:25:11 2012 +0100

    Disable console() messages

diff --git a/lib/client/kolab_client_task_resource.php b/lib/client/kolab_client_task_resource.php
new file mode 100644
index 0000000..5e3f7a2
--- /dev/null
+++ b/lib/client/kolab_client_task_resource.php
@@ -0,0 +1,329 @@
+<?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_resource extends kolab_client_task
+{
+    protected $ajax_only = true;
+
+    protected $menu = array(
+        'add'  => 'resource.add',
+    );
+
+    /**
+     * Default action.
+     */
+    public function action_default()
+    {
+        $this->output->set_object('content', 'resource', true);
+        $this->output->set_object('task_navigation', $this->menu());
+
+        $this->action_list();
+    }
+
+    /**
+     * Users list action.
+     */
+    public function action_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'    => array('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 resources list
+        $result = $this->api->post('resources.list', null, $post);
+        $count  = $result->get('count');
+        $result = (array) $result->get('list');
+
+        //console($result);
+
+        // 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('resource.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('resource.list.records', $start, $end, $count)), true);
+            $prev = kolab_html::a(array(
+                'class' => 'prev' . ($prev ? '' : ' disabled'),
+                'href'  => '#',
+                'onclick' => $prev ? "kadm.command('resource.list', {page: $prev})" : "return false",
+            ));
+            $next = kolab_html::a(array(
+                'class' => 'next' . ($next ? '' : ' disabled'),
+                'href'  => '#',
+                'onclick' => $next ? "kadm.command('resource.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('resource.info', '$idx')");
+                $rows[] = array('id' => $i, 'class' => 'selectable', 'cells' => $cells);
+            }
+        }
+        else {
+            $rows[] = array('cells' => array(
+                0 => array('class' => 'empty-body', 'body' => $this->translate('resource.norecords')
+            )));
+        }
+
+        $table = kolab_html::table(array(
+            'id'    => 'resourcelist',
+            '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->watermark('taskcontent');
+        $this->output->set_object('resourcelist', $table);
+    }
+
+    /**
+     * Resource adding (form) action.
+     */
+    public function action_add()
+    {
+        $data   = $this->get_input('data', 'POST');
+        $output = $this->resource_form(null, $data, true);
+
+        $this->output->set_object('taskcontent', $output);
+    }
+
+    /**
+     * Resource information (form) action.
+     */
+    public function action_info()
+    {
+        $id         = $this->get_input('id', 'POST');
+        $result     = $this->api->get('resource.info', array('resource' => $id));
+        $resource   = $result->get();
+
+        //console("action_info()", $resource);
+
+        $output     = $this->resource_form(null, $resource);
+
+        $this->output->set_object('taskcontent', $output);
+    }
+
+    private function resource_form($attribs, $data = array())
+    {
+        if (empty($attribs['id'])) {
+            $attribs['id'] = 'resource-form';
+        }
+
+        //console("resource_form(\$attribs, \$data)", $attribs, $data);
+
+        // Form sections
+        $sections = array(
+            'system'        => 'resource.system',
+            'other'         => 'resource.other',
+        );
+
+        // field-to-section map and fields order
+        $fields_map = array(
+            'type_id'                   => 'system',
+            'type_id_name'              => 'system',
+
+            'cn'                        => 'system',
+            'ou'                        => 'system',
+            'preferredlanguage'         => 'system',
+
+            'mail'                      => 'system',
+            'alias'                     => 'system',
+            'mailalternateaddress'      => 'system',
+
+            'member'                    => 'system',
+            'uniquemember'              => 'system',
+            'memberurl'                 => 'system',
+
+            'nsrole'                    => 'system',
+            'nsroledn'                  => 'system',
+
+            /* Kolab Settings */
+            'kolabhomeserver'           => 'system',
+            'mailhost'                  => 'system',
+            'mailquota'                 => 'system',
+            'kolabfreebusyfuture'       => 'system',
+            'kolabinvitationpolicy'     => 'system',
+            'kolabdelegate'             => 'system',
+            'kolaballowsmtprecipient'   => 'system',
+            'kolaballowsmtpsender'      => 'system',
+        );
+
+        // Prepare fields
+        list($fields, $types, $type) = $this->form_prepare('resource', $data);
+
+        //console("Result from form_prepare", $fields, $types, $type);
+
+        $add_mode  = empty($data['id']);
+        $accttypes = array();
+
+        foreach ($types as $idx => $elem) {
+            $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']);
+        }
+
+        // Add resource type id selector
+        $fields['type_id'] = array(
+            'section'  => 'system',
+            'type'     => kolab_form::INPUT_SELECT,
+            'options'  => $accttypes,
+            'onchange' => "kadm.resource_save(true, 'system')",
+        );
+
+        //console($accttypes);
+
+        // Hide account type selector if there's only one type
+        if (count($accttypes) < 2 || !$add_mode) {
+            //console("setting type_id form type to hidden");
+            $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN;
+        }
+
+        // Create mode
+        if ($add_mode) {
+            // Page title
+            $title = $this->translate('resource.add');
+        }
+        // Edit mode
+        else {
+            $title = $data['cn'];
+
+            // Add resource type name
+            $fields['type_id_name'] = array(
+                'label'    => 'resource.type_id',
+                'section'  => 'system',
+                'value'    => $accttypes[$type]['content'],
+            );
+        }
+
+        // Create form object and populate with fields
+        $form = $this->form_create('resource', $attribs, $sections, $fields, $fields_map, $data, $add_mode);
+
+        $form->set_title(kolab_html::escape($title));
+
+        $this->output->add_translation('resource.add.success', 'resource.edit.success', 'resource.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')),
+                'email' => kolab_html::escape($this->translate('search.email')),
+                'uid'   => kolab_html::escape($this->translate('search.uid')),
+            ),
+        ));
+        $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();
+    }
+
+}


commit de05c6a4b97492fe0f178f422841355c9a32648e
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri May 25 09:24:54 2012 +0100

    Disable console() messages

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index a737277..8c46ba7 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -403,7 +403,7 @@ class kolab_api_service_form_value extends kolab_api_service
             }
 
             $resourcedata = kolab_recipient_policy::normalize_groupdata($postdata);
-            console("normalized resource data", $resourcedata);
+            //console("normalized resource data", $resourcedata);
 
             // TODO: Normalize $postdata
             $mail_local = 'resource-' . $object_type_key . '-' . strtolower($resourcedata['cn']);
@@ -895,7 +895,7 @@ class kolab_api_service_form_value extends kolab_api_service
 
         $data['attributes'] = array('cn');
 
-        console("api/form_value._list_options_resources() searching with data", $data);
+        //console("api/form_value._list_options_resources() searching with data", $data);
 
         $service = $this->controller->get_service('resources');
         $result  = $service->resources_list(null, $data);


commit fe63e4b621e160d666d591a7ba54f5ecab263e6a
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri May 25 09:24:38 2012 +0100

    Disable console() messages

diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index f30f38a..799dfa9 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -1937,7 +1937,7 @@ class LDAP
         }
 
         if (($entries = ldap_get_entries($this->conn, $search_results)) == false) {
-            console("Could not get the results of the search: " . $this->_errstr());
+            //console("Could not get the results of the search: " . $this->_errstr());
             return false;
         }
 


commit 1c22ba25e2022490414a5c4025f68e3d6cf28a40
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri May 25 09:24:04 2012 +0100

    Add labels for resource interface items

diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index ee5dca9..c647c80 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -56,12 +56,29 @@ $LANG['menu.domains'] = 'Domains';
 $LANG['menu.groups'] = 'Groups';
 $LANG['menu.kolab'] = 'Kolab';
 $LANG['menu.kolabsys'] = 'Kolab Systems';
+$LANG['menu.resources'] = 'Resources';
 $LANG['menu.technology'] = 'Technology';
 $LANG['menu.users'] = 'Users';
 
 $LANG['modifiersname'] = 'Modified by';
 $LANG['password.generate'] = 'Generate password';
 $LANG['reqtime'] = 'Request time: $1 sec.';
+
+$LANG['resource.add'] = 'Add Resource';
+$LANG['resource.add.success'] = 'Added Resource';
+$LANG['resource.cn'] = 'Name';
+$LANG['resource.delete'] = 'Delete Resource';
+$LANG['resource.delete.success'] = 'Successfully deleted Resource';
+$LANG['resource.edit'] = 'Edit Resource';
+$LANG['resource.edit.success'] = 'Successfully updated Resource';
+$LANG['resource.kolabtargetfolder'] = 'Target Folder';
+$LANG['resource.list.records'] = '$1 to $2 of $3';
+$LANG['resource.mail'] = 'Mail Address';
+$LANG['resource.other'] = 'Other';
+$LANG['resource.system'] = 'System';
+$LANG['resource.type_id'] = 'Resource Type';
+$LANG['resource.uniquemember'] = 'Collection Members';
+
 $LANG['saving'] = 'Saving data...';
 
 $LANG['search'] = 'Search';


commit 949997ac177681b07ea3dbbdceb2ed445e906cbf
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri May 25 09:23:42 2012 +0100

    Add function for resource types

diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 652cfa2..ec11136 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -498,6 +498,31 @@ class kolab_client_task
     }
 
     /**
+     * Returns list of resource types.
+     *
+     * @return array List of resource types
+     */
+    protected function resource_types()
+    {
+
+        if (isset($_SESSION['resource_types'])) {
+            return $_SESSION['resource_types'];
+        }
+
+
+        $result = $this->api->post('resource_types.list');
+        $list   = $result->get('list');
+
+
+        if (is_array($list) && !$this->config_get('devel_mode')) {
+            $_SESSION['resource_types'] = $list;
+        }
+
+        return $list;
+    }
+
+
+    /**
      * Returns list of user types.
      *
      * @return array List of user types
@@ -744,6 +769,8 @@ class kolab_client_task
      */
     protected function form_prepare($name, &$data, $extra_fields = array())
     {
+        //console("Preparing form for $name with data", $data);
+
         $types        = (array) $this->{$name . '_types'}();
 
         //console("form_prepare types", $types);
@@ -944,6 +971,7 @@ class kolab_client_task
                     $data[$fname] = (array) $data[$fname];
                 }
 
+                //console("The data for field $fname at this point is", $data[$fname]);
                 // request parameters
                 $post = array(
                     'list'        => $data[$fname],
@@ -957,6 +985,7 @@ class kolab_client_task
                 $result = $result->get('list');
 
                 $data[$fname] = $result;
+                //console("Set \$data['$fname'] to", $result);
             }
         }
 
@@ -986,7 +1015,7 @@ class kolab_client_task
      */
     protected function form_create($name, $attribs, $sections, $fields, $fields_map, $data, $add_mode)
     {
-        //console("Creating form for $name");
+        //console("Creating form for $name with data", $data);
 
         //console("Assign fields to sections", $fields);
         // Assign sections to fields





More information about the commits mailing list