"use strict"; (function () { 'use strict'; angular.module('customWidgetsModule').directive('phoneField', ['customFieldLinkFunction', 'objectValueMapperService', 'events', function (customFieldLinkFunction, objectValueMapperService, events) { return { restrict: 'E', replace: true, scope: { data: '=', isEditable: '=' }, templateUrl: 'views/custom-widgets/phone-field.html', link: function (scope) { customFieldLinkFunction(scope); var ootbKey = scope.data.members.length ? scope.data.members[0].name : null; if (angular.isDefined(scope.data.value)) { scope.data.ootbValue = scope.data.value[ootbKey]; } setContactPhoneFieldProperty(); scope.$watch('data.setValueFlag', function (value) { if (value && value !== '#$#') { scope.data.ootbValue = value; scope.onFieldValueChange(); scope.data.setValueFlag = '#$#'; } }); scope.onFieldValueChange = function () { var phoneField = objectValueMapperService.getFieldByName(scope.data.name); phoneField.value[ootbKey] = scope.data.ootbValue; var members = []; if (scope.data.members) { _.forEach(scope.data.members, function (member) { members.push(member.name); }); } scope.$emit(events.WIDGET_VALUE_CHANGE, { fieldName: scope.data.name, memberName: members }); }; scope.$on(events.DISCARD_CHANGES, function () { scope.data.ootbValue = scope.data.value[ootbKey]; var phoneField = objectValueMapperService.getFieldByName(scope.data.name); phoneField.value[ootbKey] = scope.data.ootbValue; setContactPhoneFieldProperty(); }); function setContactPhoneFieldProperty() { if (scope.data.name === 'contactPhone') { var person = objectValueMapperService.getValueByFieldName('contact'); scope.data.isReadOnly = _.isEmpty(person.company) ? true : false; } } } }; }]); }());