forked from mitchgre/gregsList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.js
245 lines (194 loc) · 4.83 KB
/
blog.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
238
239
240
241
242
243
244
function fillBlog(object,input)
{
// 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 title = input.titles[i];
var text = input.texts[i];
var p = new blog(id,title,text);
contents.push(p);
}
displayTable(object);
// displayGoalsPortlet(object);
}
/*
Mon Jul 06, 2015 16:01:15
This function is broken..
Maybe it should be deleted.
*/
function getBlogId(object,title,text)
{
$.ajax
(
{
url: "butler.php",
type: "post",
dataType: "data",
text:
{
user: object.parent.user.name,
pass: object.parent.user.password,
//func: object.updater,
// sid: link,
title: title,
text: text,
func: "getBlogId"
},
success: function(resp)
{
console.log(resp);
// if (JSON.parse(resp) === true)
if (resp == "true" )
{
console.log("got blog id");
// displayTable(object,[]);
// getStuff(object);
// object.parent.refresh();
return resp;
// call back
}
else
{
console.log("removal failed");
}
}
}
);
}
function buildBlogFormString()
{
var string = '<div id="blogUpdater" title="Update Blog Post">';
string += '<table id="blogDialogAddTable">';
string += '<tr id="blogUpdateTitleRow">';
string += '<td id="blogUpdateTitleName">title</td>';
string += '<td id="blogUpdateTitleContent">';
string += '<input id="blogUpdateEmbedTitle" value="'+null+'">';
string += '</td>';
string += '</tr>';
string += '<tr id="blogUpdateContentRow"><td>blog post:</td>';
string += '<td><textarea id="blogPostContentsToAdd"></textarea></td></tr>';
string += '</table></div>';
return string;
}
function fixBlogUpdaterDialogCSS()
{
$("#blogUpdater").css("width","100%");
$("#blogDialogAddTable").css("height","80%");
$("#blogDialogAddTable").css("width","100%");
$("#blogDialogAddTable").css("height","80%");
$( "#blogUpdateTitleRow" ).css("width","80%");
$( "#blogUpdateTitleContent" ).css("width","80%");
$( "#blogUpdateTitleContent" ).css("width","80%");
$( "#blogUpdateEmbedTitle" ).css("width","80%");
$( "#blogUpdateContentRow" ).css("width","80%");
$( "#blogUpdateContentRow" ).css("height","80%");
$( "#blogPostContentsToAdd" ).css("width","80%");
$( "#blogPostContentsToAdd" ).css("height","80%");
}
function giveBlogInsertionToButler(object,title,text,callback)
{
console.log("from giveBlogInsertionToButler: callback= ");
console.log(callback);
console.log("typeof callback == 'function'");
console.log(typeof callback == 'function');
$.ajax
(
{
url: "butler.php",
type: "post",
dataType: "text",
data:
{
user: gregsList.user.name,
pass: gregsList.user.password,
//func: object.updater,
// sid: link,
title: title,
text: text,
func: "insertBlog"
},
success: function(resp)
{
console.log(resp);
//console.log(JSON.parse(resp));
//
// if (JSON.parse(resp) === true)
// if (resp == "true" )
if ( !isNaN( resp ) )
{
// console.log("removal worked");
// displayTable(object,[]);
// getStuff(object);
// object.parent.refresh();
callback(object);
}
else
{
console.log("removal failed");
}
}
}
);
}
function insertBlog(callback)
{
// var object = this.data;
var object = this.blog;
console.log("from insertBlog: object = ");
console.log(object);
console.log("callback");
console.log(callback);
console.log("typeof callback = ");
console.log(typeof callback);
// build form
var string = buildBlogFormString();
$(string).dialog
(
{
width: "80%",
//height: "80%",
height: 400,
open: function()
{
fixBlogUpdaterDialogCSS();
},
modal:true,
buttons:
{
Cancel: function()
{
$(this).dialog("close")
},
"Update":function()
{
// get values from form
var title = $("#blogUpdateEmbedTitle")[0].value;
var text = $("#blogPostContentsToAdd")[0].value;
// display what we're doing
console.log("sending " +
"title=" + title + ", " +
"text=" + text + ", " +
" to the butler."
);
// give values to butler
$(this).dialog("close");
// emptyElement($("#scheduleUpdater")[0]);
var toDestroy =
[
"blogPostContentsToAdd",
"blogDialogAddTable",
"blogUpdater"
];
for (var i=0; i < toDestroy.length; i++)
removeElement(toDestroy[i]);
giveBlogInsertionToButler(object,title,text,callback);
// return an id
// return getBlogId(object,title,text);
}
}
}
);
}