HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/csb.komma.pro/resources/js/components/GlobalisationService.js
import { ErrorResponse } from "../global/models/errorResponse";
import { CountryLanguagesResponse } from "../global/models/countryLanguagesResponse";

class GlobalisationService
{
    constructor()
    {
        this._baseRoute = '/';
    }

    /**
     * Adds a product to the shopping cart
     *
     * @param {string} countryIso3
     */
    getLanguagesForCountryWithIso3(countryIso3) {
        let self = this;

        return new Promise(function(resolve, reject) {
            Ajax.post(
                self._baseRoute+'getLanguagesForCountryWithIso3',
                { countryIso3: countryIso3 },
                function(xhr) {
                    // let response = JSON.parse(xhr.response);
                    let isErrorResponse = ErrorResponse.is(xhr.response, false);
                    let isCountryLanguagesResponse = CountryLanguagesResponse.is(xhr.response, false);

                    if(!isErrorResponse) {
                        if(isCountryLanguagesResponse) {
                            let countryLanguagesResponse = CountryLanguagesResponse.fromJsonString(xhr.response);
                            resolve(countryLanguagesResponse);
                        }
                        else {
                            console.error('RegisterService:getLanguagesForCountryWithIso3 The response was not a valid CountryLanguagesResponse: '+xhr.response);
                            reject();
                        }
                    } else {
                        let response = ErrorResponse.fromJsonString(xhr.response);
                        reject(response);
                    }
                }
            );
        });
    };
}

export { GlobalisationService }