summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-07-30 13:32:01 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-07-30 13:32:01 (GMT)
commitb7c06cbc6efc609b10d8a7863359d669d9b54db6 (patch)
tree8b46cb52669b0e4067b81dc742a9c03dc3455e00
parente9bbaf4d12dbbf165428cb37990563c9cb147c95 (diff)
downloadkolab-wap-b7c06cbc6efc609b10d8a7863359d669d9b54db6.tar.gz
Fix handling mailquota units (Bug #1966) + some code improvements
-rw-r--r--lib/api/kolab_api_service_form_value.php12
-rw-r--r--lib/kolab_api_service.php2
-rw-r--r--lib/kolab_html.php36
-rw-r--r--public_html/js/kolab_admin.js8
4 files changed, 43 insertions, 15 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index b51529c..344a9e7 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -1176,8 +1176,16 @@ class kolab_api_service_form_value extends kolab_api_service
private function validate_mailquota($value)
{
- //return (int)($value);
- return $value;
+ // convert MB/GB into KB
+ if (preg_match('/^([0-9]+)\s*(KB|MB|GB)$/i', $value, $m)) {
+ switch (strtoupper($m[2])) {
+ case 'KB': $value = $m[1]; break;
+ case 'MB': $value = $m[1] * 1024; break;
+ case 'GB': $value = $m[1] * 1024 * 1024; break;
+ }
+ }
+
+ return (int) $value;
}
private function validate_mailalternateaddress($value)
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index fa93110..4d2f9ef 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -313,7 +313,7 @@ abstract class kolab_api_service
Log::trace("kolab_api_service::parse_input_attributes() \$special_attr_validate: " . var_export($special_attr_validate, TRUE));
- $result = array();
+ $result = array();
if (isset($type_attrs['form_fields'])) {
foreach ($type_attrs['form_fields'] as $key => $value) {
diff --git a/lib/kolab_html.php b/lib/kolab_html.php
index c0ef529..d54eabc 100644
--- a/lib/kolab_html.php
+++ b/lib/kolab_html.php
@@ -154,7 +154,7 @@ class kolab_html
}
/**
- * Input element for mail quota. user can select the unit (GB, MB)
+ * Input element for mail quota. user can select the unit (GB, MB, KB)
*
* @param array $attribs Element attributes
*
@@ -164,20 +164,32 @@ class kolab_html
{
$elem_attribs = array_merge(self::$input_attribs, self::$input_event_attribs,
self::$common_attribs, self::$event_attribs);
- $selected_option_mb = $selected_option_gb = "";
- $selected_option_kb = "selected";
- if ($attribs['value'] >= 1024 && $attribs['value'] % 1024 == 0) {
- $attribs['value'] /= 1024;
- $selected_option_kb = "";
- $selected_option_mb = "selected";
+
+ if ($attribs['value'] % 1024 == 0) {
+ if ($attribs['value'] >= 1024) {
+ $attribs['value'] /= 1024;
+ $unit = 'mb';
+ }
+ if ($attribs['value'] >= 1024) {
+ $attribs['value'] /= 1024;
+ $unit = 'gb';
+ }
}
- if ($attribs['value'] >= 1024 && $attribs['value'] % 1024 == 0) {
- $attribs['value'] /= 1024;
- $selected_option_mb = "";
- $selected_option_gb = "selected";
+
+ $options = array();
+ foreach (array('kb', 'mb', 'gb') as $u) {
+ $options[] = '<option value="' . $u . '"' . ($unit == $u ? ' selected' : '') . '>'
+ . strtoupper($u) . '</option>';
+ }
+
+ $attribs['data-type'] = 'quota';
+
+ if (empty($attribs['size'])) {
+ $attribs['size'] = 10;
}
- return sprintf('<input%s /><select name="%s-unit"><option value="kb" %s>KB</option><option value="mb" %s>MB</option><option value="gb" %s>GB</option></select>', self::attrib_string($attribs, $elem_attribs), $attribs['name'], $selected_option_kb, $selected_option_mb, $selected_option_gb);
+ return sprintf('<input%s /><select name="%s-unit">%s</select>',
+ self::attrib_string($attribs, $elem_attribs), $attribs['name'], implode($options));
}
/**
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index b5bc376..c2ee52c 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -761,6 +761,14 @@ function kolab_admin()
data.json = kadm.form_url_element_submit(this.name, data.json, form);
});
+ // quota inputs
+ $('input[data-type="quota"]', form).each(function() {
+ var unit = $('select[name="' + this.name + '-unit"]').val();
+ if (unit)
+ data.json[this.name] = this.value + unit;
+ delete data.json[this.name + '-unit'];
+ });
+
return data;
};