MDL-61864 tool_policy: coding style fixes

This commit is contained in:
Marina Glancy 2018-04-05 14:51:36 +08:00
parent 92a03f69d2
commit 673b598109
12 changed files with 43 additions and 29 deletions

View File

@ -3,6 +3,7 @@
*/**/build/
node_modules/
vendor/
admin/tool/policy/amd/src/jquery-eu-cookie-law-popup.js
admin/tool/usertours/amd/src/tour.js
auth/cas/CAS/
enrol/lti/ims-blti/

View File

@ -4,6 +4,7 @@ theme/clean/style/custom.css
theme/more/style/custom.css
node_modules/
vendor/
admin/tool/policy/amd/src/jquery-eu-cookie-law-popup.js
admin/tool/usertours/amd/src/tour.js
auth/cas/CAS/
enrol/lti/ims-blti/

View File

@ -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"}],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){b.get_strings(this.stringKeys).done(function(b){c.create({type:c.types.SAVE_CANCEL,title:b[0],body:""},d).done(function(c){this.modal=c,this.setupFormModal(a,b[1])}.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){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"}],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){b.get_strings(this.stringKeys).done(function(b){c.create({type:c.types.SAVE_CANCEL,title:b[0],body:""},d).done(function(c){this.modal=c,this.setupFormModal(a,b[1])}.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)}}});

View File

@ -1 +1 @@
define(["jquery","core/log","core/config","core/str","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f){"use strict";function g(a){this.base=a,this.initEvents()}var h={LINKS:"[data-action]",MAKE_CURRENT:'[data-action="makecurrent"]',INACTIVATE:'[data-action="inactivate"]',DELETE:'[data-action="delete"]'};return g.prototype.initEvents=function(){var g=this;g.base.on("click",h.LINKS,function(g){g.stopPropagation();var i,j,k=a(g.currentTarget);if(k.is(h.MAKE_CURRENT))i=d.get_strings([{key:"activating",component:"tool_policy"},{key:"activateconfirm",component:"tool_policy",param:{name:k.closest("[data-policy-name]").attr("data-policy-name"),revision:k.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"activateconfirmyes",component:"tool_policy"}]);else if(k.is(h.INACTIVATE))i=d.get_strings([{key:"inactivating",component:"tool_policy"},{key:"inactivatingconfirm",component:"tool_policy",param:{name:k.closest("[data-policy-name]").attr("data-policy-name"),revision:k.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"inactivatingconfirmyes",component:"tool_policy"}]);else{if(!k.is(h.DELETE))return void b.error("unknown action type detected","tool_policy/managedocsactions");i=d.get_strings([{key:"deleting",component:"tool_policy"},{key:"deleteconfirm",component:"tool_policy",param:{name:k.closest("[data-policy-name]").attr("data-policy-name"),revision:k.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"delete",component:"core"}])}return g.preventDefault(),i.then(function(a){return j=a,e.create({title:j[0],body:j[1],type:e.types.SAVE_CANCEL})}).then(function(a){return a.setSaveButtonText(j[2]),a.getRoot().on(f.save,function(){window.location.href=k.attr("href")+"&sesskey="+c.sesskey+"&confirm=1"}),a.getRoot().on(f.hidden,function(){a.destroy()}),a}).then(function(a){return a.show(),!0})})},{init:function(b){var c=a(document.getElementById(b));if(c.length)return new g(c);throw new Error("managedocsactions: Invalid base element identifier")}}});
define(["jquery","core/log","core/config","core/str","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f){"use strict";function g(a){this.base=a,this.initEvents()}var h={LINKS:"[data-action]",MAKE_CURRENT:'[data-action="makecurrent"]',INACTIVATE:'[data-action="inactivate"]',DELETE:'[data-action="delete"]'};return g.prototype.initEvents=function(){var g=this;g.base.on("click",h.LINKS,function(g){g.stopPropagation();var i,j,k=a(g.currentTarget);if(k.is(h.MAKE_CURRENT))i=d.get_strings([{key:"activating",component:"tool_policy"},{key:"activateconfirm",component:"tool_policy",param:{name:k.closest("[data-policy-name]").attr("data-policy-name"),revision:k.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"activateconfirmyes",component:"tool_policy"}]);else if(k.is(h.INACTIVATE))i=d.get_strings([{key:"inactivating",component:"tool_policy"},{key:"inactivatingconfirm",component:"tool_policy",param:{name:k.closest("[data-policy-name]").attr("data-policy-name"),revision:k.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"inactivatingconfirmyes",component:"tool_policy"}]);else{if(!k.is(h.DELETE))return void b.error("unknown action type detected","tool_policy/managedocsactions");i=d.get_strings([{key:"deleting",component:"tool_policy"},{key:"deleteconfirm",component:"tool_policy",param:{name:k.closest("[data-policy-name]").attr("data-policy-name"),revision:k.closest("[data-policy-revision]").attr("data-policy-revision")}},{key:"delete",component:"core"}])}g.preventDefault(),i.then(function(a){return j=a,e.create({title:j[0],body:j[1],type:e.types.SAVE_CANCEL})}).then(function(a){return a.setSaveButtonText(j[2]),a.getRoot().on(f.save,function(){window.location.href=k.attr("href")+"&sesskey="+c.sesskey+"&confirm=1"}),a.getRoot().on(f.hidden,function(){a.destroy()}),a.show(),!0})["catch"](function(a){return b.error(a),!1})})},{init:function(b){var c=a(document.getElementById(b));if(c.length)return new g(c);throw new Error("managedocsactions: Invalid base element identifier")}}});

View File

@ -1 +1 @@
define(["jquery","core/ajax","core/notification","core/modal_factory","core/modal_events"],function(a,b,c,d,e){var f={VIEW_POLICY:'[data-action="view"]'},g=function(){this.registerEvents()};return g.prototype.registerEvents=function(){a(f.VIEW_POLICY).click(function(f){f.preventDefault();var g=a(this).data("versionid"),h=a(this).data("behalfid"),i={versionid:g,behalfid:h},j={methodname:"tool_policy_get_policy_version",args:i},k=b.call([j]),l="",m=d.types.DEFAULT;a.when(k[0]).then(function(a){return a.result.policy?(l=a.result.policy.name,a.result.policy.content):(c.addNotification({message:a.warnings[0].message,type:"error"}),!1)}).then(function(a){if(0!=a)return d.create({title:l,body:a,type:m,large:!0}).then(function(a){return a.getRoot().on(e.hidden,function(){a.destroy()}),a})}).done(function(a){a.show()}).fail(c.exception)})},{init:function(){return new g}}});
define(["jquery","core/ajax","core/notification","core/modal_factory","core/modal_events"],function(a,b,c,d,e){var f={VIEW_POLICY:'[data-action="view"]'},g=function(){this.registerEvents()};return g.prototype.registerEvents=function(){a(f.VIEW_POLICY).click(function(f){f.preventDefault();var g=a(this).data("versionid"),h=a(this).data("behalfid"),i={versionid:g,behalfid:h},j={methodname:"tool_policy_get_policy_version",args:i},k=b.call([j]),l="",m=d.types.DEFAULT;a.when(k[0]).then(function(a){return a.result.policy?(l=a.result.policy.name,a.result.policy.content):(c.addNotification({message:a.warnings[0].message,type:"error"}),!1)}).then(function(a){return 0!=a&&d.create({title:l,body:a,type:m,large:!0}).then(function(a){return a.getRoot().on(e.hidden,function(){a.destroy()}),a})}).done(function(a){a.show()}).fail(c.exception)})},{init:function(){return new g}}});

View File

@ -97,7 +97,7 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
var formData = $(e.currentTarget).serialize();
this.showFormModal(formData, triggers);
} else {
Str.get_strings(this.stringKeys).done(function (strings) {
Str.get_strings(this.stringKeys).done(function(strings) {
Notification.alert('', strings[2], strings[3]);
});
}
@ -233,12 +233,11 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/modal_events', 'core/n
* Attach event listeners to initialise this module.
*
* @method init
* @param {string} selector The CSS selector used to find nodes that will trigger this module.
* @param {int} contextid The contextid for the course.
* @return {Promise}
* @return {AcceptOnBehalf}
*/
getInstance: function(contextid) {
new AcceptOnBehalf(contextid);
return new AcceptOnBehalf(contextid);
}
};
});

View File

@ -27,7 +27,7 @@ define([
'core/config',
'core/str',
'core/modal_factory',
'core/modal_events',
'core/modal_events'
], function($, Log, Config, Str, ModalFactory, ModalEvents) {
"use strict";
@ -42,7 +42,7 @@ define([
LINKS: '[data-action]',
MAKE_CURRENT: '[data-action="makecurrent"]',
INACTIVATE: '[data-action="inactivate"]',
DELETE: '[data-action="delete"]',
DELETE: '[data-action="delete"]'
};
/**
@ -75,7 +75,7 @@ define([
name: link.closest('[data-policy-name]').attr('data-policy-name'),
revision: link.closest('[data-policy-revision]').attr('data-policy-revision')
}},
{key: 'activateconfirmyes', component: 'tool_policy'},
{key: 'activateconfirmyes', component: 'tool_policy'}
]);
} else if (link.is(ACTION.INACTIVATE)) {
@ -85,7 +85,7 @@ define([
name: link.closest('[data-policy-name]').attr('data-policy-name'),
revision: link.closest('[data-policy-revision]').attr('data-policy-revision')
}},
{key: 'inactivatingconfirmyes', component: 'tool_policy'},
{key: 'inactivatingconfirmyes', component: 'tool_policy'}
]);
} else if (link.is(ACTION.DELETE)) {
@ -95,7 +95,7 @@ define([
name: link.closest('[data-policy-name]').attr('data-policy-name'),
revision: link.closest('[data-policy-revision]').attr('data-policy-revision')
}},
{key: 'delete', component: 'core'},
{key: 'delete', component: 'core'}
]);
} else {
@ -105,7 +105,7 @@ define([
e.preventDefault();
return promise.then(function(strs) {
promise.then(function(strs) {
strings = strs;
return ModalFactory.create({
title: strings[0],
@ -116,19 +116,19 @@ define([
}).then(function(modal) {
modal.setSaveButtonText(strings[2]);
modal.getRoot().on(ModalEvents.save, function() {
window.location.href = link.attr('href') + '&sesskey=' + Config.sesskey + '&confirm=1';
window.location.href = link.attr('href') + '&sesskey=' + Config.sesskey + '&confirm=1';
});
modal.getRoot().on(ModalEvents.hidden, function() {
modal.destroy();
});
return modal;
}).then(function(modal) {
modal.show();
return true;
}).catch(function(e) {
Log.error(e);
return false;
});
});
};
@ -137,8 +137,8 @@ define([
/**
* Factory method returning instance of the ManageDocsActions
*
* @param {string} baseid - ID of the management area wrapping element
* @return ManageDocsActions
* @param {String} baseid - ID of the management area wrapping element
* @return {ManageDocsActions}
*/
init: function(baseid) {
var base = $(document.getElementById(baseid));

View File

@ -97,6 +97,7 @@ function($, Ajax, Notification, ModalFactory, ModalEvents) {
return modal;
});
}
return false;
}).done(function(modal) {
// Show the modal.
modal.show();

View File

@ -54,6 +54,7 @@ class acceptances implements renderable, templatable {
* Contructor.
*
* @param int $userid
* @param string|moodle_url $returnurl
*/
public function __construct($userid, $returnurl = null) {
$this->userid = $userid;

View File

@ -156,7 +156,8 @@ class page_viewdoc implements renderable, templatable {
$data = (object) [
'pluginbaseurl' => (new moodle_url('/admin/tool/policy'))->out(false),
'returnurl' => $this->returnurl ? (new moodle_url($this->returnurl))->out(false) : null,
'editurl' => ($this->manage && $this->policy->status != policy_version::STATUS_ARCHIVED) ? (new moodle_url('/admin/tool/policy/editpolicydoc.php',
'editurl' => ($this->manage && $this->policy->status != policy_version::STATUS_ARCHIVED) ?
(new moodle_url('/admin/tool/policy/editpolicydoc.php',
['policyid' => $this->policy->policyid, 'versionid' => $this->policy->id]))->out(false) : null,
'numpolicy' => $this->numpolicy ? : null,
'totalpolicies' => $this->totalpolicies ? : null,

View File

@ -42,6 +42,16 @@ class behat_tool_policy extends behat_base {
*
* @Given /^the following policies exist:$/
*
* Supported table fields:
*
* - Name: Policy name (required).
* - Revision: Revision name (policy version).
* - Status: Policy version status - 'draft', 'active' or 'archived'. Defaults to 'active'.
* - Audience: Target users - 'guest', 'all' or 'loggedin'. Default to 'all'.
* - Type: 0 - site policy, 1 - privacy policy, 2 - third party policy, 99 - other.
* - Summary: Policy summary text.
* - Content: Policy full text.
*
* @param TableNode $data
*/
public function the_following_policies_exist(TableNode $data) {
@ -51,12 +61,12 @@ class behat_tool_policy extends behat_base {
}
$fields = [
'name', // Policy name (required).
'revision', // Revision name.
'policy', // Any policy identifier, can be used to generate multiple versions of the same policy.
'status', // Version status: 'draft', 'active', 'archived'. By default 'active'.
'audience', // Audience: 'guest', 'all', 'loggedin' (by default 'all').
'type', // 0 (default) - Site policy, 1 - Privacy policy, 2 - Third party policy, 99 - Other .
'name',
'revision',
'policy',
'status',
'audience',
'type',
'content',
'summary',
];

View File

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2018032900; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2018032900; // Requires this Moodle version
$plugin->component = 'tool_policy'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2018032900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2018032900; // Requires this Moodle version.
$plugin->component = 'tool_policy'; // Full name of the plugin (used for diagnostics).