summaryrefslogtreecommitdiffstats
path: root/lib/kolab_client_task.php
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-09-04 13:01:21 -0400
committerAleksander Machniak <machniak@kolabsys.com>2014-09-04 13:01:21 -0400
commit7c810d56e2acfd438805f3ba93e8a428ea7d8b59 (patch)
tree1485364d6afb39fa57832ab89e029c7a71fb38cc /lib/kolab_client_task.php
parentd10faf6e13c4aab377196f82ce63d6dca4427951 (diff)
downloadwebadmin-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.
Diffstat (limited to 'lib/kolab_client_task.php')
-rw-r--r--lib/kolab_client_task.php54
1 files changed, 48 insertions, 6 deletions
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;
}