Skip to content

Commit

Permalink
Fixed issue #17500: When mass-deleting, list survey names and ids to …
Browse files Browse the repository at this point in the history
…be deleted (#2100)

* Fixed issue #17500: When mass-deleting, list survey names and ids to be deleted

* Fixed issue #17500: When mass-deleting, list survey names and ids to be deleted

- Removed hungarian notation
- Make sure the input is an array

* Fixed issue #17500: When mass-deleting, list survey names and ids to be deleted

- Fix renderItemsSelected()

Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
  • Loading branch information
gabrieljenik and encuestabizdevgit committed Nov 10, 2021
1 parent f40c560 commit ada1d9c
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
31 changes: 31 additions & 0 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -78,6 +78,37 @@ public function deleteMultiple()
);
}

/**
* Render selected items for massive action
* @return void
*/
public function renderItemsSelected()
{
$surveyIds = json_decode(Yii::app()->request->getPost('$oCheckedItems'), true);
if(!is_array($surveyIds)) {
throw new CHttpException(400, gT('Invalid list of checked items'));
}
$results = [];

$tableLabels = [gT('Survey ID'), gT('Survey Title'), gT('Status')];
foreach ($surveyIds as $surveyId) {
if (Permission::model()->hasSurveyPermission($surveyId, 'survey', 'delete')) {
$survey = Survey::model()->findByPk($surveyId);
$results[$surveyId]['title'] = $survey->correct_relation_defaultlanguage->surveyls_title;
$results[$surveyId]['result'] = 'selected';
}
}

Yii::app()->getController()->renderPartial(
'ext.admin.survey.ListSurveysWidget.views.massive_actions._selected_survey',
[
'aResults' => $results,
'successLabel' => gT('Seleted'),
'tableLabels' => $tableLabels
]
);
}

