2016-09-11 18:40:03 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('warehost')
|
|
|
|
.controller('PageWebCtrl',function(session,config,alert,NgTableParams,$scope,$rootScope,$http,$stateParams){
|
2016-09-27 11:44:48 +02:00
|
|
|
$scope.data = [];
|
2016-09-11 18:40:03 +02:00
|
|
|
alert.set({});
|
|
|
|
$scope.obj = {};
|
|
|
|
|
|
|
|
function resetObj(){
|
|
|
|
$scope.obj = {};
|
|
|
|
}
|
|
|
|
function load(){
|
2017-02-26 15:48:12 +01:00
|
|
|
$http.get(config.api+'/web/website/'+$stateParams.websiteid+'/page').then(function(res){
|
|
|
|
session.set(res);
|
|
|
|
$scope.data = res.data.data;
|
2016-09-11 18:40:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
function submitresult(res){
|
|
|
|
session.set(res);
|
|
|
|
alert.set(res);
|
|
|
|
if(res.data.data){
|
2016-09-27 11:44:48 +02:00
|
|
|
load();
|
2016-09-11 18:40:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
resetObj();
|
|
|
|
load();
|
2016-10-17 23:43:14 +02:00
|
|
|
$rootScope.$on('warehost.session',load);
|
2016-09-11 18:40:03 +02:00
|
|
|
|
|
|
|
$scope.edit = function(a){
|
2016-09-27 11:44:48 +02:00
|
|
|
$scope.obj = a;
|
2016-09-11 18:40:03 +02:00
|
|
|
};
|
|
|
|
$scope.add = function(){
|
2016-09-27 11:44:48 +02:00
|
|
|
$scope.obj = {};
|
2016-10-11 20:50:30 +02:00
|
|
|
};
|
2016-09-27 11:44:48 +02:00
|
|
|
$scope.save = function(){
|
|
|
|
if($scope.obj.ID){
|
2016-10-17 23:43:14 +02:00
|
|
|
$http.patch(config.api+'/web/website/'+$stateParams.websiteid+'/page/'+$scope.obj.ID,$scope.obj).then(submitresult);
|
2016-09-27 11:44:48 +02:00
|
|
|
}else{
|
|
|
|
$http.post(config.api+'/web/website/'+$stateParams.websiteid+'/page',$scope.obj).then(submitresult);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.delete = function(a){
|
|
|
|
$http.delete(config.api+'/web/website/'+$stateParams.websiteid+'/page/'+a.ID).then(submitresult);
|
2016-09-11 18:40:03 +02:00
|
|
|
};
|
|
|
|
});
|