forked from sehmaschine/django-grappelli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove js error $("tr input.action-select").actions is not a function
- Loading branch information
Pavel "Uznick" Shvedov
committed
May 5, 2012
1 parent
a0aec5f
commit b29ef72
Showing
1 changed file
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,135 @@ | ||
/** | ||
* GRAPPELLI ACTIONS.JS | ||
* see actions.min.js | ||
* | ||
*/ | ||
* minor modifications compared with the original js | ||
* | ||
*/ | ||
|
||
(function($) { | ||
$.fn.actions = function(opts) { | ||
var options = $.extend({}, $.fn.actions.defaults, opts); | ||
var actionCheckboxes = $(this); | ||
var list_editable_changed = false; | ||
checker = function(checked) { | ||
if (checked) { | ||
showQuestion(); | ||
$(actionCheckboxes).attr("checked", true) | ||
.parent().parent().toggleClass(options.selectedClass, checked); | ||
} else { | ||
reset(); | ||
$(actionCheckboxes).attr("checked", false) | ||
.parent().parent().toggleClass(options.selectedClass, checked); | ||
} | ||
}; | ||
updateCounter = function() { | ||
var sel = $(actionCheckboxes).filter(":checked").length; | ||
$(options.counterContainer).html(interpolate( | ||
ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), { | ||
sel: sel, | ||
cnt: _actions_icnt | ||
}, true)); | ||
$(options.allToggle).attr("checked", function() { | ||
if (sel == actionCheckboxes.length) { | ||
value = true; | ||
showQuestion(); | ||
} else { | ||
value = false; | ||
clearAcross(); | ||
} | ||
return value; | ||
}); | ||
}; | ||
showQuestion = function() { | ||
$(options.acrossClears).hide(); | ||
$(options.acrossQuestions).show(); | ||
$(options.allContainer).hide(); | ||
}; | ||
showClear = function() { | ||
$(options.acrossClears).show(); | ||
$(options.acrossQuestions).hide(); | ||
$(options.actionContainer).toggleClass(options.selectedClass); | ||
$(options.allContainer).show(); | ||
$(options.counterContainer).hide(); | ||
}; | ||
reset = function() { | ||
$(options.acrossClears).hide(); | ||
$(options.acrossQuestions).hide(); | ||
$(options.allContainer).hide(); | ||
$(options.counterContainer).show(); | ||
}; | ||
clearAcross = function() { | ||
reset(); | ||
$(options.acrossInput).val(0); | ||
$(options.actionContainer).removeClass(options.selectedClass); | ||
}; | ||
// Show counter by default | ||
$(options.counterContainer).show(); | ||
// Check state of checkboxes and reinit state if needed | ||
$(this).filter(":checked").each(function(i) { | ||
$(this).parent().parent().toggleClass(options.selectedClass); | ||
updateCounter(); | ||
if ($(options.acrossInput).val() == 1) { | ||
showClear(); | ||
} | ||
}); | ||
$(options.allToggle).show().click(function() { | ||
checker($(this).attr("checked")); | ||
updateCounter(); | ||
}); | ||
$("div.changelist-actions li.question a").click(function(event) { | ||
event.preventDefault(); | ||
$(options.acrossInput).val(1); | ||
showClear(); | ||
}); | ||
$("div.changelist-actions li.clear-selection a").click(function(event) { | ||
event.preventDefault(); | ||
$(options.allToggle).attr("checked", false); | ||
clearAcross(); | ||
checker(0); | ||
updateCounter(); | ||
}); | ||
lastChecked = null; | ||
$(actionCheckboxes).click(function(event) { | ||
if (!event) { var event = window.event; } | ||
var target = event.target ? event.target : event.srcElement; | ||
if (lastChecked && $.data(lastChecked) != $.data(target) && event.shiftKey === true) { | ||
var inrange = false; | ||
$(lastChecked).attr("checked", target.checked) | ||
.parent().parent().toggleClass(options.selectedClass, target.checked); | ||
$(actionCheckboxes).each(function() { | ||
if ($.data(this) == $.data(lastChecked) || $.data(this) == $.data(target)) { | ||
inrange = (inrange) ? false : true; | ||
} | ||
if (inrange) { | ||
$(this).attr("checked", target.checked) | ||
.parent().parent().toggleClass(options.selectedClass, target.checked); | ||
} | ||
}); | ||
} | ||
$(target).parent().parent().toggleClass(options.selectedClass, target.checked); | ||
lastChecked = target; | ||
updateCounter(); | ||
}); | ||
|
||
// GRAPPELLI CUSTOM: REMOVED ALL JS-CONFIRMS | ||
// TRUSTED EDITORS SHOULD KNOW WHAT TO DO | ||
|
||
// GRAPPELLI CUSTOM: submit on select | ||
$(options.actionSelect).attr("autocomplete", "off").change(function(evt){ | ||
$(this).parents("form").submit(); | ||
}); | ||
|
||
}; | ||
/* Setup plugin defaults */ | ||
$.fn.actions.defaults = { | ||
actionContainer: "div.changelist-actions", | ||
counterContainer: "li.action-counter span.action-counter", | ||
allContainer: "div.changelist-actions li.all", | ||
acrossInput: "div.changelist-actions input.select-across", | ||
acrossQuestions: "div.changelist-actions li.question", | ||
acrossClears: "div.changelist-actions li.clear-selection", | ||
allToggle: "#action-toggle", | ||
selectedClass: "selected", | ||
actionSelect: "div.changelist-actions select" | ||
}; | ||
})(django.jQuery); | ||
|