46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
angular.module('warehost')
|
|
.controller('BlogPostWebCtrl',function(session,config,alert,NgTableParams,$scope,$rootScope,$http,$stateParams){
|
|
alert.set({});
|
|
$scope.post = {};
|
|
$scope.websiteid = $stateParams.websiteid;
|
|
|
|
function reset(){
|
|
$scope.post = {};
|
|
}
|
|
function load(){
|
|
$http.get(config.api+'/web/website/'+$stateParams.websiteid+'/blog/'+$scope.blog.ID).then(function(res){
|
|
session.set(res);
|
|
reset();
|
|
$scope.blog = res.data.data;
|
|
});
|
|
}
|
|
function submitresult(res){
|
|
session.set(res);
|
|
alert.set(res);
|
|
if(res.data.data){
|
|
load();
|
|
}
|
|
}
|
|
reset();
|
|
$rootScope.$on('warehost.session',load);
|
|
|
|
$scope.edit = function(a){
|
|
$scope.post = a;
|
|
};
|
|
$scope.add = function(){
|
|
$scope.post = {};
|
|
};
|
|
$scope.save = function(){
|
|
if($scope.post.ID){
|
|
$http.patch(config.api+'/web/website/'+$stateParams.websiteid+'/blog/'+$scope.blog.ID+'/post/'+$scope.post.ID, $scope.post).then(submitresult);
|
|
}else{
|
|
$http.post(config.api+'/web/website/'+$stateParams.websiteid+'/blog/'+$scope.blog.ID+'/post', $scope.post).then(submitresult);
|
|
}
|
|
};
|
|
$scope.delete = function(a){
|
|
$http.delete(config.api+'/web/website/'+$stateParams.websiteid+'/blog/'+$scope.blog.ID+'/post/'+a.ID).then(submitresult);
|
|
};
|
|
});
|