wcs: use sessionStorage to store current submission context (#48503)
This commit is contained in:
parent
3918e5f8ec
commit
c48e3bf3c9
|
@ -941,6 +941,9 @@ class BackofficeSubmissionCell(WcsDataBaseCell):
|
|||
class Meta:
|
||||
verbose_name = _('Backoffice Submission')
|
||||
|
||||
class Media:
|
||||
js = ('/jsi18n', 'js/combo.submission.js',)
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
context = super(BackofficeSubmissionCell, self).get_cell_extra_context(context)
|
||||
all_formdefs = context.pop('all_formdefs')
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
$(function () {
|
||||
$(window).on('pageshow', update_submission_href);
|
||||
|
||||
$(document).on('combo:cell-loaded combo:submission-context-update', update_submission_href);
|
||||
|
||||
$(window).on('storage', function (event) {
|
||||
if (event.originalEvent != undefined && event.originalEvent.key.includes('wcs_submission_context')) {
|
||||
$('document').trigger('combo:submission-context-update');
|
||||
}
|
||||
});
|
||||
|
||||
function update_submission_href() {
|
||||
const channel = window.sessionStorage.wcs_submission_context_channel;
|
||||
let url;
|
||||
|
||||
$('.wcs-bo-submission-link').each(function (i, anchor) {
|
||||
if (anchor.orig_href != undefined) {
|
||||
url = anchor.orig_href;
|
||||
} else {
|
||||
url = anchor.href;
|
||||
anchor.orig_href = anchor.href;
|
||||
}
|
||||
if (channel == 'phone') {
|
||||
if (url.includes('?')) {
|
||||
url += '&';
|
||||
} else {
|
||||
url += '?';
|
||||
}
|
||||
url += 'channel=' + encodeURIComponent(channel);
|
||||
let caller = window.sessionStorage.wcs_submission_context_caller;
|
||||
if (caller != undefined) {
|
||||
url += '&caller=' + encodeURIComponent(window.sessionStorage.wcs_submission_context_caller);
|
||||
}
|
||||
} else {
|
||||
/* clean the localstorage to prevent mismatches later */
|
||||
let keys_to_delete = [];
|
||||
for (let i = 0; i < window.sessionStorage.length; i++) {
|
||||
const key = window.sessionStorage.key(i);
|
||||
if (key.includes('wcs_submission_context_')) {
|
||||
keys_to_delete.push(key);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < keys_to_delete.length; i++) {
|
||||
window.sessionStorage.removeItem(keys_to_delete[i]);
|
||||
}
|
||||
}
|
||||
anchor.href = url;
|
||||
})
|
||||
}
|
||||
});
|
|
@ -10,7 +10,7 @@
|
|||
{% for category_formdefs in categories_formdefs %}
|
||||
<li><h4>{{ category_formdefs.grouper }}</h4></li>
|
||||
{% for formdef in category_formdefs.list|dictsort:"title" %}
|
||||
<li><a href="{{formdef.backoffice_submission_url}}?NameID={{name_id}}&ReturnURL={{ absolute_uri|iriencode }}">{{formdef.title}}</a></li>
|
||||
<li><a class="wcs-bo-submission-link" href="{{formdef.backoffice_submission_url}}?NameID={{name_id}}&ReturnURL={{ absolute_uri|iriencode }}">{{formdef.title}}</a></li>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue