convert donate modal to ajax request

This commit is contained in:
Andrew Bauer 2020-09-19 08:55:08 -05:00
parent 467e75a11c
commit d2963fe28f
6 changed files with 36 additions and 29 deletions

View File

@ -18,10 +18,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// //
if ( !canEdit('System') ) { if ( !canEdit('System') ) return;
$view = 'error';
return;
}
$options = array( $options = array(
'go' => translate('DonateYes'), 'go' => translate('DonateYes'),
@ -45,25 +42,25 @@ $options = array(
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form name="contentForm" id="contentForm" method="post" action="?"> <form name="contentForm" id="donateForm" method="post" action="?">
<input type="hidden" name="view" value="donate"/> <?php
<input type="hidden" name="action" value="donate"/> // We have to manually insert the csrf key into the form when using a modal generated via ajax call
<p> echo getCSRFinputHTML();
<?php echo translate('DonateEnticement') ?> ?>
</p> <input type="hidden" name="view" value="donate"/>
<p> <input type="hidden" name="action" value="donate"/>
<?php echo buildSelect('option', $options); ?> <p>
</p> <?php echo translate('DonateEnticement') ?>
<div id="contentButtons"> </p>
<button type="submit"><?php echo translate('Apply') ?></button> <p>
<button type="button" data-on-click="closeWindow"><?php echo translate('Close') ?></button> <?php echo buildSelect('option', $options); ?>
</div> </p>
</form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="submit" class="btn btn-primary" id="donateApplyBtn"><?php echo translate('Apply') ?></button>
<button type="button" class="btn btn-primary">Understood</button> <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo translate('Close') ?></button>
</div> </div>
</form>
</div> </div>
</div> </div>
</div> </div>

View File

@ -49,6 +49,6 @@ if ( $action == 'donate' && isset($_REQUEST['option']) ) {
Warning("Unknown value for option in donate: $option"); Warning("Unknown value for option in donate: $option");
break; break;
} // end switch option } // end switch option
$view = 'none'; $redirect = '?view=console';
} }
?> ?>

View File

@ -438,7 +438,5 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
</form> </form>
<?php <?php
include('function.php'); include('function.php');
// Include Donate Modal
include('donate.php');
xhtmlFooter(); xhtmlFooter();
?> ?>

View File

@ -133,7 +133,24 @@ function initPage() {
window.location.assign('?view=version'); window.location.assign('?view=version');
} }
if ( showDonatePopup ) { if ( showDonatePopup ) {
$j('#donate').modal('show'); $j.getJSON(thisUrl + '?request=modal&modal=donate')
.done(function(data) {
if ( $j('#donate').length ) {
$j('#donate').replaceWith(data.html);
} else {
$j("body").append(data.html);
}
$j('#donate').modal('show');
// Manage the Apply button
$j('#donateApplyBtn').click(function(evt) {
evt.preventDefault();
$j('#donateForm').submit();
});
})
.fail(function(jqxhr, textStatus, error) {
console.log("Request Failed: " + textStatus + ", " + error);
console.log("Response Text: " + jqxhr.responseText);
});
} }
// Makes table sortable // Makes table sortable

View File

@ -1,3 +0,0 @@
if ( action == 'donate' && option == 'go' ) {
zmWindow('/donate/');
}

View File

@ -1,2 +0,0 @@
var action = '<?php echo isset($_REQUEST['action'])?validJsStr($_REQUEST['action']):'' ?>';
var option = '<?php echo isset($_REQUEST['option'])?validJsStr($_REQUEST['option']):'' ?>';