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

60 lines
1.7 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){
2017-03-21 18:16:32 +01:00
$scope.posturlOptions = [
{key:0, label: '/title'},
{key:1, label: '/year/month/title'}
];
2017-03-20 23:03:10 +01:00
$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;
2017-03-21 18:16:32 +01:00
for(var i in $scope.bloglist){
blog = $scope.bloglist[i];
if(blog.ID === Number($stateParams.blogid)) {
$http.get(config.api+'/web/website/'+$stateParams.websiteid+'/blog/'+$stateParams.blogid).then(setBlog);
2017-03-20 23:03:10 +01:00
return;
}
}
if($scope.bloglist.length > 0 && $stateParams.blogid !== '-1'){
2017-03-21 18:16:32 +01:00
$http.get(config.api+'/web/website/'+$stateParams.websiteid+'/blog/'+$scope.bloglist[0].ID).then(setBlog);
2017-03-20 23:03:10 +01:00
}
});
}
2017-03-21 18:16:32 +01:00
function setBlog(res) {
$scope.blog = res.data.data;
}
2017-03-20 23:03:10 +01:00
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);
};
});