diff --git a/Service Portal Widgets/Location hierarchy/README.md b/Service Portal Widgets/Location hierarchy/README.md new file mode 100644 index 0000000000..b33e65426a --- /dev/null +++ b/Service Portal Widgets/Location hierarchy/README.md @@ -0,0 +1,3 @@ +This widget allows you to hierarchically choose a location for the catalog item variable. + +With small additional setup you can adjust it to your own structure. You also need a variable (preferably multi line text) to save the output of this widget. diff --git a/Service Portal Widgets/Location hierarchy/client controller.js b/Service Portal Widgets/Location hierarchy/client controller.js new file mode 100644 index 0000000000..d3b3c7a5a7 --- /dev/null +++ b/Service Portal Widgets/Location hierarchy/client controller.js @@ -0,0 +1,79 @@ +api.controller=function($scope, spModal) { + var c = this; + c.newLocations = []; + + c.server.get({ + action: 'getChildren', + type: 'city', + parent: null + }).then((res) => { + c.locations = res.data.locations; + $scope.locations = res.data.locations.selected; + $scope.locations.room = ''; + }); + + c.changeCity = (newSysId) => { + $scope.locations.city = c.locations.available.city.filter((city) => city.sys_id === newSysId)[0]; + $scope.locations['building/structure'] = c.locations.default['building/structure']; + $scope.locations.floor = c.locations.default.floor; + $scope.locations.zone = c.locations.default.zone; + + c.getChildren('building/structure', newSysId); + } + + c.changeBuilding = (newSysId) => { + $scope.locations['building/structure'] = c.locations.available['building/structure'].filter((building) => building.sys_id === newSysId)[0]; + $scope.locations.floor = c.locations.default.floor; + $scope.locations.zone = c.locations.default.zone; + + c.getChildren('floor', newSysId); + } + + c.changeFloor = (newSysId) => { + $scope.locations.floor = c.locations.available.floor.filter((floor) => floor.sys_id === newSysId)[0]; + $scope.locations.zone = c.locations.default.zone; + + c.getChildren('zone', newSysId); + } + + c.changeZone = (newSysId) => { + $scope.locations.zone = c.locations.available.zone.filter((zone) => zone.sys_id === newSysId)[0]; + } + + c.changeRoom = () => { + //c.newLocations.push($scope.locations.zone.name + $scope.locations.room); + } + + c.addNewLocation = () => { + 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); + if ($scope.page.g_form) { + $scope.page.g_form.setValue('locks_locations_new_locations_added', c.newLocations.join('\n')); + } + $scope.locations.room = ''; + } + + c.notListedModal = (type) => { + spModal.prompt('Please enter missing value for the ' + type) + .then(value => { + $scope.locations[type] = {name: '* ' + value, sys_id: '-2'}; + }); + } + + c.getChildren = (type, parent) => { + c.server.get({ + action: 'getChildren', + type: type, + parent: parent + }).then((res) => { + c.locations.available[type] = res.data.locations.available[type]; + }); + } + + c.allSelected = () => { + return $scope.locations && + $scope.locations.city.sys_id !== '-1' && + $scope.locations['building/structure'].sys_id !== '-1' && + $scope.locations.floor.sys_id !== '-1' && + $scope.locations.zone.sys_id !== '-1' + } +}; diff --git a/Service Portal Widgets/Location hierarchy/css.css b/Service Portal Widgets/Location hierarchy/css.css new file mode 100644 index 0000000000..95a9011751 --- /dev/null +++ b/Service Portal Widgets/Location hierarchy/css.css @@ -0,0 +1,11 @@ +.location-picker-input { + padding: 6px 12px; + color: #555555; + border: 1px solid #939393; + border-radius: 4px; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); + -webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; + -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; + transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; +} diff --git a/Service Portal Widgets/Location hierarchy/html.html b/Service Portal Widgets/Location hierarchy/html.html new file mode 100644 index 0000000000..f7fc7b3166 --- /dev/null +++ b/Service Portal Widgets/Location hierarchy/html.html @@ -0,0 +1,47 @@ +

+ Describe the new location +

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
diff --git a/Service Portal Widgets/Location hierarchy/server script.js b/Service Portal Widgets/Location hierarchy/server script.js new file mode 100644 index 0000000000..d3cdcd37ae --- /dev/null +++ b/Service Portal Widgets/Location hierarchy/server script.js @@ -0,0 +1,41 @@ +(function() { + data.locations = { + available: { + city: [], + 'building/structure': [], + floor: [], + zone: [] + }, + default: { + city: {name: 'Pick a city', sys_id: '-1'}, + 'building/structure': {name: 'Pick a building', sys_id: '-1'}, + floor: {name: 'Pick a floor', sys_id: '-1'}, + zone: {name: 'Pick a corridor', sys_id: '-1'} + } + }; + + data.locations.selected = data.locations.default; + + if (input && input.action === 'getChildren' && input.type) { + data.locations.available[input.type] = getData(input.type, input.parent); + } + + function getData(locationType, parent) { + let ret = []; + let gq = new global.GlideQuery('cmn_location').where('cmn_location_type', locationType); + + if (!gs.nil(parent)) + gq = gq.where('parent', parent); + + gq + .orderBy('name') + .select('name') + .forEach(function(childLocation){ + ret.push({ + sys_id: childLocation.sys_id, + name: childLocation.name + }); + }); + return ret; + } +})();