kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
6.3 KiB
194 lines
6.3 KiB
9 years ago
|
// -- copyright
|
||
|
// OpenProject is a project management system.
|
||
|
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
|
// ++
|
||
|
|
||
9 years ago
|
function inplaceEditorEditPane($timeout, EditableFieldsState, FocusHelper, inplaceEditAll) {
|
||
9 years ago
|
return {
|
||
|
transclude: true,
|
||
9 years ago
|
require: '^wpField',
|
||
|
templateUrl: '/components/inplace-edit/edit-pane/edit-pane.directive.html',
|
||
9 years ago
|
|
||
9 years ago
|
controllerAs: 'editPaneController',
|
||
|
controller: InplaceEditorEditPaneController,
|
||
9 years ago
|
|
||
9 years ago
|
link: function(scope, element, attrs, fieldController) {
|
||
9 years ago
|
var field = scope.field;
|
||
9 years ago
|
|
||
9 years ago
|
scope.fieldSchema = field.getFieldSchema();
|
||
9 years ago
|
scope.fieldController = fieldController;
|
||
|
scope.editableFieldsState = EditableFieldsState;
|
||
|
|
||
|
scope.focusInput = function() {
|
||
|
$timeout(function() {
|
||
|
var inputElement = element.find('.focus-input');
|
||
|
FocusHelper.focus(inputElement);
|
||
|
inputElement.triggerHandler('keyup');
|
||
|
scope.editPaneController.markActive();
|
||
|
inputElement.off('focus.inplace').on('focus.inplace', function() {
|
||
|
scope.$apply(function() {
|
||
|
scope.editPaneController.markActive();
|
||
9 years ago
|
});
|
||
|
});
|
||
9 years ago
|
});
|
||
|
};
|
||
9 years ago
|
|
||
9 years ago
|
if (!inplaceEditAll.state) {
|
||
9 years ago
|
element.bind('keydown keypress', function(e) {
|
||
9 years ago
|
if (e.keyCode === 27) {
|
||
9 years ago
|
scope.$apply(function() {
|
||
|
scope.editPaneController.discardEditing();
|
||
9 years ago
|
});
|
||
|
}
|
||
9 years ago
|
});
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
scope.$watch('fieldController.isEditing', function(isEditing) {
|
||
9 years ago
|
if (isEditing && !inplaceEditAll.state) {
|
||
9 years ago
|
scope.focusInput();
|
||
9 years ago
|
|
||
9 years ago
|
} else if (inplaceEditAll.state && EditableFieldsState.isFocusField(field.name)) {
|
||
9 years ago
|
$timeout(function () {
|
||
|
var focusElement = element.find('.focus-input');
|
||
|
focusElement.length && focusElement.focus()[0].select();
|
||
|
});
|
||
9 years ago
|
}
|
||
9 years ago
|
});
|
||
|
}
|
||
|
};
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
function InplaceEditorEditPaneController($scope,
|
||
|
$element,
|
||
|
$location,
|
||
|
$timeout,
|
||
|
EditableFieldsState,
|
||
|
inplaceEditStorage,
|
||
|
inplaceEditMultiStorage,
|
||
|
inplaceEditErrors,
|
||
|
I18n,
|
||
|
inplaceEditAll) {
|
||
9 years ago
|
|
||
9 years ago
|
var vm = this;
|
||
9 years ago
|
var field = $scope.field;
|
||
9 years ago
|
var fieldLabel = field.getLabel();
|
||
9 years ago
|
var wpStore = inplaceEditMultiStorage.stores.workPackage;
|
||
9 years ago
|
|
||
9 years ago
|
this.saveTitle = I18n.t('js.inplace.button_save', { attribute: fieldLabel });
|
||
|
this.cancelTitle = I18n.t('js.inplace.button_cancel', { attribute: fieldLabel });
|
||
9 years ago
|
|
||
9 years ago
|
this.submit = function() {
|
||
9 years ago
|
var detectedViolations = [];
|
||
9 years ago
|
|
||
9 years ago
|
if (vm.editForm.$invalid) {
|
||
9 years ago
|
Object.keys(vm.editForm.$error).forEach(function(error) {
|
||
|
|
||
9 years ago
|
if (vm.editForm.$error[error]) {
|
||
9 years ago
|
var localizationArgs = _.extend({ field: field.getLabel() }, field.getFieldSchema());
|
||
|
detectedViolations.push(I18n.t('js.inplace.errors.' + error, localizationArgs));
|
||
9 years ago
|
}
|
||
|
});
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
if (detectedViolations.length) {
|
||
9 years ago
|
inplaceEditErrors.errors = inplaceEditErrors.errors || {};
|
||
|
inplaceEditErrors.errors[field.name] = detectedViolations.join(' ');
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
inplaceEditMultiStorage.save().then(function () {
|
||
|
$location.hash(null);
|
||
|
$timeout(function() {
|
||
|
$element[0].scrollIntoView(false);
|
||
|
});
|
||
|
|
||
|
}).catch(function () {
|
||
|
$scope.focusInput();
|
||
|
});
|
||
9 years ago
|
};
|
||
9 years ago
|
|
||
9 years ago
|
this.discardEditing = function() {
|
||
9 years ago
|
$scope.fieldController.isEditing = false;
|
||
9 years ago
|
EditableFieldsState.discard(field.name);
|
||
9 years ago
|
};
|
||
9 years ago
|
|
||
9 years ago
|
this.isActive = function() {
|
||
9 years ago
|
return EditableFieldsState.isActiveField(field.name);
|
||
9 years ago
|
};
|
||
9 years ago
|
|
||
9 years ago
|
this.markActive = function() {
|
||
9 years ago
|
wpStore.active = true;
|
||
9 years ago
|
EditableFieldsState.currentField = field.name;
|
||
9 years ago
|
};
|
||
9 years ago
|
|
||
9 years ago
|
this.isRequired = function() {
|
||
|
return field.isRequired();
|
||
|
};
|
||
|
|
||
9 years ago
|
$scope.inplaceEditAll = inplaceEditAll;
|
||
|
|
||
|
$scope.$watch('inplaceEditAll.state', function(state) {
|
||
9 years ago
|
$scope.fieldController.isEditing = state;
|
||
|
$scope.fieldController.lockFocus = true;
|
||
|
});
|
||
9 years ago
|
|
||
|
$scope.$watch('field.value', function(value) {
|
||
|
if ($scope.fieldController.isEditing) {
|
||
|
var pendingChanges = EditableFieldsState.getPendingFormChanges();
|
||
|
pendingChanges[field.name] = value;
|
||
|
vm.markActive();
|
||
|
}
|
||
|
}, true);
|
||
|
|
||
|
$scope.$watchCollection('field.resource.form', function(form) {
|
||
|
var strategy = field.getInplaceEditStrategy();
|
||
|
|
||
|
if (field.name === 'date' && strategy === 'date') {
|
||
9 years ago
|
//noinspection TypeScriptUnresolvedVariable
|
||
9 years ago
|
form.pendingChanges = EditableFieldsState.getPendingFormChanges();
|
||
|
form.pendingChanges['startDate'] =
|
||
|
form.pendingChanges['dueDate'] =
|
||
|
field.value ? field.value['dueDate'] : null;
|
||
|
}
|
||
|
|
||
|
if (strategy !== $scope.strategy) {
|
||
|
$scope.strategy = strategy;
|
||
9 years ago
|
$scope.templateUrl = '/components/inplace-edit/field-templates/edit/' + strategy + '.html';
|
||
9 years ago
|
}
|
||
|
});
|
||
|
|
||
|
$scope.$on('form.updateRequired', function() {
|
||
9 years ago
|
inplaceEditStorage.refreshWorkPackageForm();
|
||
9 years ago
|
});
|
||
|
|
||
|
$scope.$on('workPackageRefreshed', function() {
|
||
|
vm.discardEditing();
|
||
|
});
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
angular
|
||
|
.module('openproject.inplace-edit')
|
||
|
.directive('inplaceEditorEditPane', inplaceEditorEditPane);
|