Bruno17 / MIGX

MIGX for revo 2.2 and above
83 stars 78 forks source link

aftersave hook error and success messages #290

Closed labr1005 closed 7 years ago

labr1005 commented 7 years ago

I'm not sure if I'm doing it correct, but looking at the code of core/components/processors/default/update.php if I do this in my aftersave snippet

return json_encode(array('error' => 'My error message'));

I get a nice ExtJs modal displaying the error message on top of the currently opened MIGXdb editing window (which stays open).

  1. Is this the correct way to stop my aftersave snippet?

  2. Is it possible to display a success message (using my aftersave snippet) after the MIGXdb editing window closed?

MODX 2.5.4 MIGX 2.9.6

labr1005 commented 7 years ago

Looks like this is not possible out of the box. Quick and dirty:

core/components/migx/processors/mgr/default/update.php

if (!empty($hooksnippet_aftersave)){
    $result = $modx->runSnippet($hooksnippet_aftersave,$snippetProperties);
    $result = $modx->fromJson($result);
    $error  = $modx->getOption('error',$result,'');
    if (!empty($error)) {
        $updateerror = true;
        $errormsg = $error;
        return;
    }
    $success  = $modx->getOption('success',$result,'');
    if (!empty($success)) {
        $message = $success;
    }
}

core/components/migx/templates/mgr/updatewindow.tpl

onSubmitSuccess: function(r){
    this.grid.refresh();
    //this.grid.collectItems();
    //this.onDirty();
    this.fp.getForm().reset();
    this.hide();
    if (r.message != '') {
        MODx.msg.alert(_('save_successful'), r.message);
    }
    return true;
}

Now you can do

return $modx->toJson(array('success' => 'Your success message'));

in your aftersave hook snippet which will display the success message after the update window has closed.