]> hackdaworld.org Git - outofuni/modular.git/commitdiff
implemented delete/decrease functions for config/counter master
authorhackbard <hackbard@hackdaworld.org>
Tue, 24 May 2016 22:26:58 +0000 (00:26 +0200)
committerhackbard <hackbard@hackdaworld.org>
Tue, 24 May 2016 22:26:58 +0000 (00:26 +0200)
app/www/css/index.css
app/www/js/index.js

index 7714f9d3a8c07ab5902a46f3d9df0555d12ab8ac..cc986191e3131c2ac9fd1d9c34dbe83b4bf7b45e 100644 (file)
@@ -66,6 +66,7 @@ body {
        margin: 3%;
        text-align: center;
        background-color: #ddd;
        margin: 3%;
        text-align: center;
        background-color: #ddd;
+       -webkit-user-select: none;
 }
 
 .mdcline {
 }
 
 .mdcline {
@@ -87,6 +88,7 @@ body {
 .item {
        float: left;
        text-align: center;
 .item {
        float: left;
        text-align: center;
+       -webkit-user-select: none;
 }
 
 #mdcont {
 }
 
 #mdcont {
index 04067dcf07951617a941c5ba943fd4f4832f5583..d9d10f45dc9b5309982067fc8eb0dd05fdc87573 100644 (file)
@@ -27,6 +27,7 @@
 var modular = {
        init: function() {
                document.addEventListener('deviceready',this.startup,false);
 var modular = {
        init: function() {
                document.addEventListener('deviceready',this.startup,false);
+               document.addEventListener('backbutton',this.backbtn,false);
        },
        startup: function() {
                // indexed db
        },
        startup: function() {
                // indexed db
@@ -38,27 +39,68 @@ var modular = {
                };
                idb.init('modular',modular.dbcallback,1,stores);
        },
                };
                idb.init('modular',modular.dbcallback,1,stores);
        },
+       backbtn: function() {
+               if($('#main').css('display')=='none') {
+                       navigator.app.exitApp();
+               }
+               else {
+                       modular.dbcallback();
+               }
+       },
+       touchtimer: null,
+       longtouch: false,
        dbcallback: function() {
        dbcallback: function() {
+               $('#main').css('display','none');
+               $('#moddiag').css('display','block');
                idb.get_store_items('conf',function(item) {
                        var html="";
                        for(var i in item) {
                                cl("item "+i);
                idb.get_store_items('conf',function(item) {
                        var html="";
                        for(var i in item) {
                                cl("item "+i);
-                               objdbg(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');
                                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);
                        });
                        $('.mdcbtn').click(function(event) {
                                var conf=$(this).attr('data-id');
                                modular.init_config(conf);
                        });
+                       */
+                       $('.mdcbtn').mouseup(function() {
+                               clearTimeout(modular.touchtimer);
+                               if(!modular.longtouch) {
+                                       cl("click!");
+                                       var conf=$(this).attr('data-id');
+                                       modular.init_config(conf);
+                               }
+                               return false;
+                       });
+                       $('.mdcbtn').mousedown(function(event) {
+                               modular.longtouch=false;
+                               modular.touchtimer=setTimeout(function() {
+                                       cl("long touch!");
+                                       modular.longtouch=true;
+                                       var did=$(event.target).attr('data-id');
+                                       modular.del_conf(Number(did));
+                               },500);
+                               return false;
+                       });
                });
                $('.mdni').change(function(event) {
                        modular.md_input_event(event.target.id);
                });
        },
                });
                $('.mdni').change(function(event) {
                        modular.md_input_event(event.target.id);
                });
        },
+       del_conf: function (did) {
+               idb.del_item_by_key('conf',did,function() {
+                       setTimeout(function() {
+                               cl("deleted configuration "+did+"...");
+                               modular.dbcallback();
+                       },200);
+               });
+       },
        md_input_event: function(id) {
                var html="";
                var valid=true;
        md_input_event: function(id) {
                var html="";
                var valid=true;
@@ -118,7 +160,11 @@ var modular = {
                                        };
                                        idb.add_store_item('conf',item,
                                                           function() {
                                        };
                                        idb.add_store_item('conf',item,
                                                           function() {
-                                               modular.init_config('last');
+                                               setTimeout(function() {
+                                                       modular.init_config(
+                                                               'last'
+                                                       );
+                                               },200);
                                        });
                                });
                        break;
                                        });
                                });
                        break;
@@ -133,6 +179,7 @@ var modular = {
                        cl("starting up last configuration!");
                        idb.get_store_items('conf',function(item) {
                                for(var i in item);
                        cl("starting up last configuration!");
                        idb.get_store_items('conf',function(item) {
                                for(var i in item);
+                               cl("  last config is "+i);
                                modular.start_counter(item[i]);
                                modular.confignum=Number(i);
                                modular.config=item[i];
                                modular.start_counter(item[i]);
                                modular.confignum=Number(i);
                                modular.config=item[i];
@@ -165,12 +212,37 @@ var modular = {
                        $(id).html(conf.itemname[i-1]+": "+conf.cnt[i-1]);
                        vert_align_text(id);
                }
                        $(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)
                });
                $('.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)
                });
+               */
+               $('.item').mouseup(function() {
+                       clearTimeout(modular.touchtimer);
+                       if(!modular.longtouch) {
+                               cl("click!");
+                               var id='#'+event.target.id;
+                               var istr=event.target.id.replace("item","");
+                               var i=Number(istr);
+                               modular.inc_counter(id,i)
+                       }
+                       return false;
+               });
+               $('.item').mousedown(function(event) {
+                       modular.longtouch=false;
+                       modular.touchtimer=setTimeout(function() {
+                               cl("long touch!");
+                               modular.longtouch=true;
+                               var id='#'+event.target.id;
+                               var istr=event.target.id.replace("item","");
+                               var i=Number(istr);
+                               modular.dec_counter(id,i)
+                       },500);
+                       return false;
+               });
        },
        inc_counter: function(id,i) {
                var conf=modular.config;
        },
        inc_counter: function(id,i) {
                var conf=modular.config;
@@ -190,6 +262,25 @@ var modular = {
                                $(id).html(html);
                        });
                });
                                $(id).html(html);
                        });
                });
+       },
+       dec_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("decreased counter for item "+i-1+
+                          " to "+conf.cnt[i-1]);
+                       idb.update_store_item('conf',cn,conf,function() {
+                               $(id).html(html);
+                       });
+               });
        }
 };
 
        }
 };