Skip to content

Commit

Permalink
Fixed issue #15450: The GridView in "Saved but not submitted[...]" is…
Browse files Browse the repository at this point in the history
… incomplete and lacks pagination and filtering
  • Loading branch information
lacrioque committed Oct 23, 2019
1 parent d26da62 commit ace7349
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 57 deletions.
32 changes: 21 additions & 11 deletions application/controllers/admin/saved.php
Expand Up @@ -40,23 +40,33 @@ public function view($iSurveyId)
}

$aThisSurvey = getSurveyInfo($iSurveyId);
$oSavedControlModel = SavedControl::model();
$oSavedControlModel->sid = $iSurveyId;
$aData['model'] = $oSavedControlModel;
$aData['sSurveyName'] = $aThisSurvey['name'];
$aData['iSurveyId'] = $iSurveyId;
$aData['dataProvider'] = new CActiveDataProvider('SavedControl', array(
'criteria'=>array(
'condition'=>'sid=:sid',
'params'=>[':sid'=>$iSurveyId],
),
'countCriteria'=>array(
'condition'=>'sid=:sid',
'params'=>[':sid'=>$iSurveyId],
),
));
$aData['SavedControlModel'] = SavedControl::model();
// Set page size
if (Yii::app()->request->getPost('savedResponsesPageSize')) {
Yii::app()->user->setState('savedResponsesPageSize', Yii::app()->request->getPost('savedResponsesPageSize'));
}
$aData['savedResponsesPageSize'] = Yii::app()->user->getState('savedResponsesPageSize', Yii::app()->params['defaultPageSize']);
$aViewUrls[] = 'savedlist_view';
$this->_renderWrappedTemplate('saved', $aViewUrls, $aData);
}

/**
* Undocumented function
*
* @todo write function
* @param [type] $surveyid
* @param [type] $id
* @return void
*/
public function resend_accesscode($surveyid, $id) {

}


