Files
meanTorrent/modules/articles/client/controllers/admin/article.client.controller.js
Michael Leanos 89075cb8d3 feat(articles): Article Admin feature (#807)
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.
2016-07-25 17:34:06 -07:00

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;
}
}
}
}());