summaryrefslogtreecommitdiffstats
path: root/public_html
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-03-15 13:53:15 +0100
committerAleksander Machniak <alec@alec.pl>2012-03-15 13:53:15 +0100
commitef127300c69f7b701011a513b3712f2ca1b12641 (patch)
tree881f50046b416a33b67d3f4b0b9ba34cb1cb4186 /public_html
parente850aeb57db53fb2e70412f79ac57507715cc849 (diff)
downloadwebadmin-ef127300c69f7b701011a513b3712f2ca1b12641.tar.gz
Fix list widget
Diffstat (limited to 'public_html')
-rw-r--r--public_html/.htaccess16
-rw-r--r--public_html/js/kolab_admin.js27
-rw-r--r--public_html/skins/default/ui.js65
3 files changed, 64 insertions, 44 deletions
diff --git a/public_html/.htaccess b/public_html/.htaccess
deleted file mode 100644
index b228331..0000000
--- a/public_html/.htaccess
+++ /dev/null
@@ -1,16 +0,0 @@
-<IfModule mod_rewrite.c>
- RewriteEngine on
- RewriteBase /~vanmeeuwen/kolab-wap/public_html
-
- # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_URI} !=/favicon.ico
- RewriteRule ^api/(.*)\.(.*)$ api/index.php?service=$1&method=$2 [L,QSA]
-
-</IfModule>
-
-AddDefaultCharset UTF-8
-
-php_value error_reporting 6135
-
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 08b6f31..26f1c10 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -412,6 +412,10 @@ function kolab_admin()
}
};
+ /*********************************************************/
+ /********* Forms *********/
+ /*********************************************************/
+
this.serialize_form = function(id)
{
var i, v, json = {},
@@ -429,13 +433,17 @@ function kolab_admin()
this.trigger_event('form-serialize', {id: id, json: json});
+ // convert values of list elements to array type
+ $('textarea[data-type="list"]', form).each(function() {
+ var name = this.name;
+ // maybe already converted by skin engine
+ if (json[name] && !$.isArray(json[name]))
+ json[name] = $(this).val().split("\n");
+ });
+
return json;
};
- /*********************************************************/
- /********* Forms *********/
- /*********************************************************/
-
this.form_value_change = function(events)
{
var i, j, e, elem, name, elem_name,
@@ -466,11 +474,18 @@ function kolab_admin()
this.form_value_response = function(response)
{
+ var i, val;
if (!this.api_response(response))
return;
- for (var i in response.result)
- $('[name="'+i+'"]').val(response.result[i]);
+ for (i in response.result) {
+ val = response.result[i];
+ if ($.isArray(val))
+ val = val.join("\n");
+ $('[name="'+i+'"]').val(val);
+
+ this.trigger_event('form-element-update', {name: i});
+ }
};
this.form_value_error = function(name)
diff --git a/public_html/skins/default/ui.js b/public_html/skins/default/ui.js
index c4e8e9d..546c1dc 100644
--- a/public_html/skins/default/ui.js
+++ b/public_html/skins/default/ui.js
@@ -153,41 +153,61 @@ function form_serialize(data)
}
}
- data.json[this.name] = value.join("\n");
+ data.json[this.name] = value;
});
return data;
}
+// Form element update handler
+function form_element_update(data)
+{
+ var elem = $('[name="'+data.name+'"]');
+
+ if (!elem.length)
+ return;
+
+ if (elem.attr('data-type') == 'list') {
+ // remove old wrapper
+ $('span[class="listarea"]', elem.parent()).remove();
+ // insert new list element
+ form_element_wrapper(elem.get(0));
+ }
+}
+
// Form initialization
function form_init(id)
{
- var form = $('#'+id), separator = /[,\s\r\n]+/;
+ var form = $('#'+id);
// replace some textarea fields with pretty/smart input lists
$('textarea[data-type="list"]', form)
- .each(function() {
- var i, len, elem, e = $(this),
- list = this.value.split(separator),
- area = $('<span class="listarea"></span>'),
- disabled = e.attr('disabled') || e.attr('readonly');
-
- e.hide();
-
- for (i=0, len=list.length; i<len; i++) {
- elem = form_list_element(form, {
- name: this.name+'['+i+']',
- value: list[i],
- disabled: disabled
- });
- elem.appendTo(area);
- }
+ .each(function() { form_element_wrapper(this); });
+}
- if (disabled)
- area.addClass('readonly');
+// Replaces form element with smart element
+function form_element_wrapper(form_element)
+{
+ var i, len, elem, e = $(form_element),
+ list = form_element.value.split("\n"),
+ area = $('<span class="listarea"></span>'),
+ disabled = e.attr('disabled') || e.attr('readonly');
+
+ e.hide();
+
+ for (i=0, len=list.length; i<len; i++) {
+ elem = form_list_element(form_element.form, {
+ name: form_element.name+'['+i+']',
+ value: list[i],
+ disabled: disabled
+ });
+ elem.appendTo(area);
+ }
- area.appendTo(this.parentNode);
- });
+ if (disabled)
+ area.addClass('readonly');
+
+ area.appendTo(form_element.parentNode);
}
// Creates smart list element
@@ -233,3 +253,4 @@ function form_list_element(form, data)
*/
kadm.add_event_listener('form-load', form_load);
kadm.add_event_listener('form-serialize', form_serialize);
+kadm.add_event_listener('form-element-update', form_element_update);