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/blog.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-03-20 23:03:10 +01:00
'use strict';
angular.module('warehost')
.controller('BlogWebCtrl',function(session,config,alert,NgTableParams,$scope,$rootScope,$http,$stateParams){
$scope.bloglist = [];
alert.set({});
$scope.blog = {};
$scope.websiteid = $stateParams.websiteid;
function resetBlog(){
$scope.blog = {};
}
function load(){
$http.get(config.api+'/web/website/'+$stateParams.websiteid+'/blog').then(function(res){
session.set(res);
resetBlog();
$scope.bloglist = res.data.data;
var blog;
for(blog in $scope.bloglist){
if(blog.ID === $stateParams.blogid) {
$scope.blog = blog;
return;
}
}
if($scope.bloglist.length > 0 && $stateParams.blogid !== '-1'){
$scope.blog = $scope.bloglist[0];
}
});
}
function submitresult(res){
session.set(res);
alert.set(res);
if(res.data.data){
load();
}
}
resetBlog();
load();
$rootScope.$on('warehost.session',load);
$scope.save = function(){
if($scope.blog.ID){
$http.patch(config.api+'/web/website/'+$stateParams.websiteid+'/blog/'+$scope.blog.ID,$scope.blog).then(submitresult);
}else{
$http.post(config.api+'/web/website/'+$stateParams.websiteid+'/blog',$scope.blog).then(submitresult);
}
};
$scope.delete = function(a){
$http.delete(config.api+'/web/website/'+$stateParams.websiteid+'/blog/'+a.ID).then(submitresult);
};
});