forked from django-cms/django-filer
/
popup_handling.js
73 lines (66 loc) · 2.42 KB
/
popup_handling.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
/* global django */
// as of Django 2.x we need to check where jQuery is
var djQuery = window.$;
if (django.jQuery) {
djQuery = django.jQuery;
}
(function ($) {
function windowname_to_id(text) {
text = text.replace(/__dot__/g, '.');
text = text.replace(/__dash__/g, '-');
return text.split('__')[0];
}
window.dismissPopupAndReload = function (win) {
document.location.reload();
win.close();
};
window.dismissRelatedImageLookupPopup = function (
win,
chosenId,
chosenThumbnailUrl,
chosenDescriptionTxt,
chosenAdminChangeUrl
) {
var id = windowname_to_id(win.name);
var lookup = $('#' + id);
var container = lookup.closest('.filerFile');
var edit = container.find('.edit');
var image = container.find('.thumbnail_img');
var descriptionText = container.find('.description_text');
var clearer = container.find('.filerClearer');
var dropzoneMessage = container.siblings('.dz-message');
var element = container.find(':input');
var oldId = element.value;
element.val(chosenId);
element.closest('.js-filer-dropzone').addClass('js-object-attached');
if (chosenThumbnailUrl) {
image.attr('src', chosenThumbnailUrl).removeClass('hidden');
image.removeAttr('srcset'); // would be nicer, but much more complicate to also replace 'srcset'
}
descriptionText.text(chosenDescriptionTxt);
clearer.removeClass('hidden');
lookup.addClass('related-lookup-change');
edit.addClass('related-lookup-change');
if (chosenAdminChangeUrl) {
edit.attr('href', chosenAdminChangeUrl + '?_edit_from_widget=1');
}
dropzoneMessage.addClass('hidden');
if (oldId !== chosenId) {
element.trigger('change');
}
win.close();
};
window.dismissRelatedFolderLookupPopup = function (win, chosenId, chosenName) {
var id = windowname_to_id(win.name);
var clearButton = $('#id_' + id + '_clear');
var input = $('#id_' + id);
var folderName = $('#id_' + id + '_description_txt');
var addFolderButton = $('#' + id);
input.val(chosenId);
folderName.text(chosenName);
clearButton.removeClass('hidden');
addFolderButton.addClass('hidden');
win.close();
};
})(djQuery);