/**
* @todo
*/
Expand Down
Expand Up @@ -23,9 +23,11 @@ var onClickListAction = function () {
var $actionUrl = $that.data('url'); // The url of the Survey Controller action to call
var onSuccess = $that.data('on-success');
var $gridid = $('#'+$(this).closest('div.listActions').data('grid-id'));
var grididvalue = $gridid.attr('id');
var $oCheckedItems = $gridid.yiiGridView('getChecked', $(this).closest('div.listActions').data('pk')); // List of the clicked checkbox
var $oCheckedItems = JSON.stringify($oCheckedItems);
var actionType = $that.data('actionType');
var selectedList = $(".selected-items-list");

if( $oCheckedItems == '[]' ) {
//If no item selected, the error modal "please select first an item" is shown
Expand Down Expand Up @@ -106,6 +108,31 @@ var onClickListAction = function () {
var $oldModalTitle = $modalTitle.text();
var $oldModalBody = $modalBody.html();
var $oldModalButtons = $modal.find('.modal-footer-buttons'); // Modal footer with yes/no buttons
var modalShowSelected = $modal.data('show-selected');
var modalSelectedUrl = $modal.data('selected-url');

//Display selected data in modals after clicked on action
if (modalShowSelected == 'yes' && modalSelectedUrl) {

//set csrfToken for ajaxpost
var csrfToken = $('meta[name="csrf-token"]').attr("content");

//clear selected list view
selectedList.empty();

//ajaxpost to set data in the selected items div
$.ajax({
url :modalSelectedUrl,
type : 'POST',
data : {grididvalue, $oCheckedItems, csrfToken},
success: function(html, status) {
selectedList.html(html);
},
error: function(requestObject, error, errorThrown) {
console.log(error);
}
});
}

// When user close the modal, we put it back to its original state
$modal.on('hidden.bs.modal', function (e) {
Expand Down Expand Up @@ -152,6 +179,7 @@ var onClickListAction = function () {
$oldModalButtons.hide(); // Hide the 'Yes/No' buttons
$modalClose.show(); // Show the 'close' button
$ajaxLoader.show(); // Show the ajax loader
selectedList.empty(); //clear selected Item list

// Ajax request
$.ajax({
Expand Down
@@ -1,5 +1,11 @@
<!-- Modal confirmation for <?php echo $aAction['action'];?> -->
<div id="massive-actions-modal-<?php echo $aAction['action'];?>-<?php echo $key; ?>" class="modal fade" role="dialog" data-keepopen="<?php echo $aAction['keepopen'];?>">
<div id="massive-actions-modal-<?php echo $aAction['action'];?>-<?php echo $key; ?>"
class="modal fade"
role="dialog"
data-keepopen="<?php echo $aAction['keepopen'];?>"
data-show-selected="<?php if(isset($aAction['showSelected'])){ echo $aAction['showSelected']; }?>"
data-selected-url="<?php if(isset($aAction['selectedUrl'])){ echo $aAction['selectedUrl']; }?>"
>
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
Expand All @@ -10,6 +16,9 @@
<div class="modal-body">
<div class='modal-body-text'><?php echo $aAction['htmlModalBody']; ?></div>

<!-- shows list of selected items in the modal-->
<div class="selected-items-list"></div>

<?php if (isset($aAction['aCustomDatas'])):?>
<!--
Custom datas needed for action defined directly in the widget call.
Expand Down
@@ -0,0 +1,37 @@
<?php
/**
* This view display the result of selected surveys. It's rendered via ajax for the confirmation modal in survey list
*
* @var $aResults The array containing the result of each survey selection
*/
?>
<hr>
<table class="table table-striped">
<thead>
<th><?php eT('Survey ID');?></th>
<th><?php eT('Title');?></th>
<th><?php eT('Status');?></th>
</thead>

<tbody>
<?php foreach($aResults as $iSid => $result):?>
<tr>
<td>
<?php echo $iSid;?>
</td>
<td>
<?php echo $result['title'];?>
</td>
<?php if ($result['result']):?>
<td class="text-success">
<?php eT('Selected'); ?>
</td>
<?php else: ?>
<td class="text-warning">
<?php echo $result['error'] ; ?>
</td>
<?php endif;?>
</tr>
<?php endforeach;?>
</tbody>
</table>
Expand Up @@ -29,6 +29,8 @@
'actionType' => 'modal',
'modalType' => 'yes-no',
'keepopen' => 'yes',
'showSelected' => 'yes',
'selectedUrl' => App()->createUrl('/admin/survey/sa/renderItemsSelected/'),
'sModalTitle' => gT('Delete surveys'),
'htmlModalBody' => gT('Are you sure you want to delete all those surveys?'),
),
Expand All @@ -53,6 +55,8 @@
'actionType' => 'modal',
'modalType' => 'yes-no',
'keepopen' => 'yes',
'showSelected' => 'yes',
'selectedUrl' => App()->createUrl('/admin/survey/sa/renderItemsSelected/'),
'sModalTitle' => gT('Set survey theme'),
'htmlModalBody' => $this->controller->renderFile(__DIR__.'/_select_survey_theme.php',array(),true),
),
Expand All @@ -70,6 +74,8 @@
'actionType' => 'modal',
'modalType' => 'yes-no',
'keepopen' => 'yes',
'showSelected' => 'yes',
'selectedUrl' => App()->createUrl('/admin/survey/sa/renderItemsSelected/'),
'sModalTitle' => gT('Change survey group'),
'htmlModalBody' => $this->controller->renderFile(__DIR__.'/_change_survey_group.php',array(),true),
),
Expand Down Expand Up @@ -102,6 +108,8 @@
'actionType' => 'modal',
'modalType' => 'yes-no',
'keepopen' => 'yes',
'showSelected' => 'yes',
'selectedUrl' => App()->createUrl('/admin/survey/sa/renderItemsSelected/'),
'sModalTitle' => gT('Export survey archive'),
'htmlModalBody' => gT('This will export the survey archive (.lsa) for all selected active surveys. They will be provided in a single ZIP archive.').' '.gT('Continue?'),
),
Expand All @@ -120,6 +128,8 @@
'actionType' => 'modal',
'modalType' => 'yes-no',
'keepopen' => 'yes',
'showSelected' => 'yes',
'selectedUrl' => App()->createUrl('/admin/survey/sa/renderItemsSelected/'),
'sModalTitle' => gT('Export survey structure'),
'htmlModalBody' => gT('This will export the survey structure (.lss) for all selected active surveys. They will be provided in a single ZIP archive.').' '.gT('Continue?'),

Expand All @@ -136,6 +146,8 @@
'actionType' => 'modal',
'modalType' => 'yes-no',
'keepopen' => 'yes',
'showSelected' => 'yes',
'selectedUrl' => App()->createUrl('/admin/survey/sa/renderItemsSelected/'),
'sModalTitle' => gT('Export printable survey'),
'htmlModalBody' => gT('This will export a printable version of your survey.').' '.gT('Continue?'),
),
Expand All @@ -152,6 +164,8 @@
'actionType' => 'modal',
'modalType' => 'yes-no',
'keepopen' => 'yes',
'showSelected' => 'yes',
'selectedUrl' => App()->createUrl('/admin/survey/sa/renderItemsSelected/'),
'sModalTitle' => gT('Set expiry date'),
'htmlModalBody' => $this->controller->renderFile(__DIR__.'/_expiry_dialog.php',array(),true),
),
Expand Down

0 comments on commit ada1d9c

Please sign in to comment.