summaryrefslogtreecommitdiffstats
path: root/public_html
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 /public_html
parent64a5c4f7a510dd7fed443ec3d5a3c4b6898eabf4 (diff)
downloadwebadmin-db5d28fb5bcf6cd09377b0bad104c3db28372e19.tar.gz
Some improvements in forms
Diffstat (limited to 'public_html')
-rw-r--r--public_html/js/kolab_admin.js114
-rw-r--r--public_html/skins/default/style.css7
2 files changed, 75 insertions, 46 deletions
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 {