Make escape cancel edition and restore pristine value

pull/4233/head
Oliver Günther 9 years ago
parent c6844255f9
commit c2d0828c98
  1. 1
      frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.directive.html
  2. 22
      frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.directive.ts

@ -1,6 +1,7 @@
<div ng-click="vm.isEditable && vm.activate()" class="wp-edit-field -small" <div ng-click="vm.isEditable && vm.activate()" class="wp-edit-field -small"
ng-class="{ '-error': vm.errorenous, '-active': vm.active }"> ng-class="{ '-error': vm.errorenous, '-active': vm.active }">
<form ng-if="vm.workPackage && vm.active" <form ng-if="vm.workPackage && vm.active"
name="vm.wpEditForm"
ng-submit="vm.submit()"> ng-submit="vm.submit()">
<ng-include src="vm.field.template"></ng-include> <ng-include src="vm.field.template"></ng-include>

@ -33,9 +33,11 @@ import {Field} from "./wp-edit-field.module";
export class WorkPackageEditFieldController { export class WorkPackageEditFieldController {
public formCtrl: WorkPackageEditFormController; public formCtrl: WorkPackageEditFormController;
public wpEditForm:ng.IFormController;
public fieldName:string; public fieldName:string;
public field:Field; public field:Field;
public errorenous:boolean; public errorenous:boolean;
protected pristineValue:any;
protected _active:boolean = false; protected _active:boolean = false;
@ -56,6 +58,7 @@ export class WorkPackageEditFieldController {
} }
public activate() { public activate() {
this.pristineValue = angular.copy(this.workPackage[this.fieldName]);
this.setupField().then(() => { this.setupField().then(() => {
this._active = this.field.schema.writable; this._active = this.field.schema.writable;
}); });
@ -74,6 +77,13 @@ export class WorkPackageEditFieldController {
this.$element.toggleClass('-error', error) this.$element.toggleClass('-error', error)
} }
public reset() {
this.workPackage[this.fieldName] = this.pristineValue;
this.wpEditForm.$setPristine();
this.deactivate();
this.pristineValue = null;
}
protected setupField():ng.IPromise<any> { protected setupField():ng.IPromise<any> {
return this.formCtrl.loadSchema().then(schema => { return this.formCtrl.loadSchema().then(schema => {
this.field = this.wpEditField.getField( this.field = this.wpEditField.getField(
@ -82,7 +92,12 @@ export class WorkPackageEditFieldController {
} }
} }
function wpEditFieldLink(scope, element, attrs, controllers:[WorkPackageEditFormController, WorkPackageEditFieldController]) { function wpEditFieldLink(
scope,
element,
attrs,
controllers: [WorkPackageEditFormController, WorkPackageEditFieldController],
$timeout) {
controllers[1].formCtrl = controllers[0]; controllers[1].formCtrl = controllers[0];
controllers[1].formCtrl.fields[scope.vm.fieldName] = scope.vm; controllers[1].formCtrl.fields[scope.vm.fieldName] = scope.vm;
@ -100,6 +115,11 @@ function wpEditFieldLink(scope, element, attrs, controllers:[WorkPackageEditForm
}) })
element.addClass(scope.vm.fieldName); element.addClass(scope.vm.fieldName);
element.keyup(event => {
if (event.keyCode === 27) {
$timeout(_ => scope.vm.reset());
}
})
} }
function wpEditField() { function wpEditField() {

Loading…
Cancel
Save