remove code duplicated from drop down directive

pull/3701/head
Jens Ulferts 9 years ago
parent d641e44d24
commit dd0eaf23d4
  1. 16
      frontend/app/components/inplace-edit/directives/field-edit/edit-type/edit-type.directive.html
  2. 84
      frontend/app/components/inplace-edit/directives/field-edit/edit-type/edit-type.directive.js

@ -1,15 +1,3 @@
<div class="dropdown-wrapper">
<label
class="hidden-for-sighted"
for="inplace-edit--write-value--{{::field.name}}">
{{::field.getLabel()}}
</label>
<select
ng-disabled="fieldController.state.isBusy"
ng-model="field.value.props"
title="{{ fieldController.editTitle }}"
class="inplace-edit-select"
id="inplace-edit--write-value--{{::field.name}}"
ng-options="option as option.name for option in customEditorController.allowedValues track by option.hrefTracker">
</select>
<div class="type-wrapper">
<inplace-editor-drop-down></inplace-editor-drop-down>
</div>

@ -39,24 +39,7 @@ function inplaceEditorType(EditableFieldsState, FocusHelper, WorkPackageService)
templateUrl: '/components/inplace-edit/directives/field-edit/edit-type/' +
'edit-type.directive.html',
controller: InplaceEditorTypeController,
controllerAs: 'customEditorController',
link: function(scope, element, attrs, fieldController) {
var field = scope.field;
fieldController.state.isBusy = true;
scope.emptyField = !scope.field.isRequired();
scope.customEditorController.updateAllowedValues(field.name).then(function() {
fieldController.state.isBusy = false;
if (!EditableFieldsState.forcedEditState) {
EditableFieldsState.editAll.state || FocusHelper.focusUiSelect(element);
}
});
scope.$watch('field.value.props', function(newValue, oldValue) {
if (newValue.hrefTracker !== oldValue.hrefTracker) {
scope.$emit('form.updateRequired');
@ -66,70 +49,3 @@ function inplaceEditorType(EditableFieldsState, FocusHelper, WorkPackageService)
};
}
inplaceEditorType.$inject = ['EditableFieldsState', 'FocusHelper', 'WorkPackageService'];
function InplaceEditorTypeController($q, $scope, I18n, WorkPackageFieldConfigurationService) {
this.allowedValues = [];
this.updateAllowedValues = function(field) {
var customEditorController = this;
return $q(function(resolve) {
$scope.field.getAllowedValues()
.then(function(values) {
var sorting = WorkPackageFieldConfigurationService
.getDropdownSortingStrategy(field);
if (sorting !== null) {
values = _.sortBy(values, sorting);
}
if (!$scope.field.isRequired()) {
values = addEmptyOption(values);
}
addHrefTracker(values);
customEditorController.allowedValues = values;
resolve();
});
});
};
var addEmptyOption = function(values) {
var emptyOption = { props: { href: null,
name: $scope.field.placeholder } };
if (!$scope.field.isRequired()) {
var arrayWithEmptyOption = [emptyOption.props];
values = arrayWithEmptyOption.concat(values);
if ($scope.field.value === null) {
$scope.field.value = emptyOption;
}
}
return values;
};
// We have to maintain a separate property just to track the object by
// in the template. This is due to angular aparently not being able to
// track correclty with a field having null as it's value. It does work for
// 'null' (String) however.
var addHrefTracker = function(values) {
_.forEach(values, function(value) {
value.hrefTracker = String(value.href);
});
$scope.field.value.props.hrefTracker = String($scope.field.value.props.href);
};
}
InplaceEditorTypeController.$inject = [
'$q',
'$scope',
'I18n',
'WorkPackageFieldConfigurationService'];

Loading…
Cancel
Save