<![CDATA[ API (PHP) Method to Generate Confirmation Dialog? - My Forums]]> https://forums.modx.com/thread/?thread=104844 <![CDATA[API (PHP) Method to Generate Confirmation Dialog?]]> https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563762 smg6511v2 Jan 25, 2019, 04:19 PM https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563762 <![CDATA[Re: API (PHP) Method to Generate Confirmation Dialog?]]> https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-564006
Anyway, now I've got some Ext questions that I'll pose in a new post since it strays a bit from the subject of this thread. Again, thanks for your thoughts on this!]]>
smg6511v2 Feb 08, 2019, 04:15 AM https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-564006
<![CDATA[Re: API (PHP) Method to Generate Confirmation Dialog?]]> https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563894
If I were doing it, I think I'd either use NewsPublisher and hijack *its* "Save" button, or (more likely) just create a CMP where you'd have control over everything that happens and wouldn't have to worry about what else is going on.

Another option would be FormIt2DB which I think could have a postHook that would display your rejection notice (not as a popup, but as an error message). I think FormIt also has the option of custom validators. I could be wrong. I've never done this, so I don't know how practical this suggestion is.]]>
BobRay Feb 01, 2019, 11:39 PM https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563894
<![CDATA[Re: API (PHP) Method to Generate Confirmation Dialog?]]> https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563882 Ext.override method could be used to either alter or add to classes/components/methods already established in the manager's create.js and update.js. For what I'm trying to do, clicking save would first have to invoke a custom processor to perform the validation logic, which upon sending success would allow the normal create/update process to continue or call MODx.msg.confirm should user interaction be necessary. If that's plausible, I'm not quite sure of how to go about it, in terms of coding the override.

All this also has me pondering whether this part of my application — allowing managers to build a library or people and organizations which are used/displayed in various ways — is better built in a CMP or CRC. Without the desire for the finer-grained, multi-level validation I could build this in normal resources and a handful of TVs, using Collections to simplify the display and navigation of the library.]]>
smg6511v2 Feb 01, 2019, 04:49 AM https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563882
<![CDATA[Re: API (PHP) Method to Generate Confirmation Dialog?]]> https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563772
One solution is to catch the process even earlier when the user clicks on the "Save" button. Your JS code can intercept that click and (if the user says no) prevent the default action of the button, or (if the user says Yes) return without doing anything and let MODX continue saving the resource.

You'd want to have your plugin inject your JS code in OnDocFormRender or OnDocFormPrerender, because it needs to be there before "Save" is clicked. On the other hand, the logic for presenting the confirm button would have to all be in the JS code since the information you need to make that decision won't be there until the "Save" button is actually pressed.

This would be the OnDocFormRender (or Prerender) code:

if ($mode == modSystemEvent::MODE_UPD) {
    $modx->regClientStartupScript('path/to/js/file.js');
}

return ''


That's all the PHP code you'd have.

I can't think of any way to do it using either of the DocFormSave events since there's no good way to interact with the user in them.



]]>
BobRay Jan 27, 2019, 07:18 AM https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563772
<![CDATA[Re: API (PHP) Method to Generate Confirmation Dialog?]]> https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563771
Thanks for the pointers. I'm aware of the modExt method and will go that route. Given that this plugin is checking a normal modResource document, I'm guessing that I'd do this in upd mode (lifted from /manager/assets/modext/sections/resource/update.js):
MODx.msg.confirm({
    text: 'message text'
    ,url: MODx.config.connector_url
    ,params: {
        action: 'resource/update'
        ,id: this.config.resource
    }
    ,listeners: {
        success: {fn:function(r) {
            MODx.loadPage('resource/update', 'id='+r.object.id);
        },scope:this}
    }
});


... with the only difference in new mode being that the params would be:
,params: {
    action: 'resource/create'
}


Does that look right? The only other question is whether it's better to fire this OnBeforeDocFormSave or OnDocFormSave?]]>
smg6511v2 Jan 26, 2019, 10:58 PM https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563771
<![CDATA[Re: API (PHP) Method to Generate Confirmation Dialog?]]> https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563769
In ExtJS/modExt, it would be:

MODx.msg.confirm( ...


In JQuery, you'd need to create a dialog as describe here:

https://stackoverflow.com/questions/12617084/jquery-confirm-dialog

You could also use plain JavaScript.

In any case, you'd want to stop the default action if the user chooses not to proceed, maybe with a "Save Cancelled" message.



]]>
BobRay Jan 26, 2019, 03:58 AM https://forums.modx.com/thread/104844/api-php-method-to-generate-confirmation-dialog#dis-post-563769