87 lines
4.0 KiB
JavaScript
87 lines
4.0 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by viktor.shevchenko on 2/13/2015.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.directive('foundationSelector', ['events', 'foundationService',
|
|
function (events, foundationService) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
templateUrl: 'views/common/foundation-selector.html',
|
|
scope: {
|
|
type: '@',
|
|
inline: '=',
|
|
typeaheadMode: '=',
|
|
useChunking: '=',
|
|
multiple: '=',
|
|
options: '=',
|
|
selectedFoundations: '=',
|
|
isEditable: '=?',
|
|
isRequired: '=?',
|
|
isFullWidth: '=?'
|
|
},
|
|
controller: 'FoundationSelectorController',
|
|
link: function ($scope, element) {
|
|
if ($scope.isFullWidth) {
|
|
$scope.fieldLengthForSm4 = true;
|
|
}
|
|
if ($scope.$parent.$parent.isNew) {
|
|
$scope.fieldLengthForSm6 = true;
|
|
}
|
|
else {
|
|
if (element.closest(".layout-renderer__child-column")[0]) {
|
|
$scope.fieldLengthForSm6 = _.includes(element.closest(".layout-renderer__child-column")[0].className, 'col-sm-6');
|
|
$scope.fieldLengthForSm4 = _.includes(element.closest(".layout-renderer__child-column")[0].className, 'col-sm-4');
|
|
}
|
|
}
|
|
if (!_.isBoolean($scope.isEditable)) {
|
|
$scope.isEditable = true;
|
|
}
|
|
$scope.focusInputElement = function ($event) {
|
|
$($event.currentTarget).parent().focus();
|
|
};
|
|
$scope.focusFirstInputElement = function ($event) {
|
|
$($event.currentTarget).parents('.fd-selector').children().first().find('.dropdown-input__button').focus();
|
|
};
|
|
function populateFields() {
|
|
if (!$scope.multiple && $scope.selectedFoundations) {
|
|
_.forEach($scope.fdSelector.fdFields, function (field) {
|
|
field.value = $scope.selectedFoundations[field.attribute];
|
|
});
|
|
}
|
|
}
|
|
populateFields();
|
|
$scope.focusNextInputElement = function ($event) {
|
|
var nextElement = $($event.currentTarget).parents('.dropdown').next();
|
|
if (nextElement.hasClass('dropdown')) {
|
|
nextElement.find('.dropdown-input__button').focus();
|
|
}
|
|
else {
|
|
nextElement.find('button').focus();
|
|
}
|
|
};
|
|
$scope.$watch('selectedFoundations', function (newValue) {
|
|
if (newValue) {
|
|
populateFields();
|
|
}
|
|
});
|
|
function refreshFields(event, company) {
|
|
if ($scope.selectedFoundations.companyName !== company.name) {
|
|
$scope.selectedFoundations.companyName = company.name;
|
|
_.forEach($scope.fdSelector.fdFields, function (field) {
|
|
field.value = field.name === 'company' ? $scope.selectedFoundations[field.attribute] : null;
|
|
});
|
|
if (!$scope.multiple) {
|
|
$scope.selectedFoundations = foundationService.collectValues($scope.fdSelector);
|
|
}
|
|
}
|
|
}
|
|
$scope.$on(events.CLEAR_FOUNDATION_SERVICE, refreshFields);
|
|
}
|
|
};
|
|
}]);
|
|
}());
|