Skip to content

Commit

Permalink
Dev: Possible to remove one single participant share (CPDB)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 28, 2016
1 parent 5a51b69 commit 2f0f4a7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
34 changes: 30 additions & 4 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -161,6 +161,8 @@ public function editValueParticipantPanel()
case "rejectShareParticipant":
$this->rejectShareParticipant();
break;
case "deleteSingleParticipantShare":
$this->deleteSingleParticipantShare();
default:
echo "";
break;
Expand Down Expand Up @@ -1809,6 +1811,8 @@ public function sharePanel()
$aData['searchstring'] = $searchstring;
App()->getClientScript()->registerPackage('bootstrap-switch');

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

// Loads the participant panel view and display participant view
$this->_renderWrappedTemplate('participants', array('participantsPanel', 'sharePanel'), $aData);
}
Expand Down Expand Up @@ -2174,6 +2178,7 @@ public function shareParticipant()
}

/**
* Deletes *all* shares for this participant
* @return void
*/
public function rejectShareParticipant()
Expand All @@ -2184,6 +2189,29 @@ public function rejectShareParticipant()
ls\ajax\AjaxHelper::outputSuccess(gT("Participant removed from sharing"));
}

/**
* Deletes a single participant share
* Called by Ajax; echoes success/error
* @param string $participantId
* @param int $share_uid
* @return void
*/
public function deleteSingleParticipantShare($participantId, $shareUid)
{
$participantShare = ParticipantShare::model()->findByPk(array(
'participant_id' => $participantId,
'share_uid' => $shareUid
));

if (empty($participantShare)) {
ls\ajax\AjaxHelper::outputError(gT('Found no participant share'));
}
else {
$participantShare->delete();
ls\ajax\AjaxHelper::outputSuccess(gT('Participant share deleted'));
}
}

/**
* @return void
*/
Expand All @@ -2193,13 +2221,11 @@ public function changeSharedEditableStatus()
$can_edit = Yii::app()->request->getPost('can_edit');
$shareModel = ParticipantShare::model()->findByAttributes(array('participant_id' => $participant_id));

if ($shareModel)
{
if ($shareModel) {
$shareModel->can_edit = ($can_edit == 'true' ? 1 : 0);
$success = $shareModel->save();
}
else
{
else {
$success = false;
}
echo json_encode(array("newValue" => $can_edit, "success" => $success));
Expand Down
3 changes: 3 additions & 0 deletions application/models/Participant.php
Expand Up @@ -98,6 +98,9 @@ public function relations()
// return ($count!==0 ? $count : '');
// }

/**
* @return string
*/
public function getButtons(){
$buttons = "<div style='white-space: nowrap'>";
$raw_button_template = ""
Expand Down
16 changes: 11 additions & 5 deletions application/models/ParticipantShare.php
Expand Up @@ -128,14 +128,20 @@ public function getCanEditHtml(){
public function getButtons()
{
$loggedInUser = yii::app()->user->getId();
if($this->participant->owner_uid == $loggedInUser)
{
return "<a href='#' data-toggle='modal' data-target='#confirmation-modal' data-onclick='rejectParticipantShareAjax(\"".$this->participant_id."\")'>"
if($this->participant->owner_uid == $loggedInUser) {
$url = Yii::app()->createUrl(
'admin/participants/sa/deleteSingleParticipantShare',
array(
'participantId' => urlencode($this->participant_id),
'shareUid' => $this->share_uid
)
);

return "<a href='#' data-toggle='modal' data-target='#confirmation-modal' data-onclick='(function() { LS.CPDB.deleteSingleParticipantShare(\"" . $url . "\"); })'>"
. "<button class='btn btn-xs btn-default action_delete_shareParticipant'><i class='fa fa-trash text-danger'></i></button>"
. "</a>";
}
else
{
else {
return '';
}
}
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/participants/sharePanel_view.php
Expand Up @@ -15,7 +15,7 @@
'filter'=>$model,
'ajaxType' => 'POST',
'afterAjaxUpdate' => 'LS.CPDB.bindButtons',
'template' => "{items}\n<div id='tokenListPager'><div class=\"col-sm-4\" id=\"massive-action-container\"></div><div class=\"col-sm-4 pager-container \">{pager}</div><div class=\"col-sm-4 summary-container\">{summary}</div></div>",
'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(
'pageSizeShareParticipantView',
Expand Down
6 changes: 4 additions & 2 deletions scripts/admin/admin_core.js
Expand Up @@ -219,7 +219,7 @@ $(document).ready(function(){
});
}
else {
throw "Confirmation modal: onclick is not a function.";
throw "Confirmation modal: onclick is not a function. Wrap data-onclick content in (function() { ... }).";
}

}
Expand Down Expand Up @@ -964,7 +964,9 @@ LS.ajax = function(options) {
notifyFader(response.success, 'well-lg bg-primary text-center');
}

oldSuccess(response);
if (oldSuccess) {
oldSuccess(response);
}
};

return $.ajax(options);
Expand Down
21 changes: 20 additions & 1 deletion scripts/admin/participantpanel.js
Expand Up @@ -389,6 +389,24 @@ LS.CPDB = (function() {
);
},

/**
* Call server to delete ONE single participant share
* @param {string} participantId
* @param {number} shareUid
* @return
*/
deleteSingleParticipantShare = function(url) {
console.log('url', url);
LS.ajax({
url: url,
method: "GET",
dataType: 'json',
success: function(result){
$.fn.yiiGridView.update('share_central_participants',{});
}
});
},

/**
* Bind all JS functions to button clicks
* @return
Expand Down Expand Up @@ -416,7 +434,8 @@ LS.CPDB = (function() {
onClickExport: onClickExport,
bindButtons: bindButtons,
shareMassiveAction: shareMassiveAction,
addParticipantToSurvey: addParticipantToSurvey
addParticipantToSurvey: addParticipantToSurvey,
deleteSingleParticipantShare: deleteSingleParticipantShare
};

})();
Expand Down

0 comments on commit 2f0f4a7

Please sign in to comment.