initial checkin of modular app
authorhackbard <hackbard@hackdaworld.org>
Sun, 15 May 2016 10:28:59 +0000 (12:28 +0200)
committerhackbard <hackbard@hackdaworld.org>
Sun, 15 May 2016 10:28:59 +0000 (12:28 +0200)
app/config.xml [new file with mode: 0644]
app/www/css/index.css [new file with mode: 0644]
app/www/index.html [new file with mode: 0644]
app/www/js/config.js [new file with mode: 0644]
app/www/js/index.js [new file with mode: 0644]
app/www/js/jquery.js [new symlink]

diff --git a/app/config.xml b/app/config.xml
new file mode 100644 (file)
index 0000000..f781c08
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version='1.0' encoding='utf-8'?>
+<widget id="org.hackdaworld.modular" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
+    <name>Modular</name>
+    <description>
+        A simple app to count whatever you like.
+    </description>
+    <author email="hackbard@hackdaworld.org" href="http://hackdaworld.org">
+        hackbard@hackdaworld.org
+    </author>
+    <content src="index.html" />
+    <plugin name="cordova-plugin-whitelist" spec="1" />
+    <access origin="*" />
+    <allow-intent href="http://*/*" />
+    <allow-intent href="https://*/*" />
+    <allow-intent href="tel:*" />
+    <allow-intent href="sms:*" />
+    <allow-intent href="mailto:*" />
+    <allow-intent href="geo:*" />
+    <platform name="android">
+        <allow-intent href="market:*" />
+    </platform>
+    <platform name="ios">
+        <allow-intent href="itms:*" />
+        <allow-intent href="itms-apps:*" />
+    </platform>
+</widget>
diff --git a/app/www/css/index.css b/app/www/css/index.css
new file mode 100644 (file)
index 0000000..7714f9d
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+html {
+       height: 100%;
+}
+
+body {
+       height: 100%;
+       margin: 0;
+       background-color: black;
+}
+
+#main {
+       width: 100%;
+       height: 100%;
+       display: none;
+}
+
+#moddiag {
+       width: 100%;
+       height: 100%;
+}
+
+.mod {
+       width: 42.5%;
+       height: 80%;
+       margin-top: 5%;
+       margin-left: 5%;
+       background-color: white;
+       float: left;
+}
+
+.mdhead {
+       width: 100%;
+       height: 10%;
+       text-align: center;
+}
+
+.mdmain {
+       width: 97%;
+       height: 90%;
+       margin-left: 3%;
+       overflow: auto;
+}
+
+.mdcbtn {
+       width: 90%;
+       height: 10%;
+       margin: 3%;
+       text-align: center;
+       background-color: #ddd;
+}
+
+.mdcline {
+       width: 30%;
+       float: left;
+}
+
+.mdcinput {
+       width: 70%;
+       float: left;
+}
+
+#mdnc {
+       width: 100%;
+       margin-top: 3%;
+       clear: left;
+}
+
+.item {
+       float: left;
+       text-align: center;
+}
+
+#mdcont {
+}
+
+#mdnew {
+}
+
diff --git a/app/www/index.html b/app/www/index.html
new file mode 100644 (file)
index 0000000..8d44014
--- /dev/null
@@ -0,0 +1,99 @@
+<!DOCTYPE html>
+
+<!--
+       modular: simple app to count whatever you like
+       author: hackbard@hackdaworld.org
+-->
+
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+     KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+
+<html>
+       <head>
+               <title>Modular</title>
+
+               <meta name="format-detection" content="telephone=no">
+               <meta name="msapplication-tap-highlight" content="no">
+               <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
+
+               <link rel="stylesheet" type="text/css" href="css/index.css">
+
+               <!--
+               <link rel="stylesheet" type="text/css"
+                     href="mobile/jquery.mobile-1.4.5.css">
+               <script type="text/javascript"
+                       src="mobile/jquery.mobile-1.4.5.min.js"></script>
+               -->
+
+               <script type="text/javascript" src="cordova.js"></script>
+               <script type="text/javascript" src="js/jquery.js"></script>
+               <script type="text/javascript" src="js/jsutils/utils.js">
+               </script>
+               <script type="text/javascript" src="js/jsutils/idb.js">
+               </script>
+               <script type="text/javascript" src="js/config.js"></script>
+               <script type="text/javascript" src="js/index.js"></script>
+       </head>
+       <body>
+               <div id=main>
+               </div>
+               <div id=moddiag>
+                       <div class=mod>
+                               <div class=mdhead>
+                               Continue counting ...
+                               </div>
+                               <div id=mdcont class=mdmain>
+                               </div>
+                       </div>
+                       <div class=mod>
+                               <div class=mdhead>
+                               New setup!
+                               </div>
+                               <div class=mdmain>
+                                       <div class=mdcline>Name</div>
+                                       <div class=mdcinput>
+                                               <input id=mdiname value=New
+                                                      class=mdni type=text>
+                                       </div>
+                                       <div class=mdcline>Total</div>
+                                       <div class=mdcinput>
+                                               <input id=mditot value=0
+                                                      min=1 max=99
+                                                      class=mdni type=number>
+                                       </div>
+                                       <div class=mdcline>Rows</div>
+                                       <div class=mdcinput>
+                                               <input id=mdirows value=0
+                                                      min=1 max=99
+                                                      class=mdni type=number>
+                                       </div>
+                                       <div class=mdcline>Columns</div>
+                                       <div class=mdcinput>
+                                               <input id=mdicols size=3 value=0
+                                                      min=1 max=99
+                                                      class=mdni type=number>
+                                       </div>
+                                       <div id=mdnc>
+                                       </div>
+                               </div>
+                       </div>
+               </div>
+       </body>
+</html>
+
diff --git a/app/www/js/config.js b/app/www/js/config.js
new file mode 100644 (file)
index 0000000..19b0480
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* db */
+
+var db_conf_store = {
+       keyname: true,
+       keytype: 'autoIncrement',
+       content: {
+               1: [
+                       {
+                               'name': 'FooBar',
+                               'items': 2,
+                               'rows': 1,
+                               'cols': 2,
+                               'itemname': ['Foo','Bar'],
+                               'cnt': [0,0],
+                               'colors': ['red','blue']
+                       },
+                       {
+                               'name': 'Alice, Bob, Dan and Eve',
+                               'items': 4,
+                               'rows': 2,
+                               'cols': 2,
+                               'itemname': ['Alice','Bob','Dan','Eve'],
+                               'cnt': [0,0,0,0],
+                               'colors': ['red','green','blue','yellow']
+                       }
+               ]
+       }
+}
+
+var db_count_store = {
+       keyname: true,
+       keytype: 'autoIncrement'
+}
+
diff --git a/app/www/js/index.js b/app/www/js/index.js
new file mode 100644 (file)
index 0000000..04067dc
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ *
+ * modular: simple app to count whatever you like
+ * author: hackbrd@hackdaworld.org
+ *
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var modular = {
+       init: function() {
+               document.addEventListener('deviceready',this.startup,false);
+       },
+       startup: function() {
+               // indexed db
+               //idb.name='modular';
+               //idb.del();
+               var stores={
+                       'conf': db_conf_store,
+                       'count': db_count_store
+               };
+               idb.init('modular',modular.dbcallback,1,stores);
+       },
+       dbcallback: function() {
+               idb.get_store_items('conf',function(item) {
+                       var html="";
+                       for(var i in item) {
+                               cl("item "+i);
+                               objdbg(item[i]);
+                               html+="<div data-id="+i+" class=mdcbtn>"+
+                                     item[i].name+"</div>";
+                       }
+                       $('#mdcont').html(html);
+                       vert_align_text('.mdhead');
+                       vert_align_text('.mdcbtn');
+                       $('.mdcbtn').click(function(event) {
+                               var conf=$(this).attr('data-id');
+                               modular.init_config(conf);
+                       });
+               });
+               $('.mdni').change(function(event) {
+                       modular.md_input_event(event.target.id);
+               });
+       },
+       md_input_event: function(id) {
+               var html="";
+               var valid=true;
+               switch(id) {
+               case 'mditot':
+               case 'mdirows':
+               case 'mdicols':
+                       var rows=$('#mdirows').val();
+                       var cols=$('#mdicols').val();
+                       var tot=$('#mditot').val();
+                       if(tot>rows*cols) {
+                               html="<br><b>Pleas increas rows "+
+                                    "and/or columns ...</b>";
+                               valid=false;
+                       }
+                       if((rows>0)&&(cols>0))
+                               html+="<br>Row-Column: Name Color";
+                       else
+                               valid=false;
+                       var t=0;
+                       var s="<br>";
+                       for(var r=1;r<=rows;r++) {
+                               for(var c=1;c<=cols;c++) {
+                                       t+=1;
+                                       if(tot<t) break;
+                                       s+=r+"-"+c+": "+
+                                          "<input class=mdiin type=text"+
+                                          " name=n"+t+">"+
+                                          "<input class=mdiic type=color"+
+                                          " name=c"+t+"><br>";
+                               }
+                       }
+                       var go="";
+                       if(valid)
+                               go="<br><button id=mdngo>Go</button>";
+                       $('#mdnc').html(html+s+go);
+                       if(valid)
+                               $('#mdngo').click(function() {
+                                       var na=[];
+                                       var ca=[];
+                                       var cnta=[];
+                                       $('.mdiin').each(function() {
+                                               na.push($(this).val());
+                                               cnta.push(0);
+                                       });
+                                       $('.mdiic').each(function() {
+                                               ca.push($(this).val());
+                                       });
+                                       var item={
+                                               name: $('#mdiname').val(),
+                                               items: tot,
+                                               rows: rows,
+                                               cols: cols,
+                                               itemname: na,
+                                               cnt: cnta,
+                                               colors: ca
+                                       };
+                                       idb.add_store_item('conf',item,
+                                                          function() {
+                                               modular.init_config('last');
+                                       });
+                               });
+                       break;
+               default:
+                       break;
+               }
+       },
+       confignum: 0,
+       config: {},
+       init_config: function(conf) {
+               if(conf=='last') {
+                       cl("starting up last configuration!");
+                       idb.get_store_items('conf',function(item) {
+                               for(var i in item);
+                               modular.start_counter(item[i]);
+                               modular.confignum=Number(i);
+                               modular.config=item[i];
+                       },0,-1);
+               }
+               else {
+                       cl("starting configuration "+conf);
+                       idb.get_item_by_key('conf',Number(conf),function(item) {
+                               modular.start_counter(item);
+                               modular.confignum=Number(conf);
+                               modular.config=item;
+                       });
+               }
+       },
+       start_counter: function(conf) {
+               $('#moddiag').css('display','none');
+               $('#main').css('display','block');
+               var ww=100/conf.cols;
+               var wh=100/conf.rows;
+               var html="";
+               for(var i=1;i<=conf.items;i++) {
+                       html+="<div id=item"+i+" class=item></div>";
+               }
+               $('#main').html(html);
+               for(var i=1;i<=conf.items;i++) {
+                       var id="#item"+i;
+                       $(id).css('width',ww+'%');
+                       $(id).css('height',wh+'%');
+                       $(id).css('background-color',conf.colors[i-1]);
+                       $(id).html(conf.itemname[i-1]+": "+conf.cnt[i-1]);
+                       vert_align_text(id);
+               }
+               $('.item').click(function(event) {
+                       var id='#'+event.target.id;
+                       var istr=event.target.id.replace("item","");
+                       var i=Number(istr);
+                       modular.inc_counter(id,i)
+               });
+       },
+       inc_counter: function(id,i) {
+               var conf=modular.config;
+               var cn=modular.confignum;
+               conf.cnt[i-1]+=1;
+               var html=conf.itemname[i-1]+": "+conf.cnt[i-1];
+               cntitem={
+                       date: (new Date()).toString(),
+                       confignum: cn,
+                       itemnum: i-1,
+                       counter: conf.cnt[i-1]
+               };
+               idb.add_store_item('count',cntitem,function() {
+                       cl("increased counter for item "+i-1+
+                          " to "+conf.cnt[i-1]);
+                       idb.update_store_item('conf',cn,conf,function() {
+                               $(id).html(html);
+                       });
+               });
+       }
+};
+
+$(document).ready(function() {
+       if('cordova' in window) {
+               modular.init();
+       }
+       else {
+               modular.startup();
+       }
+});
+
diff --git a/app/www/js/jquery.js b/app/www/js/jquery.js
new file mode 120000 (symlink)
index 0000000..195a6cd
--- /dev/null
@@ -0,0 +1 @@
+jquery-2.2.3.min.js
\ No newline at end of file