| author | gibus |
| Mon, 01 Oct 2012 11:00:56 +0200 | |
| changeset 469 | 08d57b273596 |
| parent 466 | f00e34a4476b |
| child 490 | 57c1ba71f642 |
| permissions | -rw-r--r-- |
| 0 | 1 |
gShowingAllComments = false ; |
| 466 | 2 |
// indexOf method of Array is unknown by stupid IE. |
3 |
if (!Array.prototype.indexOf) { |
|
4 |
Array.prototype.indexOf = function(obj, start) { |
|
5 |
for (var i = (start || 0), j = this.length; i < j; i++) { |
|
6 |
if (this[i] === obj) { return i; } |
|
7 |
} |
|
8 |
return -1; |
|
9 |
} |
|
10 |
} |
|
| 0 | 11 |
// YUI : queue, overlay |
12 |
Sync = function() { |
|
| 341 | 13 |
// this queue handles both animations and io requests |
14 |
this._q = null ; |
|
15 |
|
|
16 |
this._iPreventClick = false ; // oh really ? |
|
| 0 | 17 |
} |
18 |
||
19 |
Sync.prototype = { |
|
| 341 | 20 |
init : function (iComment) { |
21 |
this._q = new CY.AsyncQueue() ; |
|
| 0 | 22 |
// pr2 this._q = new CY.Queue() ; |
| 341 | 23 |
}, |
24 |
|
|
25 |
setPreventClickOn : function () { |
|
26 |
CY.log("setPreventClickOn !") ; |
|
27 |
if (gLayout.isInFrame()) |
|
28 |
parent.f_interfaceFreeze() |
|
29 |
this._iPreventClick = true ; |
|
30 |
}, |
|
| 0 | 31 |
|
| 341 | 32 |
setPreventClickOff : function () { |
33 |
CY.log("setPreventClickOff !") ; |
|
34 |
if (gLayout.isInFrame()) |
|
35 |
parent.f_interfaceUnfreeze() |
|
36 |
this._iPreventClick = false ; |
|
37 |
}, |
|
| 0 | 38 |
|
| 341 | 39 |
removeCommentRet : function(args) { |
40 |
var successfull = args['successfull'] ; |
|
41 |
|
|
42 |
var iComment = (successfull) ? args['failure']['iComment'] : args['success']['iComment'] ; |
|
43 |
|
|
44 |
if (successfull) { |
|
45 |
var filterData = args['returned']['filterData'] ; |
|
46 |
if (gLayout.isInFrame()) { |
|
47 |
parent.f_updateFilterData(filterData) ; |
|
48 |
} |
|
49 |
|
|
50 |
var y = gIComments.getTopPosition()[1] ; |
|
51 |
|
|
52 |
var comment = gDb.getComment(iComment.commentId) ; |
|
53 |
this._q.add( |
|
54 |
function(){ |
|
55 |
|
|
56 |
unpaintCommentScope(comment) ; |
|
57 |
gIComments.close(comment.id) ; |
|
58 |
gIComments.remove(comment.id) ; |
|
59 |
if (comment.reply_to_id != null) |
|
60 |
gIComments.refresh(comment.reply_to_id) ; |
|
61 |
|
|
62 |
gDb.del(comment) ; |
|
63 |
|
|
64 |
if (gLayout.isInFrame()) { |
|
65 |
if (gDb.comments.length == 0 && gDb.allComments.length != 0) { |
|
66 |
parent.f_enqueueMsg(gettext("no filtered comments left")) ; |
|
67 |
parent.resetFilter() ; |
|
68 |
} |
|
69 |
else { |
|
70 |
// just counting here ... |
|
71 |
var filterRes = gDb.computeFilterResults() ; |
|
72 |
updateFilterResultsCount(filterRes['nbDiscussions'], filterRes['nbComments'], filterRes['nbReplies']) ; |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
); |
|
77 |
|
|
78 |
this._animateTo(y) ; |
|
79 |
} |
|
80 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
81 |
this.resume() ; |
|
82 |
}, |
|
83 |
|
|
84 |
moderateCommentRet : function(args) { |
|
85 |
var successfull = args['successfull'] ; |
|
| 0 | 86 |
|
| 341 | 87 |
var iComment = (successfull) ? args['failure']['iComment'] : args['success']['iComment'] ; |
| 0 | 88 |
|
| 341 | 89 |
if (successfull) { |
90 |
var ret = args['returned'] ; |
|
91 |
var comment = ret['comment'] ; |
|
| 0 | 92 |
|
| 341 | 93 |
gDb.upd(comment) ; |
94 |
|
|
95 |
var shouldReset = gLayout.isInFrame() && !parent.f_isFrameFilterFieldsInit() ; |
|
96 |
if (shouldReset){ |
|
97 |
parent.resetFilter() ; |
|
98 |
this._showSingleComment(comment) ; |
|
99 |
} |
|
100 |
else |
|
101 |
iComment.changeModeration(comment) ; |
|
102 |
} |
|
| 0 | 103 |
|
| 341 | 104 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
105 |
this.resume() ; |
|
106 |
}, |
|
107 |
|
|
108 |
saveCommentRet : function(args) { |
|
109 |
var successfull = args['successfull'] ; |
|
110 |
if (successfull) { |
|
111 |
var formId = args['success']['formId'] ; |
|
112 |
var ret = args['returned'] ; |
|
113 |
|
|
114 |
removeFormErrMsg(formId) ; |
|
115 |
|
|
116 |
if ('errors' in ret) { // validation error |
|
117 |
var errors = ret['errors'] ; |
|
118 |
for (var eltName in errors) { |
|
119 |
addFormErrMsg(formId, eltName, errors[eltName]) ; |
|
120 |
} |
|
121 |
this._animateToTop() ; |
|
122 |
} |
|
123 |
else { |
|
124 |
var isReply = function() {return (gNewReply != null) && (formId == gNewReply['ids']['formId']) ;} ; |
|
125 |
var isNewComment = function() {return (gICommentForm != null) && (formId == gICommentForm['formId']) ;} ; |
|
126 |
var isEdit = function() {return (gEdit != null) && (formId == gEdit['ids']['formId']) ;} ; |
|
127 |
|
|
128 |
// doing this here for the a priori moderation case |
|
129 |
if (isNewComment()) |
|
130 |
this.hideICommentForm(cleanICommentForm()) ; |
|
131 |
else if (isEdit()) |
|
132 |
this._hideEditForm() ; |
|
133 |
else if (isReply()) |
|
134 |
this._hideNewReplyForm() ; |
|
135 |
|
|
136 |
if ("ask_for_notification" in ret) { |
|
137 |
if (ret['ask_for_notification']) { |
|
138 |
// TODO ask for notification ...or use AUTO_CONTRIB ? |
|
139 |
parent.f_yesNoDialog(gettext("Do you want to be notified of all replies in all discussions you participated in?"), gettext("Reply notification"), |
|
140 |
function() { // special case : no waiting for the return, no error check, nothing ! |
|
141 |
var cfg = { |
|
142 |
method: "POST", |
|
143 |
data: urlEncode({'fun':'ownNotify', 'key':sv_key, 'version_key':sv_version_key, 'email':ret['email'], 'active':false}) |
|
144 |
} ; |
|
145 |
CY.io(sv_client_url, cfg); |
|
146 |
}, this, null, |
|
147 |
function() { // special case : no waiting for the return, no error check, nothing ! |
|
148 |
var cfg = { |
|
149 |
method: "POST", |
|
150 |
data: urlEncode({'fun':'ownNotify', 'key':sv_key, 'version_key':sv_version_key, 'email':ret['email'], 'active':true}) |
|
151 |
} ; |
|
152 |
CY.io(sv_client_url, cfg); |
|
153 |
}, this, null) ; |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
|
|
158 |
if ("comment" in ret) { // won't be when add with a priori moderation |
|
159 |
var comment = ret['comment'] ; |
|
160 |
|
|
161 |
gDb.upd(comment) ; |
|
162 |
|
|
163 |
var shouldReset = gLayout.isInFrame() && !parent.f_isFrameFilterFieldsInit() ; |
|
164 |
if (shouldReset) |
|
165 |
parent.resetFilter() ; |
|
166 |
else { // ASSUMING filter is in init state ! (because when not // TODO $$$$$$$$$$$ this isn't true anymore .... when passing filter arguments in url !! |
|
167 |
// in frame for now data can't be filtered) |
|
168 |
if (comment.reply_to_id == null) { // not a reply |
|
169 |
unpaintCommentScope(comment) ; // for the edit case |
|
170 |
paintCommentScope(comment) ; |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
// UPDATE FILTER DATA // TODO move ???? |
|
175 |
var filterData = ret['filterData'] ; |
|
176 |
if (gLayout.isInFrame()) { |
|
177 |
parent.f_updateFilterData(filterData) ; |
|
178 |
updateResetFilterResultsCount() ; |
|
179 |
} |
|
| 0 | 180 |
|
| 341 | 181 |
if (isReply()) { // add reply case |
182 |
if (!shouldReset) { |
|
183 |
this._insertReply(comment) ; |
|
184 |
} |
|
185 |
} |
|
186 |
else { // edit (reply or comment) or add (comment) case |
|
187 |
this._showSingleComment(comment) ; |
|
188 |
} |
|
189 |
} |
|
190 |
else |
|
191 |
this._animateToTop() ; |
|
192 |
} |
|
| 0 | 193 |
|
| 341 | 194 |
} |
195 |
else { // TODO ? ALL ret-FUNCTIONS ? |
|
196 |
this._q.add({id:"expl", fn:function () {CY.log('in example .........') ;}}) ; |
|
197 |
this._q.promote("expl") ; |
|
198 |
} |
|
| 0 | 199 |
|
| 341 | 200 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
201 |
this.resume() ; |
|
202 |
}, |
|
203 |
|
|
204 |
example : function () { |
|
205 |
CY.log('in example .........') ; |
|
206 |
}, |
|
| 0 | 207 |
|
| 341 | 208 |
moderateComment : function(iComment, state) { |
209 |
var comment = gDb.getComment(iComment['commentId']) ; |
|
| 0 | 210 |
this._q.add( |
| 341 | 211 |
{fn:CY.bind(this.setPreventClickOn, this)}, |
212 |
{autoContinue:false, fn:CY.bind(doExchange, null, "editComment", {'comment_key':comment.key, 'state':state}, null, this.moderateCommentRet, this, {'iComment':iComment}, gettext("could not save comment"))} |
|
213 |
).run(); |
|
214 |
}, |
|
215 |
|
|
216 |
_saveComment : function(serverFun, formId) { |
|
| 0 | 217 |
this._q.add( |
| 341 | 218 |
{fn:CY.bind(this.setPreventClickOn, this)}, |
219 |
{autoContinue:false, fn:CY.bind(doExchange, null, serverFun, {}, formId, this.saveCommentRet, this, {'formId':formId}, gettext("could not save comment"))} |
|
220 |
).run(); |
|
221 |
}, |
|
222 |
|
|
223 |
editComment : function() { |
|
224 |
this._saveComment("editComment", gEdit['ids']['formId']) ; |
|
225 |
}, |
|
226 |
|
|
227 |
saveComment : function(formId) { |
|
228 |
this._saveComment("addComment", formId) ; |
|
229 |
}, |
|
230 |
|
|
231 |
removeComment : function(iComment) { |
|
232 |
checkForOpenedDialog(iComment, function() { |
|
233 |
if (gLayout.isInFrame()) { |
|
234 |
parent.f_yesNoDialog(gettext("Are you sure you want to delete this comment?"), gettext("Warning"), function() { this.animateToTop() ;}, this, null, function() { |
|
235 |
var comment = gDb.getComment(iComment.commentId) ; |
|
236 |
this._q.add( |
|
237 |
{fn:CY.bind(this.setPreventClickOn, this)}, |
|
238 |
{autoContinue:false, fn:CY.bind(doExchange, null, "removeComment", {'comment_key':comment.key}, null, this.removeCommentRet, this, {'iComment':iComment}, gettext("could not remove comment"))} |
|
239 |
).run(); |
|
240 |
}, this, null) ; |
|
241 |
|
|
242 |
} |
|
243 |
// else { |
|
244 |
// alert("TODO : can't yet delete comments when not embed in text_view_frame because can't 'dialog' confirmation") ; |
|
245 |
// } |
|
246 |
|
|
247 |
}, this, null) ; |
|
248 |
}, |
|
249 |
|
|
250 |
resume : function(commentDbIds, mouseXY) { |
|
251 |
this._q.run() ; |
|
252 |
}, |
|
253 |
|
|
254 |
resetAutoContinue : function(callbackId) { |
|
255 |
this._q.getCallback(callbackId).autoContinue = true; |
|
256 |
}, |
|
257 |
|
|
258 |
hideICommentForm : function(funObj) { |
|
259 |
// this._q.add({fn:function() {persistICommentFormValues();}}) ; |
|
260 |
this._q.add({autoContinue:false, fn:CY.bind(gICommentForm['animationHide'].run, gICommentForm['animationHide'])}) ; |
|
261 |
// this._q.add({fn:function() {cleanICommentForm();}}) ; |
|
262 |
if (funObj) |
|
263 |
this._q.add(funObj) ; |
|
264 |
}, |
|
265 |
|
|
266 |
/* ANIMATION DRIVEN INTERFACE CHANGES */ |
|
267 |
|
|
268 |
showCommentForm : function(iComment) { |
|
269 |
checkForOpenedDialog(null, function() { |
|
270 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
|
271 |
this._q.add({fn:function() { |
|
272 |
if (iComment == null) { |
|
273 |
var selection = getSelectionInfo() ; |
|
274 |
updateICommentFormSelection(selection) ; |
|
275 |
} |
|
276 |
showICommentForm(iComment); |
|
277 |
}}) ; |
|
278 |
this._q.add({autoContinue:false, fn:CY.bind(gICommentForm['animationShow'].run, gICommentForm['animationShow'])}, |
|
279 |
{fn:CY.bind(this.setPreventClickOff, this)} |
|
280 |
).run(); |
|
281 |
}, this, null) ; |
|
282 |
}, |
|
283 |
|
|
284 |
showEditForm : function(iComment) { |
|
285 |
checkForOpenedDialog(null, function() { |
|
286 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
|
| 0 | 287 |
|
| 341 | 288 |
this._q.add({fn:function() { |
289 |
showEditForm(iComment) ; |
|
290 |
}}); |
|
291 |
this._animateToTop() ; |
|
292 |
|
|
293 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
|
294 |
this._q.run() ; |
|
295 |
}, this, null) ; |
|
296 |
}, |
|
297 |
|
|
298 |
showReplyForm : function(iComment) { |
|
299 |
checkForOpenedDialog(null, function() { |
|
300 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
|
| 0 | 301 |
|
| 341 | 302 |
this._q.add({fn:function() { |
303 |
instanciateNewReplyForm(iComment) ; |
|
304 |
}}); |
|
305 |
this._animateToTop() ; |
|
306 |
|
|
307 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
|
308 |
this._q.run() ; |
|
309 |
}, this, null) ; |
|
310 |
}, |
|
311 |
|
|
312 |
cancelICommentForm : function() { |
|
| 0 | 313 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
314 |
|
|
| 341 | 315 |
// this._q.add({fn:function() {cleanICommentForm();}}) ; |
316 |
this.hideICommentForm() ; |
|
317 |
|
|
| 0 | 318 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
319 |
this._q.run() ; |
|
| 341 | 320 |
}, |
321 |
cancelEdit : function() { |
|
| 0 | 322 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
323 |
|
|
| 341 | 324 |
this._q.add({fn:function() {cancelEditForm();}}) ; |
325 |
this._animateToTop() ; |
|
326 |
|
|
| 0 | 327 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
328 |
this._q.run() ; |
|
| 341 | 329 |
}, |
330 |
cancelReply : function() { |
|
| 0 | 331 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
332 |
|
|
| 341 | 333 |
this._q.add({fn:function() {cancelNewReplyForm();}}) ; |
334 |
this._animateToTop() ; |
|
335 |
|
|
| 0 | 336 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
337 |
this._q.run() ; |
|
| 341 | 338 |
}, |
339 |
changeScopeFormClick : function() { |
|
| 0 | 340 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}); |
341 |
|
|
| 341 | 342 |
this._q.add({fn:function() {changeScopeFormClick();}}) ; |
343 |
this._animateToTop() ; |
|
344 |
|
|
| 0 | 345 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}); |
346 |
this._q.run() ; |
|
| 341 | 347 |
}, |
348 |
// this is invoked during queue execution |
|
349 |
_hideNewReplyForm : function() { |
|
350 |
this._q.add({fn:function() { |
|
351 |
cleanNewReplyForm() ; |
|
352 |
cancelNewReplyForm() ;}}) ; |
|
353 |
}, |
|
354 |
// this is invoked during queue execution |
|
355 |
_hideEditForm : function() { |
|
356 |
this._q.add({fn:function() { |
|
357 |
cancelEditForm() ;}}) ; |
|
358 |
}, |
|
359 |
// this is invoked during queue execution |
|
360 |
_insertReply : function(comment) { |
|
361 |
this._q.add({fn:function() { |
|
362 |
var parentComment = gDb.getComment(comment.reply_to_id) ; |
|
363 |
var parentThread = gDb.getThreads([parentComment]) ; |
|
364 |
var previousComment = parentThread[parentThread.length - 2] ; // - 2 because now that comment has been added comment is parentThread[parentThread.length - 1] |
|
| 0 | 365 |
|
| 341 | 366 |
var iComment = gIComments.insertAfter(previousComment, comment) ; |
367 |
// iComment CAN'T BE NULL ! (TODO check that there is a |
|
368 |
// check server side that parent exists when adding a reply |
|
369 |
// !) |
|
370 |
|
|
371 |
var parentPosition = gIComments.getPosition(comment.reply_to_id) ; |
|
372 |
iComment.setPosition(parentPosition) ; |
|
373 |
|
|
374 |
// check if activation is necessary (will always be ?) |
|
375 |
var comment_path = gDb.getPath(comment) ; |
|
376 |
var topComment = comment_path[comment_path.length - 1] ; |
|
377 |
if (gIComments.isTopActive(topComment.id)) |
|
378 |
iComment.activate() ; |
|
| 0 | 379 |
|
| 341 | 380 |
iComment.show() ;}}) ; |
381 |
this._animateToTop() ; |
|
382 |
}, |
|
383 |
_showSingleComment : function(comment) { |
|
384 |
if (comment != null) { |
|
385 |
var path = gDb.getPath(comment) ; |
|
386 |
var topAncestorComment = path[path.length - 1] ; |
|
387 |
var topY = 0 ; |
|
388 |
if (comment['start_wrapper'] != -1) |
|
389 |
topY = CY.get(".c-id-"+topAncestorComment.id).getY() ; |
|
390 |
else |
|
391 |
topY = CY.get('document').get('scrollTop') ; |
|
392 |
|
|
393 |
this._showComments([topAncestorComment.id], topY, false) ; |
|
394 |
// optim when browsing comments with no reply |
|
395 |
if (topAncestorComment.replies.length > 0) |
|
396 |
this._animateTo(topY) ; |
|
397 |
} |
|
398 |
}, |
|
399 |
_showFocusSingleComment : function(topComment, focusComment, reply) { |
|
400 |
if (topComment != null) { |
|
401 |
var topY = 0 ; |
|
402 |
if (topComment['start_wrapper'] != -1) |
|
403 |
topY = CY.get(".c-id-"+topComment.id).getY() ; |
|
404 |
else |
|
405 |
topY = CY.get('document').get('scrollTop') ; |
|
406 |
|
|
407 |
this._showComments([topComment.id], topY, false) ; |
|
408 |
// optim when browsing comments with no reply |
|
409 |
if (topComment.replies.length > 0 || reply) |
|
410 |
this._animateToAndFocus(topY, focusComment.id, reply) ; |
|
411 |
} |
|
412 |
}, |
|
| 0 | 413 |
|
| 341 | 414 |
showSingleComment : function(comment) { |
415 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
416 |
this._showSingleComment(comment) ; |
|
417 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
418 |
this._q.run(); |
|
419 |
}, |
|
420 |
|
|
421 |
showFocusSingleComment : function(topComment, focusComment, reply) { |
|
422 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
423 |
this._showFocusSingleComment(topComment, focusComment, reply) ; |
|
424 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
425 |
this._q.run(); |
|
426 |
}, |
|
427 |
|
|
428 |
browse : function(order, whereto) { |
|
429 |
var comment = gIComments.browse(order, whereto) ; |
|
430 |
if (comment != null) |
|
431 |
this.showSingleComment(comment) ; |
|
432 |
}, |
|
433 |
|
|
434 |
_showComments : function(commentDbIds, topY, atDocumentTop) { |
|
435 |
this._q.add( |
|
436 |
{fn:function() { |
|
437 |
gShowingAllComments = atDocumentTop ; |
|
438 |
gIComments.hide() ; |
|
| 421 | 439 |
hideToc(); |
| 341 | 440 |
var cs = CY.Array.map(commentDbIds, function(id) { return gDb.getComment(id)Â ; }) ; |
441 |
var comments = gDb.getThreads(cs)Â ; |
|
442 |
gIComments.fetch(comments) ; |
|
443 |
|
|
444 |
if (commentDbIds.length > 0) { |
|
445 |
if (atDocumentTop) { |
|
446 |
CY.get('document').set('scrollTop', 0) ; |
|
447 |
} |
|
448 |
else { |
|
449 |
gIComments.activate(commentDbIds[0]) ; |
|
450 |
var scopeStart = CY.get(".c-id-"+commentDbIds[0]) ; |
|
451 |
if (scopeStart && !scopeStart.inViewportRegion()) // scopeStart could be null when comment has no scope |
|
452 |
scopeStart.scrollIntoView(true) ; |
|
453 |
} |
|
454 |
} |
|
455 |
|
|
456 |
gIComments.setPosition([gConf['iCommentLeftPadding'], topY]) ; |
|
457 |
|
|
458 |
gIComments.show() ; |
|
459 |
}}) ; |
|
460 |
}, |
|
461 |
|
|
462 |
_animateTo : function(topY) { |
|
463 |
this._q.add({fn:function() { |
|
464 |
gIComments.setAnimationToPositions(topY) ; |
|
465 |
}}, |
|
466 |
{id:"animationRun", autoContinue:false, fn:CY.bind(gIComments.runAnimations, gIComments)} |
|
467 |
) ; |
|
468 |
}, |
|
469 |
|
|
470 |
_animateToAndFocus : function(topY, focusCommentId, reply) { |
|
471 |
this._q.add({fn:function() { |
|
472 |
gIComments.setAnimationToPositionsAndFocus(topY, focusCommentId, reply) ; |
|
473 |
}}, |
|
474 |
{id:"animationRun", autoContinue:false, fn:CY.bind(gIComments.runAnimations, gIComments)} |
|
475 |
) ; |
|
476 |
}, |
|
477 |
|
|
478 |
_animateToTop : function() { |
|
479 |
var topPos = gIComments.getTopPosition() ; |
|
480 |
if (topPos != null) |
|
481 |
this._animateTo(topPos[1]) ; |
|
482 |
}, |
|
483 |
|
|
484 |
animateToTop : function() { |
|
485 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
486 |
this._animateToTop() ; |
|
487 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
488 |
this._q.run(); |
|
489 |
}, |
|
490 |
|
|
491 |
showAllComments : function() { |
|
492 |
checkForOpenedDialog(null, function() { |
|
493 |
gShowingAllComments = true ; |
|
494 |
var allTopComments = CY.Array.map(gDb.comments, function(c){return c.id;}) ; |
|
|
432
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
495 |
// Reorder if by scope. |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
496 |
if (parent.$("#browse_by").val() == 'scope') { |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
497 |
allTopComments.sort(function (a,b) { |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
498 |
if (gDb.ordered_comment_ids['scope'].indexOf(a) < gDb.ordered_comment_ids['scope'].indexOf(b)) |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
499 |
return -1; |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
500 |
if (gDb.ordered_comment_ids['scope'].indexOf(a) > gDb.ordered_comment_ids['scope'].indexOf(b)) |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
501 |
return 1 |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
502 |
return 0 |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
503 |
}); |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
504 |
} |
| 375 | 505 |
// GIB: go down the 'add comment' icon |
506 |
this.showComments(allTopComments, [0,30], true) ; |
|
| 341 | 507 |
}, this, null) ; |
508 |
}, |
|
| 0 | 509 |
|
| 341 | 510 |
showScopeRemovedComments : function() { |
511 |
checkForOpenedDialog(null, function() { |
|
512 |
gShowingAllComments = true ; |
|
513 |
var scopeRemovedComments = CY.Array.filter(gDb.comments, function(comment) { return (comment.start_wrapper == -1)Â ; }) ; |
|
514 |
var scopeRemovedCommentIds = CY.Array.map(scopeRemovedComments, function(c){return c.id;}) ; |
|
|
432
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
515 |
// Reorder if by scope. |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
516 |
if (parent.$("#browse_by").val() == 'scope') { |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
517 |
scopeRemovedCommentIds.sort(function (a,b) { |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
518 |
if (gDb.ordered_comment_ids['scope'].indexOf(a) < gDb.ordered_comment_ids['scope'].indexOf(b)) |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
519 |
return -1; |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
520 |
if (gDb.ordered_comment_ids['scope'].indexOf(a) > gDb.ordered_comment_ids['scope'].indexOf(b)) |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
521 |
return 1 |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
522 |
return 0 |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
523 |
}); |
|
aad07a378d44
Respect order by scope in show all comments or show all detached comments.
gibus
parents:
421
diff
changeset
|
524 |
} |
| 375 | 525 |
// GIB: go down the 'add comment' icon |
526 |
this.showComments(scopeRemovedCommentIds, [0,30], true) ; |
|
| 341 | 527 |
|
528 |
}, this, null) ; |
|
529 |
}, |
|
| 103 | 530 |
|
| 341 | 531 |
showComments : function(commentDbIds, mouseXY, atDocumentTop) { |
532 |
checkForOpenedDialog(null, function() { |
|
533 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
534 |
this._showComments(commentDbIds, mouseXY[1], atDocumentTop) ; |
|
535 |
this._animateTo(mouseXY[1]) ; |
|
536 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
537 |
this._q.run(); |
|
538 |
}, this, null) ; |
|
539 |
}, |
|
| 0 | 540 |
|
| 341 | 541 |
openComment : function(iComment) { |
542 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
| 0 | 543 |
|
| 341 | 544 |
var y = gIComments.getTopPosition()[1] ; |
545 |
this._q.add({fn:function() { |
|
546 |
gIComments.open(iComment.commentId) ; |
|
547 |
gIComments.refresh(iComment.commentId) ; |
|
548 |
}}) ; |
|
549 |
this._animateTo(y) ; |
|
550 |
|
|
551 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
552 |
this._q.run(); |
|
553 |
}, |
|
554 |
|
|
555 |
closeComment : function(iComment) { |
|
556 |
checkForOpenedDialog(iComment, function() { |
|
557 |
this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ; |
|
558 |
|
|
559 |
var y = gIComments.getTopPosition()[1] ; |
|
560 |
this._q.add({fn:function() { |
|
561 |
var comment = gDb.getComment(iComment.commentId) ; |
|
562 |
gIComments.close(iComment.commentId) ; |
|
563 |
if (comment.reply_to_id != null) |
|
564 |
gIComments.refresh(comment.reply_to_id) ; |
|
565 |
}}) ; |
|
566 |
this._animateTo(y) ; |
|
567 |
|
|
568 |
this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ; |
|
569 |
this._q.run() ; |
|
570 |
}, this, null) ; |
|
571 |
}, |
|
572 |
|
|
573 |
activate : function(iComment) { |
|
574 |
gIComments.activate(iComment.commentId) ; |
|
575 |
} |
|
| 0 | 576 |
} |
| 341 | 577 |
|
| 0 | 578 |
readyForAction = function () { |
| 341 | 579 |
return !gSync._iPreventClick ; |
| 0 | 580 |
}; |