- Author:
- jpic
- Posted:
- October 10, 2008
- Language:
- JavaScript
- Version:
- Not specified
- Score:
- -3 (after 3 ratings)
This patch allows to open a popup to edit the selected object of either the left or right select input of a filter_horizontal or filter_vertical field, when pressing the "Insert" key.
Being a noob with general client-side issue, it's served as a patch that suits my needs. Maybe it's possible to do it cleaner by overloading the javascript methods, or get rid of the jquery dependency in order to integrate it into django trunk ... Any contribution is welcome! It's licensed under WTFPL license.
Requires jquery.
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 | Index: django/contrib/admin/media/js/SelectFilter2.js
===================================================================
--- django/contrib/admin/media/js/SelectFilter2.js (revision 9220)
+++ django/contrib/admin/media/js/SelectFilter2.js (working copy)
@@ -71,6 +71,8 @@
addEvent(filter_input, 'keydown', function(e) { SelectFilter.filter_key_down(e, field_id); });
addEvent(from_box, 'dblclick', function() { SelectBox.move(field_id + '_from', field_id + '_to'); });
addEvent(to_box, 'dblclick', function() { SelectBox.move(field_id + '_to', field_id + '_from'); });
+ addEvent(from_box, 'keypress', function(e) { SelectBox.edit(e, field_id + '_from'); });
+ addEvent(to_box, 'keypress', function(e) { SelectBox.edit(e, field_id + '_to'); });
addEvent(findForm(from_box), 'submit', function() { SelectBox.select_all(field_id + '_to'); });
SelectBox.init(field_id + '_from');
SelectBox.init(field_id + '_to');
Index: django/contrib/admin/media/js/SelectBox.js
===================================================================
--- django/contrib/admin/media/js/SelectBox.js (revision 9220)
+++ django/contrib/admin/media/js/SelectBox.js (working copy)
@@ -107,5 +107,16 @@
for (var i = 0; i < box.options.length; i++) {
box.options[i].selected = 'selected';
}
+ },
+ edit: function(event, id) {
+ // 45 = Insert
+ if ((event.which && event.which == 45) || (event.keyCode && event.keyCode == 45)) {
+ var selected_id = document.getElementById(id).value;
+ // Thanks trovster from #jquery@freenode!
+ var link = $('#'+id).parents().find('a.add-another:first').attr('href')+'../'+selected_id
+ var win = window.open(link + '?_popup=1', link, 'height=600,width=1000,resizable=yes,scrollbars=yes');
+ win.focus();
+ return false;
+ }
}
}
|
More like this
- Django Collapsed Stacked Inlines by applecat 1 year, 9 months ago
- Django Collapsed Stacked Inlines by mkarajohn 3 years, 10 months ago
- Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 6 months ago
- Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 7 months ago
- Django admin inline ordering - javascript only implementation by ojhilt 11 years, 11 months ago
Comments
Please login first before commenting.