I want to have a button on the website that opens up a modal view using bootstrap. Like so:
<button class="btn btn-primary btn-lg" id="modalButton" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
So this button is targeting a view called #myModal. Instead of loading the #myModal view from the client html, I want to make an AJAX request to the server to get #myModal view because the view will be different depending on if the user is admin or not, and that variable resides on the server.
So the request would be something like this:
$('#modalButton').click() ->
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","/modalFeedback",true);
xmlhttp.send();
Then the /modalFeedback route should check if the user is admin or not, and send back the corresponding #myModal view. I am confused on how to implement this exactly, more specifically how to return the #myModal view from the server so it opens up normally.
If someone could help me with some pseudo-code that would be extremely helpful!
UPDATE
I got it working with the bootstrap remote option (see answer below), here is how I called the modal:
a#uservoice_tab(data-toggle="modal", href="/modalFeedback.html", data-target="#myModal")
img(src='/img/icon-idea.png')
// You need to have #myModal element in the same place you have the button. Bootstrap injects the body into this element remotely
#myModal.modal.fade(tabindex='-1', role='dialog', aria-labelledby='myModalLabel', aria-hidden='true')
Here is the modalFeedback.html source in jade
.modal-dialog
.modal-content
.modal-header
button.close(type='button', data-dismiss='modal', aria-hidden='true') ×
h4#myModalLabel.modal-title Modal title
.modal-body
.modal-footer
button.btn.btn-default(type='button', data-dismiss='modal') Close
button.btn.btn-primary(type='button') Save changes