summaryrefslogtreecommitdiff
path: root/ishtar_common/static/js/ishtar.js
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/static/js/ishtar.js')
-rw-r--r--ishtar_common/static/js/ishtar.js106
1 files changed, 106 insertions, 0 deletions
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js
new file mode 100644
index 000000000..25fc3c66a
--- /dev/null
+++ b/ishtar_common/static/js/ishtar.js
@@ -0,0 +1,106 @@
+
+/* CSRFToken management */
+$.ajaxSetup({
+beforeSend: function(xhr, settings) {
+ function getCookie(name) {
+ var cookieValue = null;
+ if (document.cookie && document.cookie != '') {
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = jQuery.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
+ }
+ }
+ return cookieValue;
+ }
+ if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
+ // Only send the token to relative URLs i.e. locally.
+ xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
+ }
+}});
+
+
+$(document).ready(function(){
+ $("#main_menu > ul > li > ul").hide();
+ $("#main_menu ul ul .selected").parents().show();
+ var items = new Array('file', 'operation');
+ $("#current_file").change(function(){
+ $.post('/' + url_path + 'update-current-item/',
+ {item:'file', value:$("#current_file").val()}
+ );
+ });
+ $("#current_operation").change(function(){
+ $.post('/' + url_path + 'update-current-item/',
+ {item:'operation', value:$("#current_operation").val()}
+ );
+ });
+});
+
+$("#main_menu ul li").live('click', function(){
+ $("#main_menu ul ul").hide('slow');
+ $(this).find('ul').show('slow');
+});
+
+/* manage help texts */
+$(".help_display").live("click", function(){
+ var help_text_id = $(this).attr("href") + "_help";
+ $(help_text_id).toggle();
+})
+
+var last_window;
+
+function load_window(url, speed){
+ $.ajax({
+ url: url,
+ cache: false,
+ success:function(html){
+ $("#window").append(html);
+ $("#"+last_window).show();
+ },
+ error:function(XMLHttpRequest, textStatus, errorThrows){
+ }
+ });
+}
+
+function load_url(url){
+ $.ajax({
+ url: url,
+ cache: false,
+ success:function(html){},
+ error:function(XMLHttpRequest, textStatus, errorThrows){
+ }
+ });
+}
+
+function open_window(url){
+ var newwindow = window.open(url, '_blank',
+ 'height=400,width=600,scrollbars=yes');
+ if (window.focus) {newwindow.focus()}
+ return false;
+}
+
+function save_and_close_window(name_label, name_pk, item_name, item_pk){
+ var main_page = opener.document;
+ jQuery(main_page).find("#"+name_label).val(item_name);
+ jQuery(main_page).find("#"+name_pk).val(item_pk);
+ opener.focus();
+ self.close();
+}
+
+function multiRemoveItem(selItems, name, idx){
+ for(id in selItems){
+ if(selItems[id] == idx){
+ selItems.splice(id, 1);
+ }
+ }
+ jQuery("#selected_"+name+"_"+idx).remove();
+}
+
+function closeAllWindows(){
+ jQuery("#window > div").hide("slow");
+ jQuery("#window").html("");
+}