Skip to content

Commit

Permalink
Dev: Replace confirm with modal in condition delete
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Apr 18, 2016
1 parent bcd62b9 commit 7464ffc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/conditionsaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ function index($subaction, $iSurveyID=null, $gid=null, $qid=null)
{
$img_tag = '<span class="glyphicon glyphicon-trash"></span>';
$additional_main_content = CHtml::link($img_tag, '#', array(
'onclick' => "if ( confirm('".gT("Are you sure you want to delete all conditions set in this scenario?", "js")."')) { document.getElementById('deletescenario{$scenarionr['scenario']}').submit();}"
'onclick' => "if ( confirm('".gT("Are you sure you want to delete all conditions set in this scenario?", "js")."')) { document.getElementById('deletescenario{$scenarionr['scenario']}').submit();}"
));

$img_tag = '<span class="glyphicon glyphicon-pencil"></span>';
Expand Down
12 changes: 10 additions & 2 deletions application/views/admin/conditions/includes/conditions_edit.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@

<a href='#' onclick="if ( confirm('<?php eT("Are you sure you want to delete this condition?","js"); ?>')) { $('#editModeTargetVal<?php echo $rows['cid']; ?>').remove(); $('#cquestions<?php echo $rows['cid']; ?>').remove(); document.getElementById('conditionaction<?php echo $rows['cid']; ?>').submit();}">
<a
data-target="#confirmation-modal"
data-toggle="modal"
data-message="<?php eT("Are you sure you want to delete this condition?"); ?>"
data-onclick="(function() {
$('#editModeTargetVal<?php echo $rows['cid']; ?>').remove();
$('#cquestions<?php echo $rows['cid']; ?>').remove();
document.getElementById('conditionaction<?php echo $rows['cid']; ?>').submit();
});"
>
<span class="glyphicon glyphicon-trash"></span>
</a>
<a href='#' onclick='document.getElementById("subaction<?php echo $rows['cid']; ?>").value="editthiscondition"; document.getElementById("conditionaction<?php echo $rows['cid']; ?>").submit();'>
Expand Down
33 changes: 31 additions & 2 deletions scripts/admin/admin_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,39 @@ $(document).ready(function(){
$("#question_type.none").change();
}

// Confirmation modal
/**
* Confirmation modal
*
* Either provide a data-href to redirect after OK button is clicked,
* or data-onclick to be run when OK is clicked.
*/
$('#confirmation-modal').on('show.bs.modal', function(e) {
// .btn-ok is the confirm <a> in the modal
$(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
var href = $(e.relatedTarget).data('href');
var onclick = $(e.relatedTarget).data('onclick');

if (href != '' && href !== undefined) {
$(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
}
else if (onclick != '' && onclick !== undefined) {

var onclick_fn = eval(onclick);

if (typeof onclick_fn == 'function') {
$(this).find('.btn-ok').on('click', function(ev) {
$('#confirmation-modal').modal('hide');
onclick_fn();
});
}
else {
throw "Confirmation modal: onclick is not a function.";
}

}
else {
throw "Confirmation modal: Found neither data-href or data-onclick.";
}

$(this).find('.modal-body-text').html($(e.relatedTarget).data('message'));
});

Expand Down

0 comments on commit 7464ffc

Please sign in to comment.