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