71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
angular.module('warehost')
|
|
.controller('WebmenuWebCtrl',function(session,config,alert,$scope,$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 = {
|
|
Int64: e.dest.nodesScope.$nodeScope.$modelValue.ID,
|
|
Valid: true
|
|
};
|
|
}else{
|
|
$scope.obj.parentid = {Int64: 0, Valid: false};
|
|
}
|
|
$http.put(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();
|
|
|
|
$scope.edit = function(a){
|
|
$scope.obj = a.$modelValue;
|
|
};
|
|
$scope.save = function(){
|
|
if($scope.obj.ID){
|
|
$http.put(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 = {
|
|
Int64: a.$modelValue.ID,
|
|
Valid: true
|
|
};
|
|
$scope.parent = a.$modelValue;
|
|
}else{
|
|
$scope.parent = null;
|
|
}
|
|
};
|
|
});
|