Commit 43f6ee69 authored by Chenu Denis's avatar Chenu Denis

[feature] Allow update of end part in twig

parent 2ef43750
$(document).on('ready pjax:scriptcomplete',function(){
var extraSurvey = window.extraSurvey || {};
extraSurvey.timeOut = extraSurvey.timeOut || 1;
$(document).on('ready',function(){
if(window.location != window.parent.location) {
window.parent.$(window.parent.document).trigger("extrasurveyframe:on");
}
......@@ -9,8 +12,12 @@ window.onbeforeunload = function() {
window.parent.$(window.parent.document).trigger("extrasurveyframe:off");
}
};
function autoclose() {
function extraSurveyAutoclose() {
if(window.location != window.parent.location) {
window.parent.$(window.parent.document).trigger("extrasurveyframe:autoclose");
if( extraSurvey.timeOut >= 0) {
window.setTimeout(function(){
window.parent.$(window.parent.document).trigger("extrasurveyframe:autoclose");
}, extraSurvey.timeOut * 1000);
}
}
}
......@@ -15,7 +15,7 @@ $(document).on('click','[target="frame-questionExtraSurvey"]',function(event) {
"delete":false,
"saveall":false,
"saveall-quit":false,
"moveprevious":false,
"moveprev":false,
"movenext":true,
"movesubmit":true,
"close":true
......@@ -134,10 +134,11 @@ function updateHeightModalExtraSurvey(modal) {
$(document).on('extrasurveyframe:on',function(event,data) {
$("#modal-questionExtraSurvey .modal-footer button[data-action]").each(function(){
$(this).prop('disabled',$("#extra-survey-iframe").contents().find("form#limesurvey button:submit[value='"+$(this).data('action')+"']").length < 1);
if($("#extra-survey-iframe").contents().find(".completed-text").length) {
$("#modal-questionExtraSurvey").modal('hide');
if($(this).data('action') == 'saveall-quit' && $(this).prop('disabled')) {
$(this).prop('disabled',$("#extra-survey-iframe").contents().find("form#limesurvey button:submit[value='saveall']").length < 1);
}
// todo : add it in option $("#extra-survey-iframe").contents().find(".navigator").addClass("hidden");
});
$("#modal-questionExtraSurvey .modal-footer button[data-action='delete']").prop('disabled',false);
updateHeightModalExtraSurvey("#modal-questionExtraSurvey");
......@@ -155,6 +156,9 @@ $(document).on('click',"#modal-questionExtraSurvey button[data-action]",function
if($(this).data('action')=="delete") {
return;
}
if($(this).data('action')=="saveall-quit") {
return;
}
var questionExtraSurveyQid = $("#modal-questionExtraSurvey").data("questionExtraSurveyQid");
$("#extra-survey-iframe").contents().find("form#limesurvey").append("<input type='hidden' name='questionExtraSurveyQid' value='"+questionExtraSurveyQid+"'>");
$("#extra-survey-iframe").contents().find("form#limesurvey button:submit[value='"+$(this).data('action')+"']").last().click();
......@@ -163,7 +167,10 @@ $(document).on('click',"#modal-questionExtraSurvey button[data-action]",function
$(document).on('click',"#modal-questionExtraSurvey button[data-action='delete']:not('disabled')",function(e) {
$("#modal-confirm-clearall-extrasurvey").show();
$("#modal-confirm-clearall-extrasurvey .btn-confirm").on('click',function(){
$("#modal-questionExtraSurvey iframe").contents().find("#limesurvey").append("<input type='hidden' name='move' value='delete'>");
var questionExtraSurveyQid = $("#modal-questionExtraSurvey").data("questionExtraSurveyQid");
$("#modal-questionExtraSurvey iframe").contents().find("form#limesurvey").append("<input type='hidden' name='questionExtraSurveyQid' value='"+questionExtraSurveyQid+"'>");
$("#modal-questionExtraSurvey iframe").contents().find("#limesurvey").append("<input type='hidden' name='clearall' value='clearall'>");
$("#modal-questionExtraSurvey iframe").contents().find("#limesurvey").append("<input type='hidden' name='delete' value='delete'>");
$("#modal-questionExtraSurvey iframe").contents().find("#limesurvey").submit();
});
$("#modal-confirm-clearall-extrasurvey [data-dismiss]").on('click',function(){
......@@ -174,6 +181,9 @@ $(document).on('click',"#modal-questionExtraSurvey button[data-action='delete']:
});
/* Action save a quit */
$(document).on('click',"#modal-questionExtraSurvey button[data-action='saveall-quit']:not('disabled')",function(e) {
var questionExtraSurveyQid = $("#modal-questionExtraSurvey").data("questionExtraSurveyQid");
$("#extra-survey-iframe").contents().find("form#limesurvey").append("<input type='hidden' name='questionExtraSurveyQid' value='"+questionExtraSurveyQid+"'>");
$("#extra-survey-iframe").contents().find("form#limesurvey").append("<input type='hidden' name='autosaveandquit' value=1>");
$("#extra-survey-iframe").contents().find("form#limesurvey button:submit[value='saveall']").last().click();
return;
});
......@@ -307,13 +307,45 @@ class questionExtraSurvey extends PluginBase
\Yii::log("Invalid qid {$extrasurveyqid} checked for survey {$iSurveyId}", \CLogger::LEVEL_WARNING, 'plugin.questionExtraSurvey.beforeSurveypage');
}
}
if (Yii::app()->getRequest()->getPost('questionExtraSurveyQid')) { // From javascipt modal buttons
$extrasurveyqid = Yii::app()->getRequest()->getParam('extrasurveyqid');
if ($this->validateQuestionExtraSurvey($extrasurveyqid, $iSurveyId)) {
$aSessionExtraSurvey[$iSurveyId] = $extrasurveyqid;
Yii::app()->session["questionExtraSurvey"] = $aSessionExtraSurvey;
}
}
/* register needed script for external survey */
if (empty(Yii::app()->session["questionExtraSurvey"][$iSurveyId])) {
return;
}
$this->qesRegisterExtraSurveyScript($iSurveyId);
//if(App()->getrequest()->getPost()
if(App()->getrequest()->getPost('saveall') && App()->getrequest()->getPost('autosaveandquit')) {
$script = "extraSurveyAutoclose();";
Yii::app()->getClientScript()->registerScript("questionExtraSurveyComplete", $script, CClientScript::POS_END);
}
if(App()->getrequest()->getPost('saveall') && Survey::model()->findByPk($iSurveyId)->allowsave == "Y") {
$isSaveandQuit = false;
if(App()->getrequest()->getPost('autosaveandquit')) {
$isSaveandQuit = true;
} else {
if(Yii::getPathOfAlias('autoSaveAndQuit')) {
$isSaveandQuit = \autoSaveAndQuit\Utilities::isSaveAndQuit($iSurveyId) && !\autoSaveAndQuit\Utilities::isDisableSaveAndQuit($iSurveyId);
}
}
if ($isSaveandQuit) {
$script = "extraSurveyAutoclose();";
Yii::app()->getClientScript()->registerScript("questionExtraSurveyComplete", $script, CClientScript::POS_END);
}
}
if(App()->getrequest()->getPost('clearall') == "clearall" && App()->getrequest()->getPost('confirm-clearall')) {
$script = "extraSurveyAutoclose();";
Yii::app()->getClientScript()->registerScript("questionExtraSurveyComplete", $script, CClientScript::POS_END);
}
if(App()->getrequest()->getPost('clearall') == "clearall" && App()->getrequest()->getPost('delete') == 'delete') {
$this->checkDeletion($iSurveyId);
}
}
private function addSurveyToSession() {
......@@ -324,58 +356,111 @@ class questionExtraSurvey extends PluginBase
$aSessionExtraSurvey[$iSurveyId] = Yii::app()->getRequest()->getParam('extrasurveyqid');
Yii::app()->session["questionExtraSurvey"] = $aSessionExtraSurvey;
}
/**
*Add script after survey complete
* Check if delete is allwoned and add the deletion on twig part
* @param integer $surveyId;
* @return void
*/
public function afterSurveyComplete()
private function checkDeletion($surveyId)
{
$iSurveyId = $this->event->get('surveyId');
$currentSrid = $this->event->get('responseId');
$aSessionExtraSurvey = Yii::app()->session["questionExtraSurvey"];
if (!isset($aSessionExtraSurvey[$iSurveyId])) {
/* Quit if we are not in survey inside surey system */
$qid = Yii::app()->session["questionExtraSurvey"][$surveyId];
$srid = \reloadAnyResponse\Utilities::getCurrentSrid($surveyId);
$reloadedSrid = \reloadAnyResponse\Utilities::getCurrentReloadedSrid($surveyId);
if($srid != $reloadedSrid) {
$this->log(sprintf("Try to delete %s whith reloaded %s in survey %s.", $srid, $reloadedSrid, $iSurveyId), 'info');
return;
}
$extraSurveyQuestionAllowDelete = QuestionAttribute::model()->find(
'qid = :qid AND attribute = :attribute',
array(":qid" => $qid, ':attribute' => 'extraSurveyQuestionAllowDelete')
);
if(!$extraSurveyQuestionAllowDelete || !$extraSurveyQuestionAllowDelete->value) {
$this->log(sprintf("Try to delete %s whith invalid question %s in survey %s.", $srid, $qid, $iSurveyId), 'warning');
return;
}
$this->surveyState = 'completed';
$this->currentSid = $iSurveyId;
$this->currentSrid = $currentSrid;
$this->unsubscribe('getPluginTwigPath'); /* Other not needed */
$this->currentSid = $surveyId;
$this->currentSrid = $srid;
$this->subscribe('getPluginTwigPath', 'deleteAllAction');
}
/**
* Action to do when need to quit
* using tiowg event : allow qsom eother plugin to do action
*/
private function actionOnQuit() {
$currentQid = $aSessionExtraSurvey[$iSurveyId];
$extraSurveyAutoCloseSubmit = 'addjs';
if ($currentQid) {
$oQuestionAttribute = QuestionAttribute::model()->find(
"qid =:qid AND attribute = :attribute",
array(":qid"=>$currentQid,":attribute"=>'extraSurveyAutoCloseSubmit')
);
if ($oQuestionAttribute && $oQuestionAttribute->value) {
$extraSurveyAutoCloseSubmit = $oQuestionAttribute->value;
public function deleteAllAction()
{
$this->unsubscribe('getPluginTwigPath');
$surveyId = $this->currentSid;
$currentSrid = $this->currentSrid;
$oResponse = Response::model($surveyId)->findByPk($currentSrid);
if ($oResponse->delete(true)) {
if (Survey::model()->findByPk($surveyId)->savetimings == "Y") {
SurveyTimingDynamic::model($surveyId)->deleteAll("id=:srid", array(":srid"=>$currentSrid));
}
SavedControl::model()->deleteAll("sid=:sid and srid=:srid", array(":sid"=>$surveyId, ":srid"=>$currentSrid));
}
killSurveySession($surveyId);
$aSessionExtraSurvey = Yii::app()->session["questionExtraSurvey"];
unset($aSessionExtraSurvey[$iSurveyId]);
Yii::app()->session["questionExtraSurvey"] = $aSessionExtraSurvey;
if (in_array($extraSurveyAutoCloseSubmit, array('replace','addjs','js'))) {
$script = "extraSurveyAutoclose();";
Yii::app()->getClientScript()->registerScript("questionExtraSurveyComplete", $script, CClientScript::POS_END);
}
if ($currentSrid && $extraSurveyAutoCloseSubmit == 'replace' && Yii::getPathOfAlias('renderMessage')) {
\renderMessage\messageHelper::renderAlert($this->translate("Your responses was saved as complete, you can close this windows."));
$aSurveyinfo = getSurveyInfo($surveyId, App()->getLanguage());
$aSurveyinfo['include_content'] = 'questionExtraSurvey_delete';
$this->subscribe('getPluginTwigPath');
$script = "extraSurveyAutoclose();";
Yii::app()->getClientScript()->registerScript("questionExtraSurveyComplete", $script, CClientScript::POS_END);
Yii::app()->twigRenderer->renderTemplateFromFile(
"layout_global.twig",
array(
'oSurvey'=> Survey::model()->findByPk($surveyId),
'aSurveyInfo'=>$aSurveyinfo
),
false
);
}
public function afterSurveyComplete()
{
$iSurveyId = $this->getEvent()->get('surveyId');
$currentSrid = $this->getEvent()->get('responseId');
$aSessionExtraSurvey = Yii::app()->session["questionExtraSurvey"];
if (!isset($aSessionExtraSurvey[$iSurveyId])) {
/* Quit if we are not in survey inside surey system */
return;
}
if (in_array($extraSurveyAutoCloseSubmit, array('add','addjs'))) {
$this->getEvent()->getContent($this)
->addContent("<p class='alert alert-success'>".$this->translate("Your responses was saved as complete, you can close this windows.")."</p>");
$afterSurveyCompleteEvent = $this->getEvent();
$currentQid = $aSessionExtraSurvey[$iSurveyId];
$responseText = mb_strtolower(gT("Response"), 'UTF-8');
$oAttributeReponseText = QuestionAttribute::model()->find(
"qid = :qid AND language = :language and attribute = :attribute",
array(
":qid" => $currentQid,
":language" => Yii::app()->getLanguage(),
":attribute" => 'extraSurveyNameInLanguage'
)
);
if($oAttributeReponseText && $oAttributeReponseText->value) {
$responseText = $oAttributeReponseText->value;
}
unset($aSessionExtraSurvey[$iSurveyId]);
Yii::app()->session["questionExtraSurvey"] = $aSessionExtraSurvey;
$script = "extraSurveyAutoclose();";
Yii::app()->getClientScript()->registerScript("questionExtraSurveyComplete", $script, CClientScript::POS_END);
$renderData=array(
'language' => array(
"Your responses was saved as complete, you can close this windows." => $this->translate("Your responses was saved as complete, you can close this windows."),
"Your %s was saved as complete, you can close this windows." => $this->translate("Your %s was saved as complete, you can close this windows."),
"response" => $responseText
),
'aSurveyInfo' => getSurveyInfo($iSurveyId, App()->getLanguage()),
);
$this->subscribe('getPluginTwigPath');
$extraContent = Yii::app()->twigRenderer->renderPartial('/subviews/messages/questionExtraSurvey_submitted.twig', $renderData);
if($extraContent) {
$afterSurveyCompleteEvent->getContent($this)
->addContent($extraContent);
}
}
/**
* Add the script when question is rendered
* Add QID and SGQ replacement forced (because it's before this was added by core
......@@ -613,11 +698,11 @@ class questionExtraSurvey extends PluginBase
'plugins/direct', array(
'plugin' => 'questionExtraSurvey',
'function' => 'update',
'surveyid'=>$surveyId,
'token'=>$token,
'extrasurveysrid'=>$srid,
'qid'=>$oEvent->get('qid'),
'lang'=>Yii::app()->getLanguage(),
'surveyid' => $surveyId,
'token' => $token,
'extrasurveysrid' => $srid,
'qid' => $oEvent->get('qid'),
'lang' => Yii::app()->getLanguage(),
)
);
$ajaxCheckUrl = Yii::app()->getController()->createUrl(
......@@ -627,23 +712,36 @@ class questionExtraSurvey extends PluginBase
'surveyid' => $surveyId,
'token '=> $token,
'extrasurveysrid' => $srid,
'qid'=>$oEvent->get('qid'),
'lang'=>Yii::app()->getLanguage(),
'qid' => $oEvent->get('qid'),
'lang' => Yii::app()->getLanguage(),
)
);
$oSurveyFrame = Survey::model()->findByPk($surveyId);
$reponseName = empty($aQuestionAttributes['extraSurveyNameInLanguage'][Yii::app()->getLanguage()]) ? mb_strtolower(gT("Response"), 'UTF-8') : $aQuestionAttributes['extraSurveyNameInLanguage'][Yii::app()->getLanguage()];
/* Find buttons */
$buttons = array(
'delete' => (bool) $aQuestionAttributes['extraSurveyQuestionAllowDelete'],
'clearall' => false,
'saveall' => false,//($oSurveyFrame->allowsave == "Y"),
'saveall-quit' => ($oSurveyFrame->allowsave == "Y"),
'moveprevious' => ($oSurveyFrame->allowprev == "Y" && $oSurveyFrame->format != "A"),
'movenext' => ($oSurveyFrame->format != "A"),
'movesubmit' => true,
);
$clearAllAction = \reloadAnyResponse\Utilities::getReloadAnyResponseSetting($srid, 'clearAllAction');
$autoSaveAndQuitActive = \autoSaveAndQuit\Utilities::getSetting($surveyId,'autoSaveAndQuitActive');
$autoSaveAndQuitRestrict = \autoSaveAndQuit\Utilities::getSetting($surveyId,'autoSaveAndQuitRestrict');
/* If autosave and quit is always active : remove saveall */
if ($oSurveyFrame->allowsave == "Y") {
if($autoSaveAndQuitActive != 'always' || $autoSaveAndQuitRestrict == 'ondemand') {
$buttons['saveall'] = true;
}
}
$modalParams = array(
'buttons' => array(
'delete' => (bool)$aQuestionAttributes['extraSurveyQuestionAllowDelete'],
'saveall' => ($oSurveyFrame->allowsave == "Y"),
'moveprevious' => ($oSurveyFrame->allowprev == "Y" && $oSurveyFrame->format != "A"),
'movenext' => ($oSurveyFrame->format != "A"),
'movesubmit' => true,
),
'buttons' => $buttons,
'close' => !(bool)$aQuestionAttributes['extraSurveyDeleteUnsubmitted'],
'language' => array(
' Are you sure to delete this response.' => sprintf($this->translate("Are you sure to delete this %s."), $reponseName),
'Are you sure to delete this response.' => sprintf($this->translate("Are you sure to delete this %s."), $reponseName),
),
'qid'=>$oEvent->get('qid'),
);
......@@ -715,11 +813,12 @@ class questionExtraSurvey extends PluginBase
return;
}
$this->subscribe('getPluginTwigPath');
if(empty($this->getEvent()->get("screen") || $this->getEvent()->get("screen") == "navigation"
if(empty($this->getEvent()->get("screen")) || $this->getEvent()->get("screen") == "navigation") {
$this->getEvent()->append('add', array(
"subviews".DIRECTORY_SEPARATOR."navigation".DIRECTORY_SEPARATOR."questionExtraSurvey_modalDeleteConfirm.twig",
"subviews".DIRECTORY_SEPARATOR."navigation".DIRECTORY_SEPARATOR."questionExtraSurvey_modalSurvey.twig",
));
}
}
/**
......
<div class='{{ aSurveyInfo.class.clearall }}' {{ aSurveyInfo.attr.clearall }}>
<div class=" {{ aSurveyInfo.class.clearalldiv }} " {{ aSurveyInfo.attr.clearalldiv }}>
<p>{{ gT("Answers cleared") }}</p>
</div>
</div>
<div class='alert alert-success'>
{{ sprintf(language['Your %s was saved as complete, you can close this windows.'],language['response']) }}
</div>
......@@ -8,7 +8,7 @@
</div>
<div class="modal-body">
<div class="btn-group btn-group-justified" role="group" aria-label="label-confirm-clearall">
<a class="btn btn-warning btn-confirm" data-dismiss='modal'>{{ gT('Yes') }}></a>
<a class="btn btn-warning btn-confirm" data-dismiss='modal'>{{ gT('Yes') }}</a>
<a class="btn btn-default btn-cancel" data-dismiss='modal'>{{ gT('No') }}</a>
</div>
</div>
......
<!-- Bootstrap Modal Survey -->
<div id="modal-questionExtraSurvey" class="modal modal-questionExtraSurvey" tabindex="-1" role="dialog">
<div id="modal-questionExtraSurvey" class="modal fade modal-questionExtraSurvey" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
......@@ -16,7 +16,7 @@
({'type' : 'button','class' : 'btn btn-danger btn-delete','data-action' : 'delete', 'disabled' : true})
) }}
{{ C.Html.htmlButton(gT('Previous'),
({'type' : 'button','class' : 'btn btn-default btn-moveprevious','data-action' : 'delete', 'disabled' : true})
({'type' : 'button','class' : 'btn btn-default btn-moveprev','data-action' : 'moveprev', 'disabled' : true})
) }}
{{ C.Html.htmlButton(gT('Save'),
({'type' : 'button','class' : 'btn btn-info btn-saveall','data-action' : 'saveall', 'disabled' : true})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment