فهرست منبع

update js timeformat handler

Jason Rivard 7 سال پیش
والد
کامیت
de943b45d0

+ 1 - 0
server/src/main/java/password/pwm/http/servlet/ClientApiServlet.java

@@ -283,6 +283,7 @@ public class ClientApiServlet extends ControlledPwmServlet {
         settingMap.put("client.ajaxTypingWait", Integer.parseInt(config.readAppProperty(AppProperty.CLIENT_AJAX_TYPING_WAIT)));
         settingMap.put("client.activityMaxEpsRate", Integer.parseInt(config.readAppProperty(AppProperty.CLIENT_ACTIVITY_MAX_EPS_RATE)));
         settingMap.put("client.js.enableHtml5Dialog", Boolean.parseBoolean(config.readAppProperty(AppProperty.CLIENT_JS_ENABLE_HTML5DIALOG)));
+        settingMap.put("client.locale", pwmSession.getSessionStateBean().getLocale() );
         settingMap.put("client.pwShowRevertTimeout", Integer.parseInt(config.readAppProperty(AppProperty.CLIENT_PW_SHOW_REVERT_TIMEOUT)));
         settingMap.put("enableIdleTimeout", config.readSettingAsBoolean(PwmSetting.DISPLAY_IDLE_TIMEOUT));
         settingMap.put("pageLeaveNotice", config.readSettingAsLong(PwmSetting.SECURITY_PAGE_LEAVE_NOTICE_TIMEOUT));

+ 60 - 50
server/src/main/webapp/public/resources/js/main.js

@@ -25,6 +25,11 @@
 var PWM_GLOBAL = PWM_GLOBAL || {};
 var PWM_MAIN = PWM_MAIN || {};
 var PWM_VAR = PWM_VAR || {};
+var PWM_API = PWM_API || {};
+
+PWM_API.formatDate = function(dateObj) {
+    return PWM_MAIN.TimestampHandler.formatDate(dateObj);
+};
 
 PWM_MAIN.ajaxTimeout = 120 * 1000;
 
@@ -240,8 +245,8 @@ PWM_MAIN.applyFormAttributes = function() {
             PWM_MAIN.addEventHandler(linkElement, "click", function (event) {
                 event.preventDefault();
                 PWM_MAIN.showWaitDialog({loadFunction: function () {
-                    PWM_MAIN.goto(hrefValue);
-                }});
+                        PWM_MAIN.goto(hrefValue);
+                    }});
             });
             linkElement.removeAttribute('href');
         }
@@ -333,8 +338,8 @@ PWM_MAIN.goto = function(url,options) {
         executeGoto();
     } else {
         PWM_MAIN.showWaitDialog({loadFunction:function () {
-            executeGoto();
-        }});
+                executeGoto();
+            }});
     }
 };
 
@@ -345,38 +350,38 @@ PWM_MAIN.handleLoginFormSubmit = function(form, event) {
 
     require(["dojo","dojo/dom-form"], function(dojo, domForm) {
         PWM_MAIN.showWaitDialog({loadFunction: function () {
-            var options = {};
-            options['content'] = domForm.toObject(form);
-            delete options['content']['processAction'];
-            delete options['content']['pwmFormID'];
-            var url = 'login?processAction=restLogin&skipCaptcha=' + options['content']['skipCaptcha'];
-            var loadFunction = function(data) {
-                if (data['error'] === true) {
-                    PWM_MAIN.getObject('password').value = '';
-                    PWM_MAIN.showErrorDialog(data,{
-                        okAction:function(){
-                            setTimeout(function(){
-                                PWM_MAIN.getObject('password').focus();
-                            },50);
-                        }
-                    });
-                    return;
-                }
-                console.log('authentication success');
-                var nextURL = data['data']['nextURL'];
-                if (nextURL) {
-                    PWM_MAIN.goto(nextURL, {noContext: true});
-                }
-            };
-            PWM_MAIN.ajaxRequest(url,loadFunction,options);
-            if(typeof grecaptcha !== 'undefined'){
-                try {
-                    grecaptcha.reset(); // reset the
-                } catch (e) {
-                    console.log("error resetting the captcha: " + e)
+                var options = {};
+                options['content'] = domForm.toObject(form);
+                delete options['content']['processAction'];
+                delete options['content']['pwmFormID'];
+                var url = 'login?processAction=restLogin&skipCaptcha=' + options['content']['skipCaptcha'];
+                var loadFunction = function(data) {
+                    if (data['error'] === true) {
+                        PWM_MAIN.getObject('password').value = '';
+                        PWM_MAIN.showErrorDialog(data,{
+                            okAction:function(){
+                                setTimeout(function(){
+                                    PWM_MAIN.getObject('password').focus();
+                                },50);
+                            }
+                        });
+                        return;
+                    }
+                    console.log('authentication success');
+                    var nextURL = data['data']['nextURL'];
+                    if (nextURL) {
+                        PWM_MAIN.goto(nextURL, {noContext: true});
+                    }
+                };
+                PWM_MAIN.ajaxRequest(url,loadFunction,options);
+                if(typeof grecaptcha !== 'undefined'){
+                    try {
+                        grecaptcha.reset(); // reset the
+                    } catch (e) {
+                        console.log("error resetting the captcha: " + e)
+                    }
                 }
-            }
-        }});
+            }});
     });
 };
 
