Skip to content

Commit

Permalink
New feature : default template use a boostrap dialog for clearall
Browse files Browse the repository at this point in the history
Dev: 2 step without js is done too
Dev: core use confirm, related to feature #11970
  • Loading branch information
Shnoulle committed Dec 2, 2016
1 parent 1407274 commit 3af89f9
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 104 deletions.
61 changes: 0 additions & 61 deletions application/controllers/survey/index.php
Expand Up @@ -502,67 +502,6 @@ function action()
}
}


//Clear session and remove the incomplete response if requested.
if (isset($move) && $move == "clearall")
{
// delete the response but only if not already completed
$s_lang = $_SESSION['survey_'.$surveyid]['s_lang'];
if (isset($_SESSION['survey_'.$surveyid]['srid']) && !SurveyDynamic::model($surveyid)->isCompleted($_SESSION['survey_'.$surveyid]['srid']))
{
// delete the response but only if not already completed
$result= dbExecuteAssoc('DELETE FROM {{survey_'.$surveyid.'}} WHERE id='.$_SESSION['survey_'.$surveyid]['srid']." AND submitdate IS NULL");
if($result->count()>0){ // Using count() here *should* be okay for MSSQL because it is a delete statement
// find out if there are any fuqt questions - checked
$fieldmap = createFieldMap($surveyid,'short',false,false,$s_lang);
foreach ($fieldmap as $field)
{
if ($field['type'] == "|" && !strpos($field['fieldname'], "_filecount"))
{
if (!isset($qid)) { $qid = array(); }
$qid[] = $field['fieldname'];
}
}

// if yes, extract the response json to those questions
if (isset($qid))
{
$query = "SELECT * FROM {{survey_".$surveyid."}} WHERE id=".$_SESSION['survey_'.$surveyid]['srid'];
$result = dbExecuteAssoc($query);
foreach($result->readAll() as $row)
{
foreach ($qid as $question)
{
$json = $row[$question];
if ($json == "" || $json == NULL)
continue;

// decode them
$phparray = json_decode($json);

foreach ($phparray as $metadata)
{
$target = Yii::app()->getConfig("uploaddir")."/surveys/".$surveyid."/files/";
// delete those files
unlink($target.$metadata->filename);
}
}
}
}
// done deleting uploaded files
}

// also delete a record from saved_control when there is one
dbExecuteAssoc('DELETE FROM {{saved_control}} WHERE srid='.$_SESSION['survey_'.$surveyid]['srid'].' AND sid='.$surveyid);
}
killSurveySession($surveyid);
$content=templatereplace(file_get_contents($oTemplate->pstplPath."clearall.pstpl"),array());
$this->getController()->layout='survey';
$this->getController()->render("/survey/system/display",array('content'=>$content));
App()->end();
}


//Check to see if a refering URL has been captured.
if (!isset($_SESSION['survey_'.$surveyid]['refurl']))
{
Expand Down
42 changes: 25 additions & 17 deletions application/core/packages/limesurvey/survey.js
Expand Up @@ -189,43 +189,51 @@ function activateActionLink(){
event.preventDefault();
var submit=$(this).data('limesurvey-submit');
var confirmedby=$(this).data('confirmedby');
if(!confirmedby || confirm($(this).data('confirmlabel')))
{
if(!confirmedby){
$.each(submit, function(name, value) {
$("<input/>",{
'type':"hidden",
'name':name,
'value':value,
}).appendTo('form#limesurvey');
});
$.each(confirmedby, function(name, value) {
$("<input/>",{
'type':"hidden",
'name':name,
'value':value,
}).appendTo('form#limesurvey');
});
$('form#limesurvey').submit();
}else{
var submits=$.extend(submit,confirmedby);
confirmSurveyDialog($(this).data('confirmlabel'),$(this).text(),submits)
}
});
}
}

