-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuiaction.js
218 lines (218 loc) · 5.93 KB
/
uiaction.js
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//工作场景列表
var states=[
{
index:0,
name:"fList",
title:"随身拍",
tailData:'<input onclick="newDir()" class="Abutton" type="button" value="+" />'
},
{
index:1,
name:"nList",
tailData:'<input onclick="newNote()" class="Abutton" type="button" value="+" />'
},
{
index:2,
name:"nShow",
tailData:'<input onclick="edit()" class="Abutton" type="button" value="编辑" />'
},
{
index:3,
name:"nEdit",
tailData:''
}
];
//定义当前场景索引
var StateIndex=0;
var EditKey=false;
var EditId="";
var anyListClick={
//加载文件夹列表点击事件
"fListData":function(id){
var fs=$(id).getElementsByTagName("li");
for(var i=0;i<fs.length;i++){
fs[i].onmousedown=function(){
this.className="down";
(function(me){
setTimeout(function(){
me.className="";
StateIndex=1;
states[StateIndex].title=me.getElementsByTagName("p")[1].innerHTML;
//加载数据
$("nListData").innerHTML="";
DB.transaction(function(tx) {
tx.executeSql("SELECT * FROM notes where cats='" + states[StateIndex].title + "'", [],
function(tx, result) {
if(result.rows.length==0){
alert("木有数据哈!");
}else{
for(var i = 0; i < result.rows.length; i++){
$("nListData").innerHTML+='<li id="' + result.rows.item(i)['id'] + '"><div class="photo"><img src="' + result.rows.item(i)['photo'] + '"/></div><div class="word">' + result.rows.item(i)['word'] + '</div></li>';
}
anyListClick["nListData"]("nListData");
}
},
function(){
alert("error");
}
);
})
reState(states,"nList");
},500)
})(this);
}
}
},
//加载记事点击事件
"nListData":function(id){
var fs=$(id).getElementsByTagName("li");
for(var i=0;i<fs.length;i++){
fs[i].onmousedown=function(){
this.className="down";
(function(me){
setTimeout(function(){
me.className="";
StateIndex=2;
states[StateIndex].title=states[StateIndex-1].title;
reState(states,"nShow");
$("nShow-content-photo").innerHTML=me.getElementsByTagName("div")[0].innerHTML;
$("nShow-content-word").getElementsByTagName("span")[0].innerHTML=me.getElementsByTagName("div")[1].innerHTML;
EditId=me.id;
},500);
})(this);
}
}
}
}
//场景切换
var reState=function(targets,id){
for(var n=0;n<targets.length;n++){
$(targets[n].name).style.display="none";
}
$(id).style.display="block";
loadTitleBar(states[StateIndex].title,states[StateIndex].tailData);
}
//标签切换
var reTab=function(targets,id){
for(var n=0;n<targets.length;n++){
$(targets[n]).style.display="none";
}
$(id).style.display="block";
}
//加载标题栏数据
var loadTitleBar=function(title,actionBar){
$("Title").innerHTML=title;
$("Action-bar").innerHTML=actionBar;
}
//新建目录事件
var newDir=function(){
$("newDir").style.display="block";
}
//编辑当前记录
var edit=function(){
EditKey=true;
console.log(EditKey);
StateIndex=3;
states[StateIndex].title=states[StateIndex-2].title;
reState(states,"nEdit");
$("nEdit-content-word").getElementsByTagName("textarea")[0].value=$("nShow-content-word").getElementsByTagName("span")[0].innerHTML;
}
//新建目录
var saveNewDir=function(){
var _fs=$("fListData").getElementsByTagName("li");
var _sameKey=false;
var _dirName=$("dirName").value;
//判断重名
for(var i=0;i<_fs.length;i++){
if(_fs[i].getElementsByTagName("p")[1].innerHTML==_dirName){
_sameKey=true;
}
}
if(!_sameKey){
//写入新分类名
DB.transaction(function(tx) {
tx.executeSql(
"INSERT INTO cats (id,icon,name) values(?,?,?)",
[rnd_str(9,true,true,true),'imgsrc',_dirName],
null, null
);
});
//重新渲染数据
DB.transaction(function(tx){
tx.executeSql("SELECT * FROM cats", [],
function(tx, result) {
$("fListData").innerHTML="";
for(var i = 0; i < result.rows.length; i++){
$("fListData").innerHTML+='<li><p class="icon"><img sr="' + result.rows.item(i)['icon'] + '"/></p><p class="name">' + result.rows.item(i)['name'] + '</p></li>';
}
anyListClick["fListData"]("fListData");
},
function(){
alert("error");
}
);
});
$("newDir").style.display="none";
}else{
alert('已存在"' + $("dirName").value + '",请重新输入!' );
}
$("dirName").value="";
}
//新建记事
var newNote=function(){
StateIndex=2;
states[StateIndex].title=states[StateIndex-1].title;
reState(states,"nEdit");
}
//保存记事
var saveNewNote=function(){//nid:记事id
//获取描述信息
var _photo=$("nEdit-content-photo").getElementsByTagName("img")[0].src;
var _word=$("nEdit-content-word").getElementsByTagName("textarea")[0].value;
//写新记录
DB.transaction(function(tx) {
if(EditKey){
tx.executeSql(
"update notes set photo=?,word=? where id='" + EditId + "'",
[_photo,_word],
null, null
);
}else{
tx.executeSql(
"INSERT INTO notes (id,photo,word,cats) values(?,?,?,?)",
[rnd_str(9,true,true,true),_photo,_word,states[StateIndex].title],
null, null
);
}
});
//重新渲染数据
DB.transaction(function(tx) {
tx.executeSql("SELECT * FROM notes where cats='" + states[StateIndex].title + "'", [],
function(tx, result) {
$("nListData").innerHTML="";
for(var i = 0; i < result.rows.length; i++){
$("nListData").innerHTML+='<li id="' + result.rows.item(i)['id'] + '"><div class="photo"><img src="' + result.rows.item(i)['photo'] + '"/></div><div class="word">' + result.rows.item(i)['word'] + '</div></li>';
}
anyListClick["nListData"]("nListData");
GoBack();
},
function(){
alert("error");
}
);
});
}
//回到首页事件
var goHome=function(){
StateIndex=0;
reState(states,"fList");
}
//返回按钮事件
var GoBack=function(){
StateIndex--;
reState(states,states[StateIndex].name);
EditKey=false;
}
//初始化显示文件夹列表
reState(states,"fList");
//$("fList").style.display="block";