Files
meanTorrent/modules/articles/client/controllers/admin/article.client.controller.js
Michael Leanos c96f8c0b56 fix(articles): Article controllers name conflicts (#1428)
* fix(articles): Article controllers name conflicts

Fixes the naming conflicts for the Articles controllers.

Due to how Angular injects the controllers into the StateProvider,
naming conflicts were caused between the Articles public & admin module
controllers.

To resolve the issue the referenced controllers in the Articles admin
route configurations must be unique, and match up with the Admin
controllers.

* Client-side tests failing

Fixed the client-side tests that were failing due to the naming
conflicts.
2016-08-26 13:27:43 +03:00

49 lines
1.3 KiB
JavaScript

(function () {
'use strict';
angular
.module('articles.admin')
.controller('ArticlesAdminController', ArticlesAdminController);
ArticlesAdminController.$inject = ['$scope', '$state', '$window', 'articleResolve', 'Authentication'];
function ArticlesAdminController($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;
}
}
}
}());