]> Softwares of Agnibho - dietsurvey.git/commitdiff
Standardized routine.js
authorAgnibho Mondal <mondal@agnibho.com>
Tue, 28 Mar 2017 05:56:20 +0000 (11:26 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Tue, 28 Mar 2017 05:56:20 +0000 (11:26 +0530)
index.html
src/main.js
src/routine.js

index 3098cead90eabc973e7c1297631727d6421d6df9..6b934d987f6be8418a9df612af73da305d894d8b 100755 (executable)
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script>
+var NAME="DietSurvey";
 var VERSION="3.0.0";
+var STORAGE="dietsurvey_data";
+var INFO_URL="https://code.agnibho.com/dietsurvey/info.json";
+var NOTIFY=true;
     </script>
     <style>
 .loader {
@@ -49,10 +53,10 @@ var VERSION="3.0.0";
   animation: spin 2s linear infinite;
 }
 
-           @keyframes spin {
-             0% { transform: rotate(0deg); }
-             100% { transform: rotate(360deg); }
-           }
+    @keyframes spin {
+      0% { transform: rotate(0deg); }
+      100% { transform: rotate(360deg); }
+    }
     </style>
 
   </head>
index b18a14cbf2ff120da068002f499c2e9b9216ea1b..6e0dad7717c97c0ca479cac6e133dace8f4437e8 100644 (file)
@@ -53,19 +53,19 @@ new Vue({
   data: {dataObj: {family: [], food: []}, dataRef: false},
   created:function(){
     try{
-      var loc=JSON.parse(localStorage.getItem("dietsurvey_data"));
+      var loc=JSON.parse(localStorage.getItem(STORAGE));
       if(loc.version>data.version){
         this.dataRef=loc;
       }
       else{
         this.dataRef=data;
-        localStorage.setItem("dietsurvey_data", JSON.stringify(data));
+        localStorage.setItem(STORAGE, JSON.stringify(data));
       }
     }
     catch(e){
       if(!this.dataRef){
         this.dataRef=data;
-        localStorage.setItem("dietsurvey_data", JSON.stringify(data));
+        localStorage.setItem(STORAGE, JSON.stringify(data));
       }
     }
   }
index 4cc58f62036d285d306d33ee4affbc24ef549259..dd075d8b2eb3afc9341aeeddf1f1f65a428463b0 100644 (file)
@@ -23,6 +23,8 @@
    along with DietSurvey. If not, see <http://www.gnu.org/licenses/>.
  **********************************************************************/
 
+$.ajaxSetup({cache:false});
+
 $(document).ready(function(){
 
   //Remove loader
@@ -31,6 +33,9 @@ $(document).ready(function(){
 
   //Insert version code
   $(".version").text(VERSION);
+  try{
+    $(".data-ver").text(JSON.parse(localStorage.getItem(STORAGE)).version);
+  } catch(e){}
 
   //Update copyright
   $(".copyright").each(function(){
@@ -71,6 +76,16 @@ $(document).ready(function(){
     }
   });
 
+  //Use custom datepicker if Firefox
+  if($(".datepicker").length && navigator.userAgent.indexOf("Firefox")!=-1){
+    $(".datepicker").datepicker({
+      format:"yyyy-mm-dd",
+      autoclose:true
+    }).on("changeDate", function(){
+      this.dispatchEvent(new Event("input"));
+    });
+  }
+
   //Notifications
   $(window).resize(function(){
     $("#notify").width($(".container").width()-20);
@@ -78,9 +93,11 @@ $(document).ready(function(){
   $(window).scroll(function(){
     $("#notify").width($(".container").width()-20);
   });
-  $.get("https://code.agnibho.com/dietsurvey/info.json", function(data){
+  //Get data from server
+  $.get(INFO_URL, function(data){
     var vCurr=VERSION.split(".").map(Number);
     var vLtst=data.latest.split(".").map(Number);
+    //Define version comparator
     function isBiggerThan(v1, v2){
       while(v1.length<v2.length){
         v1.push(0);
@@ -95,10 +112,11 @@ $(document).ready(function(){
       }
       return false;
     }
-    if(isBiggerThan(data.latest, VERSION)){
+    //Compare versions
+    if(NOTIFY && isBiggerThan(data.latest, VERSION)){
       $("#notify").slideDown();
       $("#notify").width($(".container").width()-20);
-      $("#notify-text").text("A new version of DietSurvey is available.");
+      $("#notify-text").text("A new version of "+NAME+" is available.");
       if(document.URL.indexOf("http://")==-1 && document.URL.indexOf("https://")==-1){
         if(/(android)/i.test(navigator.userAgent)){
           $("#notify-link").attr("href", data.apk);
@@ -114,10 +132,11 @@ $(document).ready(function(){
         $("#notify-link").text("Load");
       }
     }
+    //Update app data
     try{
-      if(data.data.latest>JSON.parse(localStorage.getItem("dietsurvey_data")).version){
+      if(data.data.latest>JSON.parse(localStorage.getItem(STORAGE)).version){
         $.get(data.data.src, function(d){
-          localStorage.setItem("dietsurvey_data", JSON.stringify(d));
+          localStorage.setItem(STORAGE, JSON.stringify(d));
         });
       }
     }