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/webmenu.js

72 lines
1.8 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 = {
Int64: e.dest.nodesScope.$nodeScope.$modelValue.ID,
Valid: true
};
}else{
$scope.obj.parentid = {Int64: 0, Valid: false};
}
$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 = {
Int64: a.$modelValue.ID,
Valid: true
};
$scope.parent = a.$modelValue;
}else{
$scope.parent = null;
}
};
});