-
Notifications
You must be signed in to change notification settings - Fork 0
/
agendaviewmodel.js
executable file
·114 lines (94 loc) · 3.12 KB
/
agendaviewmodel.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
function AgendaViewModel()
{
//Data
var self = this;
self.slots = ko.observable();
self.speakers = ko.observable();
self.sessions = ko.observable();
self.selectedSession = ko.observable();
self.selectedSpeaker = ko.observable();
self.selectedSessionList = ko.observable();
var today=new Date();
var conference = new Date(2012,0,21);
self.daysToConference = parseInt((conference-today)/(24*3600*1000));
// Operations
self.goToSpeaker = function(speaker)
{
self.selectedSpeaker(speaker);
$.mobile.changePage("#speakerDetail");
};
self.goToSessionList = function(slot)
{
var orig = self.sessions();
orig = _.sortBy(orig, function(value) {return value.timeSlot});
var list = ko.utils.arrayFilter(orig, function(value) {
return value.timeSlot == slot;
});
list = _.sortBy(list, function(value) {return value.room});
list = _.reject(list, function(value){return value.title==""})
var obj = new Object();
obj.name = slot;
obj.list = ko.observable(list);;
self.selectedSessionList(obj);
$.mobile.changePage("#sessions");
};
self.goToSession = function(session)
{
self.selectedSession(session);
$.mobile.changePage("#sessionDetail");
};
$.getJSON(
"/_speeches.json",
function (data) {
data = FixModel(data);
self.sessions(data);
self.speakers(ExtractSpeakers(data));
self.slots(ExtractSlots(data));
});
}
function FixModel(data)
{
return $.each(data,function(index, value){
if(value.speaker.bio.substring(0, 4) == "http")
value.speaker.bioUrl=value.speaker.bio;
else
value.speaker.bioUrl="";
if(value.from == undefined){
value.from=value["from(4i)"]+":"+value["from(5i)"];
value.to=value["to(4i)"]+":"+value["to(5i)"];
}
else {
var from = new Date(value.from);
var to = new Date(value.to);
var fromMin = from.getMinutes();
var toMin = to.getMinutes();
var toMinStr = toMin+"";
var fromMinStr = fromMin+"";
if(toMin<10)
toMinStr="0"+ toMin;
if(fromMin<10)
fromMinStr="0"+ fromMin;
value.from = from.getHours()-1+":"+fromMinStr;
value.to = to.getHours()-1+":"+toMinStr;
}
value.timeSlot=value.from +" - "+value.to;
if(value.speaker.name=="-")
value.nolink=true;
else
value.nolink=false;
});
}
function ExtractSlots(data)
{
var list = _.pluck(data, "timeSlot");
list =_.compact(list);
list = _.sortBy(list, function(num) {return num});
return _.uniq(list,true);
}
function ExtractSpeakers(data)
{
var list = _.pluck(data, "speaker");
list = _.reject(list, function(value) {return value.name == "-";})
list = _.sortBy(list, function(value){return value.name});
return list;
}