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

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-09-11 18:40:03 +02:00
'use strict';
angular.module('warehost')
.controller('WebmenuWebCtrl',function(session,config,alert,$scope,$rootScope,$stateParams,$http){
2016-09-13 20:00:06 +02:00
$scope.data = [];
2016-09-11 18:40:03 +02:00
alert.set({});
2016-09-13 20:00:06 +02:00
$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){
2016-11-16 02:03:29 +01:00
$scope.obj.parentid = e.dest.nodesScope.$nodeScope.$modelValue.ID;
2016-09-13 20:00:06 +02:00
}else{
2016-11-16 02:03:29 +01:00
$scope.obj.parentid = null;
2016-09-13 20:00:06 +02:00
}
$http.patch(config.api+'/web/website/'+$stateParams.websiteid+'/menu/'+$scope.obj.ID,$scope.obj).then(submitresult);
2016-09-13 20:00:06 +02:00
}
};
2016-09-11 18:40:03 +02:00
function load(){
2016-09-13 20:00:06 +02:00
$http.get(config.api+'/web/website/'+$stateParams.websiteid+'/menu').then(function(res){
2016-09-11 18:40:03 +02:00
session.set(res);
2016-09-13 20:00:06 +02:00
$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-13 20:00:06 +02:00
load();
2016-09-11 18:40:03 +02:00
}
}
load();
$rootScope.$on('warehost.session',load);
2016-09-11 18:40:03 +02:00
$scope.edit = function(a){
2016-09-13 20:00:06 +02:00
$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);
2016-09-13 20:00:06 +02:00
}else{
2016-09-18 17:03:12 +02:00
$http.post(config.api+'/web/website/'+$stateParams.websiteid+'/menu',$scope.obj).then(submitresult);
2016-09-13 20:00:06 +02:00
}
2016-09-11 18:40:03 +02:00
};
$scope.delete = function(a){
2016-09-18 17:03:12 +02:00
$http.delete(config.api+'/web/website/'+$stateParams.websiteid+'/menu/'+a.$modelValue.ID).then(submitresult);
2016-09-11 18:40:03 +02:00
};
2016-09-13 20:00:06 +02:00
$scope.add = function(a){
$scope.obj = {};
if(a){
2016-11-16 02:03:29 +01:00
$scope.obj.parentid = a.$modelValue.ID;
2016-09-13 20:00:06 +02:00
$scope.parent = a.$modelValue;
}else{
$scope.parent = null;
}
2016-09-11 18:40:03 +02:00
};
});