On 02/10/2011 06:35 PM, Endi Sukma Dewata wrote:
On 2/10/2011 5:00 PM, Adam Young wrote:
Should we use one of these functions?
http://www.w3schools.com/jsref/jsref_tostring_date.asp
http://www.w3schools.com/jsref/jsref_tolocalestring.asp
http://www.w3schools.com/jsref/jsref_toutcstring.asp


Our dates are not conisdered valid dates, so we can't just use them.

Isn't it a valid UTC time? We can parse it like what you're doing now using substring(), then use the values to construct a Date object in JS. Then we can invoke one of the above methods to display a properly formatted date.

Using Date format, but only for GMT
From e010366217eb72744c828f012a4d23a5d985de11 Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Thu, 10 Feb 2011 16:48:17 -0500
Subject: [PATCH 2/2] column formatting
 Allow optional formatting for columns
 Provide Data formate for host modificaiton

date format
---
 install/ui/aci.js    |   17 ++++++++++++-----
 install/ui/host.js   |   30 +++++++++++++++++++++++++++++-
 install/ui/widget.js |    8 ++++++++
 3 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/install/ui/aci.js b/install/ui/aci.js
index 494bd9a5bd91b9c4de0210e2d9e3923d215f00e6..89caec040ea28e97406f336832bb4c4f26793b7b 100644
--- a/install/ui/aci.js
+++ b/install/ui/aci.js
@@ -227,21 +227,28 @@ IPA.target_section = function(spec) {
     that.add_field(that.attribute_table);
 
 
+    /*TODO these next two functions are work arounds for missing attribute
+      permissions for the filter text.  Remove them once that has been fixed */
     that.filter_text.update = function(){
         var value = that.filter_text.values && that.filter_text.values.length ?
             that.filter_text.values[0] : '';
-        $('input[name="'+that.filter_text.name+'"]', that.filter_text.container).val(value);
+        $('input[name="'+that.filter_text.name+'"]',
+          that.filter_text.container).val(value);
 
         var label = $('label[name="'+that.filter_text.name+'"]',
                       that.filter_text.container);
         var input = $('input[name="'+that.filter_text.name+'"]',
                       that.filter_text.container);
-
-            label.css('display', 'none');
-            input.css('display', 'inline');
-
+        label.css('display', 'none');
+        input.css('display', 'inline');
     };
 
+    that.filter_text.save = function(){
+        var input = $('input[name="'+that.filter_text.name+'"]',
+                      that.filter_text.container);
+        var value = $.trim(input.val());
+        return value === '' ? [] : [value];
+    };
 
     var target_types = [
         {
diff --git a/install/ui/host.js b/install/ui/host.js
index 86a5b820aeaaea9e6819444d27dc1d8142e4a097..1e203787158c43d014f6d24e1728df7d198a8f77 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -103,6 +103,32 @@ IPA.host_add_dialog = function (spec) {
     return that;
 };
 
+/* Take an LDAP format date in UTC and format it */
+IPA.utc_date_column_format = function(value){
+    if (!value) {
+        return "";
+    }
+    if (value.length  != "20101119025910Z".length){
+        return value;
+    }
+    /* We only handle GMT */
+    if (value.charAt(value.length -1) !== 'Z'){
+        return value;
+    }
+
+    var date = new Date();
+
+    date.setUTCFullYear(
+        value.substring(0, 4),
+        value.substring(4, 6),
+        value.substring(6, 8));
+    date.setUTCHours(
+        value.substring(8, 10),
+        value.substring(10, 12),
+        value.substring(12, 14));
+    var formated = date.toString();
+    return  formated;
+}
 
 IPA.host_search_facet = function (spec) {
 
@@ -115,7 +141,9 @@ IPA.host_search_facet = function (spec) {
         that.create_column({name:'fqdn'});
         that.create_column({name:'description'});
         //TODO use the value of this field to set enrollment status
-        that.create_column({name:'krblastpwdchange', label:'Enrolled?'});
+        that.create_column({name:'krblastpwdchange', label:'Enrolled?',
+                            format:IPA.utc_date_column_format
+                           });
         that.create_column({name:'nshostlocation'});
 
         that.search_facet_init();
diff --git a/install/ui/widget.js b/install/ui/widget.js
index 1bff1579dbb16a99c85ebb2c1c5f2b33c547a347..78a594680cf09f2fdd07e63d465b372001a34277 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -1005,6 +1005,9 @@ IPA.column = function (spec) {
 
     var that = {};
 
+    if (spec.format){
+        that.format = spec.format;
+    }
     that.name = spec.name;
     that.label = spec.label;
     that.primary_key = spec.primary_key;
@@ -1025,8 +1028,13 @@ IPA.column = function (spec) {
         container.empty();
 
         var value = record[that.name];
+        if (that.format && value){
+            value = that.format(value);
+        }
+
         value = value ? value.toString() : '';
 
+
         container.append(value);
     }
 
-- 
1.7.3.5

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to