bulk save
parent
69bfc1de56
commit
8705586d71
|
@ -14,6 +14,16 @@ R3.API.CustomCode = function(
|
|||
}
|
||||
this.eventId = apiComponent.eventId;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.compiled)) {
|
||||
apiComponent.compiled = true;
|
||||
}
|
||||
this.compiled = apiComponent.compiled;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.domId)) {
|
||||
apiComponent.domId = 'r3-code-editor';
|
||||
}
|
||||
this.domId = apiComponent.domId;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.code)) {
|
||||
|
||||
if (this.eventId === R3.Event.BEFORE_RENDER) {
|
||||
|
|
|
@ -21,14 +21,21 @@ R3.CustomCode.prototype.createInstance = function() {
|
|||
|
||||
try {
|
||||
|
||||
this.compiled = false;
|
||||
|
||||
this.instance = new Function('data', this.code).bind(this);
|
||||
|
||||
this.compiled = true;
|
||||
|
||||
} catch (error) {
|
||||
/**
|
||||
* Set the instance to true here to indicate that even though the compilation failed, the instance will be fine and
|
||||
* this component loaded fine.
|
||||
*/
|
||||
this.compiled = false;
|
||||
|
||||
this.instance = new Function('data', "console.log('compilation failed for : " + this.name + "');").bind(this);
|
||||
|
||||
}
|
||||
|
||||
__CREATE_INSTANCE__;
|
||||
|
@ -52,7 +59,9 @@ R3.CustomCode.prototype.updateInstance = function(property) {
|
|||
if (property === 'code') {
|
||||
|
||||
try {
|
||||
this.compiled = false;
|
||||
this.instance = new Function('data', this.code).bind(this);
|
||||
this.compiled = true;
|
||||
this.emit(
|
||||
R3.Event.COMPILE_SUCCESS,
|
||||
{
|
||||
|
@ -60,6 +69,7 @@ R3.CustomCode.prototype.updateInstance = function(property) {
|
|||
}
|
||||
)
|
||||
} catch (error) {
|
||||
this.compiled = false;
|
||||
this.instance = new Function('data', "console.log('compilation update failed for : " + this.name + "');").bind(this);
|
||||
this.emit(
|
||||
R3.Event.COMPILE_FAILED,
|
||||
|
@ -139,6 +149,8 @@ R3.CustomCode.prototype.launchEditor = function(){
|
|||
this.updateInstance('code');
|
||||
|
||||
}.bind(this))
|
||||
|
||||
this.editor.getWrapperElement().setAttribute('id', this.domId);
|
||||
};
|
||||
|
||||
R3.CustomCode.prototype.closeEditor = function(){
|
||||
|
|
|
@ -278,11 +278,6 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (this.savedSubscription || this.savedErrorSubscription) {
|
||||
console.warn('Another save is in progress');
|
||||
return;
|
||||
}
|
||||
|
||||
R3.Event.Emit(
|
||||
R3.Event.SAVING,
|
||||
{
|
||||
|
@ -404,15 +399,61 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
|
|||
|
||||
try {
|
||||
|
||||
apiObjects.map(
|
||||
if (data.bulk) {
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open(
|
||||
'POST',
|
||||
apiUrl + '/component/save'
|
||||
);
|
||||
|
||||
xhr.setRequestHeader("Accept", "application/json");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.setRequestHeader("x-api-authorization", apiAuthorization);
|
||||
xhr.setRequestHeader('x-api-user-token', this.apiUserToken);
|
||||
|
||||
xhr.onload = function () {
|
||||
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
|
||||
if (response.result === 'success') {
|
||||
|
||||
R3.Event.Emit(
|
||||
R3.Event.COMPONENT_SAVED,
|
||||
{
|
||||
message: response.message || 'Successfully saved the component(s)',
|
||||
component: apiObjects
|
||||
}
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
R3.Event.Emit(
|
||||
R3.Event.SAVE_COMPONENT_ERROR,
|
||||
{
|
||||
message: response.message || 'The server responded but failed to save the component(s)',
|
||||
component: apiObjects
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var data = JSON.stringify({components: apiObjects});
|
||||
|
||||
xhr.send(data);
|
||||
|
||||
} else {
|
||||
apiObjects.map(
|
||||
function (apiObject) {
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open(
|
||||
'POST',
|
||||
apiUrl + '/component/create'
|
||||
apiUrl + '/component/save'
|
||||
);
|
||||
|
||||
xhr.setRequestHeader("Accept", "application/json");
|
||||
|
@ -448,15 +489,13 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
|
|||
|
||||
};
|
||||
|
||||
var data = JSON.stringify(apiObject);
|
||||
var data = JSON.stringify({component: apiObject});
|
||||
|
||||
xhr.send(
|
||||
{
|
||||
component : data
|
||||
}
|
||||
xhr.send(data);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
|
||||
|
@ -464,10 +503,17 @@ R3.System.Storage.prototype.save = function(data, callback, errorCallback) {
|
|||
R3.Event.SAVE_COMPONENT_ERROR,
|
||||
{
|
||||
message: this.responseText,
|
||||
component : apiObject
|
||||
component : apiObjects
|
||||
}
|
||||
);
|
||||
|
||||
this.savedSubscription.remove();
|
||||
this.savedErrorSubscription.remove();
|
||||
|
||||
this.savedSubscription = null;
|
||||
this.savedErrorSubscription = null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue