mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-23 08:04:46 +00:00
Convert the page/collection privacy modal to use static onload handlers
This commit is contained in:
parent
e68478777d
commit
bbffeca771
8 changed files with 41 additions and 74 deletions
|
|
@ -21,5 +21,3 @@ wagtail/embeds/templates/wagtailembeds/chooser/embed_chosen.js
|
|||
wagtail/embeds/templates/wagtailembeds/chooser/chooser.js
|
||||
wagtail/documents/templates/wagtaildocs/chooser/chooser.js
|
||||
wagtail/documents/templates/wagtaildocs/chooser/document_chosen.js
|
||||
wagtail/admin/templates/wagtailadmin/page_privacy/set_privacy.js
|
||||
wagtail/admin/templates/wagtailadmin/page_privacy/set_privacy_done.js
|
||||
|
|
|
|||
|
|
@ -3,6 +3,39 @@ $(function() {
|
|||
$('a.action-set-privacy').on('click', function() {
|
||||
ModalWorkflow({
|
||||
url: this.href,
|
||||
onload: {
|
||||
'set_privacy': function(modal, jsonData) {
|
||||
$('form', modal.body).on('submit', function() {
|
||||
modal.postForm(this.action, $(this).serialize());
|
||||
return false;
|
||||
});
|
||||
|
||||
var restrictionTypePasswordField = $("input[name='restriction_type'][value='password']", modal.body);
|
||||
var restrictionTypeGroupsField = $("input[name='restriction_type'][value='groups']", modal.body);
|
||||
var passwordField = $(".password-field", modal.body);
|
||||
var groupsFields = $('#groups-fields', modal.body);
|
||||
|
||||
function refreshFormFields() {
|
||||
if (restrictionTypePasswordField.is(':checked')) {
|
||||
passwordField.show();
|
||||
groupsFields.hide();
|
||||
} else if (restrictionTypeGroupsField.is(':checked')){
|
||||
passwordField.hide();
|
||||
groupsFields.show();
|
||||
} else {
|
||||
passwordField.hide();
|
||||
groupsFields.hide();
|
||||
}
|
||||
}
|
||||
refreshFormFields();
|
||||
|
||||
$("input[name='restriction_type']", modal.body).on('change', refreshFormFields);
|
||||
},
|
||||
'set_privacy_done': function(modal, jsonData) {
|
||||
modal.respond('setPermission', jsonData['is_public']);
|
||||
modal.close();
|
||||
}
|
||||
},
|
||||
responses: {
|
||||
setPermission: function(isPublic) {
|
||||
if (isPublic) {
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
function(modal) {
|
||||
$('form', modal.body).on('submit', function() {
|
||||
modal.postForm(this.action, $(this).serialize());
|
||||
return false;
|
||||
});
|
||||
|
||||
var restrictionTypePasswordField = $("input[name='restriction_type'][value='password']", modal.body);
|
||||
var restrictionTypeGroupsField = $("input[name='restriction_type'][value='groups']", modal.body);
|
||||
var passwordField = $(".password-field", modal.body);
|
||||
var groupsFields = $('#groups-fields', modal.body);
|
||||
|
||||
function refreshFormFields() {
|
||||
if (restrictionTypePasswordField.is(':checked')) {
|
||||
passwordField.show();
|
||||
groupsFields.hide();
|
||||
} else if (restrictionTypeGroupsField.is(':checked')){
|
||||
passwordField.hide();
|
||||
groupsFields.show();
|
||||
} else {
|
||||
passwordField.hide();
|
||||
groupsFields.hide();
|
||||
}
|
||||
}
|
||||
refreshFormFields();
|
||||
|
||||
$("input[name='restriction_type']", modal.body).on('change', refreshFormFields);
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
function(modal, jsonData) {
|
||||
modal.respond('setPermission', jsonData['is_public']);
|
||||
modal.close();
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
function(modal) {
|
||||
$('form', modal.body).on('submit', function() {
|
||||
modal.postForm(this.action, $(this).serialize());
|
||||
return false;
|
||||
});
|
||||
|
||||
var restrictionTypePasswordField = $("input[name='restriction_type'][value='password']", modal.body);
|
||||
var restrictionTypeGroupsField = $("input[name='restriction_type'][value='groups']", modal.body);
|
||||
var passwordField = $(".password-field", modal.body);
|
||||
var groupsFields = $('#groups-fields', modal.body);
|
||||
|
||||
function refreshFormFields() {
|
||||
if (restrictionTypePasswordField.is(':checked')) {
|
||||
passwordField.show();
|
||||
groupsFields.hide();
|
||||
} else if (restrictionTypeGroupsField.is(':checked')){
|
||||
passwordField.hide();
|
||||
groupsFields.show();
|
||||
} else {
|
||||
passwordField.hide();
|
||||
groupsFields.hide();
|
||||
}
|
||||
}
|
||||
refreshFormFields();
|
||||
|
||||
$("input[name='restriction_type']", modal.body).on('change', refreshFormFields);
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
function(modal, jsonData) {
|
||||
modal.respond('setPermission', jsonData['is_public']);
|
||||
modal.close();
|
||||
}
|
||||
|
|
@ -34,8 +34,9 @@ def set_privacy(request, collection_id):
|
|||
form.save()
|
||||
|
||||
return render_modal_workflow(
|
||||
request, None, 'wagtailadmin/collection_privacy/set_privacy_done.js',
|
||||
request, None, None,
|
||||
None, json_data={
|
||||
'step': 'set_privacy_done',
|
||||
'is_public': (form.cleaned_data['restriction_type'] == 'none')
|
||||
}
|
||||
)
|
||||
|
|
@ -62,10 +63,8 @@ def set_privacy(request, collection_id):
|
|||
else:
|
||||
# no restriction set at ancestor level - can set restrictions here
|
||||
return render_modal_workflow(
|
||||
request,
|
||||
'wagtailadmin/collection_privacy/set_privacy.html',
|
||||
'wagtailadmin/collection_privacy/set_privacy.js', {
|
||||
request, 'wagtailadmin/collection_privacy/set_privacy.html', None, {
|
||||
'collection': collection,
|
||||
'form': form,
|
||||
}
|
||||
}, json_data={'step': 'set_privacy'}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -34,8 +34,9 @@ def set_privacy(request, page_id):
|
|||
form.save()
|
||||
|
||||
return render_modal_workflow(
|
||||
request, None, 'wagtailadmin/page_privacy/set_privacy_done.js',
|
||||
request, None, None,
|
||||
None, json_data={
|
||||
'step': 'set_privacy_done',
|
||||
'is_public': (form.cleaned_data['restriction_type'] == 'none')
|
||||
}
|
||||
)
|
||||
|
|
@ -62,10 +63,8 @@ def set_privacy(request, page_id):
|
|||
else:
|
||||
# no restriction set at ancestor level - can set restrictions here
|
||||
return render_modal_workflow(
|
||||
request,
|
||||
'wagtailadmin/page_privacy/set_privacy.html',
|
||||
'wagtailadmin/page_privacy/set_privacy.js', {
|
||||
request, 'wagtailadmin/page_privacy/set_privacy.html', None, {
|
||||
'page': page,
|
||||
'form': form,
|
||||
}
|
||||
}, json_data={'step': 'set_privacy'}
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue