import { Injectable } from '@angular/core'; import { Http, RequestOptionsArgs, RequestMethod, Headers, Response } from '@angular/http'; import 'rxjs/add/operator/toPromise'; import { Observable } from 'rxjs'; import { HttpService } from './service-interface'; import { CoreRemoteRestURL } from '../utils/core-remote-rest-urls'; import { TranslateService } from './translate-service'; @Injectable() export class ObjectService extends HttpService { constructor(translateService: TranslateService) { super(translateService); } readObject(objectName: string, id: number, callback: (data) => void, failureCallback?: (data) => void) { $.ajax({ async: false, type: 'GET', url: this.basicUrl + objectName + CoreRemoteRestURL.FULL_CONTEXT_URL + "/" + id + "?localized=true", contentType: "application/json", data: { isEditMode: true }, success: (response) => { console.info("Reading " + objectName + " with id: " + id + " is successfully"); callback(response); }, error: (error) => { if (failureCallback) { failureCallback(error.responseJSON); } console.error("An error has been happened while reading " + objectName + " with id: " + id, error); } }); } updateObject(objectName: string, id: number, model: any, tokenId: string, callback: (data) => void, failureCallback?: (response) => void) { $.ajax({ type: 'PUT', url: this.basicUrl + objectName + CoreRemoteRestURL.FULL_CONTEXT_URL + "/" + id, data: JSON.stringify(model), headers: { 'X-BDK-EDIT-TOKEN': tokenId }, contentType: "application/json; charset=utf-8", success: (response) => { console.info(objectName + " with id: " + id + " updating action has been done successfully"); callback(response); super.cancelEditEntity(objectName, id, tokenId, () => { }); }, error: (error) => { console.error("An error has been happened while " + objectName + " with id: " + id + " updating action: " + error); if (failureCallback) { failureCallback(error.responseJSON); } } }); } }