-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
193 lines (190 loc) · 5.23 KB
/
init.js
File metadata and controls
193 lines (190 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
Ext.ns("IAR", "IAR.ui","IAR.model");
var App = '';
var bookdb = "";
var iardb = "";
var db = "";
var ls = localStorage;
var isfbloggedin = false;
if(ls.colorscheme) {
SwitchStylesheet(ls.colorscheme);
}
else {
SwitchStylesheet("pink");
}
var bs = "";
var is = "";
// load Google search goodness
google.load("search", "1");
// once Google search is loaded, execute callback method to do other stuff
google.setOnLoadCallback(
function(){
bs = new google.search.BookSearch();
bs.setResultSetSize(8)
is = new google.search.ImageSearch();
is.setResultSetSize(8)
}
);
var pageindex = 0;
var imageindex = 0;
var totalpages = 0;
var totalbooks = 0;
Ext.setup({
tabletStartupScreen: ls.colorscheme != "" ? "images/tablet/tablet_" + ls.colorscheme + ".jpg" : 'images/tablet/tablet_pink.jpg',
phoneStartupScreen: ls.colorscheme != "" ? "images/phone/phone_" + ls.colorscheme + ".jpg" : 'images/phone/phone_pink.jpg',
layoutOnOrientationChange:true,
icon: ls.colorscheme != "" ? "images/icon/icon_" + ls.colorscheme + ".png" : 'images/icon/icon_pink.png',
glossOnIcon: true,
onReady: function() {
App = new IAR.App();
}
});
function SwitchStylesheet(ss) {
var root = sencharoot;
var color = ss;
var ss = typeof ss != "undefined" ? ss.replace(".css","") +".css" : 'pink.css';
if(Ext.getDom("masterss").href!=root+ss) {
Ext.getDom("masterss").href = root+ss;
ls.colorscheme = color;
}
}
function SearchBook(fld) {
var fld = "searchfield_"+fld;
var st = Ext.getCmp(fld).getValue();
Ext.getCmp("searchfield_1").setValue(st);
Ext.getCmp("searchfield_2").setValue(st);
if(st=="") {
return false;
}
Ext.getBody().mask('<div class="loading">Loading…</div>','loading',false);
pageindex = 1;
bs.execute(st);
bs.setSearchCompleteCallback(this,ShowSearchResults);
}
function ShowSearchResults() {
var books = {};
books.results = bs.results;
var append = pageindex == 1 ? false : true;
if(bs.results.length) {
Ext.getCmp("searchmorebutton_1").show();
Ext.getCmp("searchmorebutton_2").show();
}
Ext.getCmp("booksearchlist").getStore().loadData(books.results,append);
Ext.getCmp("booksearchlist").refresh();
var sp = Ext.getCmp("bookspanel");
sp.setActiveItem(2);
Ext.getBody().unmask();
}
function GetMoreSearchResults() {
Ext.getBody().mask('<div class="loading">Loading…</div>','loading',false);
pageindex = pageindex+1;
if(pageindex<8) {
bs.gotoPage(pageindex);
}
else {
Ext.getBody().unmask();
Ext.getCmp("searchmorebutton_1").hide();
Ext.getCmp("searchmorebutton_2").hide();
}
}
function SearchImage(fld,e) {
var st = Ext.getCmp("imagesearch").getValue();
if(st=="") {
return false;
}
Ext.getBody().mask('<div class="loading">Loading…</div>','loading',false);
imageindex = 1;
is.execute(st);
is.setSearchCompleteCallback(this,ShowImageResults);
}
function ShowImageResults() {
var images = {};
images.results = is.results;
var append = imageindex == 1 ? false : true;
if(is.results.length) {
Ext.getCmp("imagemorebutton").show();
}
Ext.getCmp("imageview").getStore().loadData(images.results,append);
Ext.getCmp("imageview").refresh();
var sp = Ext.getCmp("goalpanel");
sp.setActiveItem(3);
Ext.getBody().unmask();
}
function GetMoreImageResults() {
Ext.getBody().mask('<div class="loading">Loading…</div>','loading',false);
imageindex = imageindex+1;
if(imageindex<8) {
is.gotoPage(imageindex);
}
else {
Ext.getBody().unmask();
Ext.getCmp("imagemorebutton").hide();
}
}
function ClearImageSearch() {
var blankimagestore = new Ext.data.Store({
model: 'Images',
root: "results",
id: "blankimagestore",
data: []
});
Ext.getCmp("imageview").bindStore(blankimagestore);
Ext.getCmp("imageview").refresh();
Ext.getCmp("imagemorebutton").hide();
Ext.getCmp("imagesearch").setValue("");
}
function Import() {
db = openDatabase('Books',"",'Book Tracker',2000000);
ImportBooks();
ImportGoals();
var win = new Ext.MessageBox();
win.alert('Success!', 'Yay! You\'re data was successfully imported!', function(){
Ext.getCmp("goalpanel").checkgoals();
});
}
function ImportBooks() {
var books = Ext.StoreMgr.getByKey("booksstore");
// get books
var sqlvars = [];
var sql = "select * from books order by title";
db.transaction(function(t){
t.executeSql(sql,sqlvars,function(transaction,records) {
for(var i=0;i<records.rows.length;i++) {
var bdata = records.rows.item(i);
books.add({
bookId: bdata.bookid,
title: bdata.title,
authors: bdata.authors,
publishedYear: bdata.publishedyear,
pageCount: bdata.pagecount,
tbUrl: bdata.thumbnail,
category_id: 1
});
books.sync();
}
});
});
}
function ImportGoals() {
var goals = Ext.StoreMgr.getByKey("goalstore");
// get goals
var sqlvars = [];
var sql = "select * from rewards order by title";
db.transaction(function(t){
t.executeSql(sql,sqlvars,function(transaction,records) {
for(var i=0;i<records.rows.length;i++) {
var gdata = records.rows.item(i);
goals.add({
title: gdata.title,
description:gdata.description,
threshold: gdata.threshold,
type: gdata.type,
category_id:1,
imageurl: gdata.imageurl,
completetext:gdata.completetext,
hasseen: gdata.hasseen
});
goals.sync();
}
});
});
}