Jump to content

AutoSave Page


Soma
 Share

Recommended Posts

AutoSave

This module saves the page via ajax when editing in the admin. The interval for saving the page is configurable in the AutoSave module settings. By default it will only be enabled for unpublished pages.

  • So far it seems to work fine for all fields and supports multilanguage.
  • There's a message dialog show on top of page when saving happened with either a success or error.

Requirements

ProcessWire 2.3+. Haven't really tested with 2.3.

Known Issues

  • Nothing really obvious so far.
  • Note that when you have multiple editors editing pages, it would be possible 2 persons editing the same page would overwrite each other, since the page is autosaved! The only solution for this would be to have my PageEditSoftLock module enabled with the complete "Lock" option active, so the page would be locked for editing.

Todo

  • Add some checks, if connection is lost.
  • To be defined

This module is currently a proof of concept. This module may not be suitable for all instances, but for personal use it may help preventing loss of long edits, most likely blog posts. Not sure this should be used for regular sites with clients editing. Most likely there's some more issues that interferer with what a CMS "page save" has to deal with. So you might find some ugly stuff happening.

Thanks to Apeisa and his great Fredi font-end module, from where some logic is borrowed to save the page via ajax.

Download
https://github.com/somatonic/AutoSave

So, that would be my last stroke for this year! Have a great silvester party and a happy new 2014!

  • Like 13
Link to comment
Share on other sites

Okay, not actually doing anything on my test site (2.3.9 - with the new admin template).

But it can wait for later in the week (its new year)!

An extension to this would also be to optionally save a field onblur.

That would be useful for when filling in large numbers of fields, whereas the auto save is good for when working on a single large text field.

Link to comment
Share on other sites

Okay, not actually doing anything on my test site (2.3.9 - with the new admin template).

But it can wait for later in the week (its new year)!

