Skip to content

Commit

Permalink
Fixed issue #13790: End-URL redfirect is not working in AJAX mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jun 22, 2018
1 parent efc651f commit 26cfe78
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 14 deletions.
14 changes: 12 additions & 2 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -1183,8 +1183,17 @@ private function moveSubmitIfNeeded()


if (isset($this->aSurveyInfo['autoredirect']) && $this->aSurveyInfo['autoredirect'] == "Y" && $this->aSurveyInfo['surveyls_url']) {
//Automatically redirect the page to the "url" setting for the survey
header("Location: {$this->aSurveyInfo['surveyls_url']}");
if(json_decode($this->oTemplate->options)->ajaxmode == 'on') {
echo '{
"redirectTo" : "'.$this->aSurveyInfo['surveyls_url'].'"
}';
killSurveySession($this->iSurveyid);
Yii::app()->end();
return;
} else {
//Automatically redirect the page to the "url" setting for the survey
header("Location: {$this->aSurveyInfo['surveyls_url']}");
}
}

$this->aSurveyInfo['aLEM']['debugvalidation']['show'] = false;
Expand All @@ -1207,6 +1216,7 @@ private function moveSubmitIfNeeded()
if ($this->aSurveyInfo['printanswers'] != 'Y') {
killSurveySession($this->iSurveyid);
}

$this->aSurveyInfo['include_content'] = 'submit';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
}
Expand Down
2 changes: 1 addition & 1 deletion assets/packages/pjax/min/pjax.combined.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/packages/pjax/min/pjax.min.js

Large diffs are not rendered by default.

30 changes: 21 additions & 9 deletions assets/packages/pjax/pjax.js

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion themes/survey/vanilla/scripts/ajaxify.js
Expand Up @@ -81,14 +81,32 @@ var AjaxSubmitObject = function () {
}
};




var bindActions = function () {
var logFunction = new ConsoleShim('PJAX-LOG', (LSvar.debugMode < 1));
var jsonFound = false;
var onJsonDocument = function(jsonDocument){
logFunction.log("Found JSON document ->", jsonDocument);
if(jsonDocument.redirectTo !== undefined) {
jsonFound = true;
window.location.replace(jsonDocument.redirectTo);
}
};
var onDomDiffers = function(oldDom, newDom){
return !jsonFound;
}

var globalPjax = new Pjax({
elements: ['form#limesurvey'], // default is "a[href], form[action]"
selectors: ['#dynamicReloadContainer', '#beginScripts', '#bottomScripts'],
debug: true,
forceRedirectOnFail: true,
onJsonDocument: onJsonDocument,
onDomDiffers: onDomDiffers,
reRenderCSS : true,
logObject : new ConsoleShim('PJAX-LOG', (LSvar.debugMode < 1)),
logObject : logFunction,
scriptloadtimeout: 1500,
});
// Always bind to document to not need to bind again
Expand Down

2 comments on commit 26cfe78

@Shnoulle
Copy link
Collaborator

@Shnoulle Shnoulle commented on 26cfe78 Jun 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whaaat ! The issue is in pjax, not in the redirect …

pjax must control if have a 302 or a 301 and redirect.

1st issue here: white page for no-js browser. 2nd issue : different behaviour about session with or without ajax.

I really think this is not a fix …

See https://github.com/yiisoft/jquery-pjax/blob/c39f2393883f370d3c0d63d80a122534131b0f56/jquery.pjax.js#L277 for an example

@lacrioque
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a point there. I will look into it and apply the redirect on error logic.

Please sign in to comment.