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) |
/** * 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); }
/** * 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( data, textStatus, jqXHR ) {\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; } $ret = Html::scriptBlock("\n \$(function(){\n var lockStatusTimer ;\n \$('#alertMe').change(function( eventObject ){\n if( this.checked ) {\n lockStatusTimer = setInterval( function() {\n \$.ajax({\n url: '" . $CFG_GLPI['root_doc'] . "/ajax/unlockobject.php',\n cache: false,\n data: 'lockstatus=1&id=" . $this->fields['id'] . "',\n success: function( data, textStatus, jqXHR ) {\n if( data == 0 ) {\n clearInterval(lockStatusTimer);\n \$('#message_after_lock').fadeToggle() ;" . Html::jsConfirmCallback(__('Reload page?'), __('Item unlocked!'), "function() {\n window.location.reload(true);\n }") . "\n }\n }\n });\n },15000)\n } else {\n clearInterval(lockStatusTimer);\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><td> </td><td>" . __('Alert me when unlocked') . "</td><td> " . Html::getCheckbox(array('id' => 'alertMe')) . "</td></tr></table>"; $this->displayLockMessage($msg); }