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_nomodel(){
47 function readEntry(json) {
48 var parsed = JSON.parse(json);
49 optsGlobal.push(parsed);
52 db.transaction( function(tx) {
54 var rs = tx.executeSql('SELECT * FROM Settings');
55 for (var i = 0; i < rs.rows.length; i++) {
56 readEntry(rs.rows.item(i).json)
64 function restore(objmodel){
70 function readEntry(json) {
71 var parsed = JSON.parse(json);
72 optsGlobal.push(parsed);
73 objmodel.append(parsed);
76 db.transaction( function(tx) {
78 var rs = tx.executeSql('SELECT * FROM Settings');
79 for (var i = 0; i < rs.rows.length; i++) {
80 readEntry(rs.rows.item(i).json)
90 db.transaction( function(tx) {
91 try{tx.executeSql('DROP TABLE Settings;');}catch(e){};
92 tx.executeSql('CREATE TABLE IF NOT EXISTS Settings(id INT, json TEXT)');
94 for (var i=0;i<lopt.length;i++){
95 db.transaction( function(tx) {
96 tx.executeSql('INSERT INTO Settings VALUES(?, ?)', [i+1, lopt[i]]);
104 for (var i=0; i < obj.count; i++) {
106 var firstpartopt = obj.get(i);
108 for (var elem in firstpartopt) {
109 if (!elem.match("^attributes")) {
110 newopt += "\""+elem+"\": \"" + firstpartopt[elem] + "\",";
113 if (firstpartopt.attributes){
114 newopt += "\"attributes\":[";
115 for (var j=0; j < firstpartopt.attributes.count; j++) {
116 if (j > 0) newopt += ",";
117 var attr = firstpartopt.attributes.get(j);
118 newopt += JSON.stringify(attr);
122 newopt = newopt.slice(0, -1);
126 optsGlobal.push( JSON.parse(newopt));
131 function init_nomodel(){
132 var listopts = init_default();
134 for(var i=0;i< listopts.length;i++){
135 optsGlobal.push(listopts[i]);
140 var listopts = init_default();
142 for(var i=0;i< listopts.length;i++){
143 obj.append(listopts[i]);
144 optsGlobal.push(listopts[i]);
148 function pressandhold(){
152 function doubleclicked(){
156 function chedoxoay(){
157 console.log(optsGlobal)
161 function get_opt(idm){
162 for(var i=0;i<optsGlobal.length;i++){
163 if (optsGlobal[i].idm == idm){
164 if(optsGlobal[i].selected == "true" || optsGlobal[i].selected === true)