Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Dev: Usage of CButtonColumn for token
Dev: still CPDB
Dev: still control POST value in token
  • Loading branch information
Shnoulle committed Nov 9, 2018
1 parent 08bfb54 commit d26afa7
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 82 deletions.
6 changes: 3 additions & 3 deletions application/models/SurveyDynamic.php
Expand Up @@ -317,6 +317,7 @@ public function getGridButtons()
'data-toggle'=>"tooltip",
'title'=>gT("Edit this response")
),
'visible'=> 'boolval('.Permission::model()->hasSurveyPermission(self::$sid, 'responses', 'update').')',
);
/* downloadfile button */
$gridButtons['downloadfiles'] = array(
Expand All @@ -336,7 +337,7 @@ public function getGridButtons()
'label'=>'<span class="sr-only">'.gT("Delete all files of this response").'</span><span class="fa fa-paperclip text-danger" aria-hidden="true"></span>',
'imageUrl'=>false,
'url' => 'App()->createUrl("admin/responses/sa/actionDeleteAttachments",array("surveyid"=>'.self::$sid.',"sResponseId"=>$data->id));',
'visible'=> $surveyHasFileUploadQuestion.' && Response::model('.self::$sid.')->findByPk($data->id)->someFileExists()',
'visible'=> Permission::model()->hasSurveyPermission(self::$sid, 'responses', 'update') && $surveyHasFileUploadQuestion.' && Response::model('.self::$sid.')->findByPk($data->id)->someFileExists()',
'options' => array(
'class' => "btn btn-default btn-xs btn-deletefiles",
'data-toggle' => "tooltip",
Expand All @@ -351,12 +352,11 @@ public function getGridButtons()
'label'=>'<span class="sr-only">'.gT("Delete this response").'</span><span class="fa fa-trash text-danger" aria-hidden="true"></span>',
'imageUrl'=>false,
'url' => 'App()->createUrl("admin/responses/sa/actionDelete",array("surveyid"=>'.self::$sid.',"sResponseId"=>$data->id));',
'visible'=> $surveyHasFileUploadQuestion.' && Response::model('.self::$sid.')->findByPk($data->id)->someFileExists()',
'visible'=> 'boolval('.Permission::model()->hasSurveyPermission(self::$sid, 'responses', 'delete').')',
'options' => array(
'class' => "btn btn-default btn-xs btn-deletefiles",
'data-toggle' => "tooltip",
'title' => gT("Delete all files of this response"),
'data-confirm-utf8' => json_encode(array("confirm_ok" =>gT("Yes"),"confirm_cancel" => gT("No"))),
'data-confirm-text' => gT("Delete all files of this response"),
),
'click' => $scriptConfirm,
Expand Down
113 changes: 66 additions & 47 deletions application/models/TokenDynamic.php
Expand Up @@ -634,7 +634,7 @@ public function getStandardColsForGrid()
array(
'header' => gT('Action'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{viewresponse}{previewsurvey}',
'template'=>'{viewresponse}{spacerviewresponse}{previewsurvey}{mail}{remind}{edit}{delete}',
'buttons'=> $this->getGridButtons(),
),
array(
Expand Down Expand Up @@ -817,7 +817,19 @@ public function getGridButtons()
'data-toggle'=>"tooltip",
'title'=>gT("View response details")
),
'visible'=> '$data->survey->active == "Y" && $data->survey->anonymized != "Y" && count($data->responses) > 0',
'visible'=> (Permission::model()->hasSurveyPermission(self::$sid, 'responses', 'read') && $this->survey->active == "Y" && $this->survey->anonymized != "Y") .' && count($data->responses) > 0',
);
$gridButtons['spacerviewresponse'] = array(
'label'=>'<span class="fa fa-list-alt text-muted" aria-hidden="true"></span>',
'imageUrl'=>false,
'url' => '#',
'options' => array(
'class'=>"btn btn-default btn-xs",
'disabled' => 'disabled',
'title'=>''
),
'visible'=> (Permission::model()->hasSurveyPermission(self::$sid, 'responses', 'read') && $this->survey->active == "Y" && $this->survey->anonymized != "Y") .' && count($data->responses) == 0',
'click' => 'noaction'
);
/* previewsurvey button */
$gridButtons['previewsurvey'] = array(
Expand All @@ -830,6 +842,58 @@ public function getGridButtons()
'data-toggle'=>"tooltip",
'title'=>gT("Launch the survey with this token")
),
'visible'=> (Permission::model()->hasSurveyPermission(self::$sid, 'responses', 'create') && $this->survey->active == "Y") . ' && ( $data->completed == "N" || empty($data->completed) || $data->survey->alloweditaftercompletion == "Y")'
);
/* mailing mail button */
$gridButtons['mail'] = array(
'label'=>'<span class="sr-only">'.gT("Send email invitation").'</span><span class="icon-invite" aria-hidden="true"></span>',// fa-enveloppe-o
'imageUrl'=>false,
'url' => 'App()->createUrl("/admin/tokens/sa/email",array("surveyid"=>'.self::$sid.',"tokenids"=>$data->tid,));',
'options' => array(
'class'=>"btn btn-default btn-xs",
'data-toggle'=>"tooltip",
'title'=>gT("Send email invitation")
),
'visible'=> Permission::model()->hasSurveyPermission(self::$sid, 'tokens', 'update') . ' && ($data->sent== "N" || empty($data->sent)) && $data->emailstatus == "OK" && $data->email && $data->completed == "N" && ($data->usesleft > 0 || $data->survey->alloweditaftercompletion == "Y")',
);
/* mailing remind button */
$gridButtons['remind'] = array(
'label'=>'<span class="sr-only">'.gT("Send email reminder").'</span><span class="icon-remind" aria-hidden="true"></span>',
'imageUrl'=>false,
'url' => 'App()->createUrl("/admin/tokens/sa/remind",array("surveyid"=>'.self::$sid.',"tokenids"=>$data->tid));',
'options' => array(
'class'=>"btn btn-default btn-xs",
'data-toggle'=>"tooltip",
'title'=>gT("Send email reminder")
),
'visible'=> Permission::model()->hasSurveyPermission(self::$sid, 'tokens', 'update') . ' && !($data->sent== "N" || empty($data->sent)) && $data->emailstatus == "OK" && $data->email && $data->completed == "N" && ($data->usesleft > 0 || $data->survey->alloweditaftercompletion == "Y")',
);
/* edit button button */
$gridButtons['edit'] = array(
'label'=>'<span class="sr-only">'.gT('Edit this survey participant').'</span><span class="fa fa-edit" aria-hidden="true"></span>',
'imageUrl'=>false,
'url' => 'App()->createUrl("/admin/tokens/sa/edit",array("iSurveyId"=>'.self::$sid.',"iTokenId"=>$data->tid,"ajax"=>"true"));',
'options' => array(
'class'=>"btn btn-default btn-xs btn-edit",
'data-toggle'=>"tooltip",
'title'=>gT('Edit this survey participant'),
'data-sid' => self::$sid
),
'visible' => 'boolval('.Permission::model()->hasSurveyPermission(self::$sid, 'tokens', 'update').')',
'click' => 'startEditToken'
);
/* delete button */
$gridButtons['delete'] = array(
'label'=>'<span class="sr-only">'.gT('Delete survey participant').'</span><span class="text-warning fa fa-trash" aria-hidden="true"></span>',
'imageUrl'=>false,
'url' => 'App()->createUrl("/admin/tokens/sa/deleteToken",array("sid"=>'.self::$sid.',"sItem"=>$data->tid,"ajax"=>"true"));',
'options' => array(
'class'=>"btn btn-danger btn-xs btn-delete",
'data-toggle'=>"tooltip",
'title'=>gT('Delete survey participant'),
),
'visible' => 'boolval('.Permission::model()->hasSurveyPermission(self::$sid, 'tokens', 'delete').')',
'click' => 'confirmGridAction'
);
return $gridButtons;
}
Expand All @@ -849,51 +913,6 @@ public function getbuttons()
$sDeleteUrl = App()->createUrl("admin/tokens/sa/deleteToken/sid/".self::$sid."/sItem/$this->tid");
$button = '';

