-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreservo.js.orig
283 lines (240 loc) · 8.65 KB
/
reservo.js.orig
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
var retina = window.devicePixelRatio >= 1.3;
var reservoRestaurantData;
/* Load data */
function loadRestaurant(id, renderInput, renderStations)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
parseRestaurantJSON(xmlhttp.responseText);
if (renderInput)
createInputFields();
if (renderStations)
animateInputFieldsOut();
}
}
xmlhttp.open("POST","http://pido.cc/api_open/get_restaurant_by_id",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("id="+id);
}
function loadAvailableStationsForPlaceTimeAndPeople(id, time, people, renderStations)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
parseStationJSON(xmlhttp.responseText);
if (renderStations)
animateInputFieldsOut();
}
}
xmlhttp.open("POST","http://pido.cc/api_open/get_available_stations_for_time_and_place_and_peoplecount",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("place_id="+id+"&time="+time+"&people="+people);
}
function parseRestaurantJSON(data)
{
var parsedData = JSON.parse(data);
reservoRestaurantData = parsedData;
}
function parseStationJSON(data)
{
var parsedData = JSON.parse(data);
reservoRestaurantData.stations = parsedData;
}
/* Render page */
function createInputFields()
{
var containerSection = document.getElementById("reservo-container");
if (!containerSection)
{
containerSection = document.createElement("section");
containerSection.id = "reservo-container";
containerSection.className = "reservo-container";
var header = document.createElement("header");
header.innerHTML = "<h1>Min reservasjon</h1>";
var closeButton = document.createElement("a");
closeButton.id = "reservo-overlay-lukk";
closeButton.setAttribute("href", "#");
closeButton.className = "reservo-overlay-lukk";
closeButton.innerHTML = "x";
// We need a montage!
header.appendChild(closeButton);
containerSection.appendChild(header);
document.body.appendChild(containerSection);
}
if (document.getElementById("reservo-brev"))
return; // No need to create it twice
var inputSection = document.createElement("section");
inputSection.id = "reservo-brev";
inputSection.className = "reservo-seksjon reservo-brev reservo-active";
// Example: <input type="text" placeholder="Jan Petter">
var nameField = document.createElement("input");
nameField.type = "text";
nameField.setAttribute("placeholder", "Jan Petter");
// Example: <input type="number" max="24" min="1" value="3">
var peopleCountField = document.createElement("input");
peopleCountField.type = "number";
peopleCountField.setAttribute("max", reservoRestaurantData.max_booking);
peopleCountField.setAttribute("min", reservoRestaurantData.min_booking);
peopleCountField.setAttribute("value", "4");
//
var weekday=new Array(7);
weekday[0]="søndag";
weekday[1]="mandag";
weekday[2]="tirsdag";
weekday[3]="onsdag";
weekday[4]="torsdag";
weekday[5]="fredag";
weekday[6]="lørdag";
var date = new Date();
var today = date.getDay();
var datePicker = document.createElement("select");
for (i = 0; i < 14; i++)
{
var thisDay = today+i;
while (thisDay > 6)
thisDay -= 7;
var option = document.createElement("option");
option.value = i;
if (i > 6)
option.innerHTML = "Neste ";
option.innerHTML += weekday[thisDay];
if (i == 0)
option.innerHTML = "i dag";
if (i == 1)
option.innerHTML = "i morgen";
datePicker.appendChild(option);
}
var timePicker = document.createElement("select");
// for (time in availabletimes)
for (i = 0; i < 24*4; i++)
{
var time = i*15;
var hour = parseInt(time/60);
var minute = time-hour*60;
var option = document.createElement("option");
option.value = i;
if (minute < 10)
minute = '0'+minute;
if (hour < 10)
hour = '0'+hour;
option.innerHTML = hour + ':' + minute;
if (i == 24*3)
option.setAttribute("selected", "selected");
timePicker.appendChild(option);
}
var phoneField = document.createElement("input");
phoneField.type = "tel";
phoneField.setAttribute("placeholder", "12345678");
<<<<<<< HEAD
// Yeah a fucking montage!
var inputSectionWrapper = document.createElement("fieldset");
inputSectionWrapper.innerHTML += "Jeg, ";
inputSectionWrapper.appendChild(nameField);
inputSectionWrapper.innerHTML += " ønsker å reservere et bord for ";
inputSectionWrapper.appendChild(peopleCountField);
inputSectionWrapper.innerHTML += " personer på "+reservoRestaurantData.name+" ";
inputSectionWrapper.appendChild(datePicker);
inputSectionWrapper.innerHTML += " klokken ";
inputSectionWrapper.appendChild(timePicker);
inputSectionWrapper.innerHTML += ". Dere kan nå meg på ";
inputSectionWrapper.appendChild(phoneField);
inputSectionWrapper.innerHTML += " (mobil).<br>";
inputSection.appendChild(inputSectionWrapper);
var continueButton = document.createElement("a");
continueButton.className = "reservo-button";
continueButton.innerHTML = "Fortsett";
continueButton.setAttribute("onClick", "findAvailableStations();");
=======
var continueButton = document.createElement("button");
continueButton.innerHTML = "continue";
continueButton.setAttribute("onClick", "findAvailableStations();");
// We need a montage!
inputSection.innerHTML += "Jeg, ";
inputSection.appendChild(nameField);
inputSection.innerHTML += " ønsker å reservere et bord for ";
inputSection.appendChild(peopleCountField);
inputSection.innerHTML += " personer på "+reservoRestaurantData.name+" ";
inputSection.appendChild(datePicker);
inputSection.innerHTML += " klokken ";
inputSection.appendChild(timePicker);
inputSection.innerHTML += ". Dere kan nå meg på ";
inputSection.appendChild(phoneField);
inputSection.innerHTML += " (mobil).<br>";
>>>>>>> 2563b24b770548031964fe5e0435b627e225e2bc
inputSection.appendChild(continueButton);
containerSection.appendChild(inputSection);
var stationSection = document.createElement("section");
stationSection.id = "reservo-bordvalg";
stationSection.className = "reservo-seksjon reservo-bordvalg";
containerSection.appendChild(stationSection);
}
function addStationElementsToDOM()
{
if (!reservoRestaurantData.stations)
{
loadAvailableStationsForPlaceTimeAndPeople(5, 1364302096, 6, true);
return;
}
for (var station in reservoRestaurantData.stations)
{
var stationObject = reservoRestaurantData.stations[station];
var stationElement = document.createElement("li");
var stationImageWrapper = document.createElement("figure");
stationImageWrapper.className = "reservoFloatLeft";
stationImageWrapper.id = "station"+stationObject.id;
stationImageWrapper.setAttribute('onclick', "selectStation("+stationObject.id+");");
var stationImage = new Image();
stationImage.src = "http://pido.cc/img/stationImages/"+stationObject.imageName;
if (retina)
stationImage.src = stationImage.src.replace('.jpg', '@2x.jpg');
stationImage.style.width = "280px";
stationImage.style.height = "280px";
stationImageWrapper.appendChild(stationImage);
stationElement.appendChild(stationImageWrapper);
document.getElementById("reservo-bordvalg").appendChild(stationElement);
}
}
function animateInputFieldsOut()
{
var inputSection = document.getElementById("reservo-brev");
var stationSection = document.getElementById("reservo-bordvalg");
var containerSection = document.getElementById("reservo-container");
// Animate instead of hidden here
inputSection.className = inputSection.className.replace( /(?:^|\s)reservo-active(?!\S)/g , '');
stationSection.className += " reservo-active";
<<<<<<< HEAD
addStationElementsToDOM();
=======
containerSection.className = containerSection.className.replace( /(?:^|\s)reservo-brev-active(?!\S)/g , '');
containerSection.className += " reservo-bordvalg-active";
// addStationElementsToDOM();
>>>>>>> 2563b24b770548031964fe5e0435b627e225e2bc
}
/* Button / Control functions */
function loadReservoWithRestaurant(id)
{
loadRestaurant(id, true, false);
}
function findAvailableStations()
{
if (!reservoRestaurantData)
loadRestaurant(reservoRestaurantId, false, true);
else
animateInputFieldsOut();
}
function selectStation(id)
{
for (var station in reservoRestaurantData.stations)
{
var stationObject = reservoRestaurantData.stations[station];
var stationElement = document.getElementById("station"+stationObject.id);
stationElement.className = stationElement.className.replace( /(?:^|\s)reservoSelectedStation(?!\S)/g , '');
}
var stationElement = document.getElementById("station"+id);
stationElement.className = "reservoFloatLeft reservoSelectedStation";
}