mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-63109 privacy: Fix the initialisation of the policy acceptance modal
This commit is contained in:
parent
674ef9baac
commit
2b85015b83
@ -1 +1 @@
|
||||
define(["jquery","core/str","core/modal_factory","core/modal_events","core/notification","core/fragment","core/ajax","core/yui"],function(a,b,c,d,e,f,g,h){"use strict";var i=function(a){this.contextid=a,this.init()};return i.prototype.modal=null,i.prototype.contextid=-1,i.prototype.stringKeys=[{key:"consentdetails",component:"tool_policy"},{key:"iagreetothepolicy",component:"tool_policy"},{key:"selectusersforconsent",component:"tool_policy"},{key:"ok"},{key:"revokedetails",component:"tool_policy"},{key:"irevokethepolicy",component:"tool_policy"}],i.prototype.init=function(){var c=a("a[data-action=acceptmodal]");c.on("click",function(b){b.preventDefault();var c=a(b.currentTarget).attr("href"),d=c.slice(c.indexOf("?")+1);this.showFormModal(d)}.bind(this)),c=a("form[data-action=acceptmodal]"),c.on("submit",function(d){if(d.preventDefault(),a(d.currentTarget).find('input[type=checkbox][name="userids[]"]:checked').length){var f=a(d.currentTarget).serialize();this.showFormModal(f,c)}else b.get_strings(this.stringKeys).done(function(a){e.alert("",a[2],a[3])})}.bind(this))},i.prototype.showFormModal=function(a,d){for(var f,g=a.split("&"),h=0;h<g.length;h++){var i=g[h].split("=");"action"==i[0]&&(f=i[1])}b.get_strings(this.stringKeys).done(function(b){var e,g;"revoke"==f?(e=b[4],g=b[5]):(e=b[0],g=b[1]),c.create({type:c.types.SAVE_CANCEL,title:e,body:""},d).done(function(b){this.modal=b,this.setupFormModal(a,g)}.bind(this))}.bind(this)).fail(e.exception)},i.prototype.setupFormModal=function(a,b){var c=this.modal;c.setLarge(),c.setSaveButtonText(b),c.getRoot().on(d.hidden,this.destroy.bind(this)),c.setBody(this.getBody(a)),c.getRoot().on(d.save,this.submitForm.bind(this)),c.getRoot().on("submit","form",this.submitFormAjax.bind(this)),c.show()},i.prototype.getBody=function(a){"undefined"==typeof a&&(a={});var b={jsonformdata:JSON.stringify(a)};return f.loadFragment("tool_policy","accept_on_behalf",this.contextid,b)},i.prototype.submitFormAjax=function(a){a.preventDefault();var b=this.modal.getRoot().find("form").serialize(),c=g.call([{methodname:"tool_policy_submit_accept_on_behalf",args:{jsonformdata:JSON.stringify(b)}}]);c[0].done(function(a){a.validationerrors?this.modal.setBody(this.getBody(b)):this.close()}.bind(this)).fail(e.exception)},i.prototype.submitForm=function(a){a.preventDefault(),this.modal.getRoot().find("form").submit()},i.prototype.close=function(){this.destroy(),document.location.reload()},i.prototype.destroy=function(){h.use("moodle-core-formchangechecker",function(){M.core_formchangechecker.reset_form_dirty_state()}),this.modal.destroy()},{getInstance:function(a){return new i(a)}}});
|
||||
define(["jquery","core/str","core/modal_factory","core/modal_events","core/notification","core/fragment","core/ajax","core/yui"],function(a,b,c,d,e,f,g,h){"use strict";var i=function(a){this.contextid=a,this.init()};return i.prototype.modal=null,i.prototype.contextid=-1,i.prototype.stringKeys=[{key:"consentdetails",component:"tool_policy"},{key:"iagreetothepolicy",component:"tool_policy"},{key:"selectusersforconsent",component:"tool_policy"},{key:"ok"},{key:"revokedetails",component:"tool_policy"},{key:"irevokethepolicy",component:"tool_policy"}],i.prototype.currentTrigger=null,i.prototype.triggers={SINGLE:"a[data-action=acceptmodal]",BULK:"input[data-action=acceptmodal]"},i.prototype.init=function(){a(this.triggers.SINGLE).on("click",function(b){b.preventDefault(),this.currentTrigger=a(b.currentTarget);var c=a(b.currentTarget).attr("href"),d=c.slice(c.indexOf("?")+1);this.showFormModal(d)}.bind(this)),a(this.triggers.BULK).on("click",function(c){c.preventDefault(),this.currentTrigger=a(c.currentTarget);var d=a(c.currentTarget).closest("form");if(d.find('input[type=checkbox][name="userids[]"]:checked').length){var f=d.serialize();this.showFormModal(f)}else b.get_strings(this.stringKeys).done(function(a){e.alert("",a[2],a[3])})}.bind(this))},i.prototype.showFormModal=function(a){for(var d,f=a.split("&"),g=0;g<f.length;g++){var h=f[g].split("=");"action"==h[0]&&(d=h[1])}b.get_strings(this.stringKeys).done(function(b){var e,f;"revoke"==d?(e=b[4],f=b[5]):(e=b[0],f=b[1]),c.create({type:c.types.SAVE_CANCEL,title:e,body:""}).done(function(b){this.modal=b,this.setupFormModal(a,f)}.bind(this))}.bind(this)).fail(e.exception)},i.prototype.setupFormModal=function(a,b){var c=this.modal;c.setLarge(),c.setSaveButtonText(b),c.getRoot().on(d.hidden,this.destroy.bind(this)),c.setBody(this.getBody(a)),c.getRoot().on(d.save,this.submitForm.bind(this)),c.getRoot().on("submit","form",this.submitFormAjax.bind(this)),c.show()},i.prototype.getBody=function(a){"undefined"==typeof a&&(a={});var b={jsonformdata:JSON.stringify(a)};return f.loadFragment("tool_policy","accept_on_behalf",this.contextid,b)},i.prototype.submitFormAjax=function(a){a.preventDefault();var b=this.modal.getRoot().find("form").serialize(),c=g.call([{methodname:"tool_policy_submit_accept_on_behalf",args:{jsonformdata:JSON.stringify(b)}}]);c[0].done(function(a){a.validationerrors?this.modal.setBody(this.getBody(b)):this.close()}.bind(this)).fail(e.exception)},i.prototype.submitForm=function(a){a.preventDefault(),this.modal.getRoot().find("form").submit()},i.prototype.close=function(){this.destroy(),document.location.reload()},i.prototype.destroy=function(){h.use("moodle-core-formchangechecker",function(){M.core_formchangechecker.reset_form_dirty_state()}),this.modal.destroy(),this.currentTrigger.focus()},{getInstance:function(a){return new i(a)}}});
|
@ -82,6 +82,21 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* @var {object} currentTrigger The triggered HTML jQuery object
|
||||
* @private
|
||||
*/
|
||||
AcceptOnBehalf.prototype.currentTrigger = null;
|
||||
|
||||
/**
|
||||
* @var {object} triggers The trigger selectors
|
||||
* @private
|
||||
*/
|
||||
AcceptOnBehalf.prototype.triggers = {
|
||||
SINGLE: 'a[data-action=acceptmodal]',
|
||||
BULK: 'input[data-action=acceptmodal]'
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise the class.
|
||||
*
|
||||
@ -89,21 +104,22 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
|
||||
*/
|
||||
AcceptOnBehalf.prototype.init = function() {
|
||||
// Initialise for links accepting policies for individual users.
|
||||
var triggers = $('a[data-action=acceptmodal]');
|
||||
triggers.on('click', function(e) {
|
||||
$(this.triggers.SINGLE).on('click', function(e) {
|
||||
e.preventDefault();
|
||||
this.currentTrigger = $(e.currentTarget);
|
||||
var href = $(e.currentTarget).attr('href'),
|
||||
formData = href.slice(href.indexOf('?') + 1);
|
||||
this.showFormModal(formData);
|
||||
}.bind(this));
|
||||
|
||||
// Initialise for multiple users acceptance form.
|
||||
triggers = $('form[data-action=acceptmodal]');
|
||||
triggers.on('submit', function(e) {
|
||||
$(this.triggers.BULK).on('click', function(e) {
|
||||
e.preventDefault();
|
||||
if ($(e.currentTarget).find('input[type=checkbox][name="userids[]"]:checked').length) {
|
||||
var formData = $(e.currentTarget).serialize();
|
||||
this.showFormModal(formData, triggers);
|
||||
this.currentTrigger = $(e.currentTarget);
|
||||
var form = $(e.currentTarget).closest('form');
|
||||
if (form.find('input[type=checkbox][name="userids[]"]:checked').length) {
|
||||
var formData = form.serialize();
|
||||
this.showFormModal(formData);
|
||||
} else {
|
||||
Str.get_strings(this.stringKeys).done(function(strings) {
|
||||
Notification.alert('', strings[2], strings[3]);
|
||||
@ -116,9 +132,8 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
|
||||
* Show modal with a form
|
||||
*
|
||||
* @param {String} formData
|
||||
* @param {object} triggerElement The trigger HTML jQuery object
|
||||
*/
|
||||
AcceptOnBehalf.prototype.showFormModal = function(formData, triggerElement) {
|
||||
AcceptOnBehalf.prototype.showFormModal = function(formData) {
|
||||
var action;
|
||||
var params = formData.split('&');
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
@ -143,7 +158,7 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
|
||||
type: ModalFactory.types.SAVE_CANCEL,
|
||||
title: title,
|
||||
body: ''
|
||||
}, triggerElement).done(function(modal) {
|
||||
}).done(function(modal) {
|
||||
this.modal = modal;
|
||||
this.setupFormModal(formData, saveText);
|
||||
}.bind(this));
|
||||
@ -250,6 +265,7 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
|
||||
M.core_formchangechecker.reset_form_dirty_state();
|
||||
});
|
||||
this.modal.destroy();
|
||||
this.currentTrigger.focus();
|
||||
};
|
||||
|
||||
return /** @alias module:tool_policy/acceptmodal */ {
|
||||
|
@ -415,7 +415,7 @@ class acceptances_table extends \table_sql {
|
||||
*/
|
||||
public function wrap_html_start() {
|
||||
echo \html_writer::start_tag('form',
|
||||
['action' => new \moodle_url('/admin/tool/policy/accept.php'), 'data-action' => 'acceptmodal']);
|
||||
['action' => new \moodle_url('/admin/tool/policy/accept.php')]);
|
||||
echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]);
|
||||
echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'returnurl',
|
||||
'value' => $this->get_return_url()]);
|
||||
@ -433,8 +433,8 @@ class acceptances_table extends \table_sql {
|
||||
public function wrap_html_finish() {
|
||||
global $PAGE;
|
||||
if ($this->canagreeany) {
|
||||
echo \html_writer::empty_tag('input', ['type' => 'submit',
|
||||
'value' => get_string('consentbulk', 'tool_policy'), 'class' => 'btn btn-primary']);
|
||||
echo \html_writer::empty_tag('input', ['type' => 'submit', 'data-action' => 'acceptmodal',
|
||||
'value' => get_string('consentbulk', 'tool_policy'), 'class' => 'btn btn-primary m-t-1']);
|
||||
$PAGE->requires->js_call_amd('tool_policy/acceptmodal', 'getInstance', [\context_system::instance()->id]);
|
||||
}
|
||||
echo "</form>\n";
|
||||
|
Loading…
x
Reference in New Issue
Block a user