Skip to content

Commit

Permalink
Dev: Fix massive action delete for CPDB
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 21, 2016
1 parent 8fae3fd commit f71b86f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
33 changes: 25 additions & 8 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -361,6 +361,8 @@ public function displayParticipants()
Yii::app()->clientScript->registerPackage('bootstrap-datetimepicker');
Yii::app()->clientScript->registerPackage('bootstrap-switch');

$aData['massiveAction'] = App()->getController()->renderPartial('/admin/participants/massive_actions/_selector', array(), true, false);

// Loads the participant panel view and display participant view
$this->_renderWrappedTemplate('participants', array('participantsPanel', 'displayParticipants'), $aData);
}
Expand All @@ -374,38 +376,53 @@ public function delParticipant()
if (Permission::model()->hasGlobalPermission('participantpanel','delete'))
{
$selectoption = Yii::app()->request->getPost('selectedoption');
$iParticipantId = Yii::app()->request->getPost('participant_id');

//echo $selectoption." -- ".$iParticipantId."<br />"; die();
// First for delete one, second for massive action
$participantId = Yii::app()->request->getPost('participant_id');
$participantIds = json_decode(Yii::app()->request->getPost('sItems'), true);

if (empty($participantIds))
{
$participantIds = $participantId;
}

if (is_array($participantIds))
{
$participantIds = join($participantIds, ',');
}

// Deletes from participants only
if ($selectoption == 'po')
{
Participant::model()->deleteParticipants($iParticipantId);
Participant::model()->deleteParticipants($participantIds);
}
// Deletes from central and token table
elseif ($selectoption == 'ptt')
{
Participant::model()->deleteParticipantToken($iParticipantId);
Participant::model()->deleteParticipantToken($participantIds);
}
// Deletes from central , token and assosiated responses as well
elseif ($selectoption == 'ptta')
{
Participant::model()->deleteParticipantTokenAnswer($iParticipantId);
Participant::model()->deleteParticipantTokenAnswer($participantIds);
}
else
{
// Internal error
assert(false);
}

echo json_encode(array(
'success' => true,
'successMessage' => gT('Participant deleted')
));
die();
}
else
{
echo json_encode(array(
'success' => false,
'errorMessage' => gT('You do not have the right to do that')
'errorMessage' => gT('No permission')
));
die();
}
}

Expand Down
Expand Up @@ -79,6 +79,7 @@
'afterAjaxUpdate' => 'bindButtons',
'ajaxType' => 'POST',
'beforeAjaxUpdate' => 'insertSearchCondition',
'template' => "{items}\n<div id='tokenListPager'><div class=\"col-sm-4\" id=\"massive-action-container\">$massiveAction</div><div class=\"col-sm-4 pager-container \">{pager}</div><div class=\"col-sm-4 summary-container\">{summary}</div></div>",
'summaryText' => gT('Displaying {start}-{end} of {count} result(s).').' '. sprintf(gT('%s rows per page'),
CHtml::dropDownList(
'pageSizeParticipantView',
Expand Down
@@ -1,6 +1,6 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="participant_edit_modal"><?php echo $model->firstname."&nbsp;".$model->lastname; ?></h4>
<h4 class="modal-title" id="participant_edit_modal"><?php eT('Delete participant'); ?></h4>
</div>
<div class="modal-body form-horizontal">
<?php
Expand All @@ -9,23 +9,23 @@
array(
'id' => 'deleteParticipantActiveForm',
'action' => array('admin/participants/sa/editValueParticipantPanel'),
'htmlOptions' => array('class' => 'well form-horizontal'), // for inset effect
'htmlOptions' => array('class' => 'form-horizontal'), // for inset effect
)
);
?>
<input type="hidden" name="actionTarget" value="deleteParticipant" />
<input type="hidden" name="participant_id" value="<?php echo $model->participant_id; ?>" />
<h5><?php printf(gT("You are sure you want to delete %s from the Central participant panel?"), $model->firstname."&nbsp;".$model->lastname)?></h5>
<p><?php eT("Please choose one option."); ?></p>
<select name='selectedoption' class="form-control" >
<option value="po" selected><?php eT("Delete only from the central panel") ?></option>
<option value="pt"><?php eT("Delete from the central panel and associated surveys") ?></option>
<option value="ptta"><?php eT("Delete from central panel, associated surveys and all associated responses") ?></option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger action_save_modal_deleteParticipant" data-dismiss="modal"><?php eT('Delete Participant') ?></button>
<button type="button" class="btn btn-danger action_save_modal_deleteParticipant" data-dismiss="modal"><span class='fa fa-trash'></span>&nbsp;<?php eT('Delete') ?></button>
<button type="button" class="btn btn-default" data-dismiss="modal"><?php eT('Close') ?></button>
</div>
<?php
$this->endWidget();
?>
?>

0 comments on commit f71b86f

Please sign in to comment.