Files
meanTorrent/modules/articles/client/controllers/admin/article.client.controller.js
Mikael Korpela f44c9bce71 fix(eslint): Inconsistent spacing before function parentheses (#1844)
Defines `space-before-function-paren` eslint rule and changes files accordingly.
2017-08-14 23:50:33 +03:00

52 lines
1.6 KiB
JavaScript

(function () {
'use strict';
angular
.module('articles.admin')
.controller('ArticlesAdminController', ArticlesAdminController);
ArticlesAdminController.$inject = ['$scope', '$state', '$window', 'articleResolve', 'Authentication', 'Notification'];
function ArticlesAdminController($scope, $state, $window, article, Authentication, Notification) {
var vm = this;
vm.article = article;
vm.authentication = Authentication;
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(function () {
$state.go('admin.articles.list');
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Article deleted successfully!' });
});
}
}
// 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?
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
}
function errorCallback(res) {
Notification.error({ message: res.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Article save error!' });
}
}
}
}());