/**
* Function responsible to delete saved responses.
* @param int $surveyid
Expand Down
102 changes: 86 additions & 16 deletions application/models/SavedControl.php
Expand Up @@ -52,7 +52,6 @@ public static function model($class = __CLASS__)
return parent::model($class);
}


public function getAllRecords($condition = false)
{
if ($condition != false) {
Expand Down Expand Up @@ -89,7 +88,7 @@ public function deleteSomeRecords($condition)
$criteria = new CDbCriteria;

if ($condition != false) {
foreach ($condition as $column=>$value) {
foreach ($condition as $column => $value) {
$criteria->addCondition("$column='$value'");
}
}
Expand All @@ -102,33 +101,104 @@ public function insertRecords($data)
return $this->db->insert('saved_control', $data);
}

public function getGridButtons($surveyid)
public function getGridButtons()
{
$gridButtons = array();
$gridButtons['editresponse'] = array(
'label'=>'<span class="sr-only">'.gT("Edit").'</span><span class="fa fa-list-alt" aria-hidden="true"></span>',
'imageUrl'=>false,
'label' => '<span class="sr-only">' . gT("Edit") . '</span><span class="fa fa-list-alt" aria-hidden="true"></span>',
'imageUrl' => false,
'url' => 'App()->createUrl("admin/dataentry/sa/editdata/subaction/edit",array("surveyid"=>$data->sid,"id"=>$data->srid));',
'options' => array(
'class'=>"btn btn-default btn-xs btn-edit",
'data-toggle'=>"tooltip",
'title'=>gT("Edit response")
'class' => "btn btn-default btn-xs btn-edit",
'data-toggle' => "tooltip",
'title' => gT("Edit response"),
),
'visible' => 'boolval(' . Permission::model()->hasSurveyPermission($this->sid, 'responses', 'update') . ')',
);
$gridButtons['resend_accesscode'] = array(
'label' => '<span class="sr-only">' . gT("Edit") . '</span><span class="fa fa-refresh" aria-hidden="true"></span>',
'imageUrl' => false,
'url' => 'App()->createUrl("admin/saved/sa/resend_accesscode",array("surveyid"=>$data->sid,"id"=>$data->srid));',
'options' => array(
'class' => "btn btn-default btn-xs btn-edit",
'data-toggle' => "tooltip",
'title' => gT("Resend access code"),
),
'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'update').')',
// 'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'update').')',
'visible' => false,
);
$gridButtons['delete'] = array(
'label'=>'<span class="sr-only">'.gT("Delete").'</span><span class="text-warning fa fa-trash" aria-hidden="true"></span>',
'imageUrl'=>false,
'icon'=>false,
'label' => '<span class="sr-only">' . gT("Delete") . '</span><span class="text-warning fa fa-trash" aria-hidden="true"></span>',
'imageUrl' => false,
'icon' => false,
'url' => 'App()->createUrl("admin/saved/sa/actionDelete",array("surveyid"=>$data->sid,"scid"=>$data->scid,"srid"=>$data->srid));',
'options' => array(
'class'=>"btn btn-default btn-xs btn-delete",
'data-toggle'=>"tooltip",
'title'=>gT("Delete this entry and related response")
'class' => "btn btn-default btn-xs btn-delete",
'data-toggle' => "tooltip",
'title' => gT("Delete this entry and related response"),
),
'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'delete').')',
'visible' => 'boolval(' . Permission::model()->hasSurveyPermission($this->sid, 'responses', 'delete') . ')',
'click' => 'function(event){ window.LS.gridButton.confirmGridAction(event,$(this)); }',
);
return $gridButtons;
}

public function getColumns()
{
return array(
array(
'header' => gT("ID"),
'name' => 'scid',
'filter' => false,
),
array(
'class' => 'bootstrap.widgets.TbButtonColumn',
'template' => '{editresponse}{delete}',
//~ 'htmlOptions' => array('class' => 'text-left response-buttons'),
'buttons' => $this->gridButtons,
),
array(
'header' => gT("Identifier"),
'name' => 'identifier',
),
array(
'header' => gT("IP address"),
'name' => 'ip',
),
array(
'header' => gT("Date saved"),
'name' => 'saved_date',
),
array(
'header' => gT("Email address"),
'name' => 'email',
),
);
}

public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('sid', $this->sid, true); //will not be searchable
$criteria->compare('srid', $this->srid, true);
$criteria->compare('access_code', $this->access_code, true);

$criteria->compare('scid', $this->scid);
$criteria->compare('identifier', $this->identifier, true);
$criteria->compare('email', $this->email);
$criteria->compare('ip', $this->ip, true);
$criteria->compare('saved_thisstep', $this->saved_thisstep, true);
$criteria->compare('status', $this->status, true);
$criteria->compare('saved_date', $this->saved_date, true);
$criteria->compare('refurl', $this->refurl, true);
$pageSize = Yii::app()->user->getState('savedResponsesPageSize', Yii::app()->params['defaultPageSize']);

return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => $pageSize,
),
));
}
}
47 changes: 17 additions & 30 deletions application/views/admin/saved/savedlist_view.php
Expand Up @@ -7,39 +7,26 @@
<div class="row">
<div class="col-lg-12 content-right">
<?php
$this->widget('ext.LimeGridView.LimeGridView', array(
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'saved-grid',
'ajaxUpdate' => 'saved-grid',
'dataProvider' => $dataProvider,
'ajaxUpdate' => 'saved-grid',
'dataProvider' => $model->search(),
'columns' => $model->columns,
'filter' => $model,
'ajaxType' => 'POST',
'template' => "{items}\n<div class='row'><div class='col-sm-4 col-md-offset-4'>{pager}</div><div class='col-sm-4'>{summary}</div></div>",
'columns' => array(
array(
'header' => gT("ID"),
'name' => 'scid',
),
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{editresponse}{delete}',
//~ 'htmlOptions' => array('class' => 'text-left response-buttons'),
'buttons'=> $SavedControlModel->getGridButtons($iSurveyId),
),
array(
'header' => gT("Identifier"),
'name' => 'identifier',
),
array(
'header' => gT("IP address"),
'name' => 'ip',
),
array(
'header' => gT("Date saved"),
'name' => 'saved_date',
),
array(
'header' => gT("Email address"),
'name' => 'email',
),
'emptyText'=>gT('No customizable entries found.'),
'summaryText'=>gT('Displaying {start}-{end} of {count} result(s).').' '. sprintf(gT('%s rows per page'),
CHtml::dropDownList(
'savedResponsesPageSize',
$savedResponsesPageSize,
Yii::app()->params['pageSizeOptions'],
array(
'class'=>'changePageSize form-control',
'style'=>'display: inline; width: auto',
'onchange' => "$.fn.yiiGridView.update('saved-grid',{ data:{ savedResponsesPageSize: $(this).val() }});"
)
)
),
)
);
Expand Down

0 comments on commit ace7349

Please sign in to comment.