Skip to content

Commit

Permalink
Dev: Surveys massive actions, translated strings
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed May 23, 2016
1 parent 50527ce commit 4a280e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
7 changes: 6 additions & 1 deletion application/views/admin/survey/listSurveys_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
</button>
<ul class="dropdown-menu" aria-labelledby="surveyListActions" style="left: 15px;">
<li>
<a href="#" data-url="<?php echo App()->createUrl('/admin/survey/sa/deleteMultipleSurveys/');?>" data-action="delete" data-action-title="<?php eT('Delete surveys'); ?>">
<a href="#"
data-url="<?php echo App()->createUrl('/admin/survey/sa/deleteMultipleSurveys/');?>"
data-action="delete"
data-action-title="<?php eT('Delete surveys'); ?>"
data-modal-warning-title="<?php eT('Warning');?>"
data-modal-warning-text="<?php eT('Are you sure you want to delete all those surveys?');?>">
<span class="text-danger glyphicon glyphicon-trash"></span>
<?php eT('Delete');?>
</a>
Expand Down
26 changes: 14 additions & 12 deletions scripts/admin/admin_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ $(document).ready(function(){
$surveyActions.each(function(){
$(this).on('click', function(){
$that = $(this);
$action = $that.data('action'); // The action string, to display in the modal body (eg: sure you wann $action?)
$actionTitle = $that.data('action-title'); // The action title, to display in the modal title
$actionUrl = $that.data('url'); // The url of the Survey Controller action to call
$action = $that.data('action'); // The action string, to display in the modal body (eg: sure you wann $action?)
$actionTitle = $that.data('action-title'); // The action title, to display in the modal title
$actionUrl = $that.data('url'); // The url of the Survey Controller action to call
$checkedSid = JSON.stringify($.fn.yiiGridView.getChecked('survey-grid', 'sid')); // List of the clicked checkbox

$modal = $('#confirmation-modal'); // The modal we want to use
$actionUrl = $actionUrl + '/sSurveys/'+$checkedSid;

$modal.data('keepopen', true); // We want to update the modal content after confirmation

// Needed modal elements
Expand All @@ -75,30 +75,31 @@ $(document).ready(function(){
$oldModalTitle = $modalTitle.text();
$oldModalBody = $modalBody.html();

// New modal contents
$modalWarningTitle = $that.data('modal-warning-title'); // The action string, to display in the modal body (eg: sure you wann $action?)
$modalWarningText = $that.data('modal-warning-text');

// We update the modal
$modal.find('.modal-title').text('Warning!');
$modal.find('.modal-body-text').text("Are you sure you want to "+$action+" all those surveys?");
$modal.find('.modal-title').text($modalWarningTitle);
$modal.find('.modal-body-text').text($modalWarningText);

// When user close the modal, we put it back to its original state
$modal.on('hidden.bs.modal', function (e) {
$modal.data('onclick', null); // We reset the onclick event
$modal.data('onclick', null); // We reset the onclick event
$modalTitle.text($oldModalTitle); // the modal title
$modalBody.empty().append($oldModalBody); // modal body
$modalClose.hide(); // Hide the 'close' button
$modalYesNo.show(); // Show the 'Yes/No' buttons
})

// Define what should be done when user confirm the mass action
$modal.data('onclick', null);
$modal.data('onclick', function(){

// Update the modal elements
$modalTitle.text($actionTitle); // Change the modal title to the action title
$modalBody.empty(); // Empty the modal body
$modalYesNo.hide(); // Hide the 'Yes/No' buttons
$modalClose.show(); // Show the 'close' button

$ajaxLoader.show(); // Show the ajax loader
$ajaxLoader.show(); // Show the ajax loader

// Ajax request
$.ajax({
Expand All @@ -110,7 +111,7 @@ $(document).ready(function(){
success : function(html, statut){
$.fn.yiiGridView.update('survey-grid'); // Update the surveys list
$ajaxLoader.hide(); // Hide the ajax loader
$modalBody.empty().html(html); // Inject the returned HTML in the modal body
$modalBody.empty().html(html); // Inject the returned HTML in the modal body
},
error : function(html, statut){
$ajaxLoader.hide();
Expand All @@ -120,6 +121,7 @@ $(document).ready(function(){
});
});

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

0 comments on commit 4a280e0

Please sign in to comment.