forked from mitchgre/gregsList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedules.js
237 lines (188 loc) · 5.26 KB
/
schedules.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
function insertSchedule()
{
var object = this.data;
console.log("from insertSchedule: object = ");
console.log(object);
console.log("this.sid:");
console.log(this.sid);
var link = this.sid;
// console.log("object.destroyer:");
// console.log(object.destroyer);
// var current = object.contents[index];
// build form
var string = '<div id="scheduleUpdater" title="Update Schedule">';
string += '<table>';
string += '<tr>';
string += '<td>name</td>';
string += '<td>';
string += '<input id="embedName" value="'+null+'">';
string += '</td>';
string += '</tr>';
string += '<tr><td>description</td>';
string += '<td><input id="embedDescription" value="'+null+'"></td></tr>';
string += '<tr><td>contact</td>';
string += '<td><input id="embedContact" value="'+null+'"></td></tr>';
string += '<tr><td>start</td>';
string += '<td><input id="embedStart" value="'+'"></td></tr>';
// add datepicker here
string += '<tr><td>end</td>';
string += '<td><input id="embedEnd" value="'+'"></td></tr>';
// add datepicker here
string += '</table></div>';
$(string).dialog
(
{
// http://stackoverflow.com/questions/13233321/jquery-datepicker-in-a-dialog
open: function()
{
$( "#embedStart" ).datepicker({dateFormat:"yy-mm-dd"});
$( "#embedEnd" ).datepicker({dateFormat:"yy-mm-dd"});
},
close: function()
{
$( "#embedStart" ).datepicker('destroy');
$( "#embedEnd" ).datepicker('destroy');
},
modal:true,
buttons:
{
Cancel: function()
{
$(this).dialog("close")
},
"Update":function()
{
// get values from form
var name = $("#embedName")[0].value;
var description = $("#embedDescription")[0].value;
var contact = $("#embedContact")[0].value;
var start = $("#embedStart")[0].value;
var end = $("#embedEnd")[0].value;
// display what we're doing
console.log("sending " +
"name=" + name + ", " +
"description=" + description + ", " +
"contact=" + contact + ", " +
"start=" + start + ", " +
"end=" + end + ", " +
+ " to the butler."
);
// give values to butler
$(this).dialog("close");
// emptyElement($("#scheduleUpdater")[0]);
var toDestroy =
[
"embedName","embedDescription",
"embedContact","embedStart", "embedEnd",
"scheduleUpdater"
];
for (var i=0; i < toDestroy.length; i++)
removeElement(toDestroy[i]);
$.ajax
(
{
url: "butler.php",
type: "post",
dataType: "text",
data:
{
user: object.parent.user.name,
pass: object.parent.user.password,
//func: object.updater,
// sid: link,
name: name,
description: description,
contact:contact,
start:start,
end:end,
//func: "insertSchedule"
func: "addSchedule"
},
success: function(resp)
{
console.log(resp);
//console.log(JSON.parse(resp));
//
// if (JSON.parse(resp) === true)
if (resp == "true" )
{
console.log("removal worked");
// displayTable(object,[]);
getStuff(object);
object.parent.refresh();
}
else
{
console.log("removal failed");
}
}
}
);
}
}
}
);
}
function editSchedule()
{
}
function fillSchedules(object,input)
{
console.log("fill schedules");
console.log(object);
// erase object's contents and refill them from input
object.contents = [];
var contents = object.contents;
for (var i = 0; i < input.ids.length; i++)
{
var id = input.ids[i];
var name = input.names[i]; // called 'title' in calendar
var description = input.descriptions[i];
var location = input.locations[i];
var contact = input.contacts[i];
var url = input.urls[i];
var start = input.starts[i];
var end = input.ends[i];
var p = new schedule(id,name,description,location,contact,url,start,end);
contents.push(p); // push to glo object
// calendar should have been emptied prior to calling this function
$("#calendar").fullCalendar('renderEvent',{title:name,
sid: id,
description:description,
location:location,
contact:contact,
url:url,
start:start,
end:end
},true);// add to calendars
// update portlet
$("#calendarPortlet").fullCalendar('renderEvent',{title:name,
sid: id,
description:description,
location:location,
contact:contact,
url:url,
start:start,
end:end
},true);// add to calendars
displayTable(object);
displayEventPortlet(object);
}
// no user defined table here, need to push into calendar above
// displayTable(object);
}
function displayEventPortlet(object)
{
$("#eventPortlet").empty();
var main = $("#eventPortlet")[0];
var table = createAppendedChildToParent('table',main);
table.className += "io";
for (var i = 0; i < object.contents.length; i++)
{
var tr = createAppendedChildToParent('tr',table);
var td = createAppendedChildToParent('td',tr);
var value = object.contents[i].name;
var content = document.createTextNode(value);
td.appendChild(content);
}
}