Skip to content

Commit

Permalink
CONCD-576 trigger when popup is dismissed
Browse files Browse the repository at this point in the history
  • Loading branch information
rasarkar committed Nov 21, 2023
1 parent 74205dd commit 95f9ee3
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions concordia/static/admin/custom-inline.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
/* global jQuery */

(function ($) {
$(document).ready(function () {
function displayCardTitle(element) {
var objectId = element.val();
$.ajax({
url: '/admin/serialized_object/',
data: {
model_name: 'Card',
object_id: objectId,
field_name: 'title',
},
dataType: 'json',
success: function (data) {
var title = $(
"<strong><a href='/admin/card/" +
objectId +
"/change/'>" +
data.title +
'</a></strong>',
);
var strong = element.siblings('strong');
if (strong.length > 0) {
strong.children(':first').text(data.title);
} else {
element.siblings(':last').after(title);
}
},
});
}
function triggerChangeOnField(win, chosenId) {
var element = document.getElementById(win.name);

$('input.vForeignKeyRawIdAdminField').on(
'propertychange input',
function () {
displayCardTitle($(this));
$.ajax({
url: '/admin/serialized_object/',
data: {
model_name: 'Card',
object_id: chosenId,
field_name: 'title',
},
dataType: 'json',
success: function (data) {
const newContent = document.createTextNode(data.title);
var a = document.createElement('a');
a.href = '/admin/card/' + chosenId + '/change/';
a.append(newContent);
var newStrong = document.createElement('strong');
newStrong.append(a);
var strong = element.parentNode.querySelector('strong');
if (strong) {
strong.replaceWith(newStrong);
} else {
element.parentNode.append(newStrong);
}
},
);
});
}

$(document).ready(function () {
// https://stackoverflow.com/a/33937138/10320488
window.ORIGINAL_dismissRelatedLookupPopup =
window.dismissRelatedLookupPopup;
window.dismissRelatedLookupPopup = function (win, chosenId) {
window.ORIGINAL_dismissRelatedLookupPopup(win, chosenId);
triggerChangeOnField(win, chosenId);
};
});
})(jQuery);

0 comments on commit 95f9ee3

Please sign in to comment.