From b49e851facfbf234e4daf3768049795b066d284d Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Tue, 8 Dec 2015 17:32:37 +0100 Subject: [PATCH] Remove forcedEditState flag --- .../directives/edit-pane/edit-pane.directive.js | 6 +++--- .../edit-drop-down/edit-drop-down.directive.js | 4 ++-- .../work-package-field/work-package-field.directive.js | 4 ++-- .../services/editable-fields-state.service.js | 9 ++++----- .../routes/controllers/work-package-show.controller.js | 3 +-- .../work-package-comment.directive.js | 10 +++++----- .../controllers/details-tab-overview-controller.js | 3 --- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/frontend/app/components/inplace-edit/directives/edit-pane/edit-pane.directive.js b/frontend/app/components/inplace-edit/directives/edit-pane/edit-pane.directive.js index 183aafae2d..ff56743bc2 100644 --- a/frontend/app/components/inplace-edit/directives/edit-pane/edit-pane.directive.js +++ b/frontend/app/components/inplace-edit/directives/edit-pane/edit-pane.directive.js @@ -59,9 +59,9 @@ function inplaceEditorEditPane($timeout, EditableFieldsState, FocusHelper, inpla }); }; - if (!EditableFieldsState.forcedEditState) { + if (!inplaceEditAll.state) { element.bind('keydown keypress', function(e) { - if (e.keyCode === 27 && !inplaceEditAll.state) { + if (e.keyCode === 27) { scope.$apply(function() { scope.editPaneController.discardEditing(); }); @@ -70,7 +70,7 @@ function inplaceEditorEditPane($timeout, EditableFieldsState, FocusHelper, inpla } scope.$watch('fieldController.isEditing', function(isEditing) { - if (isEditing && !inplaceEditAll.state && !EditableFieldsState.forcedEditState) { + if (isEditing && !inplaceEditAll.state) { scope.focusInput(); } else if (inplaceEditAll.state && EditableFieldsState.isFocusField(field.name)) { diff --git a/frontend/app/components/inplace-edit/directives/field-edit/edit-drop-down/edit-drop-down.directive.js b/frontend/app/components/inplace-edit/directives/field-edit/edit-drop-down/edit-drop-down.directive.js index add2d9f037..4b05cf92df 100644 --- a/frontend/app/components/inplace-edit/directives/field-edit/edit-drop-down/edit-drop-down.directive.js +++ b/frontend/app/components/inplace-edit/directives/field-edit/edit-drop-down/edit-drop-down.directive.js @@ -52,8 +52,8 @@ function inplaceEditorDropDown(EditableFieldsState, FocusHelper, inplaceEditAll) scope.customEditorController.updateAllowedValues(field.name).then(function() { EditableFieldsState.isBusy = false; - if (!EditableFieldsState.forcedEditState) { - inplaceEditAll.state || FocusHelper.focusUiSelect(element); + if (!inplaceEditAll.state) { + FocusHelper.focusUiSelect(element); } }); } diff --git a/frontend/app/components/inplace-edit/directives/work-package-field/work-package-field.directive.js b/frontend/app/components/inplace-edit/directives/work-package-field/work-package-field.directive.js index 074ee2069c..4c4d82665c 100644 --- a/frontend/app/components/inplace-edit/directives/work-package-field/work-package-field.directive.js +++ b/frontend/app/components/inplace-edit/directives/work-package-field/work-package-field.directive.js @@ -46,7 +46,7 @@ function workPackageField() { }; } -function WorkPackageFieldController($scope, EditableFieldsState, inplaceEditForm) { +function WorkPackageFieldController($scope, EditableFieldsState, inplaceEditForm, inplaceEditAll) { var workPackage = EditableFieldsState.workPackage; this.state = EditableFieldsState; $scope.field = inplaceEditForm.getForm(workPackage.props.id, workPackage).field(this.fieldName); @@ -55,7 +55,7 @@ function WorkPackageFieldController($scope, EditableFieldsState, inplaceEditForm if (field.isEditable()) { this.state.isBusy = false; - this.isEditing = this.state.forcedEditState; + this.isEditing = inplaceEditAll.state; this.editTitle = I18n.t('js.inplace.button_edit', { attribute: field.getLabel() }); } } diff --git a/frontend/app/components/inplace-edit/services/editable-fields-state.service.js b/frontend/app/components/inplace-edit/services/editable-fields-state.service.js index 56d098141c..90f6087685 100644 --- a/frontend/app/components/inplace-edit/services/editable-fields-state.service.js +++ b/frontend/app/components/inplace-edit/services/editable-fields-state.service.js @@ -38,24 +38,23 @@ function EditableFieldsState(inplaceEditErrors, inplaceEditAll) { errors: inplaceEditErrors.errors, isBusy: false, currentField: null, - forcedEditState: false, focusField: 'subject', isFocusField: function (field) { - return this.focusField === field; + return EditableFieldsState.focusField === field; }, isActiveField: function (field) { - return !(this.forcedEditState || inplaceEditAll.state) && this.currentField === field; + return !inplaceEditAll.state && EditableFieldsState.currentField === field; }, getPendingFormChanges: function () { - var form = this.workPackage.form; + var form = EditableFieldsState.workPackage.form; return form.pendingChanges = form.pendingChanges || angular.copy(form.embedded.payload.props); }, discard: function (fieldName) { - delete this.getPendingFormChanges()[fieldName]; + delete EditableFieldsState.getPendingFormChanges()[fieldName]; if (inplaceEditErrors.errors && inplaceEditErrors.hasOwnProperty(fieldName)) { delete inplaceEditErrors.errors[fieldName]; diff --git a/frontend/app/components/routes/controllers/work-package-show.controller.js b/frontend/app/components/routes/controllers/work-package-show.controller.js index 30ae77f640..df55adbd9f 100644 --- a/frontend/app/components/routes/controllers/work-package-show.controller.js +++ b/frontend/app/components/routes/controllers/work-package-show.controller.js @@ -277,7 +277,6 @@ function WorkPackageShowController($scope, $rootScope, $state, latestTab, workPa }); function activate() { - EditableFieldsState.forcedEditState = false; $scope.$watch('workPackage.schema', function(schema) { if (schema) { WorkPackagesDisplayHelper.setFocus(); @@ -286,7 +285,7 @@ function WorkPackageShowController($scope, $rootScope, $state, latestTab, workPa }); vm.groupedFields = WorkPackagesOverviewService.getGroupedWorkPackageOverviewAttributes(); - $scope.$watchCollection('vm.workPackage.form', function(form) { + $scope.$watchCollection('vm.workPackage.form', function() { var schema = WorkPackageFieldService.getSchema(vm.workPackage); var otherGroup = _.find(vm.groupedFields, {groupName: 'other'}); otherGroup.attributes = []; diff --git a/frontend/app/components/work-packages/directives/work-package-comment/work-package-comment.directive.js b/frontend/app/components/work-packages/directives/work-package-comment/work-package-comment.directive.js index d570edf546..3cf2fc541f 100644 --- a/frontend/app/components/work-packages/directives/work-package-comment/work-package-comment.directive.js +++ b/frontend/app/components/work-packages/directives/work-package-comment/work-package-comment.directive.js @@ -30,8 +30,8 @@ angular .module('openproject.workPackages.directives') .directive('workPackageComment', workPackageComment); -function workPackageComment($rootScope, $timeout, $location, EditableFieldsState, FocusHelper, I18n, - inplaceEditMultiStorage, ConfigurationService, AutoCompleteHelper, NotificationsService) { +function workPackageComment($timeout, $location, EditableFieldsState, FocusHelper, + inplaceEditMultiStorage, ConfigurationService, AutoCompleteHelper, inplaceEditAll) { function commentFieldDirectiveController($scope, $element) { var field = {}, @@ -49,7 +49,7 @@ function workPackageComment($rootScope, $timeout, $location, EditableFieldsState ctrl.placeholder = I18n.t('js.label_add_comment_title'); ctrl.state.isBusy = false; - ctrl.isEditing = ctrl.state.forcedEditState; + ctrl.isEditing = inplaceEditAll.state; ctrl.isRequired = true; ctrl.canAddComment = !!ctrl.workPackage.links.addComment; @@ -113,7 +113,7 @@ function workPackageComment($rootScope, $timeout, $location, EditableFieldsState }; ctrl.isActive = function() { - if (EditableFieldsState.forcedEditState) { + if (inplaceEditAll.state) { return false; } return ctrl.field === EditableFieldsState.currentField; @@ -124,7 +124,7 @@ function workPackageComment($rootScope, $timeout, $location, EditableFieldsState EditableFieldsState.currentField = ctrl.field; }; - if (!EditableFieldsState.forcedEditState) { + if (!inplaceEditAll.state) { $element.bind('keydown keypress', function(e) { if (e.keyCode === 27) { $scope.$apply(function() { diff --git a/frontend/app/work_packages/controllers/details-tab-overview-controller.js b/frontend/app/work_packages/controllers/details-tab-overview-controller.js index 4f44f1b9b6..4ac87f59b8 100644 --- a/frontend/app/work_packages/controllers/details-tab-overview-controller.js +++ b/frontend/app/work_packages/controllers/details-tab-overview-controller.js @@ -33,10 +33,8 @@ module.exports = function( EditableFieldsState, WorkPackageDisplayHelper, NotificationsService, - I18n, WorkPackageAttachmentsService ) { - 'use strict'; var vm = this; vm.groupedFields = []; @@ -57,7 +55,6 @@ module.exports = function( }); function activate() { - EditableFieldsState.forcedEditState = false; $scope.$watch('workPackage.schema', function(schema) { if (schema) { WorkPackageDisplayHelper.setFocus();