116 lines
5.9 KiB
JavaScript
116 lines
5.9 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.directive('editAssetOwner', ['createTicketModel', 'events', 'configurationModel', 'searchService', 'searchModel', '$timeout',
|
|
function (createTicketModel, events, configurationModel, searchService, searchModel, $timeout) {
|
|
return {
|
|
restrict: 'EA',
|
|
scope: {
|
|
update: '&',
|
|
asset: '='
|
|
},
|
|
templateUrl: 'views/asset/edit-asset-owner.html',
|
|
link: function (scope) {
|
|
var relationData = {
|
|
relationshipType: '',
|
|
type: 'person',
|
|
subType: 'People',
|
|
id: '',
|
|
details: { isPrimaryContact: true }
|
|
};
|
|
scope.showMailstopOnPersoncard = configurationModel.showMailstopOnPersoncard;
|
|
scope.showPhoneNumOnPersonCard = configurationModel.showPhoneNumOnPersonCard;
|
|
scope.siteFoundation = {
|
|
siteOptions: {
|
|
company: {
|
|
visible: false,
|
|
attribute: 'companyName'
|
|
},
|
|
region: {
|
|
attribute: 'region'
|
|
},
|
|
siteGroup: {
|
|
attribute: 'siteGroup'
|
|
},
|
|
site: {
|
|
attribute: 'name'
|
|
}
|
|
},
|
|
selectedSite: {
|
|
companyName: scope.asset.company ? scope.asset.company.name : '',
|
|
region: scope.asset.site && scope.asset.site.region ? scope.asset.site.region : '',
|
|
siteGroup: scope.asset.site && scope.asset.site.siteGroup ? scope.asset.site.siteGroup : '',
|
|
name: scope.asset.site && scope.asset.site.name ? scope.asset.site.name : ''
|
|
}
|
|
};
|
|
scope.person = {};
|
|
scope.updateAssetSite = {};
|
|
scope.state = {};
|
|
scope.selections = {};
|
|
scope.selected = {};
|
|
scope.relationData = relationData;
|
|
scope.isFieldValid = function () {
|
|
if (scope.asset && scope.asset.type === EntityVO.TYPE_NETWORK) {
|
|
return false;
|
|
}
|
|
else {
|
|
return true;
|
|
}
|
|
};
|
|
scope.assetOwnerRoles = _.find(configurationModel.get('link')[EntityVO.TYPE_PERSON], { type: EntityVO.TYPE_PERSON }).relations;
|
|
scope.getList = function (type, term) {
|
|
if (type === 'person') {
|
|
return createTicketModel.getList(type, term).then(function (data) {
|
|
scope.isTooltipOpenOwner = scope.exceedsChunkSizeOwner = data.exceedsChunkSize;
|
|
$timeout(function () {
|
|
scope.isTooltipOpenOwner = false;
|
|
}, 10000);
|
|
return data.items;
|
|
});
|
|
}
|
|
return createTicketModel.getList(type, term);
|
|
};
|
|
scope.onInputFocusBlur = function () {
|
|
scope.isTooltipOpenOwner = false;
|
|
};
|
|
scope.clearPerson = function () {
|
|
scope.person.data = '';
|
|
relationData.id = '';
|
|
scope.selectedOwner = {};
|
|
};
|
|
scope.updateAssetOwner = function ($item) {
|
|
relationData.id = $item.personId;
|
|
scope.selectedOwner = angular.copy($item);
|
|
};
|
|
scope.save = function () {
|
|
var updatedData = { relationData: relationData, siteData: scope.updateAssetSite };
|
|
scope.update({ data: updatedData });
|
|
scope.$emit(events.SAVE_CHANGES_COMPLETE);
|
|
};
|
|
var handleSaveChanges = function () {
|
|
console.log('handleSaveChanges in editAssetOwner');
|
|
scope.updateAssetSite.name = scope.siteFoundation.selectedSite.name || '';
|
|
scope.updateAssetSite.region = scope.siteFoundation.selectedSite.region || '';
|
|
scope.updateAssetSite.siteGroup = scope.siteFoundation.selectedSite.siteGroup || '';
|
|
scope.save();
|
|
};
|
|
var handleToggleEditMode = function () {
|
|
if (!_.isEmpty(scope.asset.owner)) {
|
|
scope.person.data = angular.copy(scope.asset.owner.realObject.fullName);
|
|
scope.relationData.relationshipType = angular.copy(scope.asset.owner.relationshipType);
|
|
scope.relationData.id = angular.copy(scope.asset.owner.displayId);
|
|
}
|
|
else {
|
|
// default to ownedby if empty SW00474304
|
|
scope.relationData.relationshipType = 'ownedby';
|
|
}
|
|
scope.updateAssetSite = angular.copy(scope.asset.site);
|
|
};
|
|
scope.$on(events.TOGGLE_EDIT_MODE, handleToggleEditMode);
|
|
scope.$on(events.SAVE_CHANGES, handleSaveChanges);
|
|
}
|
|
};
|
|
}]);
|
|
}());
|