source: trunk/MobileIndico/indico.js@ 18956

Last change on this file since 18956 was 18676, checked in by tbretz, 8 years ago
Fixed a problem with the sort function which showed up in Chrome
File size: 9.2 KB
Line 
1var default_url = "https://indico.scc.kit.edu/indico/";
2var default_event = 254;
3
4function process(ID, result)
5{
6 if (window.location.href.indexOf("debug")>=0)
7 $('#debug').append("<pre>"+JSON.stringify(result,null,2)+"</pre>");
8
9 $("#indico-link").attr("href", default_url+"/event/"+ID)
10
11 var conf = result['results'][ID];
12
13 var list = "";
14
15 // Sort the days into the correct order
16 var days = [];
17 for (var day in conf)
18 days.push([ day, conf[day] ]);
19 days.sort(function(a, b) { return a[0] > b[0]; });
20
21 for (var d=0; d<days.length; d++)
22 {
23 var day = days[d][0]; // "20161206"
24
25 // Convert "20161206" -> "2016/12/06"
26 var date = day.substr(0, 4)+"&thinsp;/&thinsp;"+day.substr(4, 2)+"&thinsp;/&thinsp;"+day.substr(6,2);
27
28 // Date accordion
29 list += "<div class='indico' data-role='collapsible' data-theme='b' data-inset='false'>";
30 list += "<h1>"+date+"</h1>";
31 //list += "<div id='"+day+"' data-role='collapsible-set' data-filter='true' data-input='#filter' data-mini='true' data-theme='a' data-content-theme='a'>";
32
33 var content = days[d][1];
34
35 // Sort all slots in a days by startDate/time
36 var slots = [];
37 for (var slot in content)
38 slots.push([ content[slot].startDate.time, content[slot]]);
39 slots.sort(function(a, b) { return a[0]==b[0] ? 0 : (a[0] > b[0] ? 1 : -1) });
40
41 // Loop over all slots (sessions)
42 for (var s=0; s<slots.length; s++)
43 {
44 var e = slots[s][1]; // entry
45
46 // Accordion for each session
47 list += "<div class='session' data-role='collapsible' data-inset='false'>";
48 list += "<h1 class='date'>"+e.startDate.time.substr(0,5)+"&thinsp;-&thinsp;"+e.endDate.time.substr(0,5)+"&ensp;"+e.title+"</h1>";
49 //list += "<h1 class='date'>"+e.startDate.time.substr(0,5)+" ["+e.duration+"'] "+e.title+"</h1>";
50 //list += "<h1 class='date'>"+e.startDate.time.substr(0,5)+" - "+e.endDate.time.substr(0,5)+" ["+e.duration+"'] "+e.title+"</h1>";
51
52
53 // =======================================================
54 list += "<div class='body'>";
55
56
57 // -------------------------------------------------------
58 list += "<span class='type' style='background-color:"+e.color+";'>"+e.entryType;
59 if (e.location.length+e.room.length>0)
60 {
61 list += "<span class='location'>";
62 list += " ["+e.room;
63 if (e.location.length>0 && e.room.length>0)
64 list += ", ";
65 list += e.location+"]";
66 list += "</span>"
67 }
68 list += "</span>";
69 // -------------------------------------------------------
70
71
72 // Sort all entries in a session by startDate/time
73 var entries = [];
74 for (var entry in e.entries)
75 entries.push([ e.entries[entry].startDate.time, e.entries[entry]]);
76 entries.sort(function(a, b) { return a[0] > b[0]; });
77 // description, title, material, url, entryType, presenters []
78
79 for (var i=0; i<entries.length; i++)
80 {
81 var e = entries[i][1];
82
83 // =======================================================
84 list += "<div class='contribution' data-role='collapsible' data-collapsed-icon='carat-d' and data-expanded-icon='carat-u'>";
85 list += "<h1>";
86
87
88 // -------------------------------------------------------
89 list += "<span class='date'>"+e.startDate.time.substr(0,5)+" ";
90 list += "<a class='title' href='"+e.url+"'>"+e.title+"</a>";
91 list += "</span>";
92 // -------------------------------------------------------
93
94
95 // -------------------------------------------------------
96 list += "<span class='presenters'>";
97 var p = e.presenters;
98 for (var j=0; j<p.length; j++)
99 {
100 list += p[j].name;
101 if (p[j].affiliation.length>0)
102 list += " ["+p[j].affiliation+"]";
103 if (p[j].email.length>0)
104 list += " <a class='email' href='email:"+p[j].email+"'>"+p[j].email+"</a>";
105 list += "<br/>";
106 }
107 list += "</span>"; // presenters
108 list += "</h1>";
109 // -------------------------------------------------------
110
111
112 list += "<span class='description'>"+e.description+"</span>"; // Abstract
113
114
115 // -------------------------------------------------------
116 list += "<span class='material'>";
117 var m = e.material;
118 for (var j=0; j<m.length; j++)
119 {
120 list += "<span class='title'>"+m[j].title+": </span>";
121
122 list += "<span class='resources'>";
123 var r = m[j].resources;
124 for (var k=0; k<r.length; k++)
125 {
126 list += "<a class='url' href='"+r[k].url+"'>"+r[k].name+"</a>";
127 if (r[k].description.length>0)
128 list += "<span class='description'>" + m[k].description + "</span>";
129 }
130 list += "</span>";
131
132 if (m[j].description.length>0)
133 list += "<span class='description'> ["+m[j].description+"]</span>";
134
135 }
136 list += "</span>"; // indico-contribution-material
137 // -------------------------------------------------------
138
139
140 list += "</div>"; // indico-contribution
141 // =======================================================
142 }
143
144 list += "</div>"; // indico-session-body
145 // =======================================================
146
147
148 list += "</div>"; // collapsible "indico-session"
149
150 /*
151
152 "material": [
153 {
154 "_type": "Slides",
155 "description": "",
156 "title": "Slides",
157 "_fossil": "materialMinimal",
158 "protectionURL": "https://indico.scc.kit.edu/indico/event/215/manage/session/3/contribution/28/material/?returnURL=",
159 "type": "",
160 "id": "slides",
161 "resources": [
162 {
163 "_type": "LocalFile",
164 "name": "Auger-HEAT.pdf",
165 "url": "https://indico.scc.kit.edu/indico/event/215/session/3/contribution/28/material/slides/0.pdf",
166 "_fossil": "localFileMinimal",
167 "protectionURL": "https://indico.scc.kit.edu/indico/event/215/manage/session/3/contribution/28/material/?returnURL=",
168 "description": ""
169 }*/
170
171 // HERE WE NEED TO LOOP OVER THE CONTRIBUTIONS
172
173 //alert(JSON.stringify(slots[s][1]));
174 //break;
175
176 // entryType "Session" "Contribution" "Break"
177 // isPoster,
178 // startDate { date, tz }
179 // endDate { date, tz }
180 // duration
181 // contribDuration,
182 // color
183 // textColor,
184 // title
185 // slotTitle
186 // location
187 // room,
188 // conveners []
189 // material []
190 // entries { }
191 // url,
192 // pdf
193 //
194 // sessionSlotId
195 // conferenceId
196 // inheritRoom
197 // uniqueid
198 // _fossil "linedTimeSchEntry"
199 // _type "LinkedTimeSchEntry"
200 // sessionCode,
201 // sessionid,
202 // inheritLoc,
203 }
204
205 //list += "</div>"; // collapsible-set "day"
206 list += "</div>"; // collapsible
207 }
208
209 $('#list').append(list);
210 $('#list').collapsibleset('refresh');
211}
212
213function read(json)
214{
215 var ID = Object.keys(json.results);
216
217 process(ID, json);
218
219 $('#footer').css("position", "relative");
220 $.mobile.loading('hide');
221}
222
223function onReady()
224{
225 $.mobile.loading('show', {
226 text: "Loading timetable...",
227 textVisible: true,
228 /* theme: "a", */
229 });
230
231 /*---------------------------------------------------------------------------------------------
232 Request the timetabel of the indico event we are interested in
233 ----------------------------------------------------------------------------------------------*/
234
235 var cmd = window.location.href.split("?")[1];
236
237 var ID = cmd ? cmd.split("&").find(function(str){ return str.split("=")[0]=="id"; }) : null;
238 var URL = cmd ? cmd.split("&").find(function(str){ return str.split("=")[0]=="url"; }) : null;
239
240 if (ID)
241 default_event = ID.split("=")[1];
242 if (URL)
243 default_url = URL.split("=")[1];
244
245 $.getJSON(default_url+"/export/timetable/"+default_event+".jsonp?callback=?");
246 //$.getJSON(indico_url+"/export/event/"+ID+".jsonp?callback=?");
247 // json.results[0].title
248}
249
250$('document').ready(onReady);
Note: See TracBrowser for help on using the repository browser.