var modular = {
init: function() {
document.addEventListener('deviceready',this.startup,false);
+ document.addEventListener('backbutton',this.backbtn,false);
},
startup: function() {
// indexed db
};
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+="<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').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;
};
idb.add_store_item('conf',item,
function() {
- modular.init_config('last');
+ setTimeout(function() {
+ modular.init_config(
+ 'last'
+ );
+ },200);
});
});
break;
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];
$(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;
$(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);
+ });
+ });
}
};