2 Copyright (C) 2011 by Cuong Le <metacuong@gmail.com>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>
23 return openDatabaseSync("LichVietDB", "1.0", "LichVietDB SQL", 5000);
26 function delete_old_db(){
28 db.transaction( function(tx) { try {
29 tx.executeSql('DROP TABLE Settings;');
34 function init_default(){
36 {idm:1,name:"Chế Độ Xoay",selected:true},
37 {idm:2,name:"Lịch Hệ Thống",selected:false},
38 {idm:3,name:"Nhấn 2 Lần Liên Tiếp<br>Tới Ngày Dương",selected:true},
39 {idm:4,name:"Nhấn Giữ<br>Xem Ngày Tốt/Xấu ...",selected:true}
43 function restore(objmodel){
49 function readEntry(json) {
50 var parsed = JSON.parse(json);
51 optsGlobal.push(parsed);
52 objmodel.append(parsed);
55 db.transaction( function(tx) {
57 var rs = tx.executeSql('SELECT * FROM Settings');
58 for (var i = 0; i < rs.rows.length; i++) {
59 readEntry(rs.rows.item(i).json)
69 db.transaction( function(tx) {
70 try{tx.executeSql('DROP TABLE Settings;');}catch(e){};
71 tx.executeSql('CREATE TABLE IF NOT EXISTS Settings(id INT, json TEXT)');
73 for (var i=0;i<lopt.length;i++){
74 db.transaction( function(tx) {
75 tx.executeSql('INSERT INTO Settings VALUES(?, ?)', [i+1, lopt[i]]);
83 for (var i=0; i < obj.count; i++) {
85 var firstpartopt = obj.get(i);
87 for (var elem in firstpartopt) {
88 if (!elem.match("^attributes")) {
89 newopt += "\""+elem+"\": \"" + firstpartopt[elem] + "\",";
92 if (firstpartopt.attributes){
93 newopt += "\"attributes\":[";
94 for (var j=0; j < firstpartopt.attributes.count; j++) {
95 if (j > 0) newopt += ",";
96 var attr = firstpartopt.attributes.get(j);
97 newopt += JSON.stringify(attr);
101 newopt = newopt.slice(0, -1);
105 optsGlobal.push( JSON.parse(newopt));
111 var listopts = init_default();
113 for(var i=0;i< listopts.length;i++){
114 obj.append(listopts[i]);
115 optsGlobal.push(listopts[i]);
119 function pressandhold(){
123 function doubleclicked(){
127 function chedoxoay(){
128 console.log(optsGlobal)
132 function get_opt(idm){
133 for(var i=0;i<optsGlobal.length;i++){
134 if (optsGlobal[i].idm == idm){
135 if(optsGlobal[i].selected == "true" || optsGlobal[i].selected == true)