You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/08/14 01:09:14 UTC
[1/2] git commit: updated refs/heads/master to 8f34dc1
Updated Branches:
refs/heads/master f87eed5b7 -> 8f34dc192
UI plugin framework: Support plugin internationalization
Allows UI plugins to contribute their own internationalized strings to
the global js dictionary. Each plugin would define a dictionary.js and
several dictionary_<locale>.js files. As each plugin is loaded, the
appropriate plugin dictionary is loaded into the global js
dictionary (with the global dictionary taking precedence in the event
of a conflict).
Original author: Chris Suich <ch...@netapp.com>
Reviewed by: Brian Federle <br...@citrix.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/cd056f45
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/cd056f45
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/cd056f45
Branch: refs/heads/master
Commit: cd056f4572130edb8edc315e626c6fab718730c5
Parents: f87eed5
Author: Brian Federle <br...@citrix.com>
Authored: Tue Aug 13 15:14:53 2013 -0700
Committer: Brian Federle <br...@citrix.com>
Committed: Tue Aug 13 15:32:08 2013 -0700
----------------------------------------------------------------------
ui/scripts/plugins.js | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cd056f45/ui/scripts/plugins.js
----------------------------------------------------------------------
diff --git a/ui/scripts/plugins.js b/ui/scripts/plugins.js
index 96ed229..50da509 100644
--- a/ui/scripts/plugins.js
+++ b/ui/scripts/plugins.js
@@ -84,6 +84,13 @@
var css = basePath + id + '.css';
var configJS = type == 'plugins' ? basePath + 'config' : null;
+ var pluginDictionary;
+ var locale;
+ if (type == 'plugins') {
+ pluginDictionary = basePath + 'dictionary';
+ locale = $.cookie('lang');
+ }
+
if (configJS) {
// Load config metadata
require([configJS]);
@@ -100,6 +107,29 @@
})
);
+ if (pluginDictionary) {
+ // Callback for extending the dictionary with new entries
+ var addToDictionary = function() {
+ var additions = cloudStack[type][id].dictionary;
+ $.extend(dictionary, additions);
+ };
+
+ // Only add a suffix if the locale is defined and not english/US
+ var suffix = '';
+ if (locale && (locale != '' && locale != 'en' & locale != 'en_US'))
+ suffix = '_'+locale;
+
+ // Attempt to load the locale's dictionary
+ require([pluginDictionary+suffix], addToDictionary, function() {
+ // If the load failed and there was no suffix, don't try again
+ if (!suffix)
+ return;
+
+ // Otherwise try to load the default dictionary
+ require([pluginDictionary], addToDictionary);
+ });
+ }
+
loadedPlugins = loadedPlugins + 1;
if (loadedPlugins === pluginTotal) {
[2/2] git commit: updated refs/heads/master to 8f34dc1
Posted by bf...@apache.org.
UI form dialog: Support dynamic unit conversion for fields
Adds a new dialog field type called 'has_units'. This field has an
input box side by side with a select box. The select box is populated
with predefined units (MB, GB, TB, for example) and uses (also
predefined) conversion functions to allow automatic updating of the
input box value when the units select box is changed.
Original author: Chris Suich <ch...@netapp.com>
Reviewed by: Brian Federle <br...@citrix.com>
Example:
fields: {
...
size: {
...
has_units: true,
units: [
{
id: 'gb',
text: 'GB',
fromBase: function(val) { ... return val; },
toBase: function(val) { ... return val; }
},
...
]
}
}
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8f34dc19
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8f34dc19
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8f34dc19
Branch: refs/heads/master
Commit: 8f34dc192f418a309baf87f85ba66f306d359432
Parents: cd056f4
Author: Brian Federle <br...@citrix.com>
Authored: Tue Aug 13 15:31:45 2013 -0700
Committer: Brian Federle <br...@citrix.com>
Committed: Tue Aug 13 15:33:31 2013 -0700
----------------------------------------------------------------------
ui/scripts/ui/dialog.js | 59 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8f34dc19/ui/scripts/ui/dialog.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js
index 1ff5401..e227ea4 100644
--- a/ui/scripts/ui/dialog.js
+++ b/ui/scripts/ui/dialog.js
@@ -459,6 +459,65 @@
$input.wrap($('<div>').addClass('range-item'));
$input.addClass("disallowSpecialCharacters");
+ } else if (field.has_units) { // An input box and a drop down with unit options
+ var textbox = $('<input>')
+ .attr({
+ type: 'text',
+ name: key
+ })
+ .css('width', 'auto');
+ var unitSelect = $('<select>')
+ .attr({
+ name: key+'_unit'
+ })
+ .data('key', key)
+ .css('width', 'auto');
+
+ $input = textbox;
+
+ textbox.appendTo($value);
+ unitSelect.appendTo($value);
+
+ $.each(field.units, function() {
+ var id = this.id;
+ var text = this.text;
+ var toBase = this.toBase;
+ var fromBase = this.fromBase;
+
+ var option = $('<option>')
+ .appendTo(unitSelect)
+ .val(_s(id))
+ .html(_s(text))
+ .data('toBase', toBase)
+ .data('fromBase', fromBase);
+ });
+
+ unitSelect.focus(function() {
+ this.oldUnit = this.value;
+ });
+
+ unitSelect.change(function() {
+ if ($(this).parent().length == 0)
+ return;
+
+ var oldUnit = this.oldUnit;
+ var newUnit = this.value;
+ var key = $(this).data('key');
+ var value = $(this).closest('form').find('input[name='+key+']').attr('value');
+
+ if (!value || value.length === 0 || !oldUnit || oldUnit == newUnit)
+ return;
+
+ var toBase = $(this).closest('form').find('option[value='+oldUnit+']').data('toBase');
+ var fromBase = $(this).closest('form').find('option[value='+newUnit+']').data('fromBase');
+
+ var baseValue = toBase(value);
+ var newValue = fromBase(baseValue);
+
+ $(this).closest('form').find('input[name='+key+']').attr('value', newValue);
+
+ this.oldUnit = newUnit;
+ })
} else { //text field
$input = $('<input>').attr({
name: key,