summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-02-21 16:53:56 +0100
committerAleksander Machniak <alec@alec.pl>2012-02-21 16:53:56 +0100
commitdb5d28fb5bcf6cd09377b0bad104c3db28372e19 (patch)
tree120244040078fd5e03cafd10c90fe3541544f95d
parent64a5c4f7a510dd7fed443ec3d5a3c4b6898eabf4 (diff)
downloadwebadmin-db5d28fb5bcf6cd09377b0bad104c3db28372e19.tar.gz
Some improvements in forms
-rw-r--r--lib/api/kolab_api_service_form_value.php1
-rw-r--r--lib/client/kolab_client_task_user.php18
-rw-r--r--lib/locale/en_US.php1
-rw-r--r--public_html/js/kolab_admin.js114
-rw-r--r--public_html/skins/default/style.css7
5 files changed, 87 insertions, 54 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index c914815..0f0ad74 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -56,7 +56,6 @@ class kolab_api_service_form_value extends kolab_api_service
return array("displayname" => $displayname);
}
-
}
public function generate_mail($getdata, $postdata)
diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index 69bb996..67d3796 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -377,10 +377,12 @@ class kolab_client_task_user extends kolab_client_task
foreach ($auto_fields as $af_idx => $af) {
foreach ($fields as $section_idx => $section) {
foreach ($section['fields'] as $idx => $field) {
- if ($idx == $af_idx && empty($field['system'])) {
- $fields[$section_idx]['fields'][$idx]['readonly'] = true;
- $fields[$section_idx]['fields'][$idx]['disabled'] = true;
- $fields[$section_idx]['fields'][$idx]['required'] = false;
+ if ($idx == $af_idx) {
+ if (empty($field['system'])) {
+ $fields[$section_idx]['fields'][$idx]['readonly'] = true;
+ $fields[$section_idx]['fields'][$idx]['disabled'] = true;
+ $fields[$section_idx]['fields'][$idx]['required'] = false;
+ }
if (!empty($af['data'])) {
foreach ($af['data'] as $afd) {
@@ -406,12 +408,14 @@ class kolab_client_task_user extends kolab_client_task
// auto-generated field values
if (!empty($event_fields[$idx])) {
$event = json_encode(array_unique($event_fields[$idx]));
- $fields[$section_idx]['fields'][$idx]['onchange'] = "kadm.form_value_change('$form_id', $event)";
+ $fields[$section_idx]['fields'][$idx]['onchange'] = "kadm.form_value_change($event)";
}
}
}
$this->output->set_env('auto_fields', $auto_fields);
+ $this->output->set_env('form_id', $form_id);
+ $this->output->add_translation('user.password.mismatch');
// Hide account type selector if there's only one type
if (count($accttypes) < 2) {
@@ -490,13 +494,13 @@ class kolab_client_task_user extends kolab_client_task
$form->add_button(array(
'value' => kolab_html::escape($this->translate('submit.button')),
- 'onclick' => "kadm.user_save('$form_id')",
+ 'onclick' => "kadm.user_save()",
));
if (!$new) {
$form->add_button(array(
'value' => kolab_html::escape($this->translate('delete.button')),
- 'onclick' => "kadm.user_delete('$form_id')",
+ 'onclick' => "kadm.user_delete()",
));
}
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index c239bb7..e06184f 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -71,6 +71,7 @@ $LANG['user.smtp-recipients.desc'] = 'Restrict allowed recipients of SMTP messag
$LANG['user.uid'] = 'Unique identity (UID)';
$LANG['user.password'] = 'Password';
$LANG['user.password-confirm'] = 'Confirm password';
+$LANG['user.password.mismatch'] = 'Passwords do not match!';
$LANG['user.homeserver'] = 'Mailbox home server';
$LANG['group.add'] = 'Add Group';
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 4e49f5e..51c89cd 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -390,18 +390,77 @@ function kolab_admin()
this.serialize_form = function(id)
{
- var i, query = $(id).serializeArray(),
- json = {};
+ var i, v, json = {},
+ form = $(id),
+ query = form.serializeArray(),
+ disabled = this.env.auto_fields;
for (i in query)
json[query[i].name] = query[i].value;
+ // read disabled fields too
+ for (i in disabled)
+ if (v = $('[name="'+i+'"]', form).val())
+ json[i] = v;
+
this.trigger_event('form-serialize', {id: id, json: json});
return json;
};
/*********************************************************/
+ /********* Forms *********/
+ /*********************************************************/
+
+ this.form_value_change = function(events)
+ {
+ var i, j, data, e, elem, name, elem_name,
+ form = $('#'+this.env.form_id),
+ type_id = $('[name="user_type_id"]', form).val();
+
+ this.set_busy(true, 'loading');
+
+ for (i=0; i<events.length; i++) {
+ name = events[i];
+ e = this.env.auto_fields[name];
+
+ if (!e)
+ continue;
+
+ data = {user_type_id: type_id};
+ for (j=0; j<e.data.length; j++) {
+ elem_name = e.data[j];
+ if (elem = $('[name="'+elem_name+'"]', form))
+ data[elem_name] = elem.val();
+ }
+
+ this.api_post('form_value.generate_'+name, data, 'form_value_response');
+ }
+
+ this.set_busy(false);
+ };
+
+ this.form_value_response = function(response)
+ {
+ if (!this.api_response(response))
+ return;
+
+ for (var i in response.result)
+ $('[name="'+i+'"]').val(response.result[i]);
+ };
+
+ this.form_value_error = function(name)
+ {
+ $('[name="'+name+'"]', $('#'+this.env.form_id)).addClass('error');
+ }
+
+ this.form_error_clear = function()
+ {
+ $('input,textarea', $('#'+this.env.form_id)).removeClass('error');
+
+ }
+
+ /*********************************************************/
/********* Client commands *********/
/*********************************************************/
@@ -432,57 +491,26 @@ function kolab_admin()
};
- this.user_save = function(props)
- {
- var data = this.serialize_form('#'+props);
- this.api_post('user.add', data, 'user_save_response');
- };
-
- this.user_save_response = function(response)
- {
- if (!this.api_response(response))
- return;
- };
-
- /*********************************************************/
- /********* Forms *********/
- /*********************************************************/
-
- this.form_value_change = function(form_id, events)
+ this.user_save = function()
{
- var i, j, data, e, elem, name, elem_name,
- form = $('#'+form_id),
- type_id = $('[name="user_type_id"]', form).val();
+ var data = this.serialize_form('#'+this.env.form_id);
- this.set_busy(true, 'loading');
+ this.form_error_clear();
- for (i=0; i<events.length; i++) {
- name = events[i];
- e = this.env.auto_fields[name];
-
- if (!e)
- continue;
-
- data = {user_type_id: type_id};
- for (j=0; j<e.data.length; j++) {
- elem_name = e.data[j];
- if (elem = $('[name="'+elem_name+'"]', form))
- data[elem_name] = elem.val();
- }
-
- this.api_post('form_value.generate_'+name, data, 'form_value_response');
+ // check password
+ if (data.password != data.password2) {
+ this.display_message('user.password.mismatch', 'error');
+ this.form_value_error('password2');
+ return;
}
- this.set_busy(false);
+ this.api_post('user.add', data, 'user_save_response');
};
- this.form_value_response = function(response)
+ this.user_save_response = function(response)
{
if (!this.api_response(response))
return;
-
- for (var i in response.result)
- $('[name="'+i+'"]').val(response.result[i]);
};
};
diff --git a/public_html/skins/default/style.css b/public_html/skins/default/style.css
index dd01ec5..3141897 100644
--- a/public_html/skins/default/style.css
+++ b/public_html/skins/default/style.css
@@ -109,11 +109,13 @@ table.form td {
padding: 1px 5px;
}
-table.form tr.required input {
+table.form tr.required input,
+table.form tr.required textarea {
background-color: #f0f9ff;
}
-table.form tr.error input {
+table.form tr input.error,
+table.form tr textarea.error {
background-color: #f5e3e3;
}
@@ -482,7 +484,6 @@ textarea.readonly {
background-color: #f5f5f5;
}
-
/********* Form smart inputs *********/
span.listarea {