Q:

How to call function only after the executing of the other function is completly finished

In the following code, I would like to reload the siteadmin pages with the function siteAdmin.reloadPages() only after the storing of the pages porperties CQ.form.SlingSubmitAction(dialog.form, config);is executed sucessfully.  
the following function submits a form and then calls a callback() function, which in turn reloads the siteadmin pages:
function foo(dialog, config, callback) {
    var action = new CQ.form.SlingSubmitAction(dialog.form, config);
    dialog.form.doAction(action);
    dialog[dialog.closeAction]();

    callback();
}

function call:
foo(dialog,action, function() {
    var siteAdmin = CQ.Ext.getCmp(window.CQ_SiteAdmin_id);
    siteAdmin.reloadPages();
});

The problem is that the siteadmin pages are not reladed after the pageProperties (dialog.form) has been successfully submitted. For example the pageTitle loaded is the old value.
How to reload siteadmin pages only after the form has been successfully submitted?

A:

You can try to specify the success function in the config, something like the one shown below.
function foo(dialog, config, callback) {
    var action = new CQ.form.SlingSubmitAction(dialog.form, {
        success: function(){
            var siteAdmin = CQ.Ext.getCmp(window.CQ_SiteAdmin_id);
            siteAdmin.reloadPages();
        }
    });
    dialog.form.doAction(action);
    dialog[dialog.closeAction]();
}

This would ensure that the siteadmin is reloaded only after you request succeeds.
Check the further options available for your config here.

