Files
meanTorrent/modules/forums/client/controllers/admin/forums-admin.client.controller.js

200 lines
5.7 KiB
JavaScript
Raw Permalink Normal View History

2017-07-05 17:01:59 +08:00
(function () {
'use strict';
angular
.module('forums')
.controller('ForumsAdminController', ForumsAdminController);
ForumsAdminController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'MeanTorrentConfig', 'ForumsAdminService', 'SideOverlay', '$filter', 'NotifycationService',
'marked', 'ModalConfirmService', 'DebugConsoleService'];
2017-07-05 17:01:59 +08:00
function ForumsAdminController($scope, $state, $translate, Authentication, MeanTorrentConfig, ForumsAdminService, SideOverlay, $filter, NotifycationService,
marked, ModalConfirmService, mtDebug) {
2017-07-05 17:01:59 +08:00
var vm = this;
vm.forumsConfig = MeanTorrentConfig.meanTorrentConfig.forumsConfig;
vm.user = Authentication.user;
vm.addModeratorPopover = {
title: 'FORUMS.MODERATOR_TITLE',
templateUrl: 'add-moderator.html',
items: []
};
/**
* init
*/
vm.init = function () {
ForumsAdminService.query({}, function (items) {
vm.forums = items;
mtDebug.info(items);
2017-07-05 17:01:59 +08:00
angular.forEach(vm.forums, function (f) {
vm.addModeratorPopover.items.push(f._id, false);
});
});
};
/**
* popupCreateForum
* @param evt
*/
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
* @param f: forum
*/
vm.popupEditForum = function (evt, f) {
if (f) {
vm.forum = new ForumsAdminService(f);
vm.actionTitle = 'FORUMS.BTN_EDIT_FORUM';
vm.isEdit = true;
SideOverlay.open(evt, 'popupSlide');
}
};
/**
*
*/
vm.categoryChanged = function () {
vm.selectedForums = $filter('filter')(vm.forums, {
category: vm.forum.category
});
vm.forum.order = vm.selectedForums.length;
};
/**
* createNewForum
*/
vm.createNewForum = function () {
var f = new ForumsAdminService(vm.forum);
f.$save(function (res) {
NotifycationService.showSuccessNotify('FORUMS.ADD_SUCCESSFULLY');
vm.forum = undefined;
SideOverlay.close(null, 'popupSlide');
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 () {
var modalOptions = {
closeButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_CANCEL'),
actionButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_OK'),
headerText: $translate.instant('FORUMS.DELETE_CONFIRM_HEADER_TEXT'),
bodyText: $translate.instant('FORUMS.DELETE_CONFIRM_BODY_TEXT')
};
ModalConfirmService.showModal({}, modalOptions)
.then(function (result) {
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: forum
* @returns {*}
*/
vm.getForumDesc = function (f) {
if (f) {
return marked(f.desc, {sanitize: true});
}
};
/**
* addModerator
*/
vm.addModerator = function () {
ForumsAdminService.addModerator({
_id: vm.forum._id,
_username: vm.addModeratorPopover.username
}, function (res) {
NotifycationService.showSuccessNotify('FORUMS.ADD_MODERATOR_SUCCESSFULLY');
vm.addModeratorPopover.items[vm.forum._id] = false;
vm.init();
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.ADD_MODERATOR_FAILED');
vm.addModeratorPopover.items[vm.forum._id] = false;
});
};
/**
* addModeratorClicked
* @param f: forum
*/
vm.addModeratorClicked = function (f) {
vm.addModeratorPopover.username = undefined;
vm.addModeratorPopover.items[f._id] = true;
vm.forum = f;
};
/**
* removeModeratorClicked
* @param f forum
* @param m moderator
*/
vm.removeModeratorClicked = function (f, m) {
var modalOptions = {
closeButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_CANCEL'),
actionButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_OK'),
headerText: $translate.instant('FORUMS.DELETE_CONFIRM_HEADER_TEXT'),
bodyText: $translate.instant('FORUMS.REMOVE_CONFIRM_BODY_TEXT')
};
ModalConfirmService.showModal({}, modalOptions)
.then(function (result) {
ForumsAdminService.removeModerator({
_id: f._id,
_username: m.username
}, function (res) {
NotifycationService.showSuccessNotify('FORUMS.REMOVE_MODERATOR_SUCCESSFULLY');
vm.init();
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.REMOVE_MODERATOR_FAILED');
});
});
};
}
}());