Skip to content

Commit

Permalink
New feature: Extended mode for responses grid
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 14, 2016
1 parent a0f9fdf commit 56f2ccf
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
8 changes: 5 additions & 3 deletions application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
),

'params'=>array(
'defaultPageSize'=>10 ,
'pageSizeOptions'=>array(5=>5,10=>10,20=>20,50=>50,100=>100),
'pageSizeOptionsTokens'=>array(5=>5,10=>10,25=>25,50=>50,100=>100, 250=>250, 500=>500, 1000=>1000, 2500=>2500, 5000=>5000, 10000=>10000),
'defaultPageSize'=>10 , // Default page size for most of the grids
'pageSizeOptions'=>array(5=>5,10=>10,20=>20,50=>50,100=>100), // Default page size options for most of the grids
'pageSizeOptionsTokens'=>array(5=>5,10=>10,25=>25,50=>50,100=>100, 250=>250, 500=>500, 1000=>1000, 2500=>2500, 5000=>5000, 10000=>10000), // Tokens needs different options
'defaultEllipsizeHeaderValue'=>30, // Default max characters before ellipsizing the headers of responses grid
'defaultEllipsizeQuestionValu'=>50, // Default max characters before ellipsizing the questions inside responses grid
),

'import' => array(
Expand Down
21 changes: 21 additions & 0 deletions application/controllers/admin/responses.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,27 @@ public function index($iSurveyID)
$this->_renderWrappedTemplate('',$aViewUrls, $aData);
}


/**
* Change the value of the max characters to elipsize headers/questions in reponse grid.
* It's called via ajax request
*/
public function set_grid_display()
{
if($_POST['state']=='extended')
{
Yii::app()->user->setState('responsesGridSwitchDisplayState',true);
Yii::app()->user->setState('defaultEllipsizeHeaderValue',1000);
Yii::app()->user->setState('defaultEllipsizeQuestionValue',1000);
}
else
{
Yii::app()->user->setState('responsesGridSwitchDisplayState',false);
Yii::app()->user->setState('defaultEllipsizeHeaderValue',Yii::app()->params['defaultEllipsizeHeaderValue']);
Yii::app()->user->setState('defaultEllipsizeQuestionValue',Yii::app()->params['defaultEllipsizeQuestionValue']);
}
}

/**
* Show responses for survey
*
Expand Down
25 changes: 23 additions & 2 deletions application/models/SurveyDynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class SurveyDynamic extends LSActiveRecord
protected static $sid = 0;
protected $bHaveToken;


/**
* Returns the static model of Settings table
*
Expand Down Expand Up @@ -320,7 +319,7 @@ function getExtendedData($colName, $sLanguage, $base64jsonFieldMap)
$sFullValue = strip_tags(getExtendedAnswer(self::$sid, $oFieldMap->fieldname, $value, $sLanguage));
if (strlen($sFullValue) > 50)
{
$sElipsizedValue = ellipsize($sFullValue, 50 );
$sElipsizedValue = ellipsize($sFullValue, $this->ellipsize_question_value );
$sValue = '<span data-toggle="tooltip" data-placement="left" title="'.quoteText($sFullValue).'">'.$sElipsizedValue.'</span>';
}
else
Expand Down Expand Up @@ -550,6 +549,28 @@ public function getDefaultColumns()
return array('id', 'token', 'submitdate', 'lastpage','startlanguage', 'completed');
}

/**
* Define what value to use to ellipsize the headers of the grid
* It's using user state/default config, like for pagination
* @see: http://www.yiiframework.com/wiki/324/cgridview-keep-state-of-page-and-sort/
* @see: http://www.yiiframework.com/forum/index.php?/topic/8994-dropdown-for-pagesize-in-cgridview
*/
public function getEllipsize_header_value()
{
return Yii::app()->user->getState('defaultEllipsizeHeaderValue',Yii::app()->params['defaultEllipsizeHeaderValue']);
}

/**
* Define what value to use to ellipsize the question in the grid
* It's using user state/default config, like for pagination.
* @see: http://www.yiiframework.com/wiki/324/cgridview-keep-state-of-page-and-sort/
* @see: http://www.yiiframework.com/forum/index.php?/topic/8994-dropdown-for-pagesize-in-cgridview
*/
public function getEllipsize_question_value()
{
return Yii::app()->user->getState('defaultEllipsizeQuestionValue',Yii::app()->params['defaultEllipsizeQuestionValue']);
}

public function search()
{
$pageSize = Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);
Expand Down
27 changes: 25 additions & 2 deletions application/views/admin/responses/listResponses_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@
<?php eT("You can use operators in the search filters (eg: >, <, >=, <=, = )");?>
</p>

<!-- Display mode -->
<div class="row">
<div class="pull-right">
<div class="form text-right">
<div class="form-group">
<?php $this->widget(
'yiiwheels.widgets.switch.WhSwitch',
array(
'name' => 'reponses-display-mode',
'onLabel' => gT('Extended'),
'offLabel' => gT('Compact'),
'offColor' => 'default',
'value' => Yii::app()->user->getState('responsesGridSwitchDisplayState'),
'htmlOptions'=> array(
'data-url'=>App()->createUrl('/admin/responses/set_grid_display/')
),
));
?>
</div>
</div>
</div>
</div>


<div class="row">
<div class="content-right scrolling-wrapper" >
<?php
Expand Down Expand Up @@ -116,7 +140,7 @@

$aColumns[]=
array(
'header' => '<span data-toggle="tooltip" data-placement="bottom" title="'.quoteText(strip_tags($fieldmap[$column->name]['question'])).'">'.$colName.' <br/> '.ellipsize($fieldmap[$column->name]['question'], 30).'</span>',
'header' => '<span data-toggle="tooltip" data-placement="bottom" title="'.quoteText(strip_tags($fieldmap[$column->name]['question'])).'">'.$colName.' <br/> '.ellipsize($fieldmap[$column->name]['question'], $model->ellipsize_header_value).'</span>',
'headerHtmlOptions'=>array('style'=>'min-width: 350px;'),
'name' => $column->name,
'type' => 'raw',
Expand Down Expand Up @@ -195,7 +219,6 @@
'name' => "no",
'id' => "no",
'value' => '',

));
?>
</div>
20 changes: 20 additions & 0 deletions scripts/admin/listresponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ $(document).ready(function(){
});
});


$('#reponses-display-mode').on('switchChange.bootstrapSwitch', function(event, state) {
$actionUrl = $(this).data('url');
$display = (state==true)?'extended':'compact';
console.log($display);
$postDatas = {state:$display};
$.ajax({
url : $actionUrl,
type : 'POST',
data : $postDatas,

// html contains the buttons
success : function(html, statut){
$.fn.yiiGridView.update('responses-grid');
},
error : function(html, statut){
console.log(html);
}
});
});
});

0 comments on commit 56f2ccf

Please sign in to comment.