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.
75 lines
2.3 KiB
75 lines
2.3 KiB
8 years ago
|
import {WorkPackageTable} from '../../wp-fast-table';
|
||
|
import {States} from '../../../states.service';
|
||
8 years ago
|
import {cellClassName, editableClassName} from '../../builders/cell-builder';
|
||
8 years ago
|
import {TableEventHandler} from '../table-events-registry';
|
||
|
import {injectorBridge} from '../../../angular/angular-injector-bridge.functions';
|
||
8 years ago
|
import {rowClassName} from '../../builders/row-builder';
|
||
|
import {WorkPackageEditForm} from '../../../wp-edit-form/work-package-edit-form';
|
||
|
import {State} from '../../../../helpers/reactive-fassade';
|
||
|
import {TableRowEditContext} from '../../../wp-edit-form/table-row-edit-context';
|
||
8 years ago
|
import {ClickOrEnterHandler} from '../click-or-enter-handler';
|
||
8 years ago
|
|
||
8 years ago
|
export class EditCellHandler extends ClickOrEnterHandler implements TableEventHandler {
|
||
8 years ago
|
// Injections
|
||
8 years ago
|
public states:States;
|
||
|
|
||
8 years ago
|
public get EVENT() {
|
||
|
return 'click.table.cell, keydown.table.cell';
|
||
|
}
|
||
|
|
||
|
public get SELECTOR() {
|
||
|
return `.${cellClassName}.${editableClassName}`;
|
||
|
}
|
||
|
|
||
8 years ago
|
constructor() {
|
||
8 years ago
|
super();
|
||
8 years ago
|
injectorBridge(this);
|
||
|
}
|
||
|
|
||
8 years ago
|
protected processEvent(table: WorkPackageTable, evt:JQueryEventObject) {
|
||
8 years ago
|
console.log('Start editing row!');
|
||
8 years ago
|
evt.preventDefault();
|
||
8 years ago
|
|
||
8 years ago
|
// Locate the cell from event
|
||
|
let target = jQuery(evt.target);
|
||
|
// Get the target field name
|
||
|
let fieldName = target.data('fieldName');
|
||
|
|
||
|
if (!fieldName) {
|
||
|
console.warn('Click handled by cell not a field?');
|
||
|
console.warn(target);
|
||
|
}
|
||
|
|
||
|
// Locate the row
|
||
|
let rowElement = target.closest(`.${rowClassName}`);
|
||
|
let row = table.rowObject(rowElement.data('workPackageId'));
|
||
|
|
||
|
// Get any existing edit state for this work package
|
||
|
let state = this.editState(row.workPackageId);
|
||
8 years ago
|
let form = state.getCurrentValue() || this.startEditing(state, row.workPackageId);
|
||
8 years ago
|
|
||
|
// Set editing context to table
|
||
8 years ago
|
form.editContext = new TableRowEditContext(rowElement, row);
|
||
8 years ago
|
|
||
|
// Activate the field
|
||
|
form.activate(fieldName);
|
||
8 years ago
|
|
||
|
return false;
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
private startEditing(state, workPackageId:number):WorkPackageEditForm {
|
||
|
let form = new WorkPackageEditForm(workPackageId);
|
||
8 years ago
|
state.put(form);
|
||
|
return form;
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
/**
|
||
|
* Retrieve the edit state for this work package
|
||
|
*/
|
||
|
private editState(workPackageId:number):State<WorkPackageEditForm> {
|
||
8 years ago
|
return this.states.editing.get(workPackageId.toString());
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
EditCellHandler.$inject = ['states'];
|