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) |
/** * 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); }