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 HomeService extends HttpService { constructor(http: Http,translateService: TranslateService) { super(translateService); } createInstance(objectName: string, requestBody: {}, callback: (data) => void, failureCallback?: (response) => void) { $.ajax({ type: 'POST', url: this.basicUrl + objectName + CoreRemoteRestURL.FULL_CONTEXT_URL, data: JSON.stringify(requestBody), headers: { "Content-Type": "application/json; charset=utf-8" }, success: (response) => { console.info(objectName + " Creation action has been done successfully"); callback(response); }, error: (error) => { if (failureCallback) { failureCallback(error.responseJSON); } console.error("An error has been happened while " + objectName + " creation action: " + error); } }); } activateBatchInstances(objectName: string, objects: any[], callback: (data) => void, failureCallback?: (response) => void) { $.ajax({ type: 'POST', url: this.basicUrl + objectName + CoreRemoteRestURL.ACTIVTION_URL, data: JSON.stringify({ data: objects }), contentType: "application/json", success: (response) => { console.info(objectName + " Batch Activation has been done successfully"); callback(response); }, error: (error) => { console.error("An error has been happened while " + objectName + " Batch activation. "); if (failureCallback) { failureCallback(error.responseJSON); } } }); } deactivateBatchInstances(objectName: string, objects: any[], callback: (data) => void, failureCallback?: (response) => void) { $.ajax({ type: 'POST', url: this.basicUrl + objectName + CoreRemoteRestURL.DEACTIVTION_URL, data: JSON.stringify({ data: objects }), contentType: "application/json", success: (response) => { console.info(objectName + " Batch De-activation has been done successfully"); callback(response); }, error: (error) => { console.error("An error has been happened while " + objectName + " Batch de-activation. "); if (failureCallback) { failureCallback(error.responseJSON); } } }); } checkValidity(id: number) { //TODO: check validity of the current object return true; } addToFavorites(id: number) { //TODO: add current object to the favorites } removeFromFavorites(id: number) { //TODO: remove current object from the favorites } checkObjectFavority(id: number) { return true; } }