Html::jsConfirmCallback PHP Method

jsConfirmCallback() static public method

Summary of confirmCallback Is a replacement for Javascript native confirm function Beware that native confirm is synchronous by nature (will block browser waiting an answer from user, but that this is emulating the confirm behaviour by using callbacks functions when user presses 'Yes' or 'No' buttons.
static public jsConfirmCallback ( $msg, $title, $yesCallback = null, $noCallback = null )
$msg string message to be shown
$title string title for dialog box
$yesCallback string function that will be called when 'Yes' is pressed (default null)
$noCallback string function that will be called when 'No' is pressed (default null)
    static function jsConfirmCallback($msg, $title, $yesCallback = null, $noCallback = null)
    {
        return "\n         // the Dialog and its properties.\n         \$('<div></div>').dialog({\n            open: function(event, ui) { \$('.ui-dialog-titlebar-close').hide(); },\n            close: function(event, ui) { \$(this).remove(); },\n            resizable: false,\n            modal: true,\n            title: '" . Toolbox::addslashes_deep($title) . "',\n            buttons: {\n               'Yes': function () {\n                     \$(this).dialog('close');\n                     " . ($yesCallback !== null ? '(' . $yesCallback . ')()' : '') . "\n                  },\n               'No': function () {\n                     \$(this).dialog('close');\n                     " . ($noCallback !== null ? '(' . $noCallback . ')()' : '') . "\n                  }\n            }\n         }).text('" . Toolbox::addslashes_deep($msg) . "');\n      ";
    }

Usage Example

Example #1
0
 /**
  * Summary of setLockedByMessage
  * Shows 'Locked by ' message and proposes to request unlock from locker
  **/
 private function setLockedByMessage()
 {
     global $CFG_GLPI;
     // should get locking user info
     $user = new User();
     $user->getFromDBByQuery(" WHERE id = " . $this->fields['users_id']);
     $useremail = new UserEmail();
     $showAskUnlock = $useremail->getFromDBByQuery(" WHERE users_id = " . $this->fields['users_id'] . "\n                                                            AND is_default = 1 ") && $CFG_GLPI['use_mailing'] == 1;
     $completeUserName = formatUserName(0, $user->fields['name'], $user->fields['realname'], $user->fields['firstname']);
     if ($showAskUnlock) {
         $ret = Html::scriptBlock("\n         function askUnlock() {\n            \$('#message_after_lock').fadeToggle() ;\n            " . Html::jsConfirmCallback(__('Ask for unlock item?'), $this->itemtypename . " #" . $this->itemid, "function() {\n                  \$.ajax({\n                     url: '" . $CFG_GLPI['root_doc'] . "/ajax/unlockobject.php',\n                     cache: false,\n                     data: 'requestunlock=1&id=" . $this->fields['id'] . "',\n                     success: function( jqXHR, textStatus ) {\n                           " . Html::jsAlertCallback($completeUserName, __('Request sent to'), "function() { \$('#message_after_lock').fadeToggle() ; }") . "\n                        }\n                     });\n               }", "function() {\n                  \$('#message_after_lock').fadeToggle() ;\n               }") . "\n         }\n\n         ");
         echo $ret;
     }
     $msg = "<table><tr><td class=red nowrap>";
     $msg .= __('Locked by ') . "<a href='" . $user->getLinkURL() . "'>{$completeUserName}</a> -> " . Html::convDateTime($this->fields['date_mod']);
     $msg .= "</td><td nowrap>";
     if ($showAskUnlock) {
         $msg .= "<a class='vsubmit' onclick='javascript:askUnlock();'>" . __('Ask for unlock') . "</a>";
     }
     $msg .= "</td></tr></table>";
     $this->displayLockMessage($msg);
 }
All Usage Examples Of Html::jsConfirmCallback
Html