Skip to content

Commit

Permalink
dev: topbarbutton reset for surveymenu and surveymenuentry
Browse files Browse the repository at this point in the history
  • Loading branch information
Trischi80 committed Aug 13, 2021
1 parent 0292bd2 commit aa120c8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
5 changes: 3 additions & 2 deletions application/views/admin/super/fullpagebar_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ class='btn btn-default'
<!-- Reset -->
<?php if (isset($fullpagebar['menus']['buttons']['reset']) && $fullpagebar['menus']['buttons']['reset']) :?>
<a class="btn btn-warning"
href="#restoremodal"
data-toggle="modal">
id="restoreBtn"
href="#"
>
<i class="fa fa-refresh"></i>&nbsp;
<?php eT('Reset') ?>
</a>
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/surveymenu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</div>
</div>

<div class="modal fade" id="restoremodal" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static">
<div class="modal fade" id="restoremodalsurveymenu" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/surveymenu_entries/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</div>
</div>

<div class="modal fade" id="restoremodal" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static">
<div class="modal fade" id="restoreModalSurveyMenuEntry" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog" role="document">
<div class="modal-content">
<?php
Expand Down
40 changes: 36 additions & 4 deletions assets/packages/surveymenufunctions/surveymenufunctionswrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,45 @@ var SurveyMenuFunctionsWrapper = function (targetCreateModal, targetGrid, urls)
success: function (result) {
$.fn.yiiGridView.update(targetGrid);
},
error: function(error){
error: function (error) {
console.log(error);
}
});
},
/**
* Returns the correct modal for restoring data
* (surveymenu or surveymenuentry
* @returns {*}
*/
getModal = function () {
let active_tab = $("ul.tabs li a.active").attr('href');
let restoreModal = '';
switch (active_tab) {
case '#surveymenues':
restoreModal = $('#restoremodalsurveymenu');
break;
case '#surveymenuentries':
default:
restoreModal = $('#restoreModalSurveyMenuEntry');
}
return restoreModal;
},
openRestoreModal = function () {
let restoreModal = getModal();
restoreModal.modal('show');
},
runRestoreModal = function () {
$('#restoremodal').find('.modal-content').html('<div class="ls-flex align-items-center align-content-center" style="height:200px"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div>')
//depending on which tab is active, the correct modal must be taken
// restoremodalsurveymenu and restoremodal
let restoreModal = getModal();
restoreModal.find('.modal-content').html('<div ' + 'class="ls-flex align-items-center align-content-center" style="height:200px"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div>')
$.ajax({
url: urls.restoreEntriesUrl,
data: {},
method: 'POST',
dataType: 'json',
success: function (result) {
console.log(result);
$('#restoremodal').find('.modal-content').html('<div class="ls-flex align-items-center align-content-center" style="height:200px">' + result.message + '</div>');
restoreModal.find('.modal-content').html('<div class="ls-flex align-items-center align-content-center" style="height:200px">' + result.message + '</div>');

if (result.success)
setTimeout(function () {
Expand All @@ -105,6 +129,10 @@ var SurveyMenuFunctionsWrapper = function (targetCreateModal, targetGrid, urls)
e.preventDefault();
runRestoreModal();
});

$('#restoreBtn').on('click', function (e) {
openRestoreModal();
});

$('#createnewmenuentry').on('click', function (e) {
e.stopPropagation();
Expand Down Expand Up @@ -161,6 +189,10 @@ var SurveyMenuFunctionsWrapper = function (targetCreateModal, targetGrid, urls)
e.preventDefault();
runRestoreModal();
});

$('#restoreBtn').on('click', function (e) {
openRestoreModal();
});

$('#createnewmenu').on('click', function (e) {
e.stopPropagation();
Expand Down

0 comments on commit aa120c8

Please sign in to comment.