authorization
parent
763d6c141e
commit
b849a949e6
|
@ -423,16 +423,6 @@ GameLib.Component.prototype.saveToRemoteAPI = function() {
|
||||||
|
|
||||||
GameLib.Component.prototype.save = function(remote) {
|
GameLib.Component.prototype.save = function(remote) {
|
||||||
|
|
||||||
var event = GameLib.Event.GET_API_URL;
|
|
||||||
|
|
||||||
if (remote) {
|
|
||||||
event = GameLib.Event.GET_REMOTE_API_URL
|
|
||||||
}
|
|
||||||
|
|
||||||
this.publish(
|
|
||||||
event,
|
|
||||||
null,
|
|
||||||
function(data) {
|
|
||||||
this.buildIdToObject();
|
this.buildIdToObject();
|
||||||
|
|
||||||
for (var property in this.idToObject) {
|
for (var property in this.idToObject) {
|
||||||
|
@ -456,17 +446,11 @@ GameLib.Component.prototype.save = function(remote) {
|
||||||
this.publish(
|
this.publish(
|
||||||
GameLib.Event.SAVE_COMPONENT,
|
GameLib.Event.SAVE_COMPONENT,
|
||||||
{
|
{
|
||||||
apiUrl : data.apiUrl,
|
apiObject: apiObject,
|
||||||
apiObject : apiObject
|
remote: remote
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.bind(this),
|
|
||||||
function(error) {
|
|
||||||
console.error(error);
|
|
||||||
throw new Error('Failed to get API URL: ' + error.message);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
};
|
|
@ -179,6 +179,7 @@ GameLib.System.Storage.prototype.delete = function(data) {
|
||||||
|
|
||||||
xhr.setRequestHeader("Accept", "application/json");
|
xhr.setRequestHeader("Accept", "application/json");
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
|
xhr.setRequestHeader("x-authorization", urlData.passwoid);
|
||||||
|
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
if (this.readyState === 4) {
|
if (this.readyState === 4) {
|
||||||
|
@ -226,12 +227,21 @@ GameLib.System.Storage.prototype.delete = function(data) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'Saves' data to baseURL
|
* 'Saves' data to somewhere
|
||||||
*/
|
*/
|
||||||
GameLib.System.Storage.prototype.save = function(data) {
|
GameLib.System.Storage.prototype.save = function(data) {
|
||||||
|
|
||||||
|
var event = GameLib.Event.GET_API_URL;
|
||||||
|
|
||||||
|
if (data.remote) {
|
||||||
|
event = GameLib.Event.GET_REMOTE_API_URL
|
||||||
|
}
|
||||||
|
|
||||||
|
this.publish(
|
||||||
|
event,
|
||||||
|
null,
|
||||||
|
function(urlData) {
|
||||||
if (typeof XMLHttpRequest === 'undefined') {
|
if (typeof XMLHttpRequest === 'undefined') {
|
||||||
console.log('Implement server side save here');
|
console.log('Implement server side save here');
|
||||||
return;
|
return;
|
||||||
|
@ -241,11 +251,12 @@ GameLib.System.Storage.prototype.save = function(data) {
|
||||||
|
|
||||||
xhr.open(
|
xhr.open(
|
||||||
'POST',
|
'POST',
|
||||||
data.apiUrl + '/component/create'
|
urlData.apiUrl + '/component/create'
|
||||||
);
|
);
|
||||||
|
|
||||||
xhr.setRequestHeader("Accept", "application/json");
|
xhr.setRequestHeader("Accept", "application/json");
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
|
xhr.setRequestHeader("x-authorization", urlData.passwoid);
|
||||||
|
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
if (this.readyState === 4) {
|
if (this.readyState === 4) {
|
||||||
|
@ -282,6 +293,8 @@ GameLib.System.Storage.prototype.save = function(data) {
|
||||||
component : data.apiObject,
|
component : data.apiObject,
|
||||||
session : this.token
|
session : this.token
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue