[Kimchi-devel] [PATCH V3] [Wok 4/7] Multi-Culture support : Added support for converters in widget wok.list.js

archus at linux.vnet.ibm.com archus at linux.vnet.ibm.com
Tue May 10 20:58:28 UTC 2016


From: Archana Singh <archus at linux.vnet.ibm.com>

Added support to have converters in wok.list.js widget.
To use widgets opts should have converters(list of converters should have to)
and field which needs to use the defined converters it should have
e.g.
new wok.widget.List({
..
converters: {
    "date-locale-converter": {
      to: function(value)
          {
           var dte = new Date(value);
           var options = { year: 'numeric', month: 'long', day: 'numeric' };
           return dte.toLocaleDateString(wok.lang.get_locale(), options);
          }
      },
     "time-locale-converter": {
       to: function(time)
          {
           var dte = new Date((new Date(0)).toDateString()+' ' + time);
           return dte.toLocaleTimeString(wok.lang.get_locale());
          }
     }
    }
..

fields: [{
    name: ..
    converters: "date-locale-converter"
    ..
    }],
..
..
});

Signed-off-by: Archana Singh <archus at linux.vnet.ibm.com>
---
 ui/js/src/wok.list.js | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/ui/js/src/wok.list.js b/ui/js/src/wok.list.js
index f40b2e2..3b3055e 100644
--- a/ui/js/src/wok.list.js
+++ b/ui/js/src/wok.list.js
@@ -111,6 +111,7 @@ wok.widget.List.prototype = (function() {
 
     var fillBody = function(container, fields) {
         var data = this.data;
+        var converters = this.opts.converters;
         var tbody = ($('ul', container).length && $('ul', container)) || $('<ul></ul>').appendTo(container);
         tbody.empty();
         if (typeof data !== 'undefined' && data.length > 0) {
@@ -123,6 +124,15 @@ wok.widget.List.prototype = (function() {
                 var checkboxName = $('ul', container).parent().parent().parent().attr('id') + '-check' || $(container).parent().parent().parent().attr('id') + '-check';
                 $.each(fields, function(fi, field) {
                     var value = getValue(field.name, row);
+                    if(field.converter){
+                        var converter = field.converter;
+                        if(converters[converter]){
+                            var to = converters[converter]['to'];
+                            value = to(value);
+                        }else{
+                            console.error('converter ' + converters[converter] + ' not defined');
+                        }
+                    }
                     if (field.type === 'status' && field.name === 'enabled') {
                         styleClass = (value === true ? '' : ' disabled');
                         state = [
@@ -299,4 +309,4 @@ wok.widget.List.prototype = (function() {
         reload: reload,
         showMessage: showMessage
     };
-})();
\ No newline at end of file
+})();
-- 
1.8.3.1




More information about the Kimchi-devel mailing list