2 $
.fn
.actions
= function(opts
) {
3 var options
= $
.extend({}, $
.fn
.actions
.defaults
, opts
);
4 var actionCheckboxes
= $
(this);
5 var list_editable_changed
= false;
6 checker
= function(checked
) {
12 $
(actionCheckboxes
).attr("checked", checked
)
13 .parent().parent().toggleClass(options
.selectedClass
, checked
);
15 updateCounter
= function() {
16 var sel
= $
(actionCheckboxes
).filter(":checked").length
;
17 $
(options
.counterContainer
).html(interpolate(
18 ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel
), {
22 $
(options
.allToggle
).attr("checked", function() {
23 if (sel
== actionCheckboxes
.length
) {
33 showQuestion
= function() {
34 $
(options
.acrossClears
).hide();
35 $
(options
.acrossQuestions
).show();
36 $
(options
.allContainer
).hide();
38 showClear
= function() {
39 $
(options
.acrossClears
).show();
40 $
(options
.acrossQuestions
).hide();
41 $
(options
.actionContainer
).toggleClass(options
.selectedClass
);
42 $
(options
.allContainer
).show();
43 $
(options
.counterContainer
).hide();
46 $
(options
.acrossClears
).hide();
47 $
(options
.acrossQuestions
).hide();
48 $
(options
.allContainer
).hide();
49 $
(options
.counterContainer
).show();
51 clearAcross
= function() {
53 $
(options
.acrossInput
).val(0);
54 $
(options
.actionContainer
).removeClass(options
.selectedClass
);
56 // Show counter by default
57 $
(options
.counterContainer
).show();
58 // Check state of checkboxes and reinit state if needed
59 $
(this).filter(":checked").each(function(i
) {
60 $
(this).parent().parent().toggleClass(options
.selectedClass
);
62 if ($
(options
.acrossInput
).val() == 1) {
66 $
(options
.allToggle
).show().click(function() {
67 checker($
(this).attr("checked"));
70 $
("div.actions span.question a").click(function(event
) {
71 event
.preventDefault();
72 $
(options
.acrossInput
).val(1);
75 $
("div.actions span.clear a").click(function(event
) {
76 event
.preventDefault();
77 $
(options
.allToggle
).attr("checked", false);
83 $
(actionCheckboxes
).click(function(event
) {
84 if (!event
) { var event
= window
.event
; }
85 var target
= event
.target ? event
.target
: event
.srcElement
;
86 if (lastChecked
&& $
.data(lastChecked
) != $
.data(target
) && event
.shiftKey
== true) {
88 $
(lastChecked
).attr("checked", target
.checked
)
89 .parent().parent().toggleClass(options
.selectedClass
, target
.checked
);
90 $
(actionCheckboxes
).each(function() {
91 if ($
.data(this) == $
.data(lastChecked
) || $
.data(this) == $
.data(target
)) {
92 inrange
= (inrange
) ?
false : true;
95 $
(this).attr("checked", target
.checked
)
96 .parent().parent().toggleClass(options
.selectedClass
, target
.checked
);
100 $
(target
).parent().parent().toggleClass(options
.selectedClass
, target
.checked
);
101 lastChecked
= target
;
104 $
('form#changelist-form table#result_list tr').find('td:gt(0) :input').change(function() {
105 list_editable_changed
= true;
107 $
('form#changelist-form button[name="index"]').click(function(event
) {
108 if (list_editable_changed
) {
109 return confirm(gettext("You have unsaved changes on individual editable fields. If you run an action, your unsaved changes will be lost."));
112 $
('form#changelist-form input[name="_save"]').click(function(event
) {
113 var action_changed
= false;
114 $
('div.actions select option:selected').each(function() {
116 action_changed
= true;
119 if (action_changed
) {
120 if (list_editable_changed
) {
121 return confirm(gettext("You have selected an action, but you haven't saved your changes to individual fields yet. Please click OK to save. You'll need to re-run the action."));
123 return confirm(gettext("You have selected an action, and you haven't made any changes on individual fields. You're probably looking for the Go button rather than the Save button."));
128 /* Setup plugin defaults */
129 $
.fn
.actions
.defaults
= {
130 actionContainer
: "div.actions",
131 counterContainer
: "span.action-counter",
132 allContainer
: "div.actions span.all",
133 acrossInput
: "div.actions input.select-across",
134 acrossQuestions
: "div.actions span.question",
135 acrossClears
: "div.actions span.clear",
136 allToggle
: "#action-toggle",
137 selectedClass
: "selected"