/**
* function for replacing submit after confirm
*/
function confirmSurveyDialog(text,title,submits){
if(confirm(text)){
$.each(submits, function(name, value) {
$("<input/>",{
'type':"hidden",
'name':name,
'value':value,
}).appendTo('form#limesurvey');
});
$('form#limesurvey').submit();
}
}
/**
* Ask confirmation on click on .needconfirm
*/
function activateConfirmButton(){
$(document).on('click',"button[data-confirmedby]", function(event){
// @todo : allow multiple here : remove extra
var btnConfirm=$(this);
var cbConfirm=$(this).parent().find("[name='"+$(this).data('confirmedby')+"']");
if(!$(cbConfirm).is(":checked"))
{
text=$(cbConfirm).parent("label").text();
if (confirm(text)) {
$(cbConfirm).clone().addClass('ls-js-hidden').appendTo('#limesurvey').prop('checked',true);
return true;
}
return false;
event.preventDefault();
var submits = { };
submits[$(btnConfirm).attr('name')]=$(btnConfirm).val();
submits[$(cbConfirm).attr('name')]=$(cbConfirm).val();
confirmSurveyDialog($(cbConfirm).parent("label").text(),$(btnConfirm).text(),submits)
}
});
}
Expand Down
71 changes: 62 additions & 9 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -361,9 +361,9 @@ public function run($surveyid,$args)
<!-- INPUT NAMES -->
<input type='hidden' name='fieldnames' value='{$hiddenfieldnames}' id='fieldnames' />\n";
// <-- END FEATURE - SAVE

// The default submit button
echo CHtml::htmlButton("default",array('type'=>'submit','id'=>"defaultbtn",'value'=>"default",'name'=>'move','class'=>"submit hidden",'style'=>'display:none'));
// <-- START THE SURVEY -->
if ($surveyMode == 'survey')
{
if (isset($thissurvey['showwelcome']) && $thissurvey['showwelcome'] == 'N')
Expand All @@ -379,13 +379,9 @@ public function run($surveyid,$args)
{
echo templatereplace(file_get_contents($sTemplateViewPath."privacy.pstpl"), array(), $redata) . "\n";
}
}

// <-- START THE SURVEY -->
if ($surveyMode != 'survey')
{
/* Why survey.pstpl is not included in all in one mode ?*/
}else{/* survey.pstpl is not included in all in one mode : welcome replace needed functionnality inside form for default template */
echo templatereplace(file_get_contents($sTemplateViewPath."survey.pstpl"), array(), $redata);

}

// runonce element has been changed from a hidden to a text/display:none one. In order to workaround an not-reproduced issue #4453 (lemeur)
Expand Down Expand Up @@ -865,7 +861,7 @@ private function moveFirstChecks()
$LEMsessid = $this->LEMsessid;

if ( $move=="clearcancel"){
$moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, true, false, true);
$moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, false);
}

/* quota submitted */
Expand Down Expand Up @@ -914,6 +910,7 @@ private function setMoveResult()
}

$moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'],false,false); // if late in the survey, will re-validate contents, which may be overkill

unset($_SESSION[$LEMsessid]['LEMtokenResume']);
}else if (!$LEMskipReprocessing){

Expand Down Expand Up @@ -944,7 +941,9 @@ private function setMoveResult()
$moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['totalsteps'] + 1, false);
}
}

if ( $move=='clearall'){
$this->manageClearAll();
}
if ( $move=='changelang'){
// jump to current step using new language, processing POST values
$moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, true, true, true); // do process the POST data
Expand Down Expand Up @@ -1631,4 +1630,58 @@ private function getErrorHtmlMessage()
return "";
}
}

