Skip to content

Commit

Permalink
Fixed issue #12962: Massive actions not working without reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 29, 2017
1 parent 903a146 commit 7ab1556
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion application/core/LSYii_ClientScript.php
Expand Up @@ -520,7 +520,7 @@ public function renderBodyEnd(&$output)
if (isset($this->scripts[self::POS_POSTSCRIPT])) {
if ($fullPage) {
//This part is different to reflect the changes needed in the backend by the pjax loading of pages
$scripts[] = "jQuery(document).off('pjax:scriptcomplete').on('ready pjax:scriptcomplete', function() {\n".implode("\n", $this->scripts[self::POS_POSTSCRIPT])."\n});";
$scripts[] = "jQuery(document).off('pjax:scriptcomplete.mainBottom').on('ready pjax:scriptcomplete.mainBottom', function() {\n".implode("\n", $this->scripts[self::POS_POSTSCRIPT])."\n});";
} else {
$scripts[] = implode("\n", $this->scripts[self::POS_POSTSCRIPT]);
}
Expand Down
Expand Up @@ -59,7 +59,7 @@ public function run()

// Before, it was using: Yii::app()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(dirname(__FILE__) . '/assets/listActions.js'));
// Now, registerScriptFile will use or not the asset manager depending on context
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig("extensionsurl").'admin/grid/MassiveActionsWidget/assets/listActions.js');
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig("extensionsurl").'admin/grid/MassiveActionsWidget/assets/listActions.js', LSYii_ClientScript::POS_BEGIN);

}

