66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
angular.module('warehost')
|
|
.controller('WebmenuWebCtrl',function(session,config,alert,$scope,$rootScope,$stateParams,$http){
|
|
$scope.data = [];
|
|
alert.set({});
|
|
|
|
$scope.treeOptions = {
|
|
accept: function(){
|
|
return true;
|
|
},
|
|
beforeDrop: function (){
|
|
return true;
|
|
},
|
|
dropped: function(e){
|
|
$scope.obj = e.source.nodeScope.$modelValue;
|
|
$scope.obj.position = e.dest.index;
|
|
if(e.dest.nodesScope.$nodeScope){
|
|
$scope.obj.parentid = e.dest.nodesScope.$nodeScope.$modelValue.ID;
|
|
}else{
|
|
$scope.obj.parentid = null;
|
|
}
|
|
$http.patch(config.api+'/web/website/'+$stateParams.websiteid+'/menu/'+$scope.obj.ID,$scope.obj).then(submitresult);
|
|
}
|
|
};
|
|
|
|
function load(){
|
|
$http.get(config.api+'/web/website/'+$stateParams.websiteid+'/menu').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();
|
|
}
|
|
}
|
|
load();
|
|
$rootScope.$on('warehost.session',load);
|
|
|
|
$scope.edit = function(a){
|
|
$scope.obj = a.$modelValue;
|
|
};
|
|
$scope.save = function(){
|
|
if($scope.obj.ID){
|
|
$http.patch(config.api+'/web/website/'+$stateParams.websiteid+'/menu/'+$scope.obj.ID,$scope.obj).then(submitresult);
|
|
}else{
|
|
$http.post(config.api+'/web/website/'+$stateParams.websiteid+'/menu',$scope.obj).then(submitresult);
|
|
}
|
|
};
|
|
$scope.delete = function(a){
|
|
$http.delete(config.api+'/web/website/'+$stateParams.websiteid+'/menu/'+a.$modelValue.ID).then(submitresult);
|
|
};
|
|
$scope.add = function(a){
|
|
$scope.obj = {};
|
|
if(a){
|
|
$scope.obj.parentid = a.$modelValue.ID;
|
|
$scope.parent = a.$modelValue;
|
|
}else{
|
|
$scope.parent = null;
|
|
}
|
|
};
|
|
});
|