import * as InformationService from '../services/flightInformationService'; export interface IUpdateResonse { Success: boolean; Error: string; } export class BaseEditorController { public field: InformationService.IFlightInformation; public model: InformationService.IFlightInformationModel; public definition: InformationService.IFlightEditor; public instance: ionic.popup.IonicPopupPromise; public status: string; public error: string; public updateUrl: string; constructor(private $http: ng.IHttpService, private $rootScope: ng.IRootScopeService, private $timeout: ng.ITimeoutService, private api: any) { this.updateUrl = this.api.endpoint + this.definition.Url; } public updateValue(requestParams: any): void { if (this.status === 'E' || this.status === 'S' || this.updateUrl === '') { this.instance.close(); return; } this.status = 'P'; this.$http.post(this.updateUrl, requestParams).success((response: IUpdateResonse) => { this.handleUpdateResult(response, requestParams); this.$rootScope.$emit('chroma:flight-updated'); }); } private handleUpdateResult(response: IUpdateResonse, request: any): void { if ((response && response.Success) || (request.IsDelete && response)) { this.status = 'S'; this.$timeout(() => { this.instance.close(); }, 600); } else { this.status = 'E'; this.error = response.Error; } } }