// View response details
if ($this->survey->isActive
&& Permission::model()->hasSurveyPermission(self::$sid, 'responses', 'read')
&& $this->survey->anonymized != 'Y') {

if (count($this->responses) > 0) {

if (count($this->responses) < 2) {
$sResponseUrl = App()->createUrl("admin/responses/sa/viewbytoken/surveyid/".self::$sid, array('token'=>$this->token));
$button .= '<a class="btn btn-default btn-xs" href="'.$sResponseUrl.'" target="_blank" role="button" data-toggle="tooltip" title="'.gT("View response details").'"><span class="fa fa-list-alt" ></span></a>';
}
// Multiple answers, give choice to user
else {
// TODO: link to Response grid filtered on the base of this Token (when responses will be rewritten using CGridView instead of jQgrid)
$sResponseUrl = App()->createUrl("admin/responses/sa/viewbytoken/surveyid/".self::$sid, array('token'=>$this->token));
$button .= '<a class="btn btn-default btn-xs" href="'.$sResponseUrl.'" target="_blank" role="button" data-toggle="tooltip" title="'.gT("View last response details").'"><span class="fa fa-list-alt" ></span></a>';
}
}
} else {
$button .= '<span class="btn btn-default btn-xs disabled blank_button" href="#"><span class="fa-fw fa" ></span></span>';
}