Expand Down
Expand Up @@ -15,13 +15,12 @@
* perform an ajax request and close
* perform an ajax request and show the result in the modal
*/
$(document).on('click', '.listActions a', function ()
{
var onClickListAction = function () {
var $that = $(this); // The cliked link
var $actionUrl = $that.data('url'); // The url of the Survey Controller action to call
var onSuccess = $that.data('on-success');
var $gridid = $('.listActions').data('grid-id');
var $oCheckedItems = $.fn.yiiGridView.getChecked($gridid, $('.listActions').data('pk')); // List of the clicked checkbox
var $gridid = $(this).closest('div.listActions').data('grid-id');
var $oCheckedItems = $.fn.yiiGridView.getChecked($gridid, $(this).closest('div.listActions').data('pk')); // List of the clicked checkbox
var $oCheckedItems = JSON.stringify($oCheckedItems);
var actionType = $that.data('actionType');

Expand Down Expand Up @@ -193,7 +192,7 @@ $(document).on('click', '.listActions a', function ()

// open the modal
$modal.modal();
});
};

/**
* Bootstrap switch extension
Expand Down Expand Up @@ -277,16 +276,16 @@ function getDefaultDateTimePickerSettings() {
}


$(document).on('ready pjax:scriptcomplete', function() {

$(document).off('pjax:scriptcomplete.listActions').on('ready pjax:scriptcomplete.listActions', function() {
prepareBsSwitchBoolean(gridId);
prepareBsSwitchInteger(gridId);


// Grid refresh: see point 3
$(document).on('actions-updated', '#'+gridId, function(){
prepareBsSwitchBoolean(gridId);
prepareBsSwitchInteger(gridId);
prepareBsDateTimePicker(gridId);
});
$( '.listActions a').off('click.listactions').on('click.listactions', onClickListAction);

});
Expand Up @@ -82,8 +82,10 @@
<?php endforeach;?>
</ul>
</div>
<script>
var gridId = "<?php echo $this->gridid;?>";
</script>

<?php App()->getClientScript()->registerScript("ListQuestions-run-pagination", "
var gridId = '".$this->gridid."';
", LSYii_ClientScript::POS_BEGIN); ?>


<!-- End of Massive actions widget : selector view -->
10 changes: 5 additions & 5 deletions application/models/QuestionGroup.php
Expand Up @@ -282,21 +282,21 @@ public function getbuttons()
// Add question to this group
if (Permission::model()->hasSurveyPermission($this->sid, 'surveycontent', 'update')) {
$url = Yii::app()->createUrl("admin/questions/sa/newquestion/surveyid/$this->sid/gid/$this->gid");
$button .= '<a class="btn btn-default list-btn '.($surveyIsActive ? 'disabled' : '').' " data-toggle="tooltip" data-placement="left" title="'.gT('Add new question to group').'" href="'.$url.'" role="button"><span class="fa fa-plus-sign " ></span></a>';
$button .= '<a class="btn btn-default list-btn '.($surveyIsActive ? 'disabled' : '').' " data-toggle="tooltip" data-placement="left" title="'.gT('Add new question to group').'" href="'.$url.'" role="button"><i class="fa fa-plus " ></i></a>';
}

// Group edition
// Edit
if (Permission::model()->hasSurveyPermission($this->sid, 'surveycontent', 'update')) {
$url = Yii::app()->createUrl("admin/questiongroups/sa/edit/surveyid/$this->sid/gid/$this->gid");
$button .= ' <a class="btn btn-default list-btn" href="'.$url.'" role="button" data-toggle="tooltip" title="'.gT('Edit group').'"><span class="fa fa-pencil " ></span></a>';
$button .= ' <a class="btn btn-default list-btn" href="'.$url.'" role="button" data-toggle="tooltip" title="'.gT('Edit group').'"><i class="fa fa-pencil " ></i></a>';
}

// View summary
if (Permission::model()->hasSurveyPermission($this->sid, 'surveycontent', 'read')) {
$url = Yii::app()->createUrl("/admin/questiongroups/sa/view/surveyid/");
$url .= '/'.$this->sid.'/gid/'.$this->gid;
$button .= ' <a class="btn btn-default list-btn" href="'.$url.'" role="button" data-toggle="tooltip" title="'.gT('Group summary').'"><span class="fa fa-list-alt " ></span></a>';
$button .= ' <a class="btn btn-default list-btn" href="'.$url.'" role="button" data-toggle="tooltip" title="'.gT('Group summary').'"><i class="fa fa-list-alt " ></i></a>';
}

// Delete
Expand All @@ -306,13 +306,13 @@ public function getbuttons()
$confirm = 'if (confirm(\''.gT("Deleting this group will also delete any questions and answers it contains. Are you sure you want to continue?", "js").'\')) { window.open(\''.Yii::app()->createUrl("admin/questiongroups/sa/delete/surveyid/$this->sid/gid/$this->gid").'\',\'_top\'); };';
$button .= '<a class="btn btn-default" data-toggle="tooltip" title="'.gT("Delete").'" href="#" role="button"
onclick="'.$confirm.'">
<span class="text-danger fa fa-trash"></span>
<i class="text-danger fa fa-trash"></i>
</a>';
} else {
$alert = 'alert(\''.gT("Impossible to delete this group because there is at least one question having a condition on its content", "js").'\'); return false;';
$button .= '<a class="btn btn-default" data-toggle="tooltip" title="'.gT("Delete").'" href="#" role="button"
onclick="'.$alert.'">
<span class="text-danger fa fa-trash"></span>
<i class="text-danger fa fa-trash"></i>
</a>';
}
}
Expand Down
22 changes: 11 additions & 11 deletions application/views/admin/survey/Question/listquestions.php
Expand Up @@ -156,16 +156,6 @@
</div>


<!-- To update rows per page via ajax -->
<script type="text/javascript">
jQuery(function($) {
jQuery(document).on("change", '#pageSize', function(){
$.fn.yiiGridView.update('question-grid',{ data:{ pageSize: $(this).val() }});
});
});
</script>



<div class="modal fade" id="question-preview" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
Expand All @@ -184,4 +174,14 @@
</div>
</div>

<?php // $this->renderPartial('/admin/survey/Question/massive_actions/_set_question_group', array('model'=>$model, 'oSurvey'=>$oSurvey)); ?>

<!-- To update rows per page via ajax -->
<?php App()->getClientScript()->registerScript("ListQuestions-pagination", "
var bindPageSizeChange = function(){
$('#pageSize').on('change', function(){
$.fn.yiiGridView.update('question-grid',{ data:{ pageSize: $(this).val() }});
});
};
", LSYii_ClientScript::POS_BEGIN); ?>

<?php App()->getClientScript()->registerScript("ListQuestions-run-pagination", "bindPageSizeChange(); ", LSYii_ClientScript::POS_POSTSCRIPT); ?>
Expand Up @@ -197,11 +197,9 @@
<!--
Some widgets in the modals need to be reloaded after grid update
-->
<script>
$(document).ready(function() {

<?php App()->getClientScript()->registerScript("ListQuestions-massiveAction-1", "
$('#question-grid').on('actions-updated', function(){
loadPositionWidget();
});
});
</script>
", LSYii_ClientScript::POS_POSTSCRIPT); ?>

Expand Up @@ -14,30 +14,30 @@
<div class="col-lg-12 content-right">

<!-- Search Box -->
<div class="row">
<div class="col-lg-12">
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl('admin/survey/sa/listquestiongroups/surveyid/'.$surveyid),
'method' => 'get',
'htmlOptions'=>array(
'class'=>'',
),
)); ?>
<div class="form-group">
<?php echo CHtml::label(gT('Search by group name:'), 'group_name', array('class'=>' control-label text-right col-sm-offset-6')); ?>
<div class=" text-right">
<?php echo $form->textField($model, 'group_name', array('class'=>'form-control')); ?>
</div>
<div class="">
<?php echo CHtml::submitButton(gT('Search','unescaped'), array('class'=>'btn btn-success')); ?>
<a href="<?php echo Yii::app()->createUrl('admin/survey/sa/listquestiongroups/surveyid/'.$surveyid);?>" class="btn btn-warning"><?php eT('Reset');?></a>
<?php $form=$this->beginWidget('TbActiveForm', array(
'action' => Yii::app()->createUrl('admin/survey/sa/listquestiongroups/surveyid/'.$surveyid),
'method' => 'get',
'htmlOptions'=>array(
'class'=>'form',
),
)); ?>
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="form-group col-sm-10">
<?php echo CHtml::label(gT('Search by group name:'), 'group_name', array('class'=>' control-label text-right col-sm-6')); ?>
<div class="col-sm-4 text-right">
<?php echo $form->textField($model, 'group_name', array('class'=>'form-control col-sm-12')); ?>
</div>
<div class="col-sm-2 text-right">
<?php echo CHtml::submitButton(gT('Search','unescaped'), array('class'=>'btn btn-success')); ?>
<a href="<?php echo Yii::app()->createUrl('admin/survey/sa/listquestiongroups/surveyid/'.$surveyid);?>" class="btn btn-warning"><?php eT('Reset');?></a>
</div>
</div>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
</div>
</div>
</div>
<?php $this->endWidget(); ?>

<!-- The table grid -->
<div class="row">
Expand Down Expand Up @@ -99,6 +99,7 @@

),
'ajaxUpdate' => true,
'afterAjaxUpdate' => 'bindPageSizeChange'
));
?>
</div>
Expand All @@ -108,10 +109,12 @@
</div>

<!-- To update rows per page via ajax -->
<script type="text/javascript">
jQuery(function($) {
jQuery(document).on("change", '#pageSize', function(){
$.fn.yiiGridView.update('question-group-grid',{ data:{ pageSize: $(this).val() }});
});
});
</script>
<?php App()->getClientScript()->registerScript("ListQuestionGroups-pagination", "
var bindPageSizeChange = function(){
$('#pageSize').on('change', function(){
$.fn.yiiGridView.update('question-group-grid',{ data:{ pageSize: $(this).val() }});
});
};
", LSYii_ClientScript::POS_BEGIN); ?>

<?php App()->getClientScript()->registerScript("ListQuestionGroups-run-pagination", "bindPageSizeChange(); ", LSYii_ClientScript::POS_POSTSCRIPT); ?>

0 comments on commit 7ab1556

Please sign in to comment.