From 0255c50081590f41bd44c914f795abb07da3f4bd Mon Sep 17 00:00:00 2001
From: Anna Cho <103462904+bwithchewoo@users.noreply.github.com>
Date: Tue, 12 Nov 2024 09:23:16 -0800
Subject: [PATCH] closes #182 autopopulating the selected record when adding
relationship
---
TEKDB/TEKDB/admin.py | 8 ++++---
TEKDB/TEKDB/static/TEKDB/js/record_form.js | 28 +++++++++++++---------
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py
index 8d10070b..6a7d54fb 100644
--- a/TEKDB/TEKDB/admin.py
+++ b/TEKDB/TEKDB/admin.py
@@ -189,6 +189,7 @@ class Meta:
}
fields = '__all__'
+
class ResourcesMediaEventsForm(forms.ModelForm):
class Meta:
model = ResourcesMediaEvents
@@ -198,6 +199,7 @@ class Meta:
'relationshipdescription': CKEditorWidget
}
fields = '__all__'
+
class PlaceAltIndigenousNameForm(forms.ModelForm):
class Meta:
@@ -539,7 +541,7 @@ class MediaAdmin(RecordAdminProxy, RecordModelAdmin):
'enteredbyname','enteredbydate')
fieldsets = (
(None, {
- 'fields': (('medianame','mediatype','limitedaccess'),'mediafile','medialink','mediadescription','media_collection',)
+ 'fields': (('medianame','mediatype','limitedaccess'),'mediafile','medialink','mediadescription','mediabulkupload',)
}),
('Review', {
'fields': (
@@ -791,7 +793,7 @@ class PlacesMediaEventsAdmin(RecordAdminProxy):
})
)
form = PlacesMediaEventsForm
-
+
class PlaceAltIndigenousNameAdmin(VersionAdmin):
fieldsets = (
('', {
@@ -844,7 +846,7 @@ class ResourceActivityCitationEventsAdmin(RecordAdminProxy):
})
)
form = ResourceActivityCitationEventsForm
-
+
class ResourceActivityMediaEventsAdmin(RecordAdminProxy):
list_display = ('resourceactivityid','mediaid','enteredbyname','enteredbydate','modifiedbyname','modifiedbydate')
fieldsets = (
diff --git a/TEKDB/TEKDB/static/TEKDB/js/record_form.js b/TEKDB/TEKDB/static/TEKDB/js/record_form.js
index 4115aa19..7ad7bba2 100644
--- a/TEKDB/TEKDB/static/TEKDB/js/record_form.js
+++ b/TEKDB/TEKDB/static/TEKDB/js/record_form.js
@@ -72,21 +72,27 @@ loadFormModal = function(module, model, id, action, base_model, base_id, fk_fiel
}
html +='/?_popup=1">';
$('#form-modal-body').html(html);
- $('#popup-iframe-form').load(function(){
+ $('#popup-iframe-form').on('load', function() {
if (action != 'delete') {
- if (action == 'add') {
- $('#popup-iframe-form').contents().find('#id_' + fk_field_id).parent().replaceWith('');
- }
- // If below only shown for 'add', users could move relationships to new records
- // For now I'm not sure this feature is intuitive or desired.
- $('#popup-iframe-form').contents().find('#id_' + fk_field_id).hide();
- $('#popup-iframe-form').contents().find('.field-box.field-' + fk_field_id).hide();
- all_buttons = $('#popup-iframe-form').contents().find('.submit-row input');
+ if (action == 'add') {
+ $('#popup-iframe-form').contents().find('#id_' + fk_field_id).parent().replaceWith('');
+ }
+ $('#popup-iframe-form').contents().find('#id_' + fk_field_id).hide();
+ $('#popup-iframe-form').contents().find('.field-box.field-' + fk_field_id).hide();
+ $('#popup-iframe-form').contents().find('label[for="id_' + fk_field_id + '"]').hide();
+ all_buttons = $('#popup-iframe-form').contents().find('.submit-row input');
} else {
- all_buttons = $('#popup-iframe-form').contents().find('form div').children(':not([type="hidden"])');
+ all_buttons = $('#popup-iframe-form').contents().find('form div').children(':not([type="hidden"])');
}
all_buttons.attr('data-toggle', 'modal');
all_buttons.attr('data-target', '#inlineFormModal');
- all_buttons.on('click', function(){iframeButtonClicked(base_model, base_id);});
+ all_buttons.on('click', function() { iframeButtonClicked(base_model, base_id); });
});
}
+
+window.addEventListener('message', function(event) {
+ // Check for the specific action you expect
+ if (event.data.action === 'closeAndRefresh') {
+ window.location.reload(); // Refresh the parent page
+ }
+});
\ No newline at end of file