sum7/warehost-frontend
sum7
/
warehost-frontend
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost-frontend/public/app/web/blogpost.js

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);
};
});