diff options
author | Aleksander Machniak <machniak@kolabsys.com> | 2014-09-04 17:01:21 (GMT) |
---|---|---|
committer | Aleksander Machniak <machniak@kolabsys.com> | 2014-09-04 17:01:21 (GMT) |
commit | 7c810d56e2acfd438805f3ba93e8a428ea7d8b59 (patch) | |
tree | 1485364d6afb39fa57832ab89e029c7a71fb38cc | |
parent | d10faf6e13c4aab377196f82ce63d6dca4427951 (diff) | |
download | kolab-wap-7c810d56e2acfd438805f3ba93e8a428ea7d8b59.tar.gz |
Fixed race conditions between generate and save requests (#1908)
Moved some shared code to form_create() and form_prepare() methods, fixed small issues.
-rw-r--r-- | lib/client/kolab_client_task_domain.php | 45 | ||||
-rw-r--r-- | lib/client/kolab_client_task_group.php | 42 | ||||
-rw-r--r-- | lib/client/kolab_client_task_ou.php | 37 | ||||
-rw-r--r-- | lib/client/kolab_client_task_resource.php | 60 | ||||
-rw-r--r-- | lib/client/kolab_client_task_role.php | 48 | ||||
-rw-r--r-- | lib/client/kolab_client_task_sharedfolder.php | 49 | ||||
-rw-r--r-- | lib/client/kolab_client_task_signup.php | 28 | ||||
-rw-r--r-- | lib/client/kolab_client_task_user.php | 36 | ||||
-rw-r--r-- | lib/kolab_client_task.php | 54 | ||||
-rw-r--r-- | public_html/js/kolab_admin.js | 4 |
10 files changed, 78 insertions, 325 deletions
diff --git a/lib/client/kolab_client_task_domain.php b/lib/client/kolab_client_task_domain.php index 5c23e8a..22cce3d 100644 --- a/lib/client/kolab_client_task_domain.php +++ b/lib/client/kolab_client_task_domain.php @@ -78,14 +78,9 @@ class kolab_client_task_domain extends kolab_client_task public function action_info() { $id = $this->get_input('id', 'POST'); - //console("action_info() on", $id); $result = $this->api_get('domain.info', array('id' => $id)); - //console("action_info() \$result", $result); - $domain = $result->get(); - //console("action_info() \$domain", $domain); - $output = $this->domain_form(array_keys($domain), $domain); $this->output->set_object('taskcontent', $output); @@ -125,32 +120,9 @@ class kolab_client_task_domain extends kolab_client_task 'inetdomainstatus' => 'system', ); - //console("domain_form() \$data", $data); - // Prepare fields - list($fields, $types, $type) = $this->form_prepare('domain', $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 domain type id selector - $fields['type_id'] = array( - 'section' => 'system', - 'type' => kolab_form::INPUT_SELECT, - 'options' => $accttypes, - 'onchange' => "kadm.domain_save(true, 'system')", - ); - - // Hide account type selector if there's only one type - if (count($accttypes) < 2 || !$add_mode) { - $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN; - } + $form = $this->form_prepare('domain', $data, array(), null, $fields_map['type_id']); + list($fields, $types, $type, $add_mode) = $form; // Create mode if ($add_mode) { @@ -169,21 +141,10 @@ class kolab_client_task_domain extends kolab_client_task else { $title = $data['associateddomain'][0]; } - - // Add domain type name - $fields['type_id_name'] = array( - 'label' => 'domain.type_id', - 'section' => 'system', - 'value' => $accttypes[$type]['content'], - ); } // Create form object and populate with fields - $form = $this->form_create('domain', $attribs, $sections, $fields, $fields_map, $data, $add_mode); - - //console("domain_form() \$form", $form); - - $form->set_title(kolab_html::escape($title)); + $form = $this->form_create('domain', $attribs, $sections, $fields, $fields_map, $data, $add_mode, $title); return $form->output(); } diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php index b442a4c..697cdb3 100644 --- a/lib/client/kolab_client_task_group.php +++ b/lib/client/kolab_client_task_group.php @@ -104,50 +104,12 @@ class kolab_client_task_group extends kolab_client_task ); // Prepare fields - list($fields, $types, $type) = $this->form_prepare('group', $data); - - $add_mode = empty($data['id']); - $accttypes = array(); - - foreach ($types as $idx => $elem) { - $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']); - } - - // Add user type id selector - $fields['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['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['type_id_name'] = array( - 'label' => 'group.type_id', - 'section' => 'system', - 'value' => $accttypes[$type]['content'], - ); - } + $form = $this->form_prepare('group', $data, array(), null, $fields_map['type_id']); + list($fields, $types, $type, $add_mode) = $form; // Create form object and populate with fields $form = $this->form_create('group', $attribs, $sections, $fields, $fields_map, $data, $add_mode); - $form->set_title(kolab_html::escape($title)); - return $form->output(); } diff --git a/lib/client/kolab_client_task_ou.php b/lib/client/kolab_client_task_ou.php index 1cddeff..6179518 100644 --- a/lib/client/kolab_client_task_ou.php +++ b/lib/client/kolab_client_task_ou.php @@ -152,36 +152,14 @@ class kolab_client_task_ou extends kolab_client_task ); // Prepare fields - list($fields, $types, $type) = $this->form_prepare('ou', $data); - - $add_mode = empty($data['id']); - $accttypes = array(); - - foreach ($types as $idx => $elem) { - $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']); - } - - // Add OU type id selector - $fields['type_id'] = array( - 'section' => 'system', - 'type' => kolab_form::INPUT_SELECT, - 'options' => $accttypes, - 'onchange' => "kadm.ou_save(true, 'system')", - ); - - // 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; - } - - $ou_roots = array_merge(array(''), $this->ou_list()); + $form = $this->form_prepare('ou', $data, array(), null, $fields_map['type_id']); + list($fields, $types, $type, $add_mode) = $form; // Add OU root selector $fields['base_dn'] = array( - 'section' => 'system', + 'section' => $fields_map['base_dn'], 'type' => kolab_form::INPUT_SELECT, - 'options' => $ou_roots, + 'options' => array_merge(array(''), $this->ou_list()), 'escaped' => true, 'default' => $data['base_dn'], ); @@ -194,13 +172,6 @@ class kolab_client_task_ou extends kolab_client_task // Edit mode else { $title = $data['ou']; - - // Add OU type name - $fields['type_id_name'] = array( - 'label' => 'ou.type_id', - 'section' => 'system', - 'value' => $accttypes[$type]['content'], - ); } // Create form object and populate with fields diff --git a/lib/client/kolab_client_task_resource.php b/lib/client/kolab_client_task_resource.php index cfea9bd..d24eb85 100644 --- a/lib/client/kolab_client_task_resource.php +++ b/lib/client/kolab_client_task_resource.php @@ -68,13 +68,10 @@ class kolab_client_task_resource extends kolab_client_task */ public function action_info() { - $id = $this->get_input('id', 'POST'); - $result = $this->api_get('resource.info', array('id' => $id)); - $resource = $result->get(); - - //console("action_info()", $resource); - - $output = $this->resource_form(null, $resource); + $id = $this->get_input('id', 'POST'); + $result = $this->api_get('resource.info', array('id' => $id)); + $resource = $result->get(); + $output = $this->resource_form(null, $resource); $this->output->set_object('taskcontent', $output); } @@ -85,8 +82,6 @@ class kolab_client_task_resource extends kolab_client_task $attribs['id'] = 'resource-form'; } - //console("resource_form(\$attribs, \$data)", $attribs, $data); - // Form sections $sections = array( 'system' => 'resource.system', @@ -125,55 +120,12 @@ class kolab_client_task_resource extends kolab_client_task ); // 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'], - ); - } + $form = $this->form_prepare('resource', $data, array(), null, $fields_map['type_id']); + list($fields, $types, $type, $add_mode) = $form; // 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)); - return $form->output(); } } diff --git a/lib/client/kolab_client_task_role.php b/lib/client/kolab_client_task_role.php index 7ff4256..7d70f39 100644 --- a/lib/client/kolab_client_task_role.php +++ b/lib/client/kolab_client_task_role.php @@ -59,7 +59,7 @@ class kolab_client_task_role extends kolab_client_task { $id = $this->get_input('id', 'POST'); $result = $this->api_get('role.info', array('id' => $id)); - $role = $result->get(); + $role = $result->get(); $output = $this->role_form(null, $role); $this->output->set_object('taskcontent', $output); @@ -99,55 +99,13 @@ class kolab_client_task_role extends kolab_client_task 'description' => 'system', ); - //console("role_form \$data", $data); - // Prepare fields - list($fields, $types, $type) = $this->form_prepare('role', $data); - - //console("role_form \$types", $types); - - $add_mode = empty($data['id']); - $accttypes = array(); - - foreach ($types as $idx => $elem) { - $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']); - } - - // Add user type id selector - $fields['type_id'] = array( - 'section' => 'system', - 'type' => kolab_form::INPUT_SELECT, - 'options' => $accttypes, - 'onchange' => "kadm.role_save(true, 'system')", - ); - - // Hide account type selector if there's only one type - if (count($accttypes) < 2 || !$add_mode) { - $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN; - } - - // Create mode - if ($add_mode) { - // Page title - $title = $this->translate('role.add'); - } - // Edit mode - else { - $title = $data['cn']; - - // Add user type name - $fields['type_id_name'] = array( - 'label' => 'role.type_id', - 'section' => 'system', - 'value' => $accttypes[$type]['content'], - ); - } + $form = $this->form_prepare('role', $data, array(), null, $fields_map['type_id']); + list($fields, $types, $type, $add_mode) = $form; // Create form object and populate with fields $form = $this->form_create('role', $attribs, $sections, $fields, $fields_map, $data, $add_mode); - $form->set_title(kolab_html::escape($title)); - return $form->output(); } diff --git a/lib/client/kolab_client_task_sharedfolder.php b/lib/client/kolab_client_task_sharedfolder.php index e2d4d18..b02e007 100644 --- a/lib/client/kolab_client_task_sharedfolder.php +++ b/lib/client/kolab_client_task_sharedfolder.php @@ -82,8 +82,6 @@ class kolab_client_task_sharedfolder extends kolab_client_task $attribs['id'] = 'sharedfolder-form'; } - //console("sharedfolder_form(\$attribs, \$data)", $attribs, $data); - // Form sections $sections = array( 'system' => 'sharedfolder.system', @@ -122,55 +120,12 @@ class kolab_client_task_sharedfolder extends kolab_client_task ); // Prepare fields - list($fields, $types, $type) = $this->form_prepare('sharedfolder', $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 sharedfolder type id selector - $fields['type_id'] = array( - 'section' => 'system', - 'type' => kolab_form::INPUT_SELECT, - 'options' => $accttypes, - 'onchange' => "kadm.sharedfolder_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('sharedfolder.add'); - } - // Edit mode - else { - $title = $data['cn']; - - // Add sharedfolder type name - $fields['type_id_name'] = array( - 'label' => 'sharedfolder.type_id', - 'section' => 'system', - 'value' => $accttypes[$type]['content'], - ); - } + $form = $this->form_prepare('sharedfolder', $data, array(), null, $fields_map['type_id']); + list($fields, $types, $type, $add_mode) = $form; // Create form object and populate with fields $form = $this->form_create('sharedfolder', $attribs, $sections, $fields, $fields_map, $data, $add_mode); - $form->set_title(kolab_html::escape($title)); - return $form->output(); } } diff --git a/lib/client/kolab_client_task_signup.php b/lib/client/kolab_client_task_signup.php index ad8a5fc..9857a34 100644 --- a/lib/client/kolab_client_task_signup.php +++ b/lib/client/kolab_client_task_signup.php @@ -206,27 +206,8 @@ class kolab_client_task_signup extends kolab_client_task ); // Prepare fields - list($fields, $types, $type) = $this->form_prepare('user', $data, array('userpassword2'), 'hosted'); - - // Add user type id selector - $accttypes = array(); - foreach ($types as $idx => $elem) { - if($elem['used_for'] == 'hosted') { - $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']); - } - } - $fields['type_id'] = array( - 'section' => 'personal', - 'type' => kolab_form::INPUT_SELECT, - 'options' => $accttypes, - 'onchange' => "kadm.change_user_type()", - ); - // Hide user types selector if only one is available - if(count($accttypes) <= 1) { - $accctype = array_shift(array_values($accttypes)); - $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN; - $fields['type_id']['value'] = $accttype['value']; - } + $form = $this->form_prepare('user', $data, array('userpassword2'), 'hosted', $fields_map['type_id']); + list($fields, $types, $type, $add_mode) = $form; // Add object type field $fields['object_type'] = array( @@ -270,9 +251,8 @@ class kolab_client_task_signup extends kolab_client_task $fields['domain']['label'] = 'signup.domain'; // Create form object and populate with fields - $form = $this->form_create('user', $attribs, array('other'), $fields, $fields_map, $data, true); - - $form->set_title($this->translate('signup.formtitle')); + $form = $this->form_create('user', $attribs, array('other'), $fields, $fields_map, $data, true + $this->translate('signup.formtitle')); $this->output->add_translation('user.password.mismatch', 'signup.wronguid', 'signup.userexists', 'internalerror', 'servererror'); diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php index 6d51754..357d7c6 100644 --- a/lib/client/kolab_client_task_user.php +++ b/lib/client/kolab_client_task_user.php @@ -173,24 +173,8 @@ class kolab_client_task_user extends kolab_client_task ); // Prepare fields - list($fields, $types, $type) = $this->form_prepare('user', $data, array('userpassword2')); - - //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 user type id selector - $fields['type_id'] = array( - 'section' => 'personal', - 'type' => kolab_form::INPUT_SELECT, - 'options' => $accttypes, - 'onchange' => "kadm.user_save(true, 'personal')", - ); + $form = $this->form_prepare('user', $data, array('userpassword2'), null, $fields_map['type_id']); + list($fields, $types, $type, $add_mode) = $form; // Add password confirmation if (isset($fields['userpassword'])) { @@ -206,11 +190,6 @@ class kolab_client_task_user extends kolab_client_task } } - // Hide account type selector if there's only one type - if (count($accttypes) < 2 || !$add_mode) { - $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN; - } - // Create mode if ($add_mode) { // copy password to password confirm field @@ -228,19 +207,10 @@ class kolab_client_task_user extends kolab_client_task // remove password $data['userpassword'] = ''; - - // Add user type name - $fields['type_id_name'] = array( - 'label' => 'user.type_id', - 'section' => 'personal', - 'value' => $accttypes[$type]['content'], - ); } // Create form object and populate with fields - $form = $this->form_create('user', $attribs, $sections, $fields, $fields_map, $data, $add_mode); - - $form->set_title(kolab_html::escape($title)); + $form = $this->form_create('user', $attribs, $sections, $fields, $fields_map, $data, $add_mode, $title); $this->output->add_translation('user.password.mismatch'); diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php index afa4a96..9160a35 100644 --- a/lib/kolab_client_task.php +++ b/lib/kolab_client_task.php @@ -999,10 +999,12 @@ class kolab_client_task * @param string $name Object name (user, group, etc.) * @param array $data Object data * @param array $extra_fields Extra field names + * @param string $used_for Object types filter + * @param string $id_section Name of section for type_id field * * @return array Fields list, Object types list, Current type ID */ - protected function form_prepare($name, &$data, $extra_fields = array(), $used_for = null) + protected function form_prepare($name, &$data, $extra_fields = array(), $used_for = null, $id_section = null) { $types = (array) $this->object_types($name, $used_for); $add_mode = empty($data['id']); @@ -1029,7 +1031,9 @@ class kolab_client_task } } - $data['type_id'] = $type = isset($default) ? $default : key($types); + reset($types); + + $data['type_id'] = $type = ($default !== null ? $default : key($types)); } if ($type) { @@ -1233,7 +1237,37 @@ class kolab_client_task ); } - $result = array($fields, $types, $type); + // Add object type id selector + if ($id_section) { + $object_types = array(); + foreach ($types as $idx => $elem) { + $object_types[$idx] = array('value' => $idx, 'content' => $elem['name']); + } + + // Add object type id selector + $fields['type_id'] = array( + 'section' => $id_section, + 'type' => kolab_form::INPUT_SELECT, + 'options' => $object_types, + 'onchange' => "kadm.{$name}_save(true, '$id_section')", + ); + + // Hide account type selector if there's only one type + if (count($object_types) < 2 || !$add_mode) { + $fields['type_id']['type'] = kolab_form::INPUT_HIDDEN; + } + + // Add object type name + if (!$add_mode && count($object_types) > 1) { + $fields['type_id_name'] = array( + 'label' => "$name.type_id", + 'section' => $id_section, + 'value' => $object_types[$type]['content'], + ); + } + } + + $result = array($fields, $types, $type, $add_mode); return $result; } @@ -1246,10 +1280,12 @@ class kolab_client_task * @param array $fields Fields list (from self::form_prepare()) * @param array $fields_map Fields map (used for sorting and sections assignment) * @param array $data Object data (with effective rights, see form_prepare()) + * @param bool $add_mode Add mode enabled + * @param string $title Page title * * @return kolab_form HTML Form object */ - protected function form_create($name, $attribs, $sections, $fields, $fields_map, $data, $add_mode) + protected function form_create($name, $attribs, $sections, $fields, $fields_map, $data, $add_mode, $title = null) { // Assign sections to fields foreach ($fields as $idx => $field) { @@ -1400,7 +1436,7 @@ class kolab_client_task if ($writeable) { $form->add_button(array( 'value' => kolab_html::escape($this->translate('button.submit')), - 'onclick' => "kadm.{$name}_save()", + 'onclick' => "kadm.command('{$name}.save')", )); } @@ -1409,7 +1445,7 @@ class kolab_client_task $id = $data['id']; $form->add_button(array( 'value' => kolab_html::escape($this->translate('button.delete')), - 'onclick' => "kadm.{$name}_delete('{$id}')", + 'onclick' => "kadm.command('{$name}.delete', '{$id}')", )); } @@ -1426,6 +1462,12 @@ class kolab_client_task $name . '.delete.confirm', $name . '.delete.force', 'add', 'edit', 'delete'); + if (empty($title)) { + $title = $add_mode ? $this->translate("$name.add") : $data['cn']; + } + + $form->set_title(kolab_html::escape($title)); + return $form; } diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js index 3fb0928..5263ba4 100644 --- a/public_html/js/kolab_admin.js +++ b/public_html/js/kolab_admin.js @@ -216,6 +216,9 @@ function kolab_admin() if (timeout > 0) window.setTimeout(function() { self.hide_message(type, type != 'loading'); }, timeout); + if (type == 'loading') + this.hide_message(type); + obj.attr('id', type == 'loading' ? 'loading' : 'message') .appendTo('body').html(msg).show(); }; @@ -2210,7 +2213,6 @@ function kolab_admin() if (data.attributes.length) this.api_post('form_value.generate', data, 'form_value_response'); - this.set_busy(false); }; this.form_value_response = function(response) |