changeset 793:d4eb8fb99b5e

Serialising GueltigVon and GueltigBis natively with Ext
author Dustin Demuth <dustin@intevation.de>
date Wed, 13 May 2015 16:01:24 +0200
parents d572ee3271ac
children bc6bc71efb78
files app/model/Messprogramm.js app/view/form/Messprogramm.js index.html resources/lib/Date.prototype.getDOY.js
diffstat 4 files changed, 33 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/app/model/Messprogramm.js	Wed May 13 13:00:13 2015 +0200
+++ b/app/model/Messprogramm.js	Wed May 13 16:01:24 2015 +0200
@@ -62,28 +62,55 @@
         name: 'gueltigVon',
         type: 'date',
         convert: function(v) {
+            var firstofyeartimestamp = new Date(
+                Date.UTC(
+                    new Date().getFullYear(),0,1))
+                .valueOf();
+            var dayToMilli = 86400000;
+
             if (!v) {
                 return v;
             }
-            return new Date(v);
+            //check if v might be a date
+            // unless we go back in time this will work
+            if (v < 1000) {
+                v = v * dayToMilli;
+                v = v + firstofyeartimestamp;
+                v = new Date(v);
+            }
+            return v;
         },
         serialize: function(value) {
             if (value instanceof Date && !isNaN(value.valueOf())) {
-                return value.getDOY();
+                return Ext.Date.getDayOfYear(value);
             }
         }
     }, {
         name: 'gueltigBis',
         type: 'date',
         convert: function(v) {
+            var firstofyeartimestamp = new Date(
+                Date.UTC(
+                    new Date().getFullYear(),0,1))
+                .valueOf();
+            var dayToMilli = 86400000;
+
             if (!v) {
                 return v;
             }
-            return new Date(v);
+
+            //check if v might be a date
+            // unless we go back in time this will work
+            if (v < 1000) {
+                v = v * dayToMilli;
+                v = v + firstofyeartimestamp;
+                v = new Date(v);
+            }
+            return v;
         },
         serialize: function(value) {
             if (value instanceof Date && !isNaN(value.valueOf())) {
-                return value.getDOY();
+                return Ext.Date.getDayOfYear(value);
             }
         }
     }, {
--- a/app/view/form/Messprogramm.js	Wed May 13 13:00:13 2015 +0200
+++ b/app/view/form/Messprogramm.js	Wed May 13 16:01:24 2015 +0200
@@ -246,7 +246,7 @@
                             labelWidth: 90,
                             anchor: '100%',
                             name: 'gueltigVon',
-                            format: 'd.m.Y H:i',
+                            format: 'd.m.Y',
                             period: 'start'
                         }, {
                             xtype: 'datetime',
@@ -254,7 +254,7 @@
                             labelWidth: 90,
                             anchor: '100%',
                             name: 'gueltigBis',
-                            format: 'd.m.Y H:i',
+                            format: 'd.m.Y',
                             period: 'end'
                         }, {
                             xtype: 'numberfield',
--- a/index.html	Wed May 13 13:00:13 2015 +0200
+++ b/index.html	Wed May 13 16:01:24 2015 +0200
@@ -18,7 +18,6 @@
     <script type="text/javascript" src="resources/lib/OpenLayers/OpenLayers.js"></script>
     <script type="text/javascript" src="resources/lib/filesaver/FileSaver.js"></script>
     <script type="text/javascript" src="resources/lib/filesaver/Blob.js"></script>
-    <script type="text/javascript" src="resources/lib/Date.prototype.getDOY.js"></script>
     <!-- <x-compile> -->
     <!-- <x-bootstrap> -->
     <script type="text/javascript" src="extjs/ext-all-debug.js"></script>
--- a/resources/lib/Date.prototype.getDOY.js	Wed May 13 13:00:13 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-
-// A new Prototype to return the Day of the Year.
-// Taken from: http://javascript.about.com/library/bldayyear.htm
-Date.prototype.getDOY = function() {
-    var onejan = new Date(this.getFullYear(),0,1);
-    return Math.ceil((this - onejan) / 86400000);
-}

http://lada.wald.intevation.org