-
Notifications
You must be signed in to change notification settings - Fork 2
/
django_cups.js
73 lines (72 loc) · 1.91 KB
/
django_cups.js
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
/*
javascript extension for django_cups app
*/
var django_cups = {};
django_cups.print_form = function(){
var print_form_url;
var print_form_dialog;
function init_form() {
$('#django_cups_tab').tabs();
$(print_form_dialog).on('click','.printer',Print);
$(print_form_dialog).on('click','.printeraddtofav',addToFavourite);
$(print_form_dialog).on('click','.printerdelfromfav',delFromFavourite);
$(print_form_dialog).on('click','.printerreload',Refresh)
}
function deinit_form() {
$(print_form_dialog).off('click');
$(print_form_dialog).remove();
}
function reload_tab() {
var current_index = $("#django_cups_tab").tabs("option","selected");
$("#django_cups_tab").tabs('load',current_index);
}
function Display(print_url) {
print_form_url = print_url;
var url = DJANGO_CUPS_PRINTFORM_URL;
print_form_dialog = $('<div style="display:hidden" id="django_cups_printform"></div>').appendTo('body');
print_form_dialog.load(url,
function (responseText, textStatus, XMLHttpRequest) {
print_form_dialog.dialog({title:"Print",
modal: true,
resizable: false,
width: 600,
height: 400,
buttons: {
'Cancel': function() {
$(this).dialog('close');
},
},
close: deinit_form
});
});
}
function addToFavourite() {
$.get($(this).attr('href'));
$('#django_cups_tab').tabs('option', 'selected', 0);
return false;
}
function delFromFavourite(){
$.get($(this).attr('href'));
reload_tab();
return false;
}
function Refresh(){
$.get($(this).attr('href'));
reload_tab();
return false;
}
function Print(){
data = $(this).attr('href');
$.get(print_form_url+data);
$(print_form_dialog).dialog('close');
return false;
}
return {
init_form:init_form,
Display:Display,
addToFavourite:addToFavourite,
delFromFavourite:delFromFavourite,
Refresh:Refresh,
Print:Print
}
}();