-
Notifications
You must be signed in to change notification settings - Fork 10
/
topicsPage.js
125 lines (113 loc) · 3.5 KB
/
topicsPage.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
Session.setDefault('forum_topic_id', false);
//-------------------------------------------------------------
// TopicsPage
Template.topicsPage.getPreferredProfileTheme = function(){
return getPreferredTheme();
};
Template.topicsPage.getPreferredButtonTheme = function(){
return getPreferredButtonTheme();
};
Template.topicsPage.showSearchPanel = function(){
if(Session.get('show_search_panel')){
return true;
}else{
false;
}
};
Template.topicsPage.topics = function(){
return Topics.find();
};
Session.setDefault('is_add_topic_visible', false);
Template.topicsPage.events({
'click #createTopicButton, tap #createTopicButton': function(){
if(Session.get('is_creating_new_topic')){
Session.set('is_creating_new_topic', false);
}else{
Session.set('is_creating_new_topic', true);
}
},
'click .delete-topic-btn, tap .delete-topic-btn': function(){
},
'click #newTopicSave, tap #newtopicSave':function(){
Topics.insert({topic: $('#newTopicInput').val(), createdBy: Meteor.user().profile.name, createdAt: new Date(), creatorId: Meteor.userId() })
Session.set('is_creating_new_topic', false);
},
'click #newTopicCancel, tap #newTopicCancel':function(){
Session.set('is_creating_new_topic', false);
}
});
Template.topicsPage.events({
'click .media, tap .media':function(){
if(Session.get('forum_admin_buttons') === false){
Session.set('forum_topic_id', this._id);
Session.set('forum_topic', this.topic);
Meteor.users.update(Meteor.userId(), {$set: {'profile.currentTopic': this._id }});
Topics.update(this._id, {$inc: { views: 1 }, $set: { lastPostId: Meteor.userId(), lastPostBy: Meteor.user().profile.name }});
Router.go('/forum/' + this._id);
}
},
'click #toggleForumAdminButton, tap #toggleForumAdminButton': function(){
if(Session.get('forum_admin_buttons')){
Session.set('forum_admin_buttons', false);
}else{
Session.set('forum_admin_buttons', true);
}
}
});
Session.setDefault('is_creating_new_topic', false);
Template.topicsPage.creatingNewTopic = function(){
return Session.get('is_creating_new_topic');
};
Template.topicsPage.getLockIcon = function(){
if(Session.get('forum_admin_buttons')){
return 'fa-unlock';
}else{
return 'fa-lock';
}
};
//-------------------------------------------------------------
// TopicItem
Template.topicItem.getTopicOwner = function(){
return this.createdBy;
};
Template.topicItem.getTopicDate = function(){
return this.createdAt;
};
Template.topicItem.getNumberReplies = function(){
return this.replies;
};
Template.topicItem.getNumberViews = function(){
return this.views;
};
Template.topicItem.getLastUpdatedBy = function(){
return this.lastPostBy;
};
Template.topicItem.getLastUpdate = function(){
return moment(this.lastPostAt).format('YYYY-MM-DD');
};
Template.topicItem.showForumAdminButtons = function(){
return Session.get('forum_admin_buttons');
};
Template.topicItem.getLockButtonText = function(){
if(this.locked){
return "Unlock";
}else{
return "Lock";
}
};
Template.topicItem.events({
'click #promoteTopicButton, tap #promoteTopicButton':function(event){
event.preventDefault();
alert('promote');
},
'click #lockTopicButton, tap #lockTopicButton':function(event){
if(this.locked){
Topics.update(this._id, {$set: {locked: false }});
}else{
Topics.update(this._id, {$set: {locked: true }});
}
},
'click #deleteTopicButton, tap #deleteTopicButton':function(event){
Topics.remove(this._id);
}
});