').addClass('comment-bannotice');
+ noticeContainer.html(config.CantPostNotice);
+ return noticeContainer;
+}());
reloadComments();
\ No newline at end of file
diff --git a/js/manage.js b/js/manage.js
index 28d4f83..8e802d3 100755
--- a/js/manage.js
+++ b/js/manage.js
@@ -1,113 +1,43 @@
-var template = '';
-var config = mw.config.get('wgFlowThreadConfig');
-
-function getAvatar(id, username) {
- if(!config) return '';
- if(id===0) {
- return config.AnonymousAvatar;
- }else{
- return config.Avatar.replace(/\$\{username\}/g, username);
- }
-}
+function createThread(post) {
+ var thread = new Thread();
+ var object = thread.object;
-function getTimeString(time) {
- var m = moment(time).locale(mw.config.get('wgUserLanguage'));
- var diff = Date.now() - time;
- if(0 < diff && diff < 24*3600*1000) {
- return m.fromNow();
- }else{
- return m.format('LL, HH:mm:ss');
- }
-}
+ thread.init(post);
-function wrapText(text) {
- var span = $('
');
- span.text(text);
- return span.wrapAll('
').parent().html();
-}
-
-function wrapPageLink(page, name) {
- var link = $('
');
- link.attr('href', mw.util.getUrl(page));
- link.text(name);
- return link.wrapAll('
').parent().html();
-}
+ // Enhance the username by adding page title
+ var pageLink = wrapPageLink(post.title, post.title);
+ object.find('.comment-user').html(
+ mw.msg('flowthread-ui-user-post-on-page', object.find('.comment-user').html(), pageLink));
-function Thread(post) {
- var self = this;
- var object = $(template);
+ thread.addButton('like', mw.msg('flowthread-ui-like') + '(' + post.like + ')', function() {
+ });
- this.post = post;
- this.object = object;
- $.data(object[0], 'thread', this);
+ thread.addButton('report', mw.msg('flowthread-ui-report') + '(' + post.report + ')', function() {
+ });
- var userlink;
- if (post.userid !== 0) {
- userlink = wrapPageLink('User:' + post.username, post.username);
- } else {
- userlink = wrapText(post.username);
+ if(!deleted){
+ thread.addButton('delete', mw.msg('flowthread-ui-delete'), function() {
+ thread.delete();
+ });
+ }else{
+ thread.addButton('recover', mw.msg('flowthread-ui-recover'), function() {
+ thread.recover();
+ });
+ thread.addButton('delete', mw.msg('flowthread-ui-erase'), function() {
+ thread.erase();
+ });
}
- var pageLink = wrapPageLink(post.title, post.title);
- object.find('.comment-user').html(mw.msg('flowthread-ui-user-post-on-page', userlink, pageLink));
-
- object.find('.comment-avatar img').attr('src', getAvatar(post.userid, post.username));
-
- object.find('.comment-text').html(post.text);
- object.find('.comment-time').text(getTimeString(post.timestamp*1000));
-
- object.find('.comment-delete').click(function() {
- self.delete(post.id);
- });
- object.find('.comment-recover').click(function() {
- self.recover(post.id);
- });
- object.find('.comment-delete').click(function() {
- self.erase(post.id);
- });
object.find('.comment-avatar').click(function() {
object.toggleClass('comment-selected');
onSelect();
- })
+ });
- object.find('.comment-like span').text('(' + post.like + ')');
- object.find('.comment-report span').text('(' + post.report + ')');
-
+ return thread;
}
-Thread.prototype.delete = function() {
- var api = new mw.Api();
- api.get({
- action: 'flowthread',
- type: 'delete',
- postid: this.post.id
- });
- this.object.remove();
-};
-
Thread.prototype.recover = function() {
var api = new mw.Api();
api.get({
@@ -174,7 +104,7 @@ function loadComments() {
var data = mw.config.get('commentjson');
$('.comment-container').html('');
data.forEach(function(item) {
- $('.comment-container').append(new Thread(item).object);
+ $('.comment-container').append(createThread(item).object);
});
}