juek / CustomSections

Developer plugin for rapid prototyping of custom section types in Typesetter CMS
GNU General Public License v2.0
3 stars 7 forks source link

Problem with cached content #11

Closed a2exfr closed 7 years ago

a2exfr commented 7 years ago

Actually this is no good

  gp_editor.SaveData = function(){
    var values = gp_editor.getValues();
    var content = encodeURIComponent( gp_editor.edit_section.html() );
    return 'gpcontent=' + content + '&' + values;
  };

because we saving new values, but content is taken old! After log out, we see old values in section. in source values and cashed content is different

Think we must set var content, after section content is replaced or add in checkdirty aditional condition to save this new replaced content.

edit: or use this .trigger("CustomSection:updated")to set check dirty true once more

juek commented 7 years ago

Hmm... I wonder if we should try to sync this with autosaving somehow.

a2exfr commented 7 years ago

Problem that save come first before section content is updated

juek commented 7 years ago

Timed autosave might also happen during section updating.

juek commented 7 years ago

We should generally only allow to save once the section is updated.

a2exfr commented 7 years ago

We should generally only allow to save once the section is updated.

Lets try it. Becase another error appears time to time. "Do not work ES3" something like that is disappers quickly. that in time of saving

juek commented 7 years ago

... and we should also disallow making changes during update is running, e.g. using loading(); -> loaded();

a2exfr commented 7 years ago

strange.... set $section['always_process_values'] to true do not help to render saved values edit : my bad, its saved in section on added

juek commented 7 years ago

strange.... set $section['always_process_values'] to true do not help to render saved values

did you create a new section with this setting? then it should. its a default value and cannot be changed later, once it is stored false.

juek commented 7 years ago

Ok, I think I got a good solution - will contribute soon

a2exfr commented 7 years ago

I also have solution but it not elegant. In short: add additional hidden input with cached content, update its value on section content update, save cached content from this input. That's all. Test it, seems that work good. What you think?

juek commented 7 years ago

Ok, here is the commit

Explanation follows...

juek commented 7 years ago

gp_editor.checkDirty() now still compares values with cached values but will only trigger gp_editor.updateSection() in case they differ. But: It will return (boolean)gp_editor.isDirty which will be set to true only by $gp.response.updateContent (when the section's content is actually rewritten).

$gp.response.updateContent will also call (new) gp_editor.resetCache()

gp_editor.isDirty will only be set to false again by gp_editor.resetDirty() which is called automatically by Typesetter's save function after everything is saved.

In order to prevent value changes in the editor UI while gp_editor.updateSection() is in AJAX process, I'll add loading(); and loaded(); to block the editor UI. E.g. when hammering on a number field's arrows, we trigger lots of changes in short time - this could cause issues.

juek commented 7 years ago

Current implementation seems to work flawlessly.