Closed cmcintosh closed 7 years ago
Im onto a fix. My issue was I was assuming setCurrent was asking for the id of the storage I was creating. it is however not.
@cmcintosh for a custom storage you only have to indicate store and load functions, eg.
storageManager.add('local2', {
load: function(keys){
var res = {};
for (var i = 0, len = keys.length; i < len; i++){
var v = localStorage.getItem(keys[i]);
if(v) res[keys[i]] = v;
}
return res;
},
store: function(data){
for(var key in data)
localStorage.setItem(key, data[key]);
}
});
...
storageManager.setCurrent('local2');
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
This is inside of a Plugin, I can confirm after init. That the editor is using the defined storage that I defined. Additionally, I can trigger editor.load() and editor.store() and see ajax calls go out if i crate them in the respective options. However, if I do not have load or store defined then I see no traffic in the network console.
` var storageManager = editor.StorageManager; var drupalStorage = storageManager.add('drupal', { type: 'remote', urlStore: '/js/grapesjs/save', urlLoad: '/js/grapesjs/load', autosave: true, params: { entity_type: drupalSettings.wembassy.siteBuilder.entity_type, 'bundle': drupalSettings.wembassy.siteBuilder.bundle, 'template': $('#gjs-pn-templates-a select').val(), 'default': 1, 'status': 1 }, load: function(keys) { console.log('Loading', keys); var res = {}; for (var i = 0, len = keys.length; i < len; i++){ var v = drupalSettings.wembassy.siteBuilder.template_data[keys[i]]; if(v) res[keys[i]] = v; } return res; }, store: function(data){ var templateData = { 'entity_type': drupalSettings.wembassy.siteBuilder.entity_type, 'bundle': drupalSettings.wembassy.siteBuilder.bundle, 'template': $('#gjs-pn-templates-a select').val(), 'data': data, 'default': 1, 'status': 1, }; $.ajax({ type: "POST", url: "/js/grapesjs/save", data: templateData, async: false, success: function(e) { console.log("Saved data", e); return true; }, dataType: "json" }); }});
`