This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
/
postlist.js
1323 lines (1198 loc) · 44 KB
/
postlist.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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* BlogPostList component.
*
* @namespace Alfresco
* @class Alfresco.BlogPostList
*/
(function()
{
/**
* YUI Library aliases
*/
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
Element = YAHOO.util.Element;
/**
* Alfresco Slingshot aliases
*/
var $html = Alfresco.util.encodeHTML;
/**
* BlogPostList constructor.
*
* @param {String} htmlId The HTML id of the parent element
* @return {Alfresco.BlogPostList} The new BlogPostList instance
* @constructor
*/
Alfresco.BlogPostList = function(htmlId)
{
/* Mandatory properties */
this.name = "Alfresco.BlogPostList";
this.id = htmlId;
/* Initialise prototype properties */
this.widgets = {};
this.currentFilter = {};
this.tagId =
{
id: 0,
tags: {}
};
/* Register this component */
Alfresco.util.ComponentManager.register(this);
/* Load YUI Components */
Alfresco.util.YUILoaderHelper.require(["button", "dom", "datasource", "datatable", "paginator", "event", "element"], this.onComponentsLoaded, this);
/* Decoupled event listeners */
YAHOO.Bubbling.on("tagSelected", this.onTagSelected, this);
YAHOO.Bubbling.on("blogConfigChanged", this.onBlogConfigChanged, this);
YAHOO.Bubbling.on("changeFilter", this.onChangeFilter, this);
YAHOO.Bubbling.on("blogpostlistRefresh", this.onBlogPostListRefresh, this);
YAHOO.Bubbling.on("deactivateAllControls", this.onDeactivateAllControls, this);
return this;
};
Alfresco.BlogPostList.prototype =
{
/**
* Object container for initialization options
*
* @property options
* @type object
*/
options:
{
/**
* Current siteId.
*
* @property siteId
* @type string
*/
siteId: "",
/**
* ContainerId representing root container
*
* @property containerId
* @type string
* @default "blog"
*/
containerId: "blog",
/**
* Initially used filter name and id.
*/
initialFilter: {},
/**
* Number of items per page
*
* @property pageSize
* @type int
*/
pageSize: 10,
/**
* Flag indicating whether the list shows a detailed view or a simple one.
*
* @property simpleView
* @type boolean
*/
simpleView: false,
/**
* Maximum length of post to show in list view
*
* @property maxContentLength
* @type int
* @default 512
*/
maxContentLength: 512
},
/**
* Current filter to filter blog post list.
*
* @property currentFilter
* @type object
*/
currentFilter: null,
/**
* Object container for storing YUI widget instances.
*
* @property widgets
* @type object
*/
widgets: null,
/**
* Object container for storing module instances.
*
* @property modules
* @type object
*/
modules: null,
/**
* Object literal used to generate unique tag ids
*
* @property tagId
* @type object
*/
tagId: null,
/**
* Tells whether an action is currently ongoing.
*
* @property busy
* @type boolean
* @see _setBusy/_releaseBusy
*/
busy: false,
/**
* Offset of first record on page
*
* @property recordOffset
* @type int
* @default 0
*/
recordOffset: 0,
/**
* Total number of posts in the current view (across all pages)
*
* @property totalRecords
* @type int
* @default 0
*/
totalRecords: 0,
/**
* Set multiple initialization options at once.
*
* @method setOptions
* @param obj {object} Object literal specifying a set of options
*/
setOptions: function BlogPostList_setOptions(obj)
{
this.options = YAHOO.lang.merge(this.options, obj);
return this;
},
/**
* Set messages for this component.
*
* @method setMessages
* @param obj {object} Object literal specifying a set of messages
* @return {Alfresco.DocumentList} returns 'this' for method chaining
*/
setMessages: function BlogPostList_setMessages(obj)
{
Alfresco.util.addMessages(obj, this.name);
return this;
},
/**
* Fired by YUILoaderHelper when required component script files have
* been loaded into the browser.
*
* @method onComponentsLoaded
*/
onComponentsLoaded: function BlogPostList_onComponentsLoaded()
{
Event.onContentReady(this.id, this.onReady, this, true);
},
/**
* Fired by YUI when parent element is available for scripting.
* Component initialisation, including instantiation of YUI widgets and event listener binding.
*
* @method onReady
*/
onReady: function BlogPostList_onReady()
{
// Reference to self used by inline functions
var me = this;
// Simple view button
this.widgets.simpleView = Alfresco.util.createYUIButton(this, "simpleView-button", this.onSimpleView);
// called by the paginator on state changes
var handlePagination = function BlogPostList_handlePagination(state, dt)
{
//me.currentPage = state.page;
me._updateBlogPostList(
{
page: state.page
});
};
// YUI Paginator definition
this.widgets.paginator = new YAHOO.widget.Paginator(
{
containers: [this.id + "-paginator"],
rowsPerPage: this.options.pageSize,
initialPage: 1,
template: this._msg("pagination.template"),
pageReportTemplate: this._msg("pagination.template.page-report"),
previousPageLinkLabel: this._msg("pagination.previousPageLinkLabel"),
nextPageLinkLabel: this._msg("pagination.nextPageLinkLabel")
});
this.widgets.paginator.subscribe("changeRequest", handlePagination);
// Hook action events for details view
var fnActionHandlerDiv = function BlogPostList_fnActionHandlerDiv(layer, args)
{
var owner = YAHOO.Bubbling.getOwnerByTagName(args[1].anchor, "div");
if (owner !== null)
{
if (typeof me[owner.className] == "function")
{
args[1].stop = true;
me[owner.className].call(me, args[1].target.offsetParent, owner);
}
}
return true;
};
YAHOO.Bubbling.addDefaultAction("blogpost-action-link-div", fnActionHandlerDiv);
// Hook action events for simple view
var fnActionHandlerSpan = function BlogPostList_fnActionHandlerSpan(layer, args)
{
var owner = YAHOO.Bubbling.getOwnerByTagName(args[1].anchor, "span");
if (owner !== null)
{
var action = owner.className;
var target = args[1].target;
if (typeof me[action] == "function")
{
me[action].call(me, target.offsetParent, owner);
args[1].stop = true;
}
}
return true;
};
YAHOO.Bubbling.addDefaultAction("blogpost-action-link-span", fnActionHandlerSpan);
// DataSource definition
var uriBlogPostList = YAHOO.lang.substitute(Alfresco.constants.URL_SERVICECONTEXT + "components/blog/site/{site}/{container}/posts",
{
site: this.options.siteId,
container: this.options.containerId
});
this.widgets.dataSource = new YAHOO.util.DataSource(uriBlogPostList,
{
responseType: YAHOO.util.DataSource.TYPE_JSON,
connXhrMode: "queueRequests",
responseSchema:
{
resultsList: "items",
metaFields:
{
recordOffset: "startIndex",
totalRecords: "total",
metadata: "metadata",
totalRecordsUpper: 'totalRecordsUpper'
}
}
});
/**
* Blog post element. We only have a list and not an acutal table, there is therefore
* only one column renderer
*
* @method renderBlogPost
* @param elCell {object}
* @param oRecord {object}
* @param oColumn {object}
* @param oData {object|string}
*/
var renderBlogPost = function BlogPostList_renderBlogPost(elCell, oRecord, oColumn, oData)
{
// hide the parent temporarily as we first insert the structure and then the content
// to avoid problems caused by broken xhtml
Dom.addClass(elCell, 'hidden');
// fetch the data and pregenerate some values
var data = oRecord.getData();
var postViewUrl = Alfresco.util.blog.generateBlogPostViewUrl(me.options.siteId, me.options.containerId, data.name);
var statusLabel = Alfresco.util.blog.generatePostStatusLabel(me, data);
//ALF-18527
var authorLink = data.author.username;
// firstName is a mandatory field for user
if (typeof data.author.firstName != "undefined")
{
authorLink = Alfresco.util.people.generateUserLink(data.author);
}
var html = "";
// detailed view
if (!me.options.simpleView)
{
html += '<div class="node post">';
// actions
html += Alfresco.util.blog.generateBlogPostActions(me, data, 'div');
// begin view
html += '<div class="nodeContent">';
html += '<span class="nodeTitle"><a href="' + postViewUrl + '">' + $html(data.title) + '</a> ';
html += '<span class="theme-color-2 nodeStatus">' + statusLabel + '</span></span>';
html += '<div class="published">';
if (!data.isDraft)
{
html += '<span class="nodeAttrLabel">' + me._msg("post.publishedOn") + ': </span>';
html += '<span class="nodeAttrValue">' + Alfresco.util.formatDate(data.releasedOn) + '</span>';
html += '<span class="separator"> </span>';
}
html += '<span class="nodeAttrLabel">' + me._msg("post.author") + ': </span>';
html += '<span class="nodeAttrValue">' + authorLink + '</span>';
if (data.isPublished && data.postLink && data.postLink.length > 0)
{
html += '<span class="separator"> </span>';
html += '<span class="nodeAttrLabel">' + me._msg("post.externalLink") + ': </span>';
html += '<span class="nodeAttrValue"><a target="_blank" href="' + data.postLink + '">' + me._msg("post.clickHere") + '</a></span>';
}
html += '</div>';
html += '<div class="content yuieditor"></div>';
html += '</div>';
// end view
html += '</div>';
// begin footer
html += '<div class="nodeFooter">';
html += '<span class="nodeAttrLabel replyTo">' + me._msg("post.replies") + ': </span>';
html += '<span class="nodeAttrValue">(' + data.commentCount + ')</span>';
html += '<span class="separator"> </span>';
html += '<span class="nodeAttrValue"><a href="' + postViewUrl + '">' + me._msg("post.read") + '</a></span>';
html += '<span class="separator"> </span>';
html += '<span class="nodeAttrLabel tagLabel">' + me._msg("label.tags") +': </span>';
if (data.tags.length > 0)
{
for (var x=0; x < data.tags.length; x++)
{
if (x > 0)
{
html += ', ';
}
html += Alfresco.util.tags.generateTagLink(me, data.tags[x]);
}
}
else
{
html += '<span class="nodeAttrValue">' + me._msg("post.noTags") + '</span>';
}
html += '</div></div>';
// end
}
// simple view
else
{
// add a class to the parent div so that we can add a separator line in the simple view
Dom.addClass(elCell, 'row-separator');
html += '<div class="node post simple">';
// begin actions
html += Alfresco.util.blog.generateBlogPostActions(me, data, 'span');
// begin view
html += '<div class="nodeContent">';
html += '<span class="nodeTitle"><a href="' + postViewUrl + '">' + $html(data.title) + '</a> ';
html += '<span class="theme-color-2 nodeStatus">' + statusLabel + '</span></span>';
html += '<div class="published">';
if (!data.isDraft)
{
html += '<span class="nodeAttrLabel">' + me._msg("post.publishedOn") + ': </span>';
html += '<span class="nodeAttrValue">' + Alfresco.util.formatDate(data.releasedOn) + '</span>';
html += '<span class="separator"> </span>';
}
html += '<span class="nodeAttrLabel">' + me._msg("post.author") + ': </span>';
html += '<span class="nodeAttrValue">' + authorLink + '</span>';
if (data.isPublished && data.postLink && data.postLink.length > 0)
{
html += '<span class="separator"> </span>';
html += '<span class="nodeAttrLabel">' + me._msg("post.externalLink") + ': </span>';
html += '<span class="nodeAttrValue"><a target="_blank" href="' + data.postLink + '">' + me._msg("post.clickHere") + '</a></span>';
}
html += '</div>';
html += '</div>';
html += '</div>';
}
// assign html
elCell.innerHTML = html;
// finally add the content. We do this here to avoid a broken page layout, as
// data.content isn't valid xhtml.
if (!me.options.simpleView)
{
var contentElem = Dom.getElementsByClassName("content", "div", elCell);
if (contentElem.length == 1)
{
contentElem[0].innerHTML = data.content;
}
}
// now show the element
Dom.removeClass(elCell, 'hidden');
};
// DataTable column defintions
var columnDefinitions = [
{
key: "blogposts", label: "BlogPosts", sortable: false, formatter: renderBlogPost
}];
// DataTable definition
this.widgets.dataTable = new YAHOO.widget.DataTable(this.id + "-postlist", columnDefinitions, this.widgets.dataSource,
{
initialLoad: false,
dynamicData: true,
MSG_EMPTY: this._msg("message.loading")
});
// Update totalRecords on the fly with value from server
this.widgets.dataTable.handleDataReturnPayload = function DL_handleDataReturnPayload(oRequest, oResponse, oPayload)
{
// Save totalRecords for Paginator update later
me.recordOffset = oResponse.meta.recordOffset;
me.totalRecords = oResponse.meta.totalRecords;
me.totalRecordsUpper = oResponse.meta.totalRecordsUpper;
oPayload = oPayload || {};
oPayload.recordOffset = oResponse.meta.recordOffset;
oPayload.totalRecords = oResponse.meta.totalRecords;
return oPayload;
}
// Prevent the DataTable from updating the Paginator widget
this.widgets.dataTable.doBeforePaginatorChange = function DL_doBeforePaginatorChange(oPaginatorState)
{
return false;
}
// Rendering complete event handler
this.widgets.dataTable.subscribe("renderEvent", function()
{
// Update the paginator if it's been created
this.widgets.paginator.setState(
{
recordOffset: this.recordOffset,
totalRecords: this.totalRecords
});
if (this.totalRecordsUpper && this.totalRecordsUpper == true)
{
this.widgets.paginator.set("pageReportTemplate", this._msg("pagination.template.page-report.more"));
}
else
{
this.widgets.paginator.set("pageReportTemplate", this._msg("pagination.template.page-report"));
}
this.widgets.paginator.render();
}, this, true);
// Custom error messages
this._setDefaultDataTableErrors(this.widgets.dataTable);
// Hook tableMsgShowEvent to clear out fixed-pixel width on <table> element (breaks resizer)
this.widgets.dataTable.subscribe("tableMsgShowEvent", function(oArgs)
{
// NOTE: Scope needs to be DataTable
this._elMsgTbody.parentNode.style.width = "";
});
// Override abstract function within DataTable to set custom error message
this.widgets.dataTable.doBeforeLoadData = function BlogPostList_doBeforeLoadData(sRequest, oResponse, oPayload)
{
if (oResponse.error)
{
try
{
var response = YAHOO.lang.JSON.parse(oResponse.responseText);
this.set("MSG_ERROR", response.message);
}
catch(e)
{
me._setDefaultDataTableErrors(me.widgets.dataTable);
}
}
else if (oResponse.results && !me.options.usePagination)
{
this.renderLoopSize = Alfresco.util.RENDERLOOPSIZE;
}
// Must return true to have the "Loading..." message replaced by the error message
return true;
};
// Enable row highlighting
this.widgets.dataTable.subscribe("rowMouseoverEvent", this.onEventHighlightRow, this, true);
this.widgets.dataTable.subscribe("rowMouseoutEvent", this.onEventUnhighlightRow, this, true);
// Load the new blog posts by default
var filterObj = YAHOO.lang.merge(
{
filterId: "new",
filterOwner: "Alfresco.BlogPostListFilter",
filterData: null
}, this.options.initialFilter);
YAHOO.Bubbling.fire("changeFilter", filterObj);
},
// Actions
/**
* Action handler for the simple view toggle button
*
* @method onSimpleView
*/
onSimpleView: function BlogPostList_onSimpleView(e, p_obj)
{
this.options.simpleView = !this.options.simpleView;
p_obj.set("label", this._msg(this.options.simpleView ? "header.detailList" : "header.simpleList"));
// refresh the list
YAHOO.Bubbling.fire("blogpostlistRefresh");
Event.preventDefault(e);
},
/**
* Handler for the view blog post action links
*
* @method onViewBlogPost
* @param row {object} DataTable row representing post to be actioned
*/
onViewBlogPost: function BlogPostList_onViewNode(row)
{
var record = this.widgets.dataTable.getRecord(row);
window.location = this._generatePostViewUrl(record.getData('name'));
},
/**
* Handler for the edit blog post action links
*
* @method onEditBlogPost
* @param row {object} DataTable row representing post to be actioned
*/
onEditBlogPost: function BlogPostList_onEditBlogPost(row)
{
var record = this.widgets.dataTable.getRecord(row);
var url = YAHOO.lang.substitute(Alfresco.constants.URL_PAGECONTEXT + "site/{site}/blog-postedit?postId={postId}",
{
site: this.options.siteId,
postId: record.getData('name')
});
window.location = url;
},
/**
* Handler for the delete blog post action links
*
* @method onDeleteBlogPost
* @param row {object} DataTable row representing post to be actioned
*/
onDeleteBlogPost: function BlogPostList_onDeleteBlogPost(row)
{
var record = this.widgets.dataTable.getRecord(row);
var me = this;
Alfresco.util.PopupManager.displayPrompt(
{
title: this._msg("message.confirm.delete.title"),
text: this._msg("message.confirm.delete", $html(record.getData('title'))),
buttons: [
{
text: this._msg("button.delete"),
handler: function BlogPostList_onDeleteBlogPost_delete()
{
this.destroy();
me._deleteBlogPostConfirm.call(me, record.getData('name'));
}
},
{
text: this._msg("button.cancel"),
handler: function BlogPostList_onDeleteBlogPost_cancel()
{
this.destroy();
},
isDefault: true
}]
});
},
/**
* Handler for the publish external action links
*
* @method onPublishExternal
* @param row {object} DataTable row representing post to be actioned
*/
onPublishExternal: function BlogPostList_onPublishExternal(row)
{
var record = this.widgets.dataTable.getRecord(row);
this._publishExternal(record.getData('name'));
},
/**
* Handler for the update external action links
*
* @method onUpdateExternal
* @param row {object} DataTable row representing post to be actioned
*/
onUpdateExternal: function BlogPostList_onUpdateExternal(row)
{
var record = this.widgets.dataTable.getRecord(row);
this._updateExternal(record.getData('name'));
},
/**
* Handler for the unpublish external action links
*
* @method onUnpublishExternal
* @param row {object} DataTable row representing post to be actioned
*/
onUnpublishExternal: function BlogPostList_onUnpublishExternal(row)
{
var record = this.widgets.dataTable.getRecord(row);
this._unpublishExternal(record.getData('name'));
},
/**
* Tag selected handler
*
* @method onTagSelected
*/
onTagSelected: function BlogPostList_onTagSelected(layer, args)
{
var obj = args[1];
if (obj && (obj.tagName !== null))
{
var filterObj =
{
filterId: obj.tagName,
filterOwner: "Alfresco.BlogPostListTags",
filterData: null
};
YAHOO.Bubbling.fire("changeFilter", filterObj);
}
},
/**
* On blog config changed h handler
*
* @method onTagSelected
*/
onBlogConfigChanged: function BlogPostList_onBlogConfigChanged(layer, args)
{
// refresh the list
this._updateBlogPostList();
},
// Actions implementation
/**
* Blog post deletion implementation
*
* @method _deleteBlogPostConfirm
* @param postId {string} the id of the blog post to delete
*/
_deleteBlogPostConfirm: function BlogPostList__deleteBlogPostConfirm(postId)
{
// show busy message
if (! this._setBusy(this._msg('message.wait')))
{
return;
}
// ajax request success handler
var onDeletedSuccess = function BlogPostList_deleteBlogPostConfirm_onDeletedSuccess(response)
{
// remove busy message
this._releaseBusy();
// reload the table data
this._updateBlogPostList();
};
// get the url to call
var url = YAHOO.lang.substitute(Alfresco.constants.PROXY_URI + "api/blog/post/site/{site}/{container}/{postId}?page=blog-postlist",
{
site: this.options.siteId,
container: this.options.containerId,
postId: encodeURIComponent(postId)
});
// execute ajax request
Alfresco.util.Ajax.request(
{
url: url,
method: "DELETE",
responseContentType : "application/json",
successMessage: this._msg("message.delete.success"),
successCallback:
{
fn: onDeletedSuccess,
scope: this
},
failureMessage: this._msg("message.delete.failure"),
failureCallback:
{
fn: function(response)
{
this._releaseBusy();
},
scope: this
}
});
},
/**
* Publishing of a blog post implementation
*
* @method _publishExternal
* @param postId {string} the id of the blog post to publish
*/
_publishExternal: function BlogPostList__publishExternal(postId)
{
// show busy message
if (! this._setBusy(this._msg('message.wait')))
{
return;
}
// ajax call success handler
var onPublishedSuccess = function BlogPostList_onPublishedSuccess(response)
{
// remove busy message
this._releaseBusy();
// reload the table data
this._updateBlogPostList();
};
// get the url to call
var url = Alfresco.util.blog.generatePublishingRestURL(this.options.siteId, this.options.containerId, postId);
// execute ajax request
Alfresco.util.Ajax.request(
{
url: url,
method: "POST",
requestContentType : "application/json",
responseContentType : "application/json",
dataObj:
{
action : "publish"
},
successMessage: this._msg("message.publishExternal.success"),
successCallback:
{
fn: onPublishedSuccess,
scope: this
},
failureMessage: this._msg("message.publishExternal.failure"),
failureCallback:
{
fn: function(response) { this._releaseBusy(); },
scope: this
}
});
},
/**
* Updating of an external published blog post implementation
*
* @method _updateExternal
* @param postId {string} the id of the blog post to update
*/
_updateExternal: function BlogPostList__updateExternal(postId)
{
// show busy message
if (! this._setBusy(this._msg('message.wait')))
{
return;
}
// ajax request success handler
var onUpdatedSuccess = function BlogPostList_onUpdatedSuccess(response)
{
// remove busy message
this._releaseBusy();
// reload the table data
this._updateBlogPostList();
};
// get the url to call
var url = Alfresco.util.blog.generatePublishingRestURL(this.options.siteId, this.options.containerId, postId);
// execute ajax request
Alfresco.util.Ajax.request(
{
url: url,
method: "POST",
requestContentType : "application/json",
responseContentType : "application/json",
dataObj:
{
action : "update"
},
successMessage: this._msg("message.updateExternal.success"),
successCallback:
{
fn: onUpdatedSuccess,
scope: this
},
failureMessage: this._msg("message.updateExternal.failure"),
failureCallback:
{
fn: function(response) { this._releaseBusy(); },
scope: this
}
});
},
/**
* Unpublishing of an external published blog post implementation
*
* @method _unpublishExternal
* @param postId {string} the id of the blog post to update
*/
_unpublishExternal: function BlogPostList__onUnpublishExternal(postId)
{
// show busy message
if (! this._setBusy(this._msg('message.wait')))
{
return;
}
// ajax request success handler
var onUnpublishedSuccess = function BlogPostList_onUnpublishedSuccess(response)
{
// remove busy message
this._releaseBusy();
// reload the table data
this._updateBlogPostList();
};
// get the url to call
var url = Alfresco.util.blog.generatePublishingRestURL(this.options.siteId, this.options.containerId, postId);
// execute ajax request
Alfresco.util.Ajax.request(
{
url: url,
method: "POST",
requestContentType : "application/json",
responseContentType : "application/json",
dataObj:
{
action : "unpublish"
},
successMessage: this._msg("message.unpublishExternal.success"),
successCallback:
{
fn: onUnpublishedSuccess,
scope: this
},
failureMessage: this._msg("message.unpublishExternal.failure"),
failureCallback:
{
fn: function(response)
{
this._releaseBusy();
},
scope: this
}
});
},
// row highlighting
/**
* Custom event handler to highlight row.
*
* @method onEventHighlightRow
* @param oArgs.event {HTMLEvent} Event object.
* @param oArgs.target {HTMLElement} Target element.
*/
onEventHighlightRow: function BlogPostList_onEventHighlightRow(oArgs)
{
// only highlight if we got actions to show
var record = this.widgets.dataTable.getRecord(oArgs.target.id);
// This event triggers for empty lists too, so record may be null.
if (record)
{
var permissions = record.getData('permissions');
if (!(permissions.edit || permissions["delete"]))
{
return;
}
var elem = Dom.getElementsByClassName('post', null, oArgs.target, null);
Dom.addClass(elem, 'over');
}
},
/**
* Custom event handler to unhighlight row.
*
* @method onEventUnhighlightRow
* @param oArgs.event {HTMLEvent} Event object.
* @param oArgs.target {HTMLElement} Target element.
*/
onEventUnhighlightRow: function BlogPostList_onEventUnhighlightRow(oArgs)
{
var elem = Dom.getElementsByClassName('post', null, oArgs.target, null);
Dom.removeClass(elem, 'over');
},
/**
* BlogPostList Change filter event handler
*
* @method onChangeFilter
* @param layer {object} Event fired (unused)
* @param args {array} Event parameters (new filterId)
*/
onChangeFilter: function BlogPostList_onChangeFilter(layer, args)
{
var obj = args[1];
if ((obj !== null) && (obj.filterId !== null))
{
this.currentFilter =
{
filterId: obj.filterId,
filterOwner: obj.filterOwner,
filterData: obj.filterData