]> Softwares of Agnibho - obscalc.git/commitdiff
Standardized routine.js
authorAgnibho Mondal <mondal@agnibho.com>
Tue, 28 Mar 2017 06:02:40 +0000 (11:32 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Tue, 28 Mar 2017 06:02:40 +0000 (11:32 +0530)
index.html
src/Settings.vue
src/main.js
src/routine.js

index 2f1f5cba6026da9205081d767f8c1b8d283b0ba4..a5224bc41942c54a34d34403de64079ea8bbf0d0 100755 (executable)
@@ -9,82 +9,86 @@
    All rights reserved
  **********************************************************************
    This file is part of ObsCalc.
-   
+
    ObsCalc is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
-   
+
    ObsCalc is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
-   along with Obscalc. If not, see <http://www.gnu.org/licenses/>.
+   along with ObsCalc. If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************
 -->
 <!DOCTYPE html>
 <html>
-    <head>
-       <title>ObsCalc</title>
-       <link rel="icon" href="dist/logo.png">
-       <meta charset="utf-8">
-       <meta name="viewport" content="width=device-width, initial-scale=1.0">
-       <script>
-        var VERSION="2.1.0";
-       </script>
-       <style>
-        .loader {
-            position: absolute;
-            left: 50%;
-            top: 50%;
-            border: 16px solid lavender;
-            border-top: 16px solid #428bca;
-            border-bottom: 16px solid #428bca;
-            border-radius: 50%;
-            width: 150px;
-            height: 150px;
-            margin: -75px 0 0 -75px;
-            animation: spin 2s linear infinite;
-        }
-        
-        @keyframes spin {
-            0% { transform: rotate(0deg); }
-            100% { transform: rotate(360deg); }
-        }
-       </style>
+  <head>
+    <title>ObsCalc</title>
+    <link rel="icon" href="dist/logo.png">
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <script>
+var NAME="ObsCalc";
+var VERSION="2.1.0";
+var STORAGE="obscalc_data";
+var INFO_URL="https://code/agnibho.com/obscalc/info.json";
+var NOTIFY=true;
+    </script>
+    <style>
+.loader {
+  position: absolute;
+  left: 50%;
+  top: 50%;
+  border: 16px solid lavender;
+  border-top: 16px solid #428bca;
+  border-bottom: 16px solid #428bca;
+  border-radius: 50%;
+  width: 150px;
+  height: 150px;
+  margin: -75px 0 0 -75px;
+  animation: spin 2s linear infinite;
+}
+
+    @keyframes spin {
+      0% { transform: rotate(0deg); }
+      100% { transform: rotate(360deg); }
+    }
+    </style>
 
-    </head>
-    <body>
-       <div class="loader"></div>
-       <div class="container" style="display:none">
-           <div id="notify" style="position:fixed;margin:10px;z-index:2;display:none">
-               <div id="notify-alert" class="alert alert-info alert-dismissible">
-                   <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
-                   <h4><span id="notify-text"></span> <a id="notify-link" href="#" class="btn btn-success btn-lg">Download</a></h4>
-               </div>
-           </div>
-           <div class="text-primary">
-               <div class="jumbotron">
-                   <h1>ObsCalc</h1>
-                   <h2>Obstetric Calculator</h2>
-               </div>
-           </div>
-           <div class="row" id="app">
-               <div class="col-sm-6">
-                   <by-date :settings="settings"></by-date>
-               </div>
-               <div class="col-sm-6">
-                   <by-usg :settings="settings"></by-usg>
-               </div>
-               <settings-btn :settings="settings"></settings-btn>
-           </div>
-           <div class="alert alert-info">
-               <h3>Copyright &copy; <span class="copyright" data-start="2016">2016</span> Agnibho Mondal</h3>
-               <h4><a href="http://www.agnibho.com" style="text-decoration:none;color:inherit">www.agnibho.com</a></h4>
-           </div>
-       </div>
-       <script src="dist/bundle.js"></script>
-    </body>
+  </head>
+  <body>
+    <div class="loader"></div>
+    <div class="container" style="display:none">
+      <div id="notify" style="position:fixed;margin:10px;z-index:2;display:none">
+        <div id="notify-alert" class="alert alert-info alert-dismissible">
+          <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
+          <h4><span id="notify-text"></span> <a id="notify-link" href="#" class="btn btn-success btn-lg">Download</a></h4>
+        </div>
+      </div>
+      <div class="text-primary">
+        <div class="jumbotron">
+          <h1>ObsCalc</h1>
+          <h2>Obstetric Calculator</h2>
+        </div>
+      </div>
+      <div class="row" id="app">
+        <div class="col-sm-6">
+          <by-date :settings="settings"></by-date>
+        </div>
+        <div class="col-sm-6">
+          <by-usg :settings="settings"></by-usg>
+        </div>
+        <settings-btn :settings="settings"></settings-btn>
+      </div>
+      <div class="alert alert-info">
+        <h3>Copyright &copy; <span class="copyright" data-start="2016">2016</span> Agnibho Mondal</h3>
+        <h4><a href="http://www.agnibho.com" style="text-decoration:none;color:inherit">www.agnibho.com</a></h4>
+      </div>
+    </div>
+    <script src="dist/bundle.js"></script>
+  </body>
 </html>
index fe87f1213b507a6078e0c077bcd95c3274d60cbf..230f718b6fb2a0c8a52b519a52f6a248b3cd2e04 100644 (file)
 <!--
-***********************************************************************
- * Title: ObsCalc
- * Description: An Obstetric Calculator
- * Author: Agnibho Mondal
- * Website: http://code.agnibho.com
- **********************************************************************
-   Copyright (c) 2016 Agnibho Mondal
-   All rights reserved
- **********************************************************************
-   This file is part of ObsCalc.
-   
-   ObsCalc is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation, either version 3 of the License, or
-   (at your option) any later version.
-   
-   ObsCalc is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with Obscalc. If not, see <http://www.gnu.org/licenses/>.
-***********************************************************************
---> 
+  ***********************************************************************
 * Title: ObsCalc
 * Description: An Obstetric Calculator
 * Author: Agnibho Mondal
 * Website: http://code.agnibho.com
 **********************************************************************
+  Copyright (c) 2016 Agnibho Mondal
+  All rights reserved
 **********************************************************************
+  This file is part of ObsCalc.
+
+  ObsCalc is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  ObsCalc is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with Obscalc. If not, see <http://www.gnu.org/licenses/>.
+  ***********************************************************************
+-->
 
 <template>
-    <div>
-       <button class="btn-fab" title="Settings" data-toggle="modal" data-target="#settings-modal"><span class="glyphicon glyphicon-cog glyphicon-center" aria-hidden="true"></span></button>
-       <div class="modal fade" id="settings-modal" tabindex="-1">
-           <div class="modal-dialog">
-               <div class="modal-content">
-                   <div class="modal-header">
-                       <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
-                   </div>
-                   <div class="modal-body">
-                       <div class="panel panel-default">
-                           <div class="panel-heading">
-                               <h4>Settings</h4>
-                           </div>
-                           <div class="panel-body">
-                               <form>
-                                   <div class="">
-                                       <div class="row">
-                                           <div class="col-sm-4 col-sm-offset-2">
-                                               <label>Date input style:</label>
-                                           </div>
-                                           <div class="col-sm-6">
-                                               <div class="radio"><label><input type="radio" name="date-style" value="cal" v-model="settings.dstyle"><strong>Calendar</strong></label></div>
-                                               <div class="radio"><label><input type="radio" name="date-style" value="txt" v-model="settings.dstyle"><strong>Textbox</strong></label></div>
-                                           </div>
-                                       </div>
-                                   </div>
-                               </form>
-                           </div>
-                       </div>
-                       <div class="panel panel-default">
-                           <div class="panel-heading">
-                               <h4><a data-toggle="collapse" href="#about-text" style="text-decoration:none;color:inherit">About</a></h4>
-                           </div>
-                           <div id="about-text" class="panel-collapse collapse">
-                               <div class="panel-body">
-                                   <p><strong>ObsCalc <span class="version"></span></strong></p>
-                                   <p>ObsCalc is a free and open source software published under GPL v3. It has been developed by Agnibho Mondal &lt;mail@agnibho.com&gt;.</p>
-                                   <p><a href="https://code.agnibho.com/obscalc/">https://code.agnibho.com/obscalc/</a></p>
-                                   <p>Copyright &copy; <span class="copyright" data-start="2016">2016</span> Agnibho Mondal</p>
-                               </div>
-                           </div>
-                       </div>
-                   </div>
-                   <div class="modal-footer">
-                       <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
-                   </div>
-               </div>
-           </div>
-       </div>
+  <div>
+    <button class="btn-fab" title="Settings" data-toggle="modal" data-target="#settings-modal"><span class="glyphicon glyphicon-cog glyphicon-center" aria-hidden="true"></span></button>
+    <div class="modal fade" id="settings-modal" tabindex="-1">
+      <div class="modal-dialog">
+        <div class="modal-content">
+          <div class="modal-header">
+            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
+          </div>
+          <div class="modal-body">
+            <div class="panel panel-default">
+              <div class="panel-heading">
+                <h4>Settings</h4>
+              </div>
+              <div class="panel-body">
+                <form>
+                  <div class="">
+                    <div class="row">
+                      <div class="col-sm-4 col-sm-offset-2">
+                        <label>Date input style:</label>
+                      </div>
+                      <div class="col-sm-6">
+                        <div class="radio"><label><input type="radio" name="date-style" value="cal" v-model="settings.dstyle"><strong>Calendar</strong></label></div>
+                        <div class="radio"><label><input type="radio" name="date-style" value="txt" v-model="settings.dstyle"><strong>Textbox</strong></label></div>
+                      </div>
+                    </div>
+                  </div>
+                </form>
+              </div>
+            </div>
+            <div class="panel panel-default">
+              <div class="panel-heading">
+                <h4><a data-toggle="collapse" href="#about-text" style="text-decoration:none;color:inherit">About</a></h4>
+              </div>
+              <div id="about-text" class="panel-collapse collapse">
+                <div class="panel-body">
+                  <p><strong>ObsCalc <span class="version"></span></strong></p>
+                  <p>ObsCalc is a free and open source software published under GPL v3. It has been developed by Agnibho Mondal &lt;mail@agnibho.com&gt;.</p>
+                  <p><a href="https://code.agnibho.com/obscalc/">https://code.agnibho.com/obscalc/</a></p>
+                  <p>Copyright &copy; <span class="copyright" data-start="2016">2016</span> Agnibho Mondal</p>
+                </div>
+              </div>
+            </div>
+          </div>
+          <div class="modal-footer">
+            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+          </div>
+        </div>
+      </div>
     </div>
+  </div>
 </template>
 
 <script>
- export default {
-     name:'Settings',
-     props:['settings'],
-     watch:{
-        'settings':{
-            handler:function(){
-                localStorage.setItem("settings", JSON.stringify(this.settings));
-            },
-            deep:true
-        }
-     }
- }
+export default {
+  name:'Settings',
+  props:['settings'],
+  watch:{
+    'settings':{
+      handler:function(){
+        localStorage.setItem("obscalc_settings", JSON.stringify(this.settings));
+      },
+      deep:true
+    }
+  }
+}
 </script>
 
 <style>
- .btn-fab{
-     position:fixed;
-     top:10px;
-     left:10px;
-     background-color:#5bc0de;
-     width:40px;
-     height:40px;
-     border-radius:100%;
-     background:#5bc0de;
-     border:none;
-     outline:none;
-     color:white;
-     font-size:30px;
-     box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
-     -webkit-tap-highlight-color:rgba(0,0,0,0);
- }
+.btn-fab{
+  position:fixed;
+  top:10px;
+  left:10px;
+  background-color:#5bc0de;
+  width:40px;
+  height:40px;
+  border-radius:100%;
+  background:#5bc0de;
+  border:none;
+  outline:none;
+  color:white;
+  font-size:30px;
+  box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
+  -webkit-tap-highlight-color:rgba(0,0,0,0);
+}
  .glyphicon-center{
-     margin-top:5px;
+   margin-top:5px;
  }
 </style>
index b91310b897fde15554e6f8dbcdd8bee969051f71..16358689b0ab860d44c4e1e85611203842d7a34c 100644 (file)
@@ -8,17 +8,17 @@
    All rights reserved
  **********************************************************************
    This file is part of ObsCalc.
-   
+
    ObsCalc is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
-   
+
    ObsCalc is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with Obscalc. If not, see <http://www.gnu.org/licenses/>.
  **********************************************************************/
@@ -45,27 +45,32 @@ import Settings from "./Settings.vue";
 
 //Start app
 new Vue({
-    el: "#app",
-    components: {
-       "by-date": ByDate,
-       "by-usg": ByUsg,
-       "settings-btn": Settings
-    },
-    data: {settings: ""},
-    mounted:function(){
-       try{
-           this.settings=JSON.parse(localStorage.getItem("settings"));
-       }
-       finally{
-           if(this.settings==null){
-               this.settings={dstyle:"cal"};
-           }
-           else if(this.settings.dstyle!="cal" && this.settings.dstyle!="txt"){
-               this.settings={dstyle:"cal"};
-           }
-       }
+  el: "#app",
+  components: {
+    "by-date": ByDate,
+    "by-usg": ByUsg,
+    "settings-btn": Settings
+  },
+  data: {settings: ""},
+  mounted:function(){
+    try{
+      this.settings=JSON.parse(localStorage.getItem("obscalc_settings"));
     }
+    catch(e){
+    }
+    finally{
+      if(this.settings==null){
+        this.settings={dstyle:"cal"};
+      }
+      else if(this.settings.dstyle!="cal" && this.settings.dstyle!="txt"){
+        this.settings={dstyle:"cal"};
+      }
+    }
+  }
 });
 
 //Routine jobs
-import "./routine.js";
+import "./routine.js"
+
+//Source Map
+//#sourceMappingURL=dist/bundle.js.map;
index cb461512c6be876865c487eee7969b6562efb70c..dd075d8b2eb3afc9341aeeddf1f1f65a428463b0 100644 (file)
 /**********************************************************************
- * Title: ObsCalc
- * Description: An Obstetric Calculator
+ * Title: DietSurvey
+ * Description: Nutritional Assessment App
  * Author: Agnibho Mondal
  * Website: http://code.agnibho.com
  **********************************************************************
    Copyright (c) 2016 Agnibho Mondal
    All rights reserved
  **********************************************************************
-   This file is part of ObsCalc.
-   
-   ObsCalc is free software: you can redistribute it and/or modify
+   This file is part of DietSurvey.
+
+   DietSurvey is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
-   
-   ObsCalc is distributed in the hope that it will be useful,
+
+   DietSurvey is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
-   along with Obscalc. If not, see <http://www.gnu.org/licenses/>.
+   along with DietSurvey. If not, see <http://www.gnu.org/licenses/>.
  **********************************************************************/
 
+$.ajaxSetup({cache:false});
+
 $(document).ready(function(){
 
-    //Remove loader
-    $(".loader").remove();
-    $(".container").fadeIn();
+  //Remove loader
+  $(".loader").remove();
+  $(".container").fadeIn();
 
-    //Insert version code
-    $(".version").text(VERSION);
+  //Insert version code
+  $(".version").text(VERSION);
+  try{
+    $(".data-ver").text(JSON.parse(localStorage.getItem(STORAGE)).version);
+  } catch(e){}
 
-    //Update copyright
-    $(".copyright").each(function(){
-       if(new Date().getFullYear()>$(this).data("start")){
-           $(this).text($(this).data("start")+"-"+new Date().getFullYear());
-       }
-       else{
-           $(this).text(new Date().getFullYear());
-       }
-    });
+  //Update copyright
+  $(".copyright").each(function(){
+    if(new Date().getFullYear()>$(this).data("start")){
+      $(this).text($(this).data("start")+"-"+new Date().getFullYear());
+    }
+    else{
+      $(this).text(new Date().getFullYear());
+    }
+  });
 
-    //Emit input on form reset
-    $("input[type='reset']").on("click", function(e){
-       this.form.reset();
-       $(this.form).find("input, select, textarea").each(function(){
-           this.dispatchEvent(new Event("input"));
-       });
+  //Emit input on form reset
+  $("input[type='reset']").on("click", function(e){
+    this.form.reset();
+    $(this.form).find("input, select, textarea").each(function(){
+      this.dispatchEvent(new Event("input"));
     });
+  });
 
-    //Use custom datepicker if Firefox
-    if(navigator.userAgent.indexOf("Firefox")!=-1){
-       $(".datepicker").datepicker({
-           format:"yyyy-mm-dd",
-           autoclose:true
-       }).on("changeDate", function(){
-           this.dispatchEvent(new Event("input"));
-       });
+  //Change focus after number input
+  $(".jump-focus").on("input", function(){
+    if($(this).val().length == $(this).prop("maxlength")){
+      var all=$("input").toArray();
+      var i=all.indexOf(this)+1;
+      $(all[i]).focus().select();
     }
-    
-    //Change focus after number input
-    $(".jump-focus").on("input", function(){
-       if($(this).val().length == $(this).prop("maxlength")){
-           var all=$("input").toArray();
-           var i=all.indexOf(this)+1;
-           $(all[i]).focus().select();
-       }
-    });
+  });
 
-    //Defocus after input finished
-    $(".stop-focus").on("input", function(){
-       if($(this).val().length == $(this).prop("maxlength")){
-           $(this).blur();
-           var target=$($(this).data("ref"));
-           console.log($(target).offset());
-           $("html, body").animate({
-               scrollTop: $(target).offset().top
-           }, 1000);
-       }
-    });
+  //Defocus after input finished
+  $(".stop-focus").on("input", function(){
+    if($(this).val().length == $(this).prop("maxlength")){
+      $(this).blur();
+      var target=$($(this).data("ref"));
+      console.log($(target).offset());
+      $("html, body").animate({
+        scrollTop: $(target).offset().top
+      }, 1000);
+    }
+  });
 
-    //Notifications
-    $(window).resize(function(){
-       $("#notify").width($(".container").width()-20);
-    });
-    $(window).scroll(function(){
-       $("#notify").width($(".container").width()-20);
-    });
-    $.get("https://code.agnibho.com/obscalc/info.json", function(data){
-       var vCurr=VERSION.split(".").map(Number);
-       var vLtst=data.latest.split(".").map(Number);
-       function isBiggerThan(v1, v2){
-           while(v1.length<v2.length){
-               v1.push(0);
-           }
-           while(v2.length<v1.length){
-               v2.push(0);
-           }
-           for(var i=0; i<v1.length; i++){
-               if(v1[i]>v2[i]){
-                   return true;
-               }
-           }
-           return false;
-       }
-       if(isBiggerThan(data.latest, VERSION)){
-           $("#notify").slideDown();
-           $("#notify").width($(".container").width()-20);
-           $("#notify-text").text("A new version of ObsCalc 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);
-                   $("#notify-link").text("Download");
-               }
-               else{
-                   $("#notify-link").attr("href", data.url);
-                   $("#notify-link").text("Load");
-               }
-           }
-           else{
-               $("#notify-link").attr("href", data.url);
-               $("#notify-link").text("Load");
-           }
-       }
+  //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);
+  });
+  $(window).scroll(function(){
+    $("#notify").width($(".container").width()-20);
+  });
+  //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);
+      }
+      while(v2.length<v1.length){
+        v2.push(0);
+      }
+      for(var i=0; i<v1.length; i++){
+        if(v1[i]>v2[i]){
+          return true;
+        }
+      }
+      return false;
+    }
+    //Compare versions
+    if(NOTIFY && isBiggerThan(data.latest, VERSION)){
+      $("#notify").slideDown();
+      $("#notify").width($(".container").width()-20);
+      $("#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);
+          $("#notify-link").text("Download");
+        }
+        else{
+          $("#notify-link").attr("href", data.url);
+          $("#notify-link").text("Load");
+        }
+      }
+      else{
+        $("#notify-link").attr("href", data.url);
+        $("#notify-link").text("Load");
+      }
+    }
+    //Update app data
+    try{
+      if(data.data.latest>JSON.parse(localStorage.getItem(STORAGE)).version){
+        $.get(data.data.src, function(d){
+          localStorage.setItem(STORAGE, JSON.stringify(d));
+        });
+      }
+    }
+    catch(e){}
+  });
 });