Confirmation popup backend and workspace

PHOTO EMBED

Thu Mar 14 2024 02:25:45 GMT+0000 (Coordinated Universal Time)

Saved by @RahmanM


// Client script to call the UI script either for backend or workspaces

g_scratchpad.vfConfirm = function(message, callback){
	// This is the backend
    if (typeof GlideModal !== 'undefined') {
        vfConfirm(message, function(result) {
            callback(result);
        });
    } else {
		// This is for the workspace
        g_ui_scripts.getUIScript('vfConfirm').then(function(uiScript) {
            uiScript().vfConfirm(message, g_modal, function(result) {
                callback(result);
            });
        });
    }
	
};



// UI Script for backend. Type = Desktop and Global=Ticked

function vfConfirm(message, callback) {
	
    var dialog = new GlideModal('glide_modal_confirm', true, 300);
    dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
    dialog.setPreference('body', new GwtMessage().format(message));
    dialog.setPreference('focusTrap', true);
    dialog.setPreference('onPromptCancel', function() {
        callback(false);
    });
    dialog.setPreference('onPromptComplete', function() {
        callback(true);
    });

    dialog.render();

}


// UI Script workspace. Mobile/Service Portal.

(function() {

    "use strict";

    return {

        vfConfirm : function(message, g_modal, callback) {
            g_modal.confirm('Confirmation', message, "", {
                "cancelTitle": "No",
                "confirmTitle": "Yes"
            }).then(
                function onSuccess() {
                    callback(true);
                },
                function onReject() {
                    callback(false);
                }
            );
        },

        type: "vfConfirm"
    };
});
content_copyCOPY