75 lines
3.4 KiB
JavaScript
75 lines
3.4 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by prenge on 22-08-2017.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('customWidgetsModule')
|
|
.directive('locationCustomField', ['events',
|
|
function (events) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
templateUrl: 'views/custom-widgets/location-field.html',
|
|
scope: {
|
|
data: '=',
|
|
context: '=',
|
|
isEditable: '='
|
|
},
|
|
link: function (scope) {
|
|
scope.$watch('data.value', function () {
|
|
scope.init();
|
|
//map of the location widget fields which will be used in expressions
|
|
var objectMapper = {
|
|
region: 'siteRegion',
|
|
site: 'siteName',
|
|
siteGroup: 'siteGroup'
|
|
};
|
|
scope.$emit(events.WIDGET_VALUE_CHANGE, { fieldName: scope.data.name, memberName: objectMapper[scope.data.value.fieldChanged] });
|
|
}, true);
|
|
},
|
|
controller: ['$scope', function ($scope) {
|
|
$scope.siteOptions = {
|
|
company: {
|
|
visible: false,
|
|
attribute: 'companyName'
|
|
},
|
|
region: {
|
|
attribute: 'region'
|
|
},
|
|
siteGroup: {
|
|
attribute: 'siteGroup'
|
|
},
|
|
site: {
|
|
attribute: 'name'
|
|
}
|
|
};
|
|
$scope.getDisplayValue = function (changeLocation) {
|
|
var location = [];
|
|
_.forOwn(changeLocation.value, function (val, key) {
|
|
if (val && key !== 'siteId' && key !== 'companyName' && key !== 'fieldChanged') {
|
|
location.push(val);
|
|
}
|
|
});
|
|
return location.join(' > ');
|
|
};
|
|
$scope.init = function () {
|
|
if (!$scope.data.value.companyName) {
|
|
$scope.data.value.companyName = $scope.context.company && $scope.context.company.name ? $scope.context.company.name : '';
|
|
}
|
|
$scope.changeLocation = $scope.getDisplayValue($scope.data);
|
|
//update the ticket object's location value, otherwise the expressions evaluation returns incorrect
|
|
//result as it falls back to the ticket object in getExactValueByFieldName in ObjectValueMapperService
|
|
$scope.context.location = {
|
|
id: $scope.data.value.siteId,
|
|
name: $scope.data.value.name,
|
|
region: $scope.data.value.region,
|
|
siteGroup: $scope.data.value.siteGroup
|
|
};
|
|
};
|
|
$scope.init();
|
|
}]
|
|
};
|
|
}]);
|
|
}());
|