Permalink
Please sign in to comment.
Browse files
* made inlineform-ready
* default object result display now contains an admin-link to object * readme-update
- Loading branch information...
Showing
with
100 additions
and 83 deletions.
- +5 −17 README.md
- +11 −5 forms.py
- +34 −49 templates/gfkajax/widget.js
- +13 −1 views.py
- +37 −11 widgets.py
@@ -1,97 +1,82 @@ | ||
$ = django.jQuery; | ||
-var GFK_{{ name }} = { | ||
+var GFK_{{ unique_form_id }} = { | ||
init: function() { | ||
// Hide original fields, and complete rows | ||
- $(".form-row:has(.gfkhidden)").hide(); | ||
- $(".column").has(".gfkhidden").hide(); // For grappelli | ||
- $(".column").has(".gfkhidden").prev().hide(); // For grappelli | ||
- $("#id_{{ name }}").hide(); | ||
+ $(".form-row:has(.gfk_{{ unique_form_id }}_fk").hide(); | ||
+ $(".column").has(".gfk_{{ unique_form_id }}_fk").hide(); // For grappelli | ||
+ $(".column").has(".gfk_{{ unique_form_id }}_fk").prev().hide(); // For grappelli | ||
+ $(".gfk_{{ unique_form_id }}_lookup").attr('id', 'lookup_'+$('.gfk_{{ unique_form_id }}_fk').attr('id')); | ||
- // Correct lookup node id | ||
- $('#lookup_id_{{ name }}').attr('id', 'lookup_' + GFK_{{ name }}.get_fk_field().attr('id')); | ||
+ old_fk_val_{{ unique_form_id}} = -1; | ||
// If our widget changed the content type, copy new value to original value | ||
- $(".gfk_widget_{{ name }}").change(function() { | ||
+ $(".gfk_{{ unique_form_id }}_input").change(function() { | ||
// Set original CT-field to valid value | ||
- bits = GFK_{{ name }}.get_ct_split(); | ||
- $('#id_{{ name }}').val(bits[0]); | ||
+ bits = GFK_{{ unique_form_id }}.get_ct_split(); | ||
+ $('.gfk_{{ unique_form_id }}_ct').val(bits[0]); | ||
// Set FK-value to nothing | ||
- GFK_{{ name }}.set_fk_value(''); | ||
+ $('.gfk_{{ unique_form_id }}_fk').val(''); | ||
// Set lookup-button to correct href | ||
- GFK_{{ name }}.update_lookup_button(); | ||
+ GFK_{{ unique_form_id }}.update_lookup_button(); | ||
}); | ||
// Initially, retrieve object rendering and set lookup target | ||
- GFK_{{ name }}.update_object(); | ||
- GFK_{{ name }}.update_lookup_button(); | ||
+ GFK_{{ unique_form_id }}.update_object(); | ||
+ GFK_{{ unique_form_id }}.update_lookup_button(); | ||
- window.setInterval("GFK_{{ name }}.monitor()", 2000); | ||
+ window.setInterval("GFK_{{ unique_form_id }}.monitor()", 2000); | ||
}, | ||
update_lookup_button: function() { | ||
- bits = GFK_{{ name }}.get_ct_split(); | ||
+ bits = GFK_{{ unique_form_id }}.get_ct_split(); | ||
+ console.log(bits); | ||
url = '/admin/' + bits[1] + '/' + bits[2] + '/?t=id'; | ||
- fk_field_id = GFK_{{ name }}.get_fk_field().attr('id'); | ||
- f = $('#lookup_'+fk_field_id); | ||
- f.attr('href', url); | ||
+ $('.gfk_{{ unique_form_id }}_lookup').attr('href', url); | ||
}, | ||
monitor: function() { | ||
- GFK_{{ name }}.update_object(); | ||
+ GFK_{{ unique_form_id }}.update_object(); | ||
}, | ||
- get_fk_field: function() { | ||
- field_name = $('#id_{{ name }}_value'); | ||
- field_instance = $('#id_' + field_name.val()); | ||
- return field_instance; | ||
- }, | ||
- | ||
- | ||
/* | ||
* Since the ct-format is is_appname_model, return a splitted version | ||
*/ | ||
get_ct_split: function() { | ||
- return $(".gfk_widget_{{ name }}").val().split('_'); | ||
- }, | ||
- | ||
- /* | ||
- * Set hidden fk field and update object string | ||
- */ | ||
- set_fk_value: function(v) { | ||
- | ||
- // Set value field to new value | ||
- f = GFK_{{ name }}.get_fk_field(); | ||
- f.val(v); | ||
- GFK_{{ name }}.update_object(); | ||
+ return $(".gfk_{{ unique_form_id }}_input").val().split('_'); | ||
}, | ||
/* | ||
* Fetch object via ajax request and display as string | ||
*/ | ||
update_object: function() { | ||
- params = { | ||
- 'ct': $('#id_{{ name }}').val(), | ||
- 'fk': GFK_{{ name }}.get_fk_field().val() | ||
- }; | ||
- | ||
- $.post('/gfkajax/', params, function(data) { | ||
- $('#gfk_{{ name }}_display').html(data); | ||
- }); | ||
- | ||
+ var ct_val = $('.gfk_{{ unique_form_id }}_ct').val(); | ||
+ var fk_val = $('.gfk_{{ unique_form_id }}_fk').val(); | ||
+ | ||
+ if ((old_fk_val_{{ unique_form_id }} == -1) || (old_fk_val_{{ unique_form_id }} != fk_val)) { | ||
+ old_fk_val_{{ unique_form_id }} = fk_val; | ||
+ params = { | ||
+ 'ct': ct_val, | ||
+ 'fk': fk_val | ||
+ }; | ||
+ $('.gfk_{{ unique_form_id }}_display').html('Updating...') | ||
+ $.post('/gfkajax/', params, function(data) { | ||
+ $('.gfk_{{ unique_form_id }}_display').html(data); | ||
+ }); | ||
+ } | ||
} | ||
}; | ||
$(document).ready(function() { | ||
- GFK_{{ name }}.init(); | ||
+ GFK_{{ unique_form_id }}.init(); | ||
}); | ||
48
widgets.py
0 comments on commit
39bb24e