summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-02-27 13:02:43 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-02-27 13:02:43 (GMT)
commit52e47e63d2c46206dff28a3d1cec782f0d5b1f23 (patch)
tree98a14dfdcf26db1c8753c554469cd6458ae73859
parent181e61d2d947e5487694b0b8d5a709125245db48 (diff)
downloadkolab-wap-52e47e63d2c46206dff28a3d1cec782f0d5b1f23.tar.gz
Code unification
-rw-r--r--public_html/js/kolab_admin.js180
1 files changed, 48 insertions, 132 deletions
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index c9836c8..e4741f2 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1412,24 +1412,7 @@ function kolab_admin()
this.domain_save = function(reload, section)
{
- var data = this.serialize_form('#'+this.env.form_id),
- action = data.id ? 'edit' : 'add';
-
- if (reload) {
- data.section = section;
- this.http_post('domain.' + action, {data: data});
- return;
- }
-
- this.form_error_clear();
-
- if (!this.check_required_fields(data)) {
- this.display_message('form.required.empty', 'error');
- return;
- }
-
- this.set_busy(true, 'saving');
- this.api_post('domain.' + action, data, 'domain_' + action + '_response');
+ this.save_handler('domain', reload, section);
};
this.domain_delete_response = function(response)
@@ -1488,32 +1471,19 @@ function kolab_admin()
this.user_save = function(reload, section)
{
- var data = this.serialize_form('#'+this.env.form_id),
- action = data.id ? 'edit' : 'add';
-
- if (reload) {
- data.section = section;
- this.http_post('user.' + action, {data: data});
- return;
- }
-
- this.form_error_clear();
-
- // check password
- if (data.userpassword != data.userpassword2) {
- this.display_message('user.password.mismatch', 'error');
- this.form_value_error('userpassword2');
- return;
- }
- delete data['userpassword2'];
+ var validate = function(obj, data) {
+ // check password
+ if (data.userpassword != data.userpassword2) {
+ obj.display_message('user.password.mismatch', 'error');
+ obj.form_value_error('userpassword2');
+ return false;
+ }
- if (!this.check_required_fields(data)) {
- this.display_message('form.required.empty', 'error');
- return;
- }
+ delete data['userpassword2'];
+ return data;
+ };
- this.set_busy(true, 'saving');
- this.api_post('user.' + action, data, 'user_' + action + '_response');
+ this.save_handler('user', reload, section, validate);
};
this.user_delete_response = function(response)
@@ -1548,24 +1518,7 @@ function kolab_admin()
this.group_save = function(reload, section)
{
- var data = this.serialize_form('#'+this.env.form_id),
- action = data.id ? 'edit' : 'add';
-
- if (reload) {
- data.section = section;
- this.http_post('group.' + action, {data: data});
- return;
- }
-
- this.form_error_clear();
-
- if (!this.check_required_fields(data)) {
- this.display_message('form.required.empty', 'error');
- return;
- }
-
- this.set_busy(true, 'saving');
- this.api_post('group.' + action, data, 'group_' + action + '_response');
+ this.save_handler('group', reload, section);
};
this.group_delete_response = function(response)
@@ -1600,24 +1553,7 @@ function kolab_admin()
this.ou_save = function(reload, section)
{
- var data = this.serialize_form('#'+this.env.form_id),
- action = data.id ? 'edit' : 'add';
-
- if (reload) {
- data.section = section;
- this.http_post('ou.' + action, {data: data});
- return;
- }
-
- this.form_error_clear();
-
- if (!this.check_required_fields(data)) {
- this.display_message('form.required.empty', 'error');
- return;
- }
-
- this.set_busy(true, 'saving');
- this.api_post('ou.' + action, data, 'ou_' + action + '_response');
+ this.save_handler('ou', reload, section);
};
this.ou_delete_response = function(response)
@@ -1652,24 +1588,7 @@ function kolab_admin()
this.resource_save = function(reload, section)
{
- var data = this.serialize_form('#'+this.env.form_id),
- action = data.id ? 'edit' : 'add';
-
- if (reload) {
- data.section = section;
- this.http_post('resource.' + action, {data: data});
- return;
- }
-
- this.form_error_clear();
-
- if (!this.check_required_fields(data)) {
- this.display_message('form.required.empty', 'error');
- return;
- }
-
- this.set_busy(true, 'saving');
- this.api_post('resource.' + action, data, 'resource_' + action + '_response');
+ this.save_handler('resource', reload, section);
};
this.resource_delete_response = function(response)
@@ -1704,24 +1623,7 @@ function kolab_admin()
this.role_save = function(reload, section)
{
- var data = this.serialize_form('#'+this.env.form_id),
- action = data.id ? 'edit' : 'add';
-
- if (reload) {
- data.section = section;
- this.http_post('role.' + action, {data: data});
- return;
- }
-
- this.form_error_clear();
-
- if (!this.check_required_fields(data)) {
- this.display_message('form.required.empty', 'error');
- return;
- }
-
- this.set_busy(true, 'saving');
- this.api_post('role.' + action, data, 'role_' + action + '_response');
+ this.save_handler('role', reload, section);
};
this.role_delete_response = function(response)
@@ -1756,24 +1658,7 @@ function kolab_admin()
this.sharedfolder_save = function(reload, section)
{
- var data = this.serialize_form('#'+this.env.form_id),
- action = data.id ? 'edit' : 'add';
-
- if (reload) {
- data.section = section;
- this.http_post('sharedfolder.' + action, {data: data});
- return;
- }
-
- this.form_error_clear();
-
- if (!this.check_required_fields(data)) {
- this.display_message('form.required.empty', 'error');
- return;
- }
-
- this.set_busy(true, 'saving');
- this.api_post('sharedfolder.' + action, data, 'sharedfolder_' + action + '_response');
+ this.save_handler('sharedfolder', reload, section);
};
this.sharedfolder_delete_response = function(response)
@@ -1981,6 +1866,37 @@ function kolab_admin()
this.api_post(type + '.delete', {'id': id}, type + '_delete_response');
};
+ // universal form save handler
+ this.save_handler = function(type, reload, section, validation_function)
+ {
+ var data = this.serialize_form('#'+this.env.form_id),
+ action = data.id ? 'edit' : 'add';
+
+ if (reload) {
+ data.section = section;
+ this.http_post(type + '.' + action, {data: data});
+ return false;
+ }
+
+ this.form_error_clear();
+
+ if (validation_function)
+ data = validation_function(this, data);
+
+ if (data === false)
+ return false;
+
+ if (!this.check_required_fields(data)) {
+ this.display_message('form.required.empty', 'error');
+ return false;
+ }
+
+ this.set_busy(true, 'saving');
+ this.api_post(type + '.' + action, data, type + '_' + action + '_response');
+
+ return true;
+ };
+
// Parses object type identifier
this.type_id_parse = function(id)
{