mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-13 02:42:23 +01:00
52 lines
1.6 KiB
JavaScript
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!' });
|
|
}
|
|
}
|
|
}
|
|
}());
|