Skip to content
Snippets Groups Projects
Commit b4ef3df8 authored by Jared Hancock's avatar Jared Hancock
Browse files

pjax: Fix help tip fetching

parent 9b0c9fc0
Branches
Tags
No related merge requests found
...@@ -42,6 +42,7 @@ class osTicket { ...@@ -42,6 +42,7 @@ class osTicket {
var $title; //Custom title. html > head > title. var $title; //Custom title. html > head > title.
var $headers; var $headers;
var $pjax_extra;
var $config; var $config;
var $session; var $session;
...@@ -163,13 +164,17 @@ class osTicket { ...@@ -163,13 +164,17 @@ class osTicket {
return $replacer->replaceVars($input); return $replacer->replaceVars($input);
} }
function addExtraHeader($header) { function addExtraHeader($header, $pjax_script=false) {
$this->headers[md5($header)] = $header; $this->headers[md5($header)] = $header;
$this->pjax_extra[md5($header)] = $pjax_script;
} }
function getExtraHeaders() { function getExtraHeaders() {
return $this->headers; return $this->headers;
} }
function getExtraPjax() {
return $this->pjax_extra;
}
function setPageTitle($title) { function setPageTitle($title) {
$this->title = $title; $this->title = $title;
......
...@@ -25,7 +25,7 @@ if(is_object($thisstaff) && $thisstaff->isStaff()) { ?> ...@@ -25,7 +25,7 @@ if(is_object($thisstaff) && $thisstaff->isStaff()) { ?>
if ($.support.pjax) { if ($.support.pjax) {
$(document).on('click', 'a', function(event) { $(document).on('click', 'a', function(event) {
if (!$(this).hasClass('no-pjax')) if (!$(this).hasClass('no-pjax'))
$.pjax.click(event, {container: $('#content')}) $.pjax.click(event, {container: $('#content'), timeout: 2000})
}) })
} }
</script> </script>
......
...@@ -113,7 +113,11 @@ ...@@ -113,7 +113,11 @@
} }
?> ?>
</ul> </ul>
<div id="content" data-pjax-container> <div id="content">
<?php } elseif ($pjax = $ost->getExtraPjax()) { # endif X_PJAX ?>
<script type="text/javascript">
<?php foreach ($pjax as $s) echo $s.";"; ?>
</script>
<?php } # endif X_PJAX ?> <?php } # endif X_PJAX ?>
<?php if($errors['err']) { ?> <?php if($errors['err']) { ?>
<div id="msg_error"><?php echo $errors['err']; ?></div> <div id="msg_error"><?php echo $errors['err']; ?></div>
......
...@@ -126,7 +126,8 @@ $page='dynamic-forms.inc.php'; ...@@ -126,7 +126,8 @@ $page='dynamic-forms.inc.php';
if($form || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) if($form || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add')))
$page='dynamic-form.inc.php'; $page='dynamic-form.inc.php';
$ost->addExtraHeader('<meta name="tip-namespace" content="forms" />'); $ost->addExtraHeader('<meta name="tip-namespace" content="forms" />',
"$('#content').data('tipNamespace', 'forms');");
$nav->setTabActive('manage'); $nav->setTabActive('manage');
require(STAFFINC_DIR.'header.inc.php'); require(STAFFINC_DIR.'header.inc.php');
require(STAFFINC_DIR.$page); require(STAFFINC_DIR.$page);
......
...@@ -24,20 +24,26 @@ jQuery(function() { ...@@ -24,20 +24,26 @@ jQuery(function() {
}); });
}, },
getHelpTips = (function() { getHelpTips = (function() {
var dfd = $.Deferred(), var dfd, cache = {};
requested = false, return function(namespace) {
namespace = $('meta[name=tip-namespace]').attr('content'); var namespace = namespace
return function() { || $('#content').data('tipNamespace')
if (namespace && dfd.state() != 'resolved' && !requested) || $('meta[name=tip-namespace]').attr('content');
requested = $.ajax({ if (!namespace)
return false;
else if (!cache[namespace])
cache[namespace] = {
dfd: dfd = $.Deferred(),
ajax: $.ajax({
url: "ajax.php/help/tips/" + namespace, url: "ajax.php/help/tips/" + namespace,
dataType: 'json', dataType: 'json',
success: function (json_config) { success: $.proxy(function (json_config) {
dfd.resolve(json_config); this.resolve(json_config);
} }, dfd)
}); })
return dfd; }
} return cache[namespace].dfd;
};
})(); })();
//Generic tip. //Generic tip.
......
...@@ -48,7 +48,8 @@ if($page && $_POST && !$errors) { ...@@ -48,7 +48,8 @@ if($page && $_POST && !$errors) {
} }
$config=($errors && $_POST)?Format::input($_POST):Format::htmlchars($cfg->getConfigInfo()); $config=($errors && $_POST)?Format::input($_POST):Format::htmlchars($cfg->getConfigInfo());
$ost->addExtraHeader('<meta name="tip-namespace" content="'.$page[1].'" />'); $ost->addExtraHeader('<meta name="tip-namespace" content="'.$page[1].'" />',
"$('#content').data('tipNamespace', '".$page[1]."');");
$nav->setTabActive('settings', ('settings.php?t='.$target)); $nav->setTabActive('settings', ('settings.php?t='.$target));
require_once(STAFFINC_DIR.'header.inc.php'); require_once(STAFFINC_DIR.'header.inc.php');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment