'use strict'; angular.module('warehost') .controller('PageWebCtrl',function(session,config,alert,NgTableParams,$scope,$rootScope,$http,$stateParams){ $scope.data = []; $scope.menulist = []; alert.set({}); $scope.obj = {}; function resetObj(){ $scope.obj = {}; } function load(){ $http.get(config.api+'/web/website/'+$stateParams.websiteid+'/page').then(function(res){ session.set(res); $scope.data = res.data.data; }); } function submitresult(res){ session.set(res); alert.set(res); if(res.data.data){ load(); } } resetObj(); load(); $rootScope.$on('warehost.session',load); $scope.edit = function(a){ $scope.obj = a; }; $scope.add = function(){ $scope.obj = {}; }; $scope.save = function(){ if($scope.obj.ID){ $http.patch(config.api+'/web/website/'+$stateParams.websiteid+'/page/'+$scope.obj.ID,$scope.obj).then(submitresult); }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); }; });