This repository has been archived by the owner on Nov 27, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_list.js
177 lines (174 loc) · 4.84 KB
/
project_list.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
var ProjectListController = PageController.extend({
init: function(elementId) {
var self = this;
this._super(elementId);
this.filter = "active";
this.projects = null;
if (APP.browser.isMobile) {
this.scroller = new iScroll(this.view.find(".ProjectList ul"), { checkDOMChanges: false, desktopCompatibility: false });
window.addEventListener('orientationChanged', this);
}
this.view.find(".Loading").style.display = "block";
this.loadProjects();
},
destroy: function() {
window.removeEventListener('orientationChanged', this);
if (this.scroller)
this.scroller.destroy();
this.scroller = null;
this._super();
},
handleEvent: function(e) {
this._super(e);
var self = this;
switch (e.type) {
case "orientationChanged":
setTimeout(function () { self.scroller.refresh(); }, 0);
break;
}
},
loadProjects: function() {
var self = this;
Project.data.find(function(projects) {
projects.sort(Project.sort.starred);
self.projects = projects;
self._render();
});
},
_render: function() {
var self = this;
var data = { projects: this.projects };
this.view.renderAt("div.ProjectList ul", "jstProjectListView", data, function() {
self.view.find(".Loading").style.display = "none";
self.view.findAll("button.star span", function(elem) { elem.innerHTML = localStorage['totalStarCount'] || 0 });
self.trigger("loaded");
if (self.scroller) {
setTimeout(function () { self.scroller.refresh() }, 100)
}
});
},
showProject: function(project) {
var projectController = new ProjectController("Project", project);
var self = this;
projectController.bind("back", function() {
/*self.show();*/
/*this.hide();*/
self.loadProjects();
this.slideOut(self);
this.destroy();
});
//this.hide();
//projectController.show();
this.slideIn(projectController);
return projectController;
},
showSearch: function(filterName, filter, sort) {
var self = this;
var searchController = new SearchController("SearchResults", this.projects, filterName, filter, sort);
searchController.bind("back", function() {
/*self.show();*/
/*this.hide();*/
self.loadProjects();
this.slideOut(self);
this.destroy();
});
/*this.hide();*/
this.actions.searchClose.call(this);
this.slideIn(searchController);
/*searchController.show();*/
},
show: function() {
this.loadProjects();
this._super();
this.element.style.display = "-webkit-box";
},
actions: {
refresh: function(e) {
var self = this;
this.view.find(".ProjectList ul").innerHTML = "";
this.view.find(".Loading").style.display = "block";
APP.debug.updateCounts();
setTimeout(function() {
self.loadProjects();
}, 2000);
},
searchOldTasks: function(e) {
var oldDate = new Date().getTime() - 1000*60*60*24*14; //secs*mins*hours
oldDate = new Date().getTime();
this.showSearch("Old Tasks", function(t) {
return (!t.isComplete && t.createdOn < oldDate);
}, function(a, b) {
return a.createdOn - b.createdOn;
});
},
searchNoProject: function(e) {
this.showSearch("No Project", function(t) {
return (!t.isComplete && t.projectKey == null);
});
},
searchIncomplete: function(e) {
this.showSearch("Incomplete", Task.filters.incomplete);
},
searchStarred: function(e) {
this.showSearch("Starred", Task.filters.star);
},
searchHighPriority: function(e) {
this.showSearch("High Priority", Task.filters.highPriority);
},
searchMediumPriority: function(e) {
this.showSearch("Medium Priority", Task.filters.mediumPriority);
},
search: function(e) {
this.view.find("#SearchPopup").style.display = "-webkit-box";
},
searchClose: function(e) {
this.view.find("#SearchPopup").style.display = "none";
},
'project': function(e) {
var project = this.projects[parseInt(e.target.getAttribute("data-index"))];
this.showProject(project);
},
'add': function(e) {
this.showProject(new Project());
},
'clear': function(e) {
Project.data.provider.nuke();
Task.data.provider.nuke();
var self = this;
setTimeout(function() {
self.loadProjects();
}, 1000);
},
'delete': function(e) {
var self = this;
var project = this.projects[parseInt(e.target.getAttribute("data-index"))];
var d = function(index) {
if (index == 0) {
project.remove(function() {
self.loadProjects();
});
}
}
var msg = "Are you sure you want to delete "+project.name;
if (APP.browser.isPhoneGap) {
navigator.notification.confirm(msg, d);
} else {
if (confirm(msg)) d(0);
}
},
'debug': function(e) {
var self = this;
var d = new DebugController('DebugMenu');
d.bind("restored", function() {
this.hide();
this.destroy();
self.loadProjects();
});
d.bind("close", function() {
this.hide();
this.destroy();
});
d.show();
}
}
});