diff options
author | Aleksander Machniak <machniak@kolabsys.com> | 2017-11-24 10:35:34 +0000 |
---|---|---|
committer | Aleksander Machniak <machniak@kolabsys.com> | 2017-11-24 10:35:34 +0000 |
commit | d9e1ef57277d8ffa022365eb2497e49428d3aa7e (patch) | |
tree | da9dbf223daeb3359a4cdf96485ade9985882046 | |
parent | 9f4605eae5f0dfb17fd4267d1072b5f79771e705 (diff) | |
download | webadmin-d9e1ef57277d8ffa022365eb2497e49428d3aa7e.tar.gz |
Add possibility to clone object types (Bifrost#T57633)
-rw-r--r-- | lib/client/kolab_client_task_settings.php | 80 | ||||
-rw-r--r-- | lib/kolab_client_task.php | 11 | ||||
-rw-r--r-- | public_html/js/kolab_admin.js | 13 |
3 files changed, 72 insertions, 32 deletions
diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php index 0c5b9b3..d811f1e 100644 --- a/lib/client/kolab_client_task_settings.php +++ b/lib/client/kolab_client_task_settings.php @@ -166,7 +166,7 @@ class kolab_client_task_settings extends kolab_client_task } /** - * Groups list action. + * Object types list action. */ public function action_type_list() { @@ -342,12 +342,50 @@ class kolab_client_task_settings extends kolab_client_task } /** - * Group information (form) action. + * Object type information (form) action. */ public function action_type_info() { - $id = $this->get_input('id', 'POST'); - $data = array(); + $id = $this->get_input('id', 'POST'); + $result = $this->read_type_data($id); + + $output = $this->type_form($result['attribs'], $result['data']); + + $this->output->set_object('taskcontent', $output); + } + + /** + * Object type adding (form) action. + */ + public function action_type_add() + { + if ($clone_id = $this->get_input('clone_id', 'POST')) { + $result = $this->read_type_data($clone_id); + $data = $result['data']; + + unset($data['id'], $data['is_default'], $data['key'], $data['name']); + } + + if (empty($data)) { + $data = $this->get_input('data', 'POST'); + + if (empty($data['type'])) { + $data['type'] = self::get_input('type', 'POST'); + if (empty($data['type']) || !in_array($data['type'], $this->object_types)) { + $data['type'] = 'user'; + } + } + } + + $output = $this->type_form(null, $data, true); + + $this->output->set_object('taskcontent', $output); + } + + private function read_type_data($id, $clone = false) + { + $data = array(); + $attribs = array(); list($type, $idx) = explode(':', $id); @@ -364,30 +402,20 @@ class kolab_client_task_settings extends kolab_client_task $data['objectclass'] = $data['attributes']['fields']['objectclass']; unset($data['attributes']['fields']['objectclass']); - } - - $output = $this->type_form(null, $data); - - $this->output->set_object('taskcontent', $output); - } - - /** - * Groups adding (form) action. - */ - public function action_type_add() - { - $data = $this->get_input('data', 'POST'); - if (empty($data['type'])) { - $data['type'] = self::get_input('type', 'POST'); - if (empty($data['type']) || !in_array($data['type'], $this->object_types)) { - $data['type'] = 'user'; + // enable Clone button + if (!$clone) { + $caps_actions = $this->get_capability('actions'); + if (!empty($caps_actions['type.add'])) { + $attribs = array('clone-button' => 'settings.type_clone'); + } } } - $output = $this->type_form(null, $data, true); - - $this->output->set_object('taskcontent', $output); + return array( + 'data' => $data, + 'attribs' => $attribs, + ); } /** @@ -395,6 +423,10 @@ class kolab_client_task_settings extends kolab_client_task */ private function type_form($attribs, $data = array()) { + if (!is_array($attribs)) { + $attribs = array(); + } + if (empty($attribs['id'])) { $attribs['id'] = 'type-form'; } diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php index 363ceb0..5365b51 100644 --- a/lib/kolab_client_task.php +++ b/lib/kolab_client_task.php @@ -1477,7 +1477,7 @@ class kolab_client_task )); } - // add delete button + // add Delete button if ($this->is_deletable($data)) { $id = $data['id']; $form->add_button(array( @@ -1486,6 +1486,15 @@ class kolab_client_task )); } + // add Clone button + if (!empty($attribs['clone-button'])) { + $id = $data['id']; + $form->add_button(array( + 'value' => kolab_html::escape($this->translate('button.clone')), + 'onclick' => "kadm.command('{$attribs['clone-button']}', '{$id}')", + )); + } + $ac_min_len = $this->config_get('autocomplete_min_length', 1, Conf::INT); $this->output->set_env('form_id', $attribs['id']); diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js index 249da95..368557a 100644 --- a/public_html/js/kolab_admin.js +++ b/public_html/js/kolab_admin.js @@ -2595,6 +2595,11 @@ function kolab_admin() this.http_post('settings.type_add', {type: $('#type_list_filter').val()}); }; + this.settings_type_clone = function(id) + { + this.http_post('settings.type_add', {type: $('#type_list_filter').val(), clone_id: id}); + }; + this.settings_type_list = function(props) { if (!props) @@ -3433,13 +3438,7 @@ function kolab_admin() if (str.charAt(0) == '"') str = str.replace(/^"/, '').replace(/"$/, '') - .replace(/\\(.?)/g, function(s, n1) { - switch (n1) { - case '\\': - return '\\'; - return n1; - } - }); + .replace(/\\(.?)/g, function(s, n1) { return n1; }); return str; }; |