1
0
mirror of https://github.com/bspeice/Melodia synced 2024-12-25 08:08:13 -05:00

Add global JS and post methods

This commit is contained in:
Bradlee Speice 2013-02-12 14:15:21 -05:00
parent 7286281e14
commit 0d467e8457
2 changed files with 86 additions and 19 deletions

View File

@ -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 %}
@ -52,28 +52,27 @@ List of block elements in this page:
<body> <body>
{# Navbar code #} {# Navbar code #}
<div class="navbar navbar-fixed-top"> <div class="navbar navbar-fixed-top">
<div class="navbar-inner"> <div class="navbar-inner">
<div class="container"> <div class="container">
<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="#"> <span class="caret"></span>
<span class="caret"></span> </a>
</a> <ul class="dropdown-menu">
<ul class="dropdown-menu"> <li id="btn_logout"><a href="/logout">Logout</a></li>
<li id="btn_logout"><a href="/logout">Logout</a></li> </ul>
</ul>
</div>
{% endblock %}
</div> </div>
{% endblock %}
</div> </div>
</div> </div>
</div>
<div class="container-fluid"> <div class="container-fluid">
<div class="row-fluid"> <div class="row-fluid">

View 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
});
}