Files
meanTorrent/modules/articles/client/controllers/articles.client.controller.js
Ryan Hutchison b3ad56efa3 feat(articles): Modify articles module to implement style guidelines.
Update the articles module to implement the style guidelines.

Much of this work is from @trainerbill

Closes #874
Closes #339
2016-01-02 01:53:59 -05:00

53 lines
1.2 KiB
JavaScript

(function () {
'use strict';
angular
.module('articles')
.controller('ArticlesController', ArticlesController);
ArticlesController.$inject = ['$scope', '$state', 'articleResolve', 'Authentication'];
function ArticlesController($scope, $state, 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 (confirm('Are you sure you want to delete?')) {
vm.article.$remove($state.go('articles.list'));
}
}
// Save Article
function save(isValid) {
if (!isValid) {
$scope.$broadcast('show-errors-check-validity', 'vm.form.articleForm');
return false;
}
// TODO: move create/update logic to service
if (vm.article._id) {
vm.article.$update(successCallback, errorCallback);
} else {
vm.article.$save(successCallback, errorCallback);
}
function successCallback(res) {
$state.go('articles.view', {
articleId: res._id
});
}
function errorCallback(res) {
vm.error = res.data.message;
}
}
}
})();