Html::jsAlertCallback PHP Méthode

jsAlertCallback() static public méthode

Summary of jsAlertCallback Is a replacement for Javascript native alert function Beware that native alert is synchronous by nature (will block browser waiting an answer from user, but that this is emulating the alert behaviour by using a callback function when user presses 'Ok' button.
static public jsAlertCallback ( $msg, $title, $okCallback = null )
$msg string message to be shown
$title string title for dialog box
$okCallback string function that will be called when 'Ok' is pressed (default null)
    static function jsAlertCallback($msg, $title, $okCallback = null)
    {
        return "\n         // 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               'Ok': function () {\n                     \$(this).dialog('close');\n                     " . ($okCallback !== null ? '(' . $okCallback . ')()' : '') . "\n                  }\n            }\n         }).text('" . Toolbox::addslashes_deep($msg) . "');\n         ";
    }

Usage Example

Exemple #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::jsAlertCallback
Html