Skip to content

Commit

Permalink
Dev: added Ajax + Grid Reload to confirmdeletemodal.js
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 20, 2018
1 parent 169f94a commit f73c171
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
15 changes: 13 additions & 2 deletions application/controllers/admin/responses.php
Expand Up @@ -151,7 +151,7 @@ public function viewquexmlpdf($iSurveyID, $iId, $sBrowseLang = '')
$message['class'] = "error";
$this->_renderWrappedTemplate('survey', array("message"=>$message), $aData);
}
}
}

/**
* View a single response in detail
Expand Down Expand Up @@ -397,7 +397,7 @@ public function browse($iSurveyId)
{
$survey = Survey::model()->findByPk($iSurveyId);
$displaymode = Yii::app()->request->getPost('displaymode', null);

if ($displaymode !== null) {
$this->set_grid_display($displaymode);
}
Expand Down Expand Up @@ -522,7 +522,18 @@ public function actionDelete($surveyid)

$iSurveyId = (int) $surveyid;
if (Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'delete')) {

$ResponseId = (Yii::app()->request->getPost('sItems') != '') ? json_decode(Yii::app()->request->getPost('sItems')) : json_decode(Yii::app()->request->getPost('sResponseId'), true);


if ( Yii::app()->request->getPost('modalTextArea') != '' ){
$ResponseId = explode(',', Yii::app()->request->getPost('modalTextArea'));

foreach($ResponseId as $key => $sResponseId){
$ResponseId[$key] = str_replace(' ', '', $sResponseId);
}
}

$aResponseId = (is_array($ResponseId)) ? $ResponseId : array($ResponseId);

$errors = 0;
Expand Down
24 changes: 23 additions & 1 deletion application/views/admin/responses/browsemenubar_view.php
Expand Up @@ -22,7 +22,7 @@
<?php else:?>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-list text-success"></span>
<span class="fa fa-list text-success"></span>
<?php eT("Responses"); ?> <span class="fa fa-caret-down"></span>
</button>
<ul class="dropdown-menu">
Expand Down Expand Up @@ -144,7 +144,29 @@
</a>
<?php endif;?>
<?php endif;?>

<!-- Batch deletion -->
<?php if (Permission::model()->hasSurveyPermission($surveyid, 'responses', 'delete')): ?>
<a
id="response-batch-deletion"
href="<?php echo $this->createUrl("/admin/responses/sa/actionDelete/", array("surveyid" => $_GET['surveyid'] )); ?>"

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Sep 3, 2018

Collaborator

WTF !

XSS and more issue here …

Edit :

Ouf … fixed before by

if ((string) (int) $params['iSurveyId'] !== (string) $params['iSurveyId']) {

But this must be really fixed (and avoided)

data-post="{}"
data-show-text-area="true"
data-use-ajax="true"
data-grid-id="responses-grid"
data-grid-reload="true"
data-text="<?php eT('Enter the list of IDs here for questions that are to be deleted, separated by comma.')?>"
title="<?php eT('Batch deletion')?>"
class="btn btn-default selector--ConfirmModal">

<span class="fa fa-trash text-danger"></span>
<?php eT("Batch deletion"); ?>
</a>
<?php endif;?>

</div>


<?php else: ?>
<div class="col-md-7 text-right col-md-offset-5">
<?php if(isset($menu['save'])): ?>
Expand Down
Expand Up @@ -35,7 +35,7 @@
'type' => 'action',
'action' => 'deleteAttachments',
//'url' => App()->createUrl("admin/responses", array("sa"=>"actionDeleteAttachments")),
'url' => App()->createUrl('/admin/responses/sa/actionDeleteAttachments/surveyid/'.$_GET['surveyid']),
'url' => App()->createUrl("/admin/responses/sa/actionDelete/", array("surveyid" => $_GET['surveyid'] )),
'iconClasses' => 'text-danger fa fa-paperclip',
'text' => gT('Delete attachments'),
'grid-reload' => 'yes',
Expand Down
56 changes: 53 additions & 3 deletions assets/packages/adminbasics/js/confirmdeletemodal.js
Expand Up @@ -12,6 +12,10 @@ var ConfirmDeleteModal = function(options){
confirmTitle = options.confirmTitle || $item.attr('title') || '',
postObject = options.postObject || $item.data('post'),
showTextArea = options.showTextArea || $item.data('show-text-area') || '',
useAjax = options.useAjax || $item.data('use-ajax') || '',
keepopen = options.keepopen || $item.data('keepopen') || '',
gridReload = options.gridReload || $item.data('grid-reload') || '',
gridid = options.gridid || $item.data('grid-id') || '',
buttonNo = options.buttonNo || $item.data('button-no') || '<i class="fa fa-times"></i>',
buttonYes = options.buttonYes || $item.data('button-yes') || '<i class="fa fa-check"></i>',
parentElement = options.parentElement || $item.data('parent-element') || 'body';
Expand Down Expand Up @@ -76,7 +80,7 @@ var ConfirmDeleteModal = function(options){
modalObject.find('.modal-body').append('<p>'+confirmText+'</p>');

if (showTextArea !== '' ){
modalObject.find('.modal-body').append('<textarea></textarea>');
modalObject.find('form').append('<textarea id="modalTextArea" name="modalTextArea" ></textarea>');
}

},
Expand All @@ -89,8 +93,54 @@ var ConfirmDeleteModal = function(options){
var self = this;
modalObject.find('.selector--button-confirm').on('click', function(e){
e.preventDefault();
modalObject.find('form').trigger('submit');
modalObject.modal('close');

if (! useAjax ){
modalObject.find('form').trigger('submit');
modalObject.modal('close');
}else{

// Ajax request
$.ajax({
url : postUrl,
type : 'POST',
data : modalObject.find('form').serialize(),

// html contains the buttons
success : function(html, statut){

if( keepopen != 'true' ){
modalObject.modal('hide'); // $modal.modal('hide');
}else{
modalObject.find('.modal-body').empty().html(html); // Inject the returned HTML in the modal body
}

// Reload grid
if (gridReload){
$('#'+gridid).yiiGridView('update'); // Update the surveys list
setTimeout(function(){
$(document).trigger("actions-updated");}, 500); // Raise an event if some widgets inside the modals need some refresh (eg: position widget in question list)
}

if (html.ajaxHelper) {
LS.ajaxHelperOnSuccess(html);
return;
}

if (onSuccess) {
var func = eval(onSuccess);
func(html);
return;
}


},
error : function(html, statut){
modalObject.find('.modal-body').empty().html(html.responseText);
console.log(html);
}
});

}
});
options.fnOnShown.call(this);
});
Expand Down

0 comments on commit f73c171

Please sign in to comment.