lib/api lib/kolab_api_service.php lib/kolab_html.php public_html/js
Aleksander Machniak
machniak at kolabsys.com
Tue Jul 30 15:32:27 CEST 2013
lib/api/kolab_api_service_form_value.php | 12 ++++++++--
lib/kolab_api_service.php | 2 -
lib/kolab_html.php | 36 ++++++++++++++++++++-----------
public_html/js/kolab_admin.js | 8 ++++++
4 files changed, 43 insertions(+), 15 deletions(-)
New commits:
commit b7c06cbc6efc609b10d8a7863359d669d9b54db6
Author: Aleksander Machniak <alec at alec.pl>
Date: Tue Jul 30 15:32:01 2013 +0200
Fix handling mailquota units (Bug #1966) + some code improvements
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;
};
More information about the commits
mailing list