@@ -395,8 +400,8 @@ PWM_MAIN.handleFormSubmit = function(form, event) {
     }
 
     PWM_MAIN.showWaitDialog({loadFunction:function(){
-        form.submit();
-    }});
+            form.submit();
+        }});
     return false;
 };
 
@@ -1652,13 +1657,11 @@ PWM_MAIN.TimestampHandler.initAllElements = function() {
 
 PWM_MAIN.TimestampHandler.testIfStringIsTimestamp = function(input, trueFunction) {
     if (input && input.length > 0) {
-        require(["dojo", "dojo/date/stamp"], function (dojo, IsoDate) {
-            input = dojo.trim(input);
-            var dateObj = IsoDate.fromISOString(input);
-            if (dateObj) {
-                trueFunction(dateObj);
-            }
-        });
+        input = input.trim();
+        var timestamp = Date.parse(input);
+        if (isNaN(timestamp) === false) {
+            trueFunction(new Date(timestamp));
+        }
     }
 };
 
@@ -1673,10 +1676,10 @@ PWM_MAIN.TimestampHandler.initElement = function(element) {
 
     require(["dojo"], function(dojo) {
         var innerText = dojo.attr(element, 'innerHTML');
-        innerText = dojo.trim(innerText);
-        PWM_MAIN.TimestampHandler.testIfStringIsTimestamp(innerText, function (dateObj) {
+        innerText = innerText.trim(innerText);
+        PWM_MAIN.TimestampHandler.testIfStringIsTimestamp(innerText, function () {
             element.setAttribute('data-timestamp-original', innerText);
-            PWM_MAIN.addEventHandler(element.id, 'click', function(){
+            PWM_MAIN.addEventHandler(element, 'click', function(){
                 var LocalizedState = !PWM_MAIN.Preferences.readSessionStorage(PWM_MAIN.TimestampHandler.PreferencesKey,true);
                 PWM_MAIN.Preferences.writeSessionStorage(PWM_MAIN.TimestampHandler.PreferencesKey, LocalizedState);
                 PWM_MAIN.TimestampHandler.updateAllElements();
@@ -1704,12 +1707,13 @@ PWM_MAIN.TimestampHandler.updateAllElements = function() {
 };
 
 PWM_MAIN.TimestampHandler.updateElement = function(element) {
-    require(["dojo","dojo/date/stamp","dojo/date/locale"], function(dojo,IsoDate,LocaleDate) {
+    require(["dojo"], function(dojo) {
         var localized = PWM_MAIN.Preferences.readSessionStorage(PWM_MAIN.TimestampHandler.PreferencesKey,true);
         if (localized) {
             var isoDateStr = element.getAttribute('data-timestamp-original');
-            var date = IsoDate.fromISOString(isoDateStr);
-            var localizedStr = LocaleDate.format(date,{formatLength:'long'});
+            var date = new Date(Date.parse(isoDateStr));
+            var localizedStr = PWM_MAIN.TimestampHandler.formatDate(date);
+
             dojo.attr(element,'innerHTML',localizedStr);
         } else {
             dojo.attr(element,'innerHTML',element.getAttribute('data-timestamp-original'));
@@ -1717,6 +1721,12 @@ PWM_MAIN.TimestampHandler.updateElement = function(element) {
     })
 };
 
+PWM_MAIN.TimestampHandler.formatDate = function(dateObj) {
+    var options = {timeZoneName:'short', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric'};
+    var locale = PWM_GLOBAL['client.locale'];
+    return dateObj.toLocaleString(locale, options);
+};
+
 PWM_MAIN.addPwmFormIDtoURL = function(url) {
     return PWM_MAIN.addParamToUrl(url,'pwmFormID',PWM_GLOBAL['pwmFormID']);
 };