// Launch the survey with this token
if (($this->completed == "N" || $this->completed == "" || $this->survey->alloweditaftercompletion == "Y")
&& Permission::model()->hasSurveyPermission(self::$sid, 'responses', 'create')) {

$button .= '<a class="btn btn-default btn-xs" href="'.$sPreviewUrl.'" target="_blank" role="button" data-toggle="tooltip" title="'.gT('Launch the survey with this token').'"><span class="icon-do" ></span></a>';
} else {
$button .= '<span class="btn btn-default btn-xs disabled blank_button" href="#"><span class="fa-fw fa" ></span></span>';
}

// Invite or Remind
if ($this->emailstatus && $this->email && Permission::model()->hasSurveyPermission(self::$sid, 'tokens', 'update')) {
if ($this->completed == 'N' && $this->usesleft > 0) {
if ($this->sent == 'N') {
$button .= '<a class="btn btn-default btn-xs" href="'.$sInviteUrl.'" role="button" data-toggle="tooltip" title="'.gT('Send email invitation').'"><span class="icon-invite" ></span></a>';
} else {
$button .= '<a class="btn btn-default btn-xs" href="'.$sRemindUrl.'" role="button" data-toggle="tooltip" title="'.gT('Send email reminder').'"><span class="icon-remind " ></span></a>';
}
} else {
$button .= '<span class="btn btn-default btn-xs disabled blank_button" href="#"><span class="fa-fw fa" ></span></span>';
}
} else {
$button .= '<span class="btn btn-default btn-xs disabled blank_button" href="#"><span class="fa-fw fa" ></span><!-- Invite or Remind --></span>';
}

// TODO: permission check
if (Permission::model()->hasSurveyPermission(self::$sid, 'tokens', 'update')) {
Expand Down
3 changes: 3 additions & 0 deletions assets/packages/adminbasics/build/adminbasics.css
Expand Up @@ -5,6 +5,9 @@
align-content: bottom;
height: 3em; }

.grid-view .button-column {
white-space: nowrap; }

.square {
background: #0f3e12;
border-radius: 0.6em;
Expand Down

0 comments on commit d26afa7

Please sign in to comment.