What do you mean? It doesn't work for you? I'm using latest PW with new admin theme (although shouldn't matter at all).

An extension to this would also be to optionally save a field onblur.

 

That would be useful for when filling in large numbers of fields, whereas the auto save is good for when working on a single large text field.

I don't think this should go as far, and not something that is easily possible.

Link to comment
Share on other sites

Just pushed an update to github with some fix.

There were some routines for TinyMCE and CKEDITOR to update the changes to the form before sending, which required some additional check for if there's really editor instances. So this most likely was your problem.

Added some additional checking for form validation. So it will show errors of the saved form and show them too.

Thanks for testing.

Link to comment
Share on other sites

Hi Soma

Happy New Year!

Okay, it is now saving, but on my limited test it saved the two text input fields on my page but not the CKeditor (inline).

I will do some more tests tomorrow sometime

Night!

  • Like 1
Link to comment
Share on other sites

Ho Joss, happy new year! 

Ok that was more helpful than just "it's not saving". Ah, of course ckeditors inline mode need some special treatment. Took me a while to figure it out but it's working now too.

Thanks.

Link to comment
Share on other sites

I know it's only a Proof of Concept, but I'm 50/50 as to whether this is a good idea or not if it's auto-saving live pages, no offense intended, as it could be updating part-changed content on a live page if you're halfway through typing when it autosaves couldn't it? Some people write/edit loooooooong pages :)

I think it would be better if it autosaved to another part of the site (under your process page for example) and if you leave the page you're editing and go back to it it could do a comparison of modified dates and ask if you want to edit the later, non-live version.

Of course, that's quite a lot more code but it's just an idea (it's also leaning towards version control too in that case).

  • Like 2
Link to comment
Share on other sites

Its a good start and is showing that this part of it works and with various fields.

It does need to be mixed with some sort of draft/versioning system, I agree, to become a full solution, but that also requires some fairly heft complications:

To start with, if you lose connection or something, when you return to the page you need to be offered the choice of the draft version or the published live version. This probably means adding an extra link in the page list actions to open a draft (only shown if it exists) 

If you are looking at the draft version, then you need to have the option of saving the draft as a draft, or publishing, which would overwrite the live version.

  • Like 1
Link to comment
Share on other sites

I know Pete. Exactly, but I didn't ask for it and will not use it cause I can hit save. 

Most of the instances I've heard of where people lost their work had to do with creating new pages that weren't yet published. For unpublished pages, the issue Pete mentioned is really not an issue at all. Perhaps a setting to limit the auto-saving to unpublished pages would be all that's needed, since that is the time when this module is likely most valuable. I'd suggest this might even be a good default setting. The 3 instances I'm aware of–Mike (cmscritic), Teppo, and Peter–would have all been for an unpublished page (I think) and would have been saved by this module. Nice job btw! 

  • Like 4
Link to comment
Share on other sites

Yeah that's what I also thought having it only for unpublished pages or also just certain templates. But first wanted to know if it's possible at all to autosave and how.

There maybe also a way to save the edits not to the page but to a file and load it on demand after a loss. Im not too keen creating new pages for it. Also I think certain fields like files will not work this way.

Speaking of drafts and live version that's something still missing in pw and I would have that on top priority. But Im not in charge of it and it's on the roadmap, though got delayed by a lot. I'm waiting for it since the beginning of using pw two half years ago. ;p Though Im really wondering if with the flexibility pw offers how to use pages and combinations of fields and hooks if a draft system really works out well... if you know what I mean... seeing also things like 'simple' clone feature is not working in all cases. No offend intended, I know Ryan is doing all he can and doing a hell of a job, but he's still "alone" on those stuff. :)

  • Like 1
Link to comment
Share on other sites

I've actually been putting some thought to drafts and think I've got some good ideas to move forward with a simple drafts system soon. Page status 4096 is reserved for Page::statusDraft. That keeps drafts in the Unpublished territory, excluded from all but "include=all" selectors. Page IDs 500-999 are reserved for drafts (so the IDs will be reusable, unlike other page IDs). I don't imagine many would need more than 500 drafts at a time, but if they do, we can make the ID reuse optional. Drafts will be an optional module, not installed by default (like autocomplete, repeaters, etc.) Versioning will be something different entirely, as I don't want versions filling up the pages tables. But versioning will likely use drafts as a transition point. 

Link to comment
Share on other sites

Aww, Soma - you make him sound so lonely!!!

Yes, really this module of yours comes into its own once a draft/versioning/something system is in play.

Just about everything I do, especially in music when composing, involves creating a new or alternative version, making a comparison against everything else and the deciding which one to use.

On versioning, there is no reason why there cannot be a versions table that hold arrayed data that can be loaded back into a form - or something like that. 

Though (and you will hate this) there is an argument to say that versioning could apply to an individual field - from the editorial point of view, being able to look through an assortment of bits and then combine them into the perfect version is fun.

I do this with Cubase - audio recordings are kept in "Lanes" and you can cut and past bits of each lane to create a whole new version.

Mind you, it can get mind bending!

Link to comment
Share on other sites

I pushed an update with default AutoSave only enabled on unpublished pages. Added option to enable it for all pages.

On versioning, there is no reason why there cannot be a versions table that hold arrayed data that can be loaded back into a form - or something like that. 

That might be true for simple text page with no files. Files and images is what makes it not so simple. And to go further there could be all kind of weird situations wehre you have references to pages that doesn't exists anymore. And so on. It's not like in a nice closed predictable environment like in a audio composing tool (I also use) or a design tool.

On the other parts I'm not commenting. :D

Link to comment
Share on other sites

Just fixed a bug with status getting cleaned. So a unpublished page would get published. It just ignores the status now, which isn't something you want to autosave anyway. (There would have to be some special treatment as ProcessPageEdit does) 

  • Like 1
Link to comment
Share on other sites

I've actually been putting some thought to drafts and think I've got some good ideas to move forward with a simple drafts system soon.  

Ryan - any ideas how much work that would be? We have need for this also in next project, so interested in providing some support (=money) for this.

  • Like 5
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...