mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-16 12:22:26 +01:00
Update the articles module to implement the style guidelines. Much of this work is from @trainerbill Closes #874 Closes #339
53 lines
1.2 KiB
JavaScript
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;
|
|
}
|
|
}
|
|
}
|
|
})();
|