2017-08-14 23:50:33 +03:00
|
|
|
(function () {
|
2016-07-25 17:34:06 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular
|
|
|
|
|
.module('articles.admin')
|
2016-08-26 03:27:43 -07:00
|
|
|
.controller('ArticlesAdminController', ArticlesAdminController);
|
2016-07-25 17:34:06 -07:00
|
|
|
|
2016-10-10 17:51:44 -04:00
|
|
|
ArticlesAdminController.$inject = ['$scope', '$state', '$window', 'articleResolve', 'Authentication', 'Notification'];
|
2016-07-25 17:34:06 -07:00
|
|
|
|
2016-10-10 17:51:44 -04:00
|
|
|
function ArticlesAdminController($scope, $state, $window, article, Authentication, Notification) {
|
2016-07-25 17:34:06 -07:00
|
|
|
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?')) {
|
2017-08-14 23:50:33 +03:00
|
|
|
vm.article.$remove(function () {
|
2016-09-30 17:55:10 -04:00
|
|
|
$state.go('admin.articles.list');
|
2016-10-10 17:51:44 -04:00
|
|
|
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Article deleted successfully!' });
|
2016-09-30 17:55:10 -04:00
|
|
|
});
|
2016-07-25 17:34:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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?
|
2016-10-10 17:51:44 -04:00
|
|
|
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
|
2016-07-25 17:34:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function errorCallback(res) {
|
2016-10-10 17:51:44 -04:00
|
|
|
Notification.error({ message: res.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Article save error!' });
|
2016-07-25 17:34:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}());
|