/**
* clear all system (no js or broken js)
* @uses $this->surveyid
* @uses $this->sTemplateViewPath
* @return void
*/
private function manageClearAll()
{
/* Maybe nest is ro move this in SurveyController */
$sessionSurvey=Yii::app()->session["survey_{$this->surveyid}"];
if(App()->request->getPost('confirm-clearall')=='confirm'){ // Previous behaviour (and javascript behaviour)
// delete the existing response but only if not already completed
if (
isset($sessionSurvey['srid'])
&& !SurveyDynamic::model($this->surveyid)->isCompleted($sessionSurvey['srid']) // see bug https://bugs.limesurvey.org/view.php?id=11978
){
$oResponse=Response::model($this->surveyid)->find("id=:srid",array(":srid"=>$sessionSurvey['srid']));
if($oResponse){
$oResponse->delete(true);/* delete response line + files uploaded , warninbg : beforeDelete don't happen with deleteAll */
}
if(Survey::model()->findByPk($this->surveyid)->savetimings=="Y"){
SurveyTimingDynamic::model($this->surveyid)->deleteAll("id=:srid",array(":srid"=>$sessionSurvey['srid'])); /* delete timings ( @todo must move it to Response )*/
}
SavedControl::model()->deleteAll("sid=:sid and srid=:srid",array(":sid"=>$this->surveyid,":srid"=>$sessionSurvey['srid']));/* saved controls (think we can have only one , but maybe ....)( @todo must move it to Response )*/
}
killSurveySession($this->surveyid);
$content=templatereplace(file_get_contents($this->sTemplateViewPath."clearall.pstpl"),array());
App()->getController()->layout='survey';
App()->getController()->render("/survey/system/display",array('content'=>$content));
App()->end();
}elseif(App()->request->getPost('confirm-clearall')!='cancel'){
LimeExpressionManager::JumpTo($sessionSurvey['step'], false, true, true, false); // do process the POST data
App()->getController()->layout="survey";
App()->getController()->bStartSurvey=true;

$aReplacements=array();
$aReplacements['FORMID'] = 'clearall';
$aReplacements['FORMHEADING'] = App()->getController()->renderPartial("/survey/frontpage/clearallForm/heading",array(),true);
$aReplacements['FORMMESSAGE'] = App()->getController()->renderPartial("/survey/frontpage/clearallForm/message",array(),true);
$aReplacements['FORMERROR'] = "";
$aReplacements['FORM'] = CHtml::beginForm(array("/survey/index","sid"=>$this->surveyid), 'post',array('id'=>'form-'.$aReplacements['FORMID'],'class'=>'ls-form'));
$aReplacements['FORM'].= CHtml::hiddenField('move','clearall',array());
$aReplacements['FORM'].= App()->getController()->renderPartial("/survey/frontpage/clearallForm/form",array(),true);
$aReplacements['FORM'].= CHtml::hiddenField('thisstep',$sessionSurvey['step']);
$aReplacements['FORM'].= CHtml::hiddenField('sid',$this->surveyid);
$aReplacements['FORM'].= CHtml::endForm();
$content = templatereplace(file_get_contents($this->sTemplateViewPath."form.pstpl"),$aReplacements);
App()->getController()->render("/survey/system/display",array(
'content'=>$content,
));
Yii::app()->end();
}
}
}
1 change: 0 additions & 1 deletion application/helpers/expressions/em_manager_helper.php
Expand Up @@ -5574,7 +5574,6 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
$updatedValues = array();
}
$message = '';

