feat(forums): edit/delete forum by oper/admin

This commit is contained in:
OldHawk
2017-07-04 13:04:38 +08:00
parent 061bc8a5f0
commit 2a1590b7f7
7 changed files with 92 additions and 26 deletions

View File

@@ -622,8 +622,14 @@
BTN_ADD_FORUM: 'Add New Forum',
BTN_EDIT_FORUM: 'Edit Forum',
BTN_ADD: '  Add   ',
BTN_EDIT: '  Edit   ',
BTN_DELETE: ' Delete  ',
ADD_SUCCESSFULLY: 'Forum added successfully',
ADD_FAILED: 'Forum added failed',
EDIT_SUCCESSFULLY: 'Forum edited successfully',
EDIT_FAILED: 'Forum edited failed',
DELETE_SUCCESSFULLY: 'Forum deleted successfully',
DELETE_FAILED: 'Forum deleted failed',
CATEGORY: {
AFFAIRS: 'Affairs',
DISCUSS: 'Discuss',
@@ -633,6 +639,7 @@
NAME: 'Forum Name',
ORDER: 'Forum Order',
CMD: 'Command',
MODERATORS: 'Moderators',
DESC: 'Description',
CATEGORY: 'Category',
READONLY: 'Only oper/admin can post new topic'

View File

@@ -621,9 +621,15 @@
FORUMS: {
BTN_ADD_FORUM: '添加版块',
BTN_EDIT_FORUM: '编辑版块',
BTN_ADD: '  添加   ',
BTN_ADD: '  添加  ',
BTN_EDIT: '  编辑  ',
BTN_DELETE: ' 删除  ',
ADD_SUCCESSFULLY: '版块添加成功',
ADD_FAILED: '版块添加失败',
EDIT_SUCCESSFULLY: '版块编辑成功',
EDIT_FAILED: '版块编辑失败',
DELETE_SUCCESSFULLY: '版块删除成功',
DELETE_FAILED: '版块删除失败',
CATEGORY: {
AFFAIRS: '站务区',
DISCUSS: '讨论区',
@@ -633,6 +639,7 @@
NAME: '版块名称',
ORDER: '版块序号',
CMD: '操作选项',
MODERATORS: '版主',
DESC: '描述',
CATEGORY: '分类',
READONLY: '只有管理员可以发起新话题'

View File

@@ -5,15 +5,15 @@
.module('forums')
.controller('ForumsController', ForumsController);
ForumsController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'MeanTorrentConfig', 'ForumsAdminService', 'SideOverlay', '$filter', 'NotifycationService'];
ForumsController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'MeanTorrentConfig', 'ForumsAdminService', 'SideOverlay', '$filter', 'NotifycationService',
'marked'];
function ForumsController($scope, $state, $translate, Authentication, MeanTorrentConfig, ForumsAdminService, SideOverlay, $filter, NotifycationService) {
function ForumsController($scope, $state, $translate, Authentication, MeanTorrentConfig, ForumsAdminService, SideOverlay, $filter, NotifycationService,
marked) {
var vm = this;
vm.forumsConfig = MeanTorrentConfig.meanTorrentConfig.forumsConfig;
vm.user = Authentication.user;
vm.forum = {};
/**
* init
*/
@@ -25,24 +25,35 @@
};
/**
* openSideOverlay
* popupCreateForum
* @param evt
*/
vm.openSideOverlay = function (evt, f) {
if (f) {
vm.forum = f;
} else {
vm.forum = {
name: '',
desc: '',
category: 'discuss',
order: 0,
readOnly: false
};
}
vm.popupCreateForum = function (evt) {
vm.forum = {
name: '',
desc: '',
category: 'discuss',
order: 0,
readOnly: false
};
vm.actionTitle = 'FORUMS.BTN_ADD_FORUM';
vm.isEdit = false;
vm.categoryChanged();
SideOverlay.open(evt, 'popupSlide');
};
/**
* popupEditForum
* @param evt
*/
vm.popupEditForum = function (evt, f) {
if (f) {
vm.forum = f;
vm.actionTitle = 'FORUMS.BTN_EDIT_FORUM';
vm.isEdit = true;
SideOverlay.open(evt, 'popupSlide');
}
};
/**
*
@@ -62,14 +73,42 @@
var f = new ForumsAdminService(vm.forum);
f.$save(function (res) {
NotifycationService.showSuccessNotify('FORUMS.ADD_SUCCESSFULLY');
vm.forum = {};
vm.forum = undefined;
SideOverlay.close(null, 'popupSlide');
$state.reload();
vm.init();
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.ADD_FAILED');
});
};
/**
* editForum
*/
vm.editForum = function () {
vm.forum.$update(function (res) {
NotifycationService.showSuccessNotify('FORUMS.EDIT_SUCCESSFULLY');
vm.forum = undefined;
SideOverlay.close(null, 'popupSlide');
vm.init();
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.EDIT_FAILED');
});
};
/**
* deleteForum
*/
vm.deleteForum = function () {
vm.forum.$remove(function (res) {
NotifycationService.showSuccessNotify('FORUMS.DELETE_SUCCESSFULLY');
vm.forum = undefined;
SideOverlay.close(null, 'popupSlide');
vm.init();
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.DELETE_FAILED');
});
};
/**
* getForumDesc
* @param f

View File

@@ -27,5 +27,6 @@
.forum-list {
.forum-desc {
word-break: break-all;
color: #999;
}
}

View File

@@ -9,7 +9,7 @@
function ForumsAdminService($resource) {
return $resource('/api/admin/forums/:forumId', {
forumId: '@_Id'
forumId: '@_id'
}, {
update: {
method: 'PUT'
@@ -25,7 +25,7 @@
function ForumsService($resource) {
return $resource('/api/forums/:forumId', {
forumId: '@_Id'
forumId: '@_id'
}, {
update: {
method: 'PUT'

View File

@@ -1,7 +1,7 @@
<section class="container padding-top-10" ng-controller="ForumsController as vm" ng-init="vm.init();">
<div class="row margin-top-20 forum-list">
<div class="col-md-10 col-md-offset-1">
<button class="btn btn-success" ng-click="vm.openSideOverlay($event)">  {{ 'FORUMS.BTN_ADD_FORUM' | translate }}  </button>
<button class="btn btn-success" ng-click="vm.popupCreateForum($event)">  {{ 'FORUMS.BTN_ADD_FORUM' | translate }}  </button>
</div>
<div class="col-sm-10 col-sm-offset-1">
@@ -16,13 +16,13 @@
<tr>
<th class="col-md-7">{{'FORUMS.FIELDS.NAME' | translate}}</th>
<th class="text-center">{{'FORUMS.FIELDS.ORDER' | translate}}</th>
<th class="text-center">{{'FORUMS.FIELDS.CMD' | translate}}</th>
<th class="text-center">{{'FORUMS.FIELDS.MODERATORS' | translate}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="f in vm.forums | filter: { category: cat.value }">
<td scope="row">
<h4>{{f.name}} <span class="badge badge_mt" ng-show="f.readOnly">R</span></h4>
<h4>{{f.name}} <span class="badge badge_mt" ng-show="f.readOnly">R</span><small>[<a href="#" ng-click="vm.popupEditForum($event, f);">Edit</a>]</small></h4>
<p class="forum-desc" ng-bind-html="vm.getForumDesc(f);"></p>
</td>
@@ -38,7 +38,7 @@
<div id="popupSlide" side-overlay="right" side-class="forum-side-overlay" side-modal side-close-on-esc side-close-on-outside-click>
<div class="forum-popup">
<h3 class="margin-left-30">{{'FORUMS.BTN_ADD_FORUM' | translate}}</h3>
<h3 class="margin-left-30">{{vm.actionTitle | translate}}</h3>
<li class="status-divider"></li>
<form class="form-horizontal margin-top-50">
<div class="form-group">
@@ -88,8 +88,19 @@
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" class="btn btn-success"
ng-click="vm.createNewForum();"
ng-hide="vm.isEdit"
ng-disabled="!vm.forum.name || !vm.forum.desc ">{{'FORUMS.BTN_ADD' | translate}}
</button>
<button type="submit" class="btn btn-success"
ng-click="vm.editForum();"
ng-show="vm.isEdit"
ng-disabled="!vm.forum.name || !vm.forum.desc ">{{'FORUMS.BTN_EDIT' | translate}}
</button>
<button type="submit" class="btn btn-success"
ng-click="vm.deleteForum();"
ng-show="vm.isEdit"
ng-disabled="!vm.forum.name || !vm.forum.desc ">{{'FORUMS.BTN_DELETE' | translate}}
</button>
</div>
</div>
</form>

View File

@@ -61,6 +61,7 @@ exports.update = function (req, res) {
forum.desc = req.body.desc;
forum.order = req.body.order;
forum.readOnly = req.body.readOnly;
forum.category = req.body.category;
forum.save(function (err) {
if (err) {