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.
124 lines
4.3 KiB
124 lines
4.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.
|
||
|
// ++
|
||
|
|
||
7 years ago
|
import {WorkPackageEditFieldController} from './wp-edit-field.directive';
|
||
|
import {States} from '../../states.service';
|
||
|
import {opWorkPackagesModule} from '../../../angular-modules';
|
||
|
import {WorkPackageEditingService} from '../../wp-edit-form/work-package-editing-service';
|
||
|
import {WorkPackageEditForm} from '../../wp-edit-form/work-package-edit-form';
|
||
|
import {SingleViewEditContext} from '../../wp-edit-form/single-view-edit-context';
|
||
|
|
||
|
export class WorkPackageEditFieldGroupController {
|
||
|
public workPackageId:string;
|
||
|
public inEditMode:boolean;
|
||
|
public fields:{ [attribute:string]:WorkPackageEditFieldController } = {};
|
||
|
|
||
|
constructor(protected $scope:ng.IScope,
|
||
|
protected states:States,
|
||
|
protected wpEditing:WorkPackageEditingService,
|
||
|
protected $rootScope:ng.IRootScopeService,
|
||
|
protected $window:ng.IWindowService,
|
||
|
protected ConfigurationService:any,
|
||
|
protected $q:ng.IQService,
|
||
|
protected I18n:op.I18n) {
|
||
8 years ago
|
const confirmText = I18n.t('js.work_packages.confirm_edit_cancel');
|
||
8 years ago
|
const requiresConfirmation = ConfigurationService.warnOnLeavingUnsaved();
|
||
9 years ago
|
|
||
9 years ago
|
$rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {
|
||
8 years ago
|
// Show confirmation message when transitioning to a new state
|
||
8 years ago
|
// that's not withing the edit mode.
|
||
7 years ago
|
if (this.isEditing && !this.allowedStateChange(toState, toParams, fromState, fromParams)) {
|
||
8 years ago
|
if (requiresConfirmation && !$window.confirm(confirmText)) {
|
||
9 years ago
|
return event.preventDefault();
|
||
|
}
|
||
|
|
||
7 years ago
|
this.stop();
|
||
9 years ago
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
7 years ago
|
public $onInit() {
|
||
|
if (this.inEditMode) {
|
||
|
this.start();
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
public get isEditing() {
|
||
|
const form = this.editingForm;
|
||
|
return (form && form.editMode);
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public register(field:WorkPackageEditFieldController) {
|
||
|
this.fields[field.fieldName] = field;
|
||
|
const form = this.editingForm;
|
||
8 years ago
|
|
||
7 years ago
|
if (form && form.editMode) {
|
||
|
form.activate(field.fieldName, true);
|
||
9 years ago
|
}
|
||
7 years ago
|
}
|
||
9 years ago
|
|
||
7 years ago
|
public start() {
|
||
|
const form = this.wpEditing.startEditing(this.workPackageId, this.editContext, true);
|
||
|
_.each(this.fields, ctrl => form.activate(ctrl.fieldName));
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public stop() {
|
||
|
this.wpEditing.stopEditing(this.workPackageId);
|
||
|
}
|
||
9 years ago
|
|
||
7 years ago
|
private get editContext() {
|
||
|
return new SingleViewEditContext(this.workPackageId, this);
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
private get editingForm():WorkPackageEditForm | undefined {
|
||
|
const state = this.wpEditing.editState(this.workPackageId);
|
||
|
return state.value;
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
private allowedStateChange(toState:any, toParams:any, fromState:any, fromParams:any) {
|
||
8 years ago
|
|
||
|
// In new/copy mode, transitions to the same controller are allowed
|
||
|
if (fromState.name.match(/\.(new|copy)$/)) {
|
||
|
return fromState.controller === toState.controller;
|
||
|
}
|
||
|
|
||
|
// When editing an existing WP, transitions on the same WP id are allowed
|
||
|
return toParams.workPackageId !== undefined && toParams.workPackageId === fromParams.workPackageId;
|
||
|
}
|
||
9 years ago
|
}
|
||
|
|
||
7 years ago
|
opWorkPackagesModule.component('wpEditFieldGroup', {
|
||
|
controller: WorkPackageEditFieldGroupController,
|
||
|
controllerAs: '$fieldsCtrl',
|
||
|
bindings: {
|
||
|
workPackageId: '<',
|
||
|
inEditMode: '<?'
|
||
|
}
|
||
|
});
|
||
9 years ago
|
|