$LEM->currentQset = array(); // reset active list of questions
$result = $LEM->_ValidateSurvey($force);
$message .= $result['message'];
Expand Down
4 changes: 0 additions & 4 deletions application/helpers/frontend_helper.php
Expand Up @@ -2454,10 +2454,6 @@ function getMove()
if(Yii::app()->request->getParam($sAccepteMove))
$move=$sAccepteMove;
}
/* Good idea, but used ? */
if($move=='clearall' && App()->request->getPost('confirm-clearall')!='confirm'){
$move="clearcancel";
}
/* default move (user don't click on a button, but use enter in a input:text or a select */
if($move=='default')
{
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/replacements_helper.php
Expand Up @@ -847,7 +847,7 @@ function doHtmlClearAll(){
if(empty($aClearAll)){
$aClearAll['button']=App()->getController()->renderPartial("/survey/system/actionButton/clearAll",array(
'value'=>'clearall',
'name'=>'clearall',
'name'=>'move',
'class'=>'ls-clearaction ls-clearall',
'confirmedby'=>'confirm-clearall',
'confirmvalue'=>'confirm',
Expand All @@ -865,7 +865,7 @@ function doHtmlClearAll(){
),true);
// To replace javascript confirm : https://ethaizone.github.io/Bootstrap-Confirmation/ or http://bootboxjs.com/documentation.html#bb-confirm-dialog or https://nakupanda.github.io/bootstrap3-dialog/ or ....
/* Don't do it in core actually, but put some language*/
App()->getClientScript()->registerScript("activateConfirmLanguage","LSvar.confirmLang=".ls_json_encode(array('yes'=>gT("Yes"),'no'=>gT("No"))),CClientScript::POS_BEGIN);
App()->getClientScript()->registerScript("activateConfirmLanguage","$.extend(LSvar.lang,".ls_json_encode(array('yes'=>gT("Yes"),'no'=>gT("No"))).")",CClientScript::POS_BEGIN);
App()->getClientScript()->registerScript("activateActionLink","activateActionLink();\n",CClientScript::POS_END);
App()->getClientScript()->registerScript("activateConfirmButton","activateConfirmButton();\n",CClientScript::POS_END);
}
Expand Down
18 changes: 18 additions & 0 deletions application/views/survey/frontpage/clearallForm/form.php
@@ -0,0 +1,18 @@
<?php
/**
* form
*
*/
?>
<div class='clearall-survey-form row'>
<div class='col-sm-7 col-md-offset-3'>
<div class="btn-group btn-group-justified" role='group' aria-label='<?php echo gT("Please confirm you want to clear your response?") ?>'>
<div class="btn-group" role="group">
<button type='submit' name="confirm-clearall" class='btn btn-warning btn-confirm' value='confirm'><?php echo gT("Yes") ?></button>
</div>
<div class="btn-group" role="group">
<button type='submit' name="move" class='btn btn-default btn-cancel' value='clearcancel'><?php echo gT("No") ?></button>
</div>
</div>
</div>
</div>
7 changes: 7 additions & 0 deletions application/views/survey/frontpage/clearallForm/heading.php
@@ -0,0 +1,7 @@
<?php
/**
* Heading
*
*/
?>
<?php echo gT("Exit and clear survey"); ?>
7 changes: 7 additions & 0 deletions application/views/survey/frontpage/clearallForm/message.php
@@ -0,0 +1,7 @@
<?php
/**
* message
* @todo : some cmlass ? Review class ?
*/
?>
<p><?php echo gT("Please confirm you want to clear your response?"); ?></p>
9 changes: 4 additions & 5 deletions application/views/survey/system/actionButton/clearAll.php
Expand Up @@ -9,6 +9,10 @@
<!-- views/survey/system/actionButton/moveNext -->
<?php
echo CHtml::openTag("div",array("class"=>"form-inline ls-{$name}-form"));
echo CHtml::openTag("label",array("class"=>"form-group hidden"));
echo CHtml::checkBox($confirmedby,false,array('id'=>false,'value'=>$confirmvalue));
echo CHtml::tag("span",array('class'=>'control-label'),gT("Please confirm you want to clear your response?"));
echo CHtml::closeTag("label");
echo CHtml::htmlButton(gT("Exit and clear survey"),array(
'type'=>'submit',
'id'=>null,
Expand All @@ -17,12 +21,7 @@
'class'=>"$class btn btn-link",
'data-confirmedby'=>$confirmedby,
'title'=>gT("This action need confirmation."),
'aria-label'=>gT("This action need confirmation with the next checkbox."), /* ? must be reviewed */
));
echo CHtml::openTag("label",array("class"=>"form-group ls-js-hidden"));
echo CHtml::checkBox($confirmedby,false,array('id'=>null,'value'=>$confirmvalue));
echo CHtml::tag("span",array('class'=>'control-label'),gT("Are you sure you want to clear all your responses?"));
echo CHtml::closeTag("label");
echo CHtml::closeTag("div");
?>
<!-- end of views/survey/system/actionButton/moveNext -->
2 changes: 1 addition & 1 deletion application/views/survey/system/actionLink/clearAll.php
Expand Up @@ -7,7 +7,7 @@
*/
?>
<li class="ls-no-js-hidden">
<a href="#" data-limesurvey-submit='<?php echo $submit ?>' data-confirmedby='<?php echo $confirm ?>' data-confirmlabel='<?php echo gT("Are you sure you want to clear all your responses?") ?>' class='<?php echo $class ?>'>
<a href="#" data-limesurvey-submit='<?php echo $submit ?>' data-confirmedby='<?php echo $confirm ?>' data-confirmlabel='<?php echo gT("Please confirm you want to clear your response?") ?>' class='<?php echo $class ?>'>
<?php echo gT("Exit and clear survey") ?>
</a>

Expand Down
Expand Up @@ -5,7 +5,7 @@
*
*/
?>
<li class="dropdown ls-index-menu index-menu-<?php echo ($type>1)? 'full':'incremental' ?>">
<li class="dropdown ls-index-menu ls-no-js-hidden index-menu-<?php echo ($type>1)? 'full':'incremental' ?>">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
<?php echo gT("Question index"); ?>
<span class="caret"></span>
Expand Down
Expand Up @@ -5,7 +5,7 @@
*
*/
?>
<li class="dropdown ls-index-menu index-menu-<?php echo ($type>1)? 'full':'incremental' ?>">
<li class="dropdown ls-index-menu ls-no-js-hidden index-menu-<?php echo ($type>1)? 'full':'incremental' ?>">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
<?php echo gT("Question index"); ?>
<span class="caret"></span>
Expand Down
1 change: 1 addition & 0 deletions templates/default/css/template.css
Expand Up @@ -37,6 +37,7 @@ padding-top:1em;padding-bottom:1em;margin-bottom:2em;
}
.top-content .form-change-lang{float:right}
.dir-rtl .top-content .form-change-lang{float:left}
.no-js .top-content .form-change-lang{display:none}

.top-container .top-content:empty{display:none}
.group-description:empty{display:none}
Expand Down

0 comments on commit 3af89f9

Please sign in to comment.