"use strict"; (function () { 'use strict'; angular.module('customWidgetsModule').directive('emailField', ['customFieldLinkFunction', 'events', 'objectValueMapperService', function (customFieldLinkFunction, events, objectValueMapperService) { return { restrict: 'E', replace: true, scope: { data: '=', isEditable: '=', ticket: '=' }, templateUrl: 'views/custom-widgets/email-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]; } scope.$watch('data.setValueFlag', function (value) { if (value && value !== '#$#') { scope.data.ootbValue = value; scope.onFieldValueChange(); scope.data.setValueFlag = '#$#'; } }); scope.onFieldValueChange = function () { var emailField = objectValueMapperService.getFieldByName(scope.data.name); emailField.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 emailField = objectValueMapperService.getFieldByName(scope.data.name); emailField.value[ootbKey] = scope.data.ootbValue; }); } }; }]); }());