mirror of
https://github.com/bspeice/Melodia
synced 2024-12-26 00:28:13 -05:00
Add global JS and post methods
This commit is contained in:
parent
7286281e14
commit
0d467e8457
@ -36,7 +36,7 @@ List of block elements in this page:
|
|||||||
|
|
||||||
{% block global_scripts %}
|
{% block global_scripts %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
{# Scripts used globally go here. #}
|
{% include global_scripts.js %}
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -59,7 +59,6 @@ List of block elements in this page:
|
|||||||
<a class="brand" href="#">{% block navbar_title %}{% endblock %}</a>
|
<a class="brand" href="#">{% block navbar_title %}{% endblock %}</a>
|
||||||
|
|
||||||
{% block navbar_content %}
|
{% block navbar_content %}
|
||||||
|
|
||||||
<div class="btn-group pull-right">
|
<div class="btn-group pull-right">
|
||||||
<a class="btn" href="#">{{ user.username }}</a>
|
<a class="btn" href="#">{{ user.username }}</a>
|
||||||
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
|
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
|
||||||
@ -69,8 +68,8 @@ List of block elements in this page:
|
|||||||
<li id="btn_logout"><a href="/logout">Logout</a></li>
|
<li id="btn_logout"><a href="/logout">Logout</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
68
web/views/templates/global_scripts.js
Normal file
68
web/views/templates/global_scripts.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* The JS below is included globally (unless a page over-rides it) */
|
||||||
|
|
||||||
|
function _default_ajax_success(data)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _default_ajax_error(data, error_string)
|
||||||
|
{
|
||||||
|
alertHTML = "<div class=\"alert alert-error\">Error processing AJAX request! Error: \"" + error_string + "\"</div>";
|
||||||
|
$('body').prepend(alertHTML);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function server_post(url, data, success_function, error_function)
|
||||||
|
{
|
||||||
|
/* Push data to the server using AJAX.
|
||||||
|
* This function returns immediately */
|
||||||
|
|
||||||
|
if (typeof(url) !== "string")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (typeof(data) !== "object")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (typeof(success_function) !== "function")
|
||||||
|
success_function = _default_ajax_success;
|
||||||
|
|
||||||
|
if (typeof(error_function) !== "function")
|
||||||
|
error_function = _default_ajax_error;
|
||||||
|
|
||||||
|
return
|
||||||
|
jQuery.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: url,
|
||||||
|
data: data,
|
||||||
|
success: success_function,
|
||||||
|
error: error_function
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function sserver_post(url, data, success_function, error_function)
|
||||||
|
{
|
||||||
|
/* Push data to the server using AJAX, and do so synchronously.
|
||||||
|
* That is, this function won't return until the request completes.*/
|
||||||
|
if (typeof(url) !== "string")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (typeof(data) !== "object")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (typeof(success_function) !== "function")
|
||||||
|
success_function = _default_ajax_success;
|
||||||
|
|
||||||
|
if (typeof(error_function) !== "function")
|
||||||
|
error_function = _default_ajax_error;
|
||||||
|
|
||||||
|
return
|
||||||
|
jQuery.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: url,
|
||||||
|
data: data,
|
||||||
|
success: success_function,
|
||||||
|
error: error_function,
|
||||||
|
async: false
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user