mirror of
https://gitlab.silvrtree.co.uk/martind2000/aodb.git
synced 2025-02-10 23:39:16 +00:00
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import {controller, directive} from '../../../infrastructure/Dectorators/Components';
|
|
import * as InformationService from '../../services/flightInformationService';
|
|
import Mod from '../../flight-detail.mod';
|
|
import * as BaseEditor from '../baseEditor';
|
|
|
|
interface IFlightUpdateRequest {
|
|
Id: string;
|
|
NewValue: string;
|
|
Mapping: string;
|
|
IsDelete: Boolean;
|
|
}
|
|
|
|
@controller(Mod, 'freeTextEditorController', ['$http', '$rootScope', '$timeout', 'api'])
|
|
export class Controller extends BaseEditor.BaseEditorController {
|
|
public value: string;
|
|
public originalValue: string;
|
|
|
|
constructor($http: ng.IHttpService, $rootScope: ng.IRootScopeService, $timeout: ng.ITimeoutService, api: any, jquery: any) {
|
|
super($http, $rootScope, $timeout, api);
|
|
this.value = this.field.Value;
|
|
this.originalValue = this.value;
|
|
}
|
|
|
|
public update(): void {
|
|
if (this.valueNotChanged()) {
|
|
this.instance.close();
|
|
return;
|
|
}
|
|
|
|
if (this.definition.Url !== '') {
|
|
this.updateValue(this.createRequestParams());
|
|
} else {
|
|
this.field.Value = this.value;
|
|
this.instance.close();
|
|
}
|
|
}
|
|
|
|
private valueNotChanged() {
|
|
if (this.value === this.originalValue) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private createRequestParams(): IFlightUpdateRequest {
|
|
return {
|
|
Id: this.model.Flight.Id,
|
|
NewValue: this.value,
|
|
Mapping: this.field.Mapping,
|
|
IsDelete: this.originalValue && this.value === ''
|
|
};
|
|
}
|
|
}
|
|
|
|
@directive(Mod, 'chromaFreetextEditor')
|
|
export class Directive implements ng.IDirective {
|
|
controller: string = Controller.$componentName;
|
|
controllerAs: string = 'vm';
|
|
templateUrl: string = 'app/flight-detail/editors/freetext/freetext.tpl.html';
|
|
restrict: string = 'E';
|
|
replace: boolean = false;
|
|
bindToController: boolean = true;
|
|
scope: any = {
|
|
field: '=',
|
|
definition: '=',
|
|
instance: '=',
|
|
model: '='
|
|
};
|
|
}
|