1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/* 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'));
}
}});
/* default function to prevent undefined */
function get_next_table_id(){}
function get_previous_table_id(){}
$(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()}
);
});
if ($(document).height() < 1.5*$(window).height()){
$('#to_bottom_arrow').hide();
$('#to_top_arrow').hide();
}
$('#language_selector').change(function(){
$('#language_form').submit();
});
if ($.isFunction($(".prettyPhoto a").prettyPhoto)){
$(".prettyPhoto a").prettyPhoto({'social_tools':''});
}
$('#current_items select').change(function(){
$(this).attr('class', $(this).children("option:selected").attr('class'));
})
});
$('#to_bottom_arrow').live('click', function(){
$("html, body").animate({ scrollTop: $(document).height() }, 1000);
});
$('#to_top_arrow').live('click', function(){
$("html, body").animate({ scrollTop: 0}, 1000);
});
$('.check-all').live('click', function(){
$(this).closest('table'
).find('input:checkbox'
).attr('checked', $(this).is(':checked'));
});
$("#main_menu ul li").live('click', function(){
var current_id = $(this).attr('id');
console.log(current_id);
$("#main_menu ul ul").not($(this).parents('ul')).not($(this).find('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();
});
$('#progress-content').live('click', function(){
$('#progress').hide();
});
var last_window;
function load_window(url, speed, on_success){
$("#progress").show();
$.ajax({
url: url,
cache: false,
success:function(html){
$("#progress").hide();
$("#window").append(html);
$("#"+last_window).show();
$("a[rel^='prettyPhoto']").prettyPhoto({'social_tools':''});
if (on_success) on_success();
},
error:function(XMLHttpRequest, textStatus, errorThrows){
$("#progress").hide();
}
});
}
function load_current_window(url, model_name){
var id = $("#current_" + model_name).val();
if (!id) return;
url = url.split('/');
url[url.length - 1] = id;
url.push('');
return load_window(url.join('/'));
}
function load_url(url){
$("#progress").show();
$.ajax({
url: url,
cache: false,
success:function(html){
$("#progress").hide();
},
error:function(XMLHttpRequest, textStatus, errorThrows){
$("#progress").hide();
}
});
}
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("");
}
|