Jump to content

[Solved] Conditional Page Save Each Time Certain Tab Is Clicked In Page Editor


netcarver
 Share

Recommended Posts

Hello all,

Can anyone point me in the right direction here. When editing the pages of a certain template, I have a tab (Fieldset Tab Open) into which I've added a runtime markup field which does state verification and, if all's good, adds an email send button to the page. I have a pages::saved() hook that takes care of the actual send should the button be clicked. 

This works fine, and is out on a production server, but it has a drawback; it requires the user to save the page before the information used to generate the send button is in sync with any changes the user has made. Even if I make the tab ajax load, this only works for the first set of changes the user makes, ie, when they switch to the tab for the first time. If they go back to one of the regular content tabs and make an additional change, the content of the send tab is now potentially stale and requires a re-save to freshen it.

To help with this workflow, I'd like to make it so that the very act of clicking on the send tab activates a page save, if needed, ensuring the content of the send tab is always in sync with the stored data. State of page changes is tracked by JS already - so this must be possible.

Whilst I'm sure I can patch my way to a solution, any help short-cutting that route would be appreciated.

Many thanks in advance,
Steve

  • Like 1
Link to comment
Share on other sites

@Zeka Thanks for the pointers. I'll take a look.

I can trigger the save with some injected JS - it's just figuring out how to make it conditional that I'm hung up on at the moment. Will do some grepping and see what that turns up, too.

Link to comment
Share on other sites

Well, I found Soma's old FormSaveReminder module - which I can dissect, but I've not found the code PW currently uses, despite grepping for the message you get when you move away from a page with unsaved edits. Perhaps my grep skills are rusty.

Update: Ok, thanks to this old blog post, I'm pretty sure I've found what I need. Will post solution once it's come together.

Link to comment
Share on other sites

All done. Simpler than I thought it would be in the end...

$(document).on('wiretabclick', function(event, newTab, oldTab) {
  old_id = oldTab.attr('id');
  new_id = newTab.attr('id');
  if ((old_id !== new_id) && (new_id === 'Inputfield_mailing_actions')) {
    var changes = $(".InputfieldFormConfirm:not(.InputfieldFormSubmitted) .InputfieldStateChanged");
    if(changes.length !== 0) {
      $('#Inputfield_save_btn').click();
    }
  }
});

The missing code was in the templates-admin/scripts/inputfields.js file at line 901.

  • Like 3
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...