mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-16 20:32:21 +01:00
This feature introduces a breaking change, that restricts the User's that can create/edit/delete Articles to only those that have the `admin` Role. Fixed ESLint issues. Resolved merge conflicts, and moved new client Article Service `createOrUpdate` functionality to new Admin feature controller. Removed edit functionality from client-side Article controller.
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('articles.admin')
|
|
.controller('ArticlesController', ArticlesController);
|
|
|
|
ArticlesController.$inject = ['$scope', '$state', '$window', 'articleResolve', 'Authentication'];
|
|
|
|
function ArticlesController($scope, $state, $window, article, Authentication) {
|
|
var vm = this;
|
|
|
|
vm.article = article;
|
|
vm.authentication = Authentication;
|
|
vm.error = null;
|
|
vm.form = {};
|
|
vm.remove = remove;
|
|
vm.save = save;
|
|
|
|
// Remove existing Article
|
|
function remove() {
|
|
if ($window.confirm('Are you sure you want to delete?')) {
|
|
vm.article.$remove($state.go('admin.articles.list'));
|
|
}
|
|
}
|
|
|
|
// Save Article
|
|
function save(isValid) {
|
|
if (!isValid) {
|
|
$scope.$broadcast('show-errors-check-validity', 'vm.form.articleForm');
|
|
return false;
|
|
}
|
|
|
|
// Create a new article, or update the current instance
|
|
vm.article.createOrUpdate()
|
|
.then(successCallback)
|
|
.catch(errorCallback);
|
|
|
|
function successCallback(res) {
|
|
$state.go('admin.articles.list'); // should we send the User to the list or the updated Article's view?
|
|
}
|
|
|
|
function errorCallback(res) {
|
|
vm.error = res.data.message;
|
|
}
|
|
}
|
|
}
|
|
}());
|