diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 0ec07fbb..561addb0 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -634,6 +634,8 @@ BTN_SUBMIT_REPLY: 'Submit New Reply', BTN_POST_NEW_TOPIC: 'Post New Topic', BTN_POST_NEW_REPLY: 'Post New Reply', + BTN_SET_READONLY: 'Set Readonly', + BTN_UNSET_READONLY: 'Unset Readonly', ADD_SUCCESSFULLY: 'Forum added successfully', ADD_FAILED: 'Forum added failed', EDIT_SUCCESSFULLY: 'Forum edited successfully', @@ -659,6 +661,8 @@ POST_REPLY_FAILED: 'Post new reply failed', TOPIC_EDIT_SUCCESSFULLY: 'Reply content modify successfully', TOPIC_EDIT_FAILED: 'Reply content modify failed', + TOPIC_TOGGLE_READONLY_SUCCESSFULLY: 'Toggle set topic readonly successfully', + TOPIC_TOGGLE_READONLY_FAILED: 'Toggle set topic readonly failed', REPLY_EDIT_SUCCESSFULLY: 'Reply content modify successfully', REPLY_EDIT_FAILED: 'Reply content modify failed', DELETE_TOPIC_SUCCESSFULLY: 'Topic deleted successfully', diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index 8122190a..3eba3190 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -634,6 +634,8 @@ BTN_SUBMIT_REPLY: '提交回复', BTN_POST_NEW_TOPIC: '发起新话题 ', BTN_POST_NEW_REPLY: '回复', + BTN_SET_READONLY: '设为只读', + BTN_UNSET_READONLY: '取消只读', ADD_SUCCESSFULLY: '版块添加成功', ADD_FAILED: '版块添加失败', EDIT_SUCCESSFULLY: '版块编辑成功', @@ -659,6 +661,8 @@ POST_REPLY_FAILED: '回复内容提交失败', TOPIC_EDIT_SUCCESSFULLY: '话题内容编辑成功', TOPIC_EDIT_FAILED: '话题内容编辑失败', + TOPIC_TOGGLE_READONLY_SUCCESSFULLY: '只读状态切换成功', + TOPIC_TOGGLE_READONLY_FAILED: '只读状态切换失败', REPLY_EDIT_SUCCESSFULLY: '回复内容修改成功', REPLY_EDIT_FAILED: '回复内容修改失败', DELETE_TOPIC_SUCCESSFULLY: '话题删除成功', diff --git a/modules/forums/client/controllers/forums-topic.client.controller.js b/modules/forums/client/controllers/forums-topic.client.controller.js index 8b811daf..6baea8da 100644 --- a/modules/forums/client/controllers/forums-topic.client.controller.js +++ b/modules/forums/client/controllers/forums-topic.client.controller.js @@ -301,6 +301,27 @@ }, 500); }; + /** + * toggleReadonly + * @param t + */ + vm.toggleReadonly = function (t) { + var topic = new TopicsService({ + forum: vm.forum._id, + _id: t._id + }); + + console.log(topic); + + topic.$toggleTopicReadonly(function (res) { + vm.topic = res; + NotifycationService.showSuccessNotify('FORUMS.TOPIC_TOGGLE_READONLY_SUCCESSFULLY'); + }, function (res) { + NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_TOGGLE_READONLY_FAILED'); + }); + + }; + /** * postReply * @param isValid diff --git a/modules/forums/client/services/topics.client.service.js b/modules/forums/client/services/topics.client.service.js index 3fa59ce9..c0df83c2 100644 --- a/modules/forums/client/services/topics.client.service.js +++ b/modules/forums/client/services/topics.client.service.js @@ -14,6 +14,14 @@ }, { update: { method: 'PUT' + }, + toggleTopicReadonly: { + method: 'PUT', + url: '/api/topics/:forumId/:topicId/toggleTopicReadonly', + params: { + forumId: '@forum', + topicId: '@_id' + } } }); } diff --git a/modules/forums/client/views/topic.client.view.html b/modules/forums/client/views/topic.client.view.html index c49c93e8..da1478c0 100644 --- a/modules/forums/client/views/topic.client.view.html +++ b/modules/forums/client/views/topic.client.view.html @@ -50,11 +50,15 @@
- {{'FORUMS.BTN_POST_NEW_TOPIC' | translate}} +
+ {{'FORUMS.BTN_POST_NEW_TOPIC' | translate}} + {{ vm.topic.readOnly ? 'FORUMS.BTN_UNSET_READONLY' : 'FORUMS.BTN_SET_READONLY' | translate}} +
-
+
diff --git a/modules/forums/server/controllers/forums.server.controller.js b/modules/forums/server/controllers/forums.server.controller.js index 6f87efd5..d6d1e706 100644 --- a/modules/forums/server/controllers/forums.server.controller.js +++ b/modules/forums/server/controllers/forums.server.controller.js @@ -140,6 +140,27 @@ exports.updateTopic = function (req, res) { }); }; +/** + * toggleTopicReadonly + * @param req + * @param res + */ +exports.toggleTopicReadonly = function (req, res) { + var topic = req.topic; + + topic.readOnly = !topic.readOnly; + + topic.save(function (err) { + if (err) { + return res.status(422).send({ + message: errorHandler.getErrorMessage(err) + }); + } else { + res.json(topic); + } + }); +}; + /** * deleteTopic * @param req diff --git a/modules/forums/server/policies/forums.server.policy.js b/modules/forums/server/policies/forums.server.policy.js index 82eda3fb..97e8ea5d 100644 --- a/modules/forums/server/policies/forums.server.policy.js +++ b/modules/forums/server/policies/forums.server.policy.js @@ -21,7 +21,8 @@ exports.invokeRolesPolicies = function () { {resources: '/api/forums/:forumId', permissions: '*'}, {resources: '/api/topics/:forumId', permissions: '*'}, {resources: '/api/topics/:forumId/:topicId', permissions: '*'}, - {resources: '/api/topics/:forumId/:topicId/:replyId', permissions: '*'} + {resources: '/api/topics/:forumId/:topicId/:replyId', permissions: '*'}, + {resources: '/api/topics/:forumId/:topicId/toggleTopicReadonly', permissions: '*'} ] }, { diff --git a/modules/forums/server/routes/forums.server.routes.js b/modules/forums/server/routes/forums.server.routes.js index f4284467..6b8c6489 100644 --- a/modules/forums/server/routes/forums.server.routes.js +++ b/modules/forums/server/routes/forums.server.routes.js @@ -23,6 +23,9 @@ module.exports = function (app) { .delete(forums.deleteTopic) .post(forums.postNewReply); + app.route('/api/topics/:forumId/:topicId/toggleTopicReadonly').all(forumsPolicy.isAllowed) + .put(forums.toggleTopicReadonly); + app.route('/api/topics/:forumId/:topicId/:replyId').all(forumsPolicy.isAllowed) .put(forums.updateReply) .delete(forums.deleteReply);