From a8da4816917174e41bec5672981269a7e7f7f0c9 Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 25 May 2016 00:26:58 +0200 Subject: [PATCH] implemented delete/decrease functions for config/counter --- app/www/css/index.css | 2 + app/www/js/index.js | 95 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/app/www/css/index.css b/app/www/css/index.css index 7714f9d..cc98619 100644 --- a/app/www/css/index.css +++ b/app/www/css/index.css @@ -66,6 +66,7 @@ body { margin: 3%; text-align: center; background-color: #ddd; + -webkit-user-select: none; } .mdcline { @@ -87,6 +88,7 @@ body { .item { float: left; text-align: center; + -webkit-user-select: none; } #mdcont { diff --git a/app/www/js/index.js b/app/www/js/index.js index 04067dc..d9d10f4 100644 --- a/app/www/js/index.js +++ b/app/www/js/index.js @@ -27,6 +27,7 @@ var modular = { init: function() { document.addEventListener('deviceready',this.startup,false); + document.addEventListener('backbutton',this.backbtn,false); }, startup: function() { // indexed db @@ -38,27 +39,68 @@ var modular = { }; 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() { + $('#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); - objdbg(item[i]); + //objdbg(item[i]); html+="
"+ item[i].name+"
"; } $('#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').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); }); }, + 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; @@ -118,7 +160,11 @@ var modular = { }; idb.add_store_item('conf',item, function() { - modular.init_config('last'); + setTimeout(function() { + modular.init_config( + 'last' + ); + },200); }); }); 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(" last config is "+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); } + /* $('.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; @@ -190,6 +262,25 @@ var modular = { $(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); + }); + }); } }; -- 2.39.2