"use strict"; (function () { 'use strict'; angular.module('assetModule') .controller('AssetController', [ '$scope', 'assetModel', 'attachmentService', '$q', 'categoriesService', 'events', '$modal', '$state', 'systemAlertService', '$filter', 'metadataModel', 'userModel', 'ticketActionService', 'googleMapService', 'relationModel', 'ciExplorerModel', 'i18nService', 'configurationModel', 'screenConfigurationModel', 'chatModel', function ($scope, assetModel, attachmentService, $q, categoriesService, events, $modal, $state, systemAlertService, $filter, metadataModel, userModel, ticketActionService, googleMapService, relationModel, ciExplorerModel, i18nService, configurationModel, screenConfigurationModel, chatModel) { var screenName = screenConfigurationModel.getScreenNameByTicketType(EntityVO.TYPE_ASSET); $scope.ciExplorerModel = ciExplorerModel; $scope.dirty = false; $scope.dropDownOptions = {}; $scope.customFieldsAvailable = false; $scope.typeSpecificCustomFieldsAvailable = false; $scope.chatModel = chatModel; var peopleRefreshRequired = false; $scope.bcmConfig = {}; /** * Public functions * */ $scope.setSection = function (sectionId) { $scope.activeSection = sectionId; }; $scope.share = function ($event) { ticketActionService.showShareDialog($scope.asset).result.then(function () { $event.currentTarget.focus(); }, function () { $event.currentTarget.focus(); }); }; $scope.follow = function () { var userLoginId = userModel.userFullData.loginId; return assetModel.followAsset(userLoginId, $scope.asset.reconciliationId); }; $scope.unfollow = function () { var userLoginId = userModel.userFullData.loginId; return assetModel.unfollowAsset(userLoginId, $scope.asset.reconciliationId); }; $scope.toggleFollowingFlag = function () { var toggleFollowingFunction = $scope.asset.following ? $scope.unfollow : $scope.follow; toggleFollowingFunction($scope.asset).then(function () { $scope.asset.following = !$scope.asset.following; }, function (error) { systemAlertService.error({ text: error.data && error.data.error, clear: false }); }); }; $scope.showPrintDialog = function ($event) { var ticketPrintDialog = $modal.open({ templateUrl: 'views/common/print-action-blade.html', controller: 'PrintController', windowClass: 'action-blade', size: 'extra-lg', resolve: { params: function () { return { entity: $scope.asset, feed: $scope.asset.feed, customFieldsAvailable: $scope.customFieldsAvailable }; } } }); ticketPrintDialog.result.finally(function () { $event.currentTarget.focus(); }); }; $scope.closeExplorer = function () { $state.go('asset', { assetId: $scope.asset.reconciliationId, assetClassId: $scope.asset.classId }); }; function mapBCMUser(action) { var bcmAuthModal = $modal.open({ templateUrl: 'views/common/bcm-credentials-template.html', windowClass: 'bcm-credential-alert-modal', controller: 'BcmCredentialAlertController' }); bcmAuthModal.result.then(function () { userModel.getBCMIntegrationConfig().then(function (bcmConfig) { $scope.bcmConfig = bcmConfig; if ($scope.bcmConfig.configLoaded && action) { $scope.bcmActionsCallbacks[action](); } }); }); } function getBCMFilterActionAndProcess(action) { var loadingModal = $modal.open({ template: '', windowClass: 'bcm-credential-alert-modal', size: 'sm' }); assetModel.getBcmFilteredActionsFromServer().then(function (bcmFilteredActions) { configureMoreActions(); loadingModal.close(); $scope.bcmFilteredActions = bcmFilteredActions; $scope.bcmActionsCallbacks[action](); }).catch(function (response) { configureMoreActions(); loadingModal.close(); if (response.data.error === 'BCM_Unauthorized') { mapBCMUser(action); } else { systemAlertService.error({ text: response.data.error, clear: false }); } }); } function confirmBCMActionAndProcess(action) { var modalInstance = systemAlertService.modal({ title: $filter('i18n')('common.notification.dirty.title'), text: $filter('i18n')('asset.bcm.' + action + '.confirm'), buttons: [ { text: $filter('i18n')('common.button.yes'), data: true }, { text: $filter('i18n')('common.button.no'), data: false } ] }); modalInstance.result.then(function (flag) { if (flag) { performBCMActionAndProcess(action); } }); } function performBCMActionAndProcess(action) { var loadingModal = $modal.open({ template: '', windowClass: 'bcm-credential-alert-modal', size: 'sm' }); assetModel.performBCMAction(action).then(function () { loadingModal.close(); systemAlertService.success({ text: $filter('i18n')('asset.bcm.' + action + '.success'), hide: 10000 }); }).catch(function (response) { loadingModal.close(); if (response.data && response.data.error) { if (response.data.error === "BCM_Unauthorized") { mapBCMUser(action); } else { systemAlertService.error({ text: response.data.error, clear: false }); } } }); } function bcmUserNotAuthorized() { systemAlertService.error({ text: $filter('i18n')('error.unauthorized'), clear: false }); } $scope.bcmActionsCallbacks = { 'showBcmAssetDetails': function () { if ($scope.bcmConfig.usermapped) { if ($scope.bcmFilteredActions.configLoaded) { if ($scope.bcmFilteredActions.actions.ConfigSummary) { $modal.open({ templateUrl: 'views/asset/bcm-asset-action-blade.html', controller: 'BcmAssetActionController', windowClass: 'action-blade', size: 'extra-lg', resolve: { linkParams: function () { return { entity: $scope.asset }; } } }); } else { bcmUserNotAuthorized(); } } else { getBCMFilterActionAndProcess('showBcmAssetDetails'); } } else { mapBCMUser('showBcmAssetDetails'); } }, 'performAuditFromBCM': function () { if ($scope.bcmConfig.usermapped) { if ($scope.bcmFilteredActions.configLoaded) { if ($scope.bcmFilteredActions.actions.PerformAudit) { performBCMActionAndProcess('performAuditFromBCM'); } else { bcmUserNotAuthorized(); } } else { getBCMFilterActionAndProcess('performAuditFromBCM'); } } else { mapBCMUser('performAuditFromBCM'); } }, 'pingDeviceFromBCM': function () { if ($scope.bcmConfig.usermapped) { if ($scope.bcmFilteredActions.configLoaded) { if ($scope.bcmFilteredActions.actions.Ping) { performBCMActionAndProcess('pingDeviceFromBCM'); } else { bcmUserNotAuthorized(); } } else { getBCMFilterActionAndProcess('pingDeviceFromBCM'); } } else { mapBCMUser('pingDeviceFromBCM'); } }, 'rebootDeviceFromBCM': function () { if ($scope.bcmConfig.usermapped) { if ($scope.bcmFilteredActions.configLoaded) { if ($scope.bcmFilteredActions.actions.Reboot) { confirmBCMActionAndProcess('rebootDeviceFromBCM'); } else { bcmUserNotAuthorized(); } } else { getBCMFilterActionAndProcess('rebootDeviceFromBCM'); } } else { mapBCMUser('rebootDeviceFromBCM'); } }, 'shutdownDeviceFromBCM': function () { if ($scope.bcmConfig.usermapped) { if ($scope.bcmFilteredActions.configLoaded) { if ($scope.bcmFilteredActions.actions.Shutdown) { confirmBCMActionAndProcess('shutdownDeviceFromBCM'); } else { bcmUserNotAuthorized(); } } else { getBCMFilterActionAndProcess('shutdownDeviceFromBCM'); } } else { mapBCMUser('shutdownDeviceFromBCM'); } }, 'wakeupDeviceFromBCM': function () { if ($scope.bcmConfig.usermapped) { if ($scope.bcmFilteredActions.configLoaded) { if ($scope.bcmFilteredActions.actions.WakeUp) { performBCMActionAndProcess('wakeupDeviceFromBCM'); } else { bcmUserNotAuthorized(); } } else { getBCMFilterActionAndProcess('wakeupDeviceFromBCM'); } } else { mapBCMUser('wakeupDeviceFromBCM'); } } }; $scope.putIntoInventoryCallbackFuncs = { 'putIntoInventory': function () { var editInventoryModal = $modal.open({ templateUrl: 'views/asset/asset-edit-inventory-blade.html', windowClass: 'action-blade', controller: 'AssetEditInventoryController', backdrop: 'custom' }); editInventoryModal.result.then(function () { configureMoreActions(); $scope.$emit(events.ASSET_DETAILS_CHANGED, { eventName: events.REFRESH_ACTIVITY_FEED }); $scope.$emit(events.ASSET_DETAILS_CHANGED, { eventName: events.REFRESH_RELATED_ITEM_LIST }); }); } }; $scope.takeOutOfInventoryCallbackFuncs = { 'takeOutOfInventory': function () { var editStatusModal = $modal.open({ templateUrl: 'views/asset/asset-edit-status-blade.html', windowClass: 'action-blade', controller: 'AssetEditStatusController', backdrop: 'custom' }); editStatusModal.result.then(function () { configureMoreActions(); $scope.$emit(events.ASSET_DETAILS_CHANGED, { eventName: events.REFRESH_ACTIVITY_FEED }); $scope.$emit(events.ASSET_DETAILS_CHANGED, { eventName: events.REFRESH_RELATED_ITEM_LIST }); }); } }; function configureMoreActions() { $scope.dropDownOptions = { 'actions': [], 'registeredCallbacks': {} }; var currentAssetType = _.findWhere($scope.metadata.assetTypes, { name: $scope.asset.assetType }); var currentSubType = _.findWhere(currentAssetType.subType, { name: assetModel.assetClassId }); if (currentSubType.putIntoInventory && $scope.asset.accessMappings.inventoryEditAllowed) { var moreDropDownActionItems = _.clone(configurationModel.get('moreActions.asset')); var callback = $scope.putIntoInventoryCallbackFuncs; if ($scope.asset.status.value === EntityVO.STATUS_IN_INVENTORY) { moreDropDownActionItems.splice(0, 1); callback = $scope.takeOutOfInventoryCallbackFuncs; } else { moreDropDownActionItems.splice(1, 1); } $scope.dropDownOptions = { 'actions': moreDropDownActionItems, 'registeredCallbacks': callback }; } //additional BCM actions if ($scope.bcmConfig.integrated && $scope.asset.bcmDeviceId) { $scope.bcmFilteredActions = assetModel.getBcmFilteredActions(); var bcmSupportedActions = [{ 'name': 'bcmAssetDetails', 'functionCallback': 'showBcmAssetDetails', 'addTopSeparator': true, 'isDisabled': !$scope.bcmFilteredActions.actions.ConfigSummary }, { 'name': 'performAudit', 'functionCallback': 'performAuditFromBCM', 'addTopSeparator': true, 'isDisabled': !$scope.bcmFilteredActions.actions.PerformAudit }, { 'name': 'ping', 'functionCallback': 'pingDeviceFromBCM', 'isDisabled': !$scope.bcmFilteredActions.actions.Ping }, { 'name': 'reboot', 'functionCallback': 'rebootDeviceFromBCM', 'isDisabled': !$scope.bcmFilteredActions.actions.Reboot }, { 'name': 'shutdown', 'functionCallback': 'shutdownDeviceFromBCM', 'isDisabled': !$scope.bcmFilteredActions.actions.Shutdown }, { 'name': 'wakeUp', 'functionCallback': 'wakeupDeviceFromBCM', 'isDisabled': !$scope.bcmFilteredActions.actions.WakeUp }]; bcmSupportedActions.forEach(function (bcmAction) { var actionItem = { label: bcmAction.name, method: bcmAction.functionCallback, addTopSeparator: bcmAction.addTopSeparator || false, isDisabled: bcmAction.isDisabled || false }; $scope.dropDownOptions.actions.push(actionItem); $scope.dropDownOptions.registeredCallbacks[bcmAction.functionCallback] = $scope.bcmActionsCallbacks[bcmAction.functionCallback]; }); } } var initDirtyFormAlert = function () { $scope.$on('$stateChangeStart', function (event, toState, toParams) { if (!$scope.dirty) { return; } if ($scope.dirty && toState.name !== EntityVO.TYPE_ASSET) { event.preventDefault(); var modalInstance = systemAlertService.modal({ title: i18nService.getLocalizedString('common.notification.dirty.title'), text: i18nService.getLocalizedString('common.notification.dirty.message'), buttons: [ { text: i18nService.getLocalizedString('common.labels.yes'), data: { stateName: toState.name, stateParams: toParams } }, { text: i18nService.getLocalizedString('common.labels.no') } ] }); modalInstance.result.then(function (data) { if (!_.isEmpty(data)) { $scope.dirty = false; $state.transitionTo(data.stateName, data.stateParams); } }); } }); }; $scope.$on('new-relations', function () { assetModel.refreshFlattenRelations(assetModel.assetId).then(onFlattenRelationsLoaded); }); $scope.refreshTicket = function () { $scope.init(assetModel.assetId, assetModel.assetClassId); assetModel.refreshFlattenRelations(assetModel.assetId).then(onFlattenRelationsLoaded); }; /** * Entry point */ $scope.init = function (assetId, assetClassId) { $scope.isAttributesCollapsed = false; $scope.activeSection = 'dates'; $scope.editHeader = false; $scope.asset = {}; $scope.asset.owner = {}; $scope.assetOwner = {}; $scope.poiOwner = {}; if (!assetId) { return; } $scope.state = { isAssetDataLoading: true, isPersonRelationsLoading: true }; assetModel.assetDetails = {}; assetModel.assetId = assetId; assetModel.assetClassId = assetClassId; var metadataPromise = metadataModel.getMetadataByType(EntityVO.TYPE_ASSET) .then(function (assetMetadataCache) { $scope.metadata = assetMetadataCache || {}; }), assetDetailsPromise = assetModel.getAssetDetailsByID(assetId, assetClassId) .then(onAssetDetailsLoaded).finally(onDataLoadComplete), assetFlattenRelationsPromise = $scope.isFullVersion ? assetModel.getFlattenRelations(assetId).then(onFlattenRelationsLoaded) : $q.when(1), screenConfigurationPromise = screenName ? screenConfigurationModel.loadScreenConfigurationAndCustomFieldLabels(screenName, EntityVO.TYPE_ASSET) : $q.when({}), assetPeopleRelationsPromise, promises; userModel.getBCMIntegrationConfig().then(function (bcmConfig) { $scope.bcmConfig = bcmConfig; }); if (peopleRefreshRequired) { assetPeopleRelationsPromise = assetModel.refreshPeopleRelations(assetId); peopleRefreshRequired = false; } else { assetPeopleRelationsPromise = $scope.isFullVersion ? assetModel.getPeopleRelations(assetId) : assetModel.getPrimaryContact(assetId); } assetPeopleRelationsPromise.finally(function () { $scope.state.isPersonRelationsLoading = false; }); promises = [metadataPromise, assetDetailsPromise, assetFlattenRelationsPromise, assetPeopleRelationsPromise, screenConfigurationPromise]; // bcm provider when removed, can break the promise array; hence bcmConfigPromise removed - SW00531904 $q.all(promises) .then(onPeopleRelationsLoaded) .finally(function () { var temp = _.find($scope.metadata.assetTypes, { 'name': $scope.asset.type }); if ($scope.asset.extensionAttrs.primaryCapability) { screenConfigurationModel.loadDynamicSelectionFieldLabels(EntityVO.TYPE_ASSET, 'SHR:SDF:AST-Capabilities', $scope.asset.extensionAttrs.primaryCapability, null, null, null, null, true).then(function (response) { $scope.asset.extensionAttrs.primaryCapability = _.find(response.items, function (item) { return item.value === $scope.asset.extensionAttrs.primaryCapability; }); $scope.asset.extensionAttrs.primaryCapability.name = $scope.asset.extensionAttrs.primaryCapability.value; }); } $scope.metadata.allCategories = $scope.metadata.categories; $scope.asset.allCategories = categoriesService.populateCategories($scope.asset.product.categorizations, $scope.metadata); $scope.asset.noCategories = (_.filter($scope.asset.allCategories, 'valueToShow')).length; $scope.asset.typeLabel = temp.label; $scope.asset.subTypeLabel = _.result(_.find(temp.subType, function (item) { return item.name.toUpperCase() === $scope.asset.subType.toUpperCase(); }), 'label'); configureMoreActions(); initDirtyFormAlert(); }); }; $scope.handleFileChange = function (fileInput) { //TODO: create ng-upload directive, which will be handling file inputs, to get rid of input class hardcoding var query = 'classId=' + $scope.asset.classId; attachmentService.uploadProfileThumbnail($scope.asset.reconciliationId, 'asset', fileInput, query) .then(function (response) { if (response.thumbnail) { $scope.asset.thumbnail = response.thumbnail; } }) .finally(function () { $scope.state.uploadingThumbnail = false; }); }; $scope.showEditStatusDialog = function () { var editStatusModal = $modal.open({ templateUrl: 'views/asset/asset-edit-status-blade.html', windowClass: 'action-blade', controller: 'AssetEditStatusController', backdrop: 'custom' }); editStatusModal.result.then(function () { $scope.$emit(events.ASSET_DETAILS_CHANGED, { eventName: events.REFRESH_ACTIVITY_FEED }); }); }; $scope.showPersonDetails = function (person, $event) { if ($event && 'href' in $event.target) { return; } if (isPeopleType(person)) { $state.go(EntityVO.TYPE_PERSON, { id: person.id.replace(/\\\\/g, '\\') }); } }; $scope.isPeopleType = function (person) { return isPeopleType(person); }; $scope.updateAssetOwner = function (updatedData) { if (updatedData.relationData.id && !(updatedData.relationData.id === assetModel.assetPrimaryContact.displayId && updatedData.relationData.relationshipType === assetModel.assetPrimaryContact.relationshipType)) { $scope.state.isAssetDataLoading = true; relationModel.addRelation({ type: 'asset', uuid: $scope.asset.reconciliationId }, [updatedData.relationData]) .then(function () { // If new owner is added successfully, remove the old one if it exist if (assetModel.assetPrimaryContact.id) { var persondata = { id: assetModel.assetPrimaryContact.id, parentId: assetModel.assetPrimaryContact.parentId, type: assetModel.assetPrimaryContact.type, relationshipType: assetModel.assetPrimaryContact.relationshipType }; assetModel.removePeople(persondata).then(function () { assetModel.refreshPeopleRelations(assetModel.assetId) .then(onPeopleRelationsLoaded) .catch(function (error) { if (error) { systemAlertService.error({ text: error.data.error, clear: false }); } }).finally(function () { $scope.state.isAssetDataLoading = false; }); }).catch(function (error) { $scope.state.isAssetDataLoading = false; if (error) { systemAlertService.error({ text: error.data.error, clear: false }); } }); } else { assetModel.getPeopleRelations(assetModel.assetId) .then(onPeopleRelationsLoaded) .catch(function (error) { if (error) { systemAlertService.error({ text: error.data.error, clear: false }); } }).finally(function () { $scope.state.isAssetDataLoading = false; }); } }).catch(function (updateAssetOwnerError) { $scope.state.isAssetDataLoading = false; if (updateAssetOwnerError) { systemAlertService.error({ text: updateAssetOwnerError.data.error, clear: false }); } }); } else if (!updatedData.relationData.id && assetModel.assetPrimaryContact.id) { $scope.state.isAssetDataLoading = true; var persondata = { id: assetModel.assetPrimaryContact.id, parentId: assetModel.assetPrimaryContact.parentId, type: assetModel.assetPrimaryContact.type, relationshipType: assetModel.assetPrimaryContact.relationshipType }; assetModel.removePeople(persondata).then(function () { assetModel.refreshPeopleRelations(assetModel.assetId) .then(function () { onPeopleRelationsLoaded(); systemAlertService.success({ text: $filter('i18n')('asset.details.people.removePeople.successMessage'), hide: 10000 }); }).catch(function (error) { if (error) { systemAlertService.error({ text: error.data.error, clear: false }); } }).finally(function () { $scope.state.isAssetDataLoading = false; }); }).catch(function (updateAssetOwnerError) { $scope.state.isAssetDataLoading = false; if (updateAssetOwnerError) { systemAlertService.error({ text: updateAssetOwnerError.data.error, clear: false }); } }); } if (assetModel.assetDetails.site.name !== updatedData.siteData.name) { $scope.state.isAssetDataLoading = true; var sitesUpdate = { siteRegion: updatedData.siteData.region, siteGroup: updatedData.siteData.siteGroup, siteName: updatedData.siteData.name }; assetModel.update(sitesUpdate) .then(function (data) { $scope.state.isAssetDataLoading = false; assetModel.updateCacheAssetDetails(data); if (data.needsReconciliation) { systemAlertService.warning({ text: $filter('i18n')('asset.reconWarning'), hide: 10000 }); } }) .catch(function (updateSiteError) { $scope.state.isAssetDataLoading = false; if (updateSiteError) { systemAlertService.error({ text: updateSiteError.data.error, clear: false }); } return $q.reject(updateSiteError); }); } }; $scope.addRelatedPeople = function ($event) { var modalInstance = $modal.open({ templateUrl: 'views/asset/relate-people.html', windowClass: 'action-blade', controller: 'RelatePeopleController', backdrop: 'custom' }); modalInstance.result.then(function (response) { $scope.state.isPersonRelationsLoading = true; assetModel.refreshPeopleRelations(assetModel.assetId) .then(function () { $scope.assetRelations = assetModel.assetRelations; $scope.assetPeopleRelations = assetModel.assetPeopleRelations; if (!response || !response.error) { systemAlertService.success({ text: $filter('i18n')('asset.details.people.addPeople.successMessage'), hide: 10000 }); } }).catch(function (error) { if (error) { systemAlertService.error({ text: error.data.error, clear: false }); } return $q.reject(error); }).finally(function () { $scope.state.isPersonRelationsLoading = false; }); if ($event && $event.currentTarget) { $event.currentTarget.focus(); } }, function () { if ($event && $event.currentTarget) { $event.currentTarget.focus(); } }); }; /** * Removes the people relationship * @param person */ $scope.removePeople = function (person) { var modalInstance = systemAlertService.modal({ title: $filter('i18n')('common.notification.delete.title'), text: $filter('i18n')('common.notification.delete.message'), buttons: [ { text: $filter('i18n')('controls.action.ok'), data: true }, { text: $filter('i18n')('controls.action.cancel'), data: false } ] }); modalInstance.result.then(function (data) { if (data) { $scope.state.isPersonRelationsLoading = true; var persondata = { id: person.id, parentId: person.parentId, type: person.type, relationshipType: person.relationshipType }; assetModel.removePeople(persondata).then(function () { assetModel.refreshPeopleRelations(assetModel.assetId) .then(function () { $scope.assetRelations = assetModel.assetRelations; $scope.assetPeopleRelations = assetModel.assetPeopleRelations; systemAlertService.success({ text: $filter('i18n')('asset.details.people.removePeople.successMessage'), hide: 10000 }); }).catch(function (error) { if (error) { systemAlertService.error({ text: error.data.error, clear: false }); } }).finally(function () { $scope.state.isPersonRelationsLoading = false; }); }); } }); }; $scope.openLaunchActionBlade = function (actionItem) { var modalInstance = $modal.open({ templateUrl: 'views/asset/asset-launch-action-blade.html', controller: 'AssetLaunchActionController', windowClass: 'action-blade', backdrop: 'custom', size: 'lg', resolve: { linkParams: function () { return { selectedItem: [$scope.asset], actionItem: actionItem }; } } }); modalInstance.result.then(function (response) { if (response && response[$scope.asset.reconciliationId]) { var refreshAssetDetails = false; _.forEach(response[$scope.asset.reconciliationId], function (data) { if (data.additionalInformation && data.additionalInformation.subActionName === 'peopleRelation') { peopleRefreshRequired = true; } else if (data.additionalInformation && data.additionalInformation.subActionName === 'assetRelation' || data.additionalInformation.subActionName === 'assetUpdate') { refreshAssetDetails = true; } }); if (peopleRefreshRequired && !refreshAssetDetails) { $scope.state.isPersonRelationsLoading = true; assetModel.refreshPeopleRelations($scope.asset.reconciliationId) .then(onPeopleRelationsLoaded) .finally(function () { $scope.state.isPersonRelationsLoading = false; peopleRefreshRequired = false; }); } else if (refreshAssetDetails) { $scope.init(assetModel.assetId, assetModel.assetClassId); } } }); }; function onPeopleRelationsLoaded() { $scope.assetPeopleRelations = assetModel.assetPeopleRelations; if (_.isEmpty(assetModel.assetPrimaryContact)) { $scope.asset.owner = {}; $scope.assetOwner = {}; } else if (_.isEmpty($scope.asset.owner) || $scope.asset.owner.id !== assetModel.assetPrimaryContact.id || $scope.asset.owner.relationshipType !== assetModel.assetPrimaryContact.relationshipType) { var owner = assetModel.assetPrimaryContact; $scope.asset.owner = angular.copy(assetModel.assetPrimaryContact); var primaryContact_1 = angular.copy(assetModel.assetPrimaryContact); //todo: need to use loginid when backend returns it if (owner.id) { assetModel.getAssetOwnerDetails(owner.id).then(function () { $scope.assetOwner = assetModel.assetOwner; $scope.assetOwnerNoAccess = !$scope.assetOwner.loginId; primaryContact_1.content = $scope.assetOwner; delete primaryContact_1.realObject; $scope.$emit(events.ADD_CUSTOMER_FROM_ASSET, primaryContact_1); }); } } } function onAssetDetailsLoaded() { $scope.asset = assetModel.assetDetails; assetModel.assetDetails.outageResourceAvailable = 1; if ($scope.asset && !_.isEmpty($scope.asset.customFields)) { $scope.customFieldsAvailable = true; } if ($scope.asset.isPoi) { if ($scope.asset.poiInfo.owner) { assetModel.getPoiOwnerDetails($scope.asset.poiInfo.owner).then(function () { $scope.poiOwner = assetModel.poiOwner; $scope.poiOwnerNoAccess = !$scope.poiOwner.loginId; }); } if ($scope.asset.poiInfo.floorMapId) { $scope.poiFloorMap = '/../smartit/rest/getfile/locationFloorMap/' + $scope.asset.poiInfo.floorMapId; } if (googleMapService.isAvailable && $scope.asset.poiId) { $scope.poiLocationLink = '#/location/' + $scope.asset.poiId; } } $scope.$emit(events.ASSET_DETAILS_LOADED, { asset: assetModel.assetDetails }); } function onFlattenRelationsLoaded() { $scope.assetFlattenRelations = assetModel.flattenRelations; } function onDataLoadComplete() { $scope.state.isAssetDataLoading = false; } function isPeopleType(person) { return person.realObject.reqType === EntityVO.TYPE_PEOPLE; } function handleToggleEditMode() { $scope.dirty = true; } function handleEditComplete() { $scope.dirty = false; } function handleShowTypeSpecificArea(event, data) { $scope.customFieldsAvailable = true; if (data.typeSpecific) { $scope.typeSpecificCustomFieldsAvailable = true; } } $scope.$on(events.PROFILE_EDIT_HEADER, function (event, value) { $scope.editHeader = value; }); $scope.$on(events.TOGGLE_EDIT_MODE, handleToggleEditMode); $scope.$on(events.EDIT_COMPLETE, handleEditComplete); $scope.$on(events.TS_CUSTOM_FIELDS_AVAILABLE, handleShowTypeSpecificArea); } ]); })();