|
| 1 | +api.controller=function($scope, spModal) { |
| 2 | + var c = this; |
| 3 | + c.newLocations = []; |
| 4 | + |
| 5 | + c.server.get({ |
| 6 | + action: 'getChildren', |
| 7 | + type: 'city', |
| 8 | + parent: null |
| 9 | + }).then((res) => { |
| 10 | + c.locations = res.data.locations; |
| 11 | + $scope.locations = res.data.locations.selected; |
| 12 | + $scope.locations.room = ''; |
| 13 | + }); |
| 14 | + |
| 15 | + c.changeCity = (newSysId) => { |
| 16 | + $scope.locations.city = c.locations.available.city.filter((city) => city.sys_id === newSysId)[0]; |
| 17 | + $scope.locations['building/structure'] = c.locations.default['building/structure']; |
| 18 | + $scope.locations.floor = c.locations.default.floor; |
| 19 | + $scope.locations.zone = c.locations.default.zone; |
| 20 | + |
| 21 | + c.getChildren('building/structure', newSysId); |
| 22 | + } |
| 23 | + |
| 24 | + c.changeBuilding = (newSysId) => { |
| 25 | + $scope.locations['building/structure'] = c.locations.available['building/structure'].filter((building) => building.sys_id === newSysId)[0]; |
| 26 | + $scope.locations.floor = c.locations.default.floor; |
| 27 | + $scope.locations.zone = c.locations.default.zone; |
| 28 | + |
| 29 | + c.getChildren('floor', newSysId); |
| 30 | + } |
| 31 | + |
| 32 | + c.changeFloor = (newSysId) => { |
| 33 | + $scope.locations.floor = c.locations.available.floor.filter((floor) => floor.sys_id === newSysId)[0]; |
| 34 | + $scope.locations.zone = c.locations.default.zone; |
| 35 | + |
| 36 | + c.getChildren('zone', newSysId); |
| 37 | + } |
| 38 | + |
| 39 | + c.changeZone = (newSysId) => { |
| 40 | + $scope.locations.zone = c.locations.available.zone.filter((zone) => zone.sys_id === newSysId)[0]; |
| 41 | + } |
| 42 | + |
| 43 | + c.changeRoom = () => { |
| 44 | + //c.newLocations.push($scope.locations.zone.name + $scope.locations.room); |
| 45 | + } |
| 46 | + |
| 47 | + c.addNewLocation = () => { |
| 48 | + c.newLocations.push('City: ' + $scope.locations.city.name + ', building: ' + $scope.locations['building/structure'].name + ', floor: ' + $scope.locations.floor.name + ', corridor: ' + $scope.locations.zone.name + ', room: * ' + $scope.locations.room); |
| 49 | + if ($scope.page.g_form) { |
| 50 | + $scope.page.g_form.setValue('locks_locations_new_locations_added', c.newLocations.join('\n')); |
| 51 | + } |
| 52 | + $scope.locations.room = ''; |
| 53 | + } |
| 54 | + |
| 55 | + c.notListedModal = (type) => { |
| 56 | + spModal.prompt('Please enter missing value for the ' + type) |
| 57 | + .then(value => { |
| 58 | + $scope.locations[type] = {name: '* ' + value, sys_id: '-2'}; |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + c.getChildren = (type, parent) => { |
| 63 | + c.server.get({ |
| 64 | + action: 'getChildren', |
| 65 | + type: type, |
| 66 | + parent: parent |
| 67 | + }).then((res) => { |
| 68 | + c.locations.available[type] = res.data.locations.available[type]; |
| 69 | + }); |
| 70 | + } |
| 71 | + |
| 72 | + c.allSelected = () => { |
| 73 | + return $scope.locations && |
| 74 | + $scope.locations.city.sys_id !== '-1' && |
| 75 | + $scope.locations['building/structure'].sys_id !== '-1' && |
| 76 | + $scope.locations.floor.sys_id !== '-1' && |
| 77 | + $scope.locations.zone.sys_id !== '-1' |
| 78 | + } |
| 79 | +}; |
0 commit comments