#88 Make plugins DB codechecker happy

This commit is contained in:
Mark Nelson 2017-02-16 20:12:19 +08:00
parent db879187bf
commit fdc5bde3d4
54 changed files with 760 additions and 395 deletions

40
.travis.yml Normal file
View file

@ -0,0 +1,40 @@
language: php
sudo: false
cache:
directories:
- $HOME/.composer/cache
php:
- 5.6
- 7.0
env:
global:
- MOODLE_BRANCH=MOODLE_32_STABLE
matrix:
- DB=pgsql
- DB=mysqli
before_install:
- phpenv config-rm xdebug.ini
- cd ../..
- composer selfupdate
- composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^1
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
install:
- moodle-plugin-ci install
script:
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
- moodle-plugin-ci codechecker
- moodle-plugin-ci csslint
- moodle-plugin-ci shifter
- moodle-plugin-ci jshint
- moodle-plugin-ci validate
- moodle-plugin-ci phpunit
- moodle-plugin-ci behat

View file

@ -22,12 +22,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
if (!defined('AJAX_SCRIPT')) {
define('AJAX_SCRIPT', true);
}
require_once(__DIR__ . '/../../config.php');
$tid = required_param('tid', PARAM_INT);
$values = required_param('values', PARAM_RAW);
$values = json_decode($values);

View file

@ -1 +1 @@
define(["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,e,f,g,h){var i=function(b){this._node=a(b),this._setEvents()};return i.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0,i.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1,i.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2,i.prototype.PIXELSINMM=3.779527559055,i.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))},i.prototype._editElement=function(a){var g=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid"),i={elementid:g};c.loadFragment("mod_customcert","editelement",h,i).done(function(a,c){f.get_string("editelement","mod_customcert").done(function(e){b.use("moodle-core-formchangechecker",function(){new d(e,"<div id='elementcontent'></div>",this._editElementDialogueConfig.bind(this,g,a,c),(void 0),(!0))}.bind(this))}.bind(this))}.bind(this)).fail(e.exception)},i.prototype._editElementDialogueConfig=function(b,c,d,e){g.replaceNode("#elementcontent",c,d),this._setPositionInForm(b);var f=a(e.getContent());f.on("click","#id_submitbutton",function(c){M.core_formchangechecker.reset_form_dirty_state(),this._saveElement(b).then(function(){this._getElementHTML(b).done(function(c){var d=this._node.find("#element-"+b),f=parseInt(a("#id_refpoint").val()),g="";f==this.CUSTOMCERT_REF_POINT_TOPLEFT?g="refpoint-left":f==this.CUSTOMCERT_REF_POINT_TOPCENTER?g="refpoint-center":f==this.CUSTOMCERT_REF_POINT_TOPRIGHT&&(g="refpoint-right"),d.empty().append(c),d.removeClass(),d.addClass("element "+g),d.attr("data-refpoint",f);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,f,h,i),e.close()}.bind(this))}.bind(this)),c.preventDefault()}.bind(this)),f.on("click","#id_cancel",function(a){e.close(),a.preventDefault()}.bind(this))},i.prototype._setPosition=function(a,c,d,e){var f=b.one("#element-"+a);d=b.one("#pdf").getX()+d*this.PIXELSINMM,e=b.one("#pdf").getY()+e*this.PIXELSINMM;var g=parseFloat(f.getComputedStyle("width")),h=f.width*this.PIXELSINMM;switch(h&&g>h&&(g=h),c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=g/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-g+2}f.setX(d),f.setY(e)},i.prototype._setPositionInForm=function(c){var d=a("#editelementform #id_posx"),e=a("#editelementform #id_posy");if(d.length&&e.length){var f=b.one("#element-"+c),g=f.getX()-b.one("#pdf").getX(),h=f.getY()-b.one("#pdf").getY(),i=parseInt(f.getData("refpoint")),j=parseFloat(f.getComputedStyle("width"));switch(i){case this.CUSTOMCERT_REF_POINT_TOPCENTER:g+=j/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:g+=j}g=Math.round(parseFloat(g/this.PIXELSINMM)),h=Math.round(parseFloat(h/this.PIXELSINMM)),d.val(g),e.val(h)}},i.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=h.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]},i.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=h.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]},{init:function(a){new i(a)}}});
define(["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,e,f,g,h){var i=function(b){this._node=a(b),this._setEvents()};return i.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0,i.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1,i.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2,i.prototype.PIXELSINMM=3.779527559055,i.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))},i.prototype._editElement=function(a){var g=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid"),i={elementid:g};c.loadFragment("mod_customcert","editelement",h,i).done(function(a,c){f.get_string("editelement","mod_customcert").done(function(e){b.use("moodle-core-formchangechecker",function(){new d(e,"<div id='elementcontent'></div>",this._editElementDialogueConfig.bind(this,g,a,c),(void 0),(!0))}.bind(this))}.bind(this))}.bind(this)).fail(e.exception)},i.prototype._editElementDialogueConfig=function(b,c,d,e){g.replaceNode("#elementcontent",c,d),this._setPositionInForm(b);var f=a(e.getContent());f.on("click","#id_submitbutton",function(c){M.core_formchangechecker.reset_form_dirty_state(),this._saveElement(b).then(function(){this._getElementHTML(b).done(function(c){var d=this._node.find("#element-"+b),f=parseInt(a("#id_refpoint").val()),g="";f==this.CUSTOMCERT_REF_POINT_TOPLEFT?g="refpoint-left":f==this.CUSTOMCERT_REF_POINT_TOPCENTER?g="refpoint-center":f==this.CUSTOMCERT_REF_POINT_TOPRIGHT&&(g="refpoint-right"),d.empty().append(c),d.removeClass(),d.addClass("element "+g),d.attr("data-refpoint",f);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,f,h,i),e.close()}.bind(this))}.bind(this)),c.preventDefault()}.bind(this)),f.on("click","#id_cancel",function(a){e.close(),a.preventDefault()})},i.prototype._setPosition=function(a,c,d,e){var f=b.one("#element-"+a);d=b.one("#pdf").getX()+d*this.PIXELSINMM,e=b.one("#pdf").getY()+e*this.PIXELSINMM;var g=parseFloat(f.getComputedStyle("width")),h=f.width*this.PIXELSINMM;switch(h&&g>h&&(g=h),c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=g/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-g+2}f.setX(d),f.setY(e)},i.prototype._setPositionInForm=function(c){var d=a("#editelementform #id_posx"),e=a("#editelementform #id_posy");if(d.length&&e.length){var f=b.one("#element-"+c),g=f.getX()-b.one("#pdf").getX(),h=f.getY()-b.one("#pdf").getY(),i=parseInt(f.getData("refpoint")),j=parseFloat(f.getComputedStyle("width"));switch(i){case this.CUSTOMCERT_REF_POINT_TOPCENTER:g+=j/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:g+=j}g=Math.round(parseFloat(g/this.PIXELSINMM)),h=Math.round(parseFloat(h/this.PIXELSINMM)),d.val(g),e.val(h)}},i.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=h.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]},i.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=h.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]},{init:function(a){new i(a)}}});

View file

@ -42,7 +42,7 @@ define(['core/yui'], function(Y) {
wide = false;
}
Y.use('moodle-core-notification', 'timers', function () {
Y.use('moodle-core-notification', 'timers', function() {
var width = '480px';
if (wide) {
width = '800px';
@ -91,10 +91,12 @@ define(['core/yui'], function(Y) {
/**
* Get content.
*
* @returns {HTMLElement}
*/
dialogue.prototype.getContent = function() {
return this.yuiDialogue.bodyNode.getDOMNode();
};
return /** @alias module:mod_customcert/dialogue */ dialogue;
return dialogue;
});

View file

@ -48,12 +48,12 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
var elementid = event.currentTarget.id.substr(8);
var contextid = this._node.attr('data-contextid');
var params = {
'elementid' : elementid
'elementid': elementid
};
fragment.loadFragment('mod_customcert', 'editelement', contextid, params).done(function(html, js) {
str.get_string('editelement', 'mod_customcert').done(function(title) {
Y.use('moodle-core-formchangechecker', function () {
Y.use('moodle-core-formchangechecker', function() {
new Dialogue(
title,
'<div id=\'elementcontent\'></div>',
@ -112,7 +112,7 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
body.on('click', '#id_cancel', function(e) {
popup.close();
e.preventDefault();
}.bind(this));
});
};
RearrangeArea.prototype._setPosition = function(elementid, refpoint, posx, posy) {
@ -176,8 +176,8 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
var promises = ajax.call([{
methodname: 'mod_customcert_get_element_html',
args: {
templateid : templateid,
elementid : elementid
templateid: templateid,
elementid: elementid
}
}]);
@ -194,9 +194,9 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
var promises = ajax.call([{
methodname: 'mod_customcert_save_element',
args: {
templateid : templateid,
elementid : elementid,
values : inputs
templateid: templateid,
elementid: elementid,
values: inputs
}
}]);
@ -205,8 +205,9 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
};
return {
init : function(selector) {
init: function(selector) {
new RearrangeArea(selector);
}
};
});
}
);

View file

@ -15,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the backup tasks that provides all the settings and steps to perform
* one complete backup of the activity.
* This file contains the backup tasks that provides all the settings and steps to perform a backup of the activity.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
@ -29,6 +28,10 @@ require_once($CFG->dirroot . '/mod/customcert/backup/moodle2/backup_customcert_s
/**
* Handles creating tasks to peform in order to create the backup.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_customcert_activity_task extends backup_activity_task {
@ -49,6 +52,9 @@ class backup_customcert_activity_task extends backup_activity_task {
/**
* Code the transformations to perform in the activity in order to get transportable (encoded) links.
*
* @param string $content
* @return mixed|string
*/
static public function encode_content_links($content) {
global $CFG;
@ -56,11 +62,11 @@ class backup_customcert_activity_task extends backup_activity_task {
$base = preg_quote($CFG->wwwroot, "/");
// Link to the list of customcerts.
$search ="/(".$base."\/mod\/customcert\/index.php\?id\=)([0-9]+)/";
$search = "/(".$base."\/mod\/customcert\/index.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@customcertINDEX*$2@$', $content);
// Link to customcert view by moduleid.
$search ="/(".$base."\/mod\/customcert\/view.php\?id\=)([0-9]+)/";
$search = "/(".$base."\/mod\/customcert\/view.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@customcertVIEWBYID*$2@$', $content);
return $content;

View file

@ -26,6 +26,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
/**
* Define the complete customcert structure for backup, with file and id annotations.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_customcert_activity_structure_step extends backup_activity_structure_step {

View file

@ -27,8 +27,11 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot . '/mod/customcert/backup/moodle2/restore_customcert_stepslib.php');
/**
* The class definition for assigning restore tasks that provides all the settings and steps
* to perform one complete restore of the activity.
* The class definition for assigning tasks that provide the settings and steps to perform a restore of the activity.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_customcert_activity_task extends restore_activity_task {

View file

@ -26,6 +26,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
/**
* Define the complete customcert structure for restore, with file and id annotations.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_customcert_activity_structure_step extends restore_activity_structure_step {

View file

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_customcert;
/**
* Creates an upload form on the settings page.
*
@ -23,10 +21,19 @@ namespace mod_customcert;
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_customcert;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/adminlib.php');
/**
* Class extends admin setting class to allow/process an uploaded file
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_link extends \admin_setting_configtext {
@ -40,6 +47,18 @@ class admin_setting_link extends \admin_setting_configtext {
*/
protected $linkname;
/**
* The admin_setting_link constructor.
*
* @param string $name
* @param string $visiblename
* @param string $description
* @param string $linkname
* @param mixed|string $link
* @param int|null $defaultsetting
* @param string $paramtype
* @param null $size
*/
public function __construct($name, $visiblename, $description, $linkname, $link, $defaultsetting,
$paramtype = PARAM_RAW, $size=null) {
$this->link = $link;

View file

@ -30,6 +30,10 @@ defined('MOODLE_INTERNAL') || die();
* Class certificate.
*
* Helper functionality for certificates.
*
* @package mod_customcert
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class certificate {
@ -202,7 +206,7 @@ class certificate {
if ($logs = $DB->get_recordset_sql($sql, $params)) {
foreach ($logs as $log) {
if (!isset($login)) {
// For the first time $login is not set so the first log is also the first login
// For the first time $login is not set so the first log is also the first login.
$login = $log->$timefield;
$lasthit = $log->$timefield;
$totaltime = 0;
@ -215,7 +219,7 @@ class certificate {
} else {
$totaltime += $delay;
}
// Now the actual log became the previous log for the next cycle
// Now the actual log became the previous log for the next cycle.
$lasthit = $log->$timefield;
}

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the form for handling editing a customcert element.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_customcert;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the form for handling the layout of the customcert instance.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_customcert;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
@ -34,12 +42,12 @@ require_once($CFG->dirroot . '/mod/customcert/includes/colourpicker.php');
class edit_form extends \moodleform {
/**
* The id of the template being used.
* @var int The id of the template being used.
*/
protected $tid = null;
/**
* The total number of pages for this cert.
* @var int The total number of pages for this cert.
*/
protected $numpages = 1;
@ -123,8 +131,8 @@ class edit_form extends \moodleform {
/**
* Some basic validation.
*
* @param $data
* @param $files
* @param array $data
* @param array $files
* @return array the errors that were found
*/
public function validation($data, $files) {
@ -285,7 +293,8 @@ class edit_form extends \moodleform {
if ($this->numpages > 1) {
// Link to delete the element.
$deletelink = new \moodle_url($editlink, $editlinkparams + array('action' => 'deletepage', 'aid' => $page->id));
$deletelink = \html_writer::tag('a', get_string('deletecertpage', 'customcert'), array('href' => $deletelink->out(false), 'class' => 'deletebutton'));
$deletelink = \html_writer::tag('a', get_string('deletecertpage', 'customcert'),
array('href' => $deletelink->out(false), 'class' => 'deletebutton'));
$mform->addElement('html', \html_writer::tag('div', $deletelink, array('class' => 'deletebutton')));
}
}

View file

@ -30,6 +30,10 @@ defined('MOODLE_INTERNAL') || die();
* Class element
*
* All customercert element plugins are based on this class.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class element {
@ -216,7 +220,9 @@ abstract class element {
*
* @param \restore_customcert_activity_task $restore
*/
public function after_restore($restore) { }
public function after_restore($restore) {
}
/**
* Magic getter for read only access.

View file

@ -15,12 +15,12 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides useful functions related to elements.
*
* @package mod_customcert
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* Provides useful functions related to elements.
*
* @package mod_customcert
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_customcert;
@ -30,6 +30,10 @@ defined('MOODLE_INTERNAL') || die();
* Class helper.
*
* Provides useful functions related to elements.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class element_helper {
@ -56,7 +60,7 @@ class element_helper {
* @param string $content the content to render
*/
public static function render_content($pdf, $element, $content) {
list($font, $attr) = \mod_customcert\element_helper::get_font($element);
list($font, $attr) = self::get_font($element);
$pdf->setFont($font, $attr, $element->size);
$fontcolour = \TCPDF_COLORS::convertHTMLColorToDec($element->colour, $fontcolour);
$pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']);
@ -107,7 +111,7 @@ class element_helper {
* @return string the html
*/
public static function render_html_content($element, $content) {
list($font, $attr) = \mod_customcert\element_helper::get_font($element);
list($font, $attr) = self::get_font($element);
$fontstyle = 'font-family: ' . $font;
if (strpos($attr, 'B') !== false) {
$fontstyle .= ': font-weight: bold';
@ -196,7 +200,7 @@ class element_helper {
public static function validate_form_element_colour($data) {
$errors = array();
// Validate the colour.
if (!\mod_customcert\element_helper::validate_colour($data['colour'])) {
if (!self::validate_colour($data['colour'])) {
$errors['colour'] = get_string('invalidcolour', 'customcert');
}
return $errors;

View file

@ -34,6 +34,10 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_viewed extends \core\event\course_module_viewed {
/**
* Initialises the event.
*/
protected function init() {
$this->data['objecttable'] = 'customcert';
parent::init();

View file

@ -27,11 +27,11 @@ defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/externallib.php");
/**
* This is the external API for this tool.
*
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* This is the external API for this tool.
*
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class external extends \external_api {
/**

View file

@ -14,13 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the form for loading customcert templates.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_customcert;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->libdir . '/formslib.php');
/**
* The form for loading customcert templates.
*

View file

@ -77,6 +77,12 @@ class verify_certificate_result implements templatable, renderable {
$this->certificatename = $result->certificatename;
}
/**
* Function to export the renderer data in a format that is suitable for a mustache template.
*
* @param \renderer_base $output Used to do a final render of any components that need to be rendered for export.
* @return \stdClass|array
*/
public function export_for_template(\renderer_base $output) {
$result = new \stdClass();
$result->userprofileurl = $this->userprofileurl;

View file

@ -68,6 +68,12 @@ class verify_certificate_results implements templatable, renderable {
$this->issues = $result->issues;
}
/**
* Function to export the renderer data in a format that is suitable for a mustache template.
*
* @param \renderer_base $output Used to do a final render of any components that need to be rendered for export.
* @return \stdClass|array
*/
public function export_for_template(\renderer_base $output) {
$result = new \stdClass();
$result->success = $this->success;

View file

@ -30,6 +30,10 @@ defined('MOODLE_INTERNAL') || die();
* Class helper.
*
* Provides useful functions.
*
* @package mod_customcert
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_helper {

View file

@ -27,6 +27,13 @@ use core\plugininfo\base;
defined('MOODLE_INTERNAL') || die();
/**
* Subplugin info class.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class customcertelement extends base {
/**

View file

@ -17,6 +17,7 @@
/**
* Class represents a customcert template.
*
* @package mod_customcert
* @copyright 2015 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -28,6 +29,7 @@ defined('MOODLE_INTERNAL') || die();
/**
* Class represents a customcert template.
*
* @package mod_customcert
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -70,7 +72,7 @@ class template {
$savedata = new \stdClass();
$savedata->id = $this->id;
$savedata->name = $data->name;
$savedata->timemodified= time();
$savedata->timemodified = time();
$DB->update_record('customcert_templates', $savedata);
}

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the class that handles uploading files.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_customcert;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
@ -21,7 +29,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->libdir.'/formslib.php');
/**
* Handles uploading files
* Handles uploading files.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
@ -43,7 +51,8 @@ class upload_image_form extends \moodleform {
'maxbytes' => $CFG->maxbytes,
'subdirs' => 1,
'accepted_types' => 'image');
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $this->filemanageroptions);
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '',
$this->filemanageroptions);
$this->add_action_buttons();
}
@ -56,7 +65,8 @@ class upload_image_form extends \moodleform {
// Editing existing instance - copy existing files into draft area.
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
file_prepare_draft_area($draftitemid, \context_system::instance()->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
file_prepare_draft_area($draftitemid, \context_system::instance()->id, 'mod_customcert', 'image', 0,
$this->filemanageroptions);
$element = $mform->getElement('customcertimage');
$element->setValue($draftitemid);
}

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This files contains the form for verifying a certificate.
*
* @package mod_customcert
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_customcert;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
@ -21,7 +29,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->libdir . '/formslib.php');
/**
* The form for verifying a certificate
* The form for verifying a certificate.
*
* @package mod_customcert
* @copyright 2017 Mark Nelson <markn@moodle.com>

View file

@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$functions = array(
'mod_customcert_save_element' => array(
'classname' => 'mod_customcert\external',

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element background image's core interaction API.
*
* @package customcertelement_bgimage
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_bgimage;
defined('MOODLE_INTERNAL') || die();
@ -34,7 +42,8 @@ class element extends \customcertelement_image\element {
*/
public function render_form_elements($mform) {
$mform->addElement('select', 'image', get_string('image', 'customcertelement_image'), self::get_images());
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $this->filemanageroptions);
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '',
$this->filemanageroptions);
}
/**

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element border's core interaction API.
*
* @package customcertelement_border
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_border;
defined('MOODLE_INTERNAL') || die();

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element categoryname's core interaction API.
*
* @package customcertelement_categoryname
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_categoryname;
defined('MOODLE_INTERNAL') || die();

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element code's core interaction API.
*
* @package customcertelement_code
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_code;
defined('MOODLE_INTERNAL') || die();
@ -45,7 +53,8 @@ class element extends \mod_customcert\element {
// Get the customcert this page belongs to.
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
// Now we can get the issue for this user.
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id), '*', MUST_EXIST);
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id),
'*', MUST_EXIST);
$code = $issue->code;
}

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element coursename's core interaction API.
*
* @package customcertelement_coursename
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_coursename;
defined('MOODLE_INTERNAL') || die();

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element date's core interaction API.
*
* @package customcertelement_date
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_date;
defined('MOODLE_INTERNAL') || die();
@ -107,7 +115,8 @@ class element extends \mod_customcert\element {
// Get the customcert this page belongs to.
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
// Now we can get the issue for this user.
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id), '*', MUST_EXIST);
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id),
'*', MUST_EXIST);
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
$date = $issue->timecreated;

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element grade's core interaction API.
*
* @package customcertelement_grade
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_grade;
defined('MOODLE_INTERNAL') || die();
@ -53,7 +61,8 @@ class element extends \mod_customcert\element {
$mform->addHelpButton('gradeitem', 'gradeitem', 'customcertelement_grade');
// The grade format.
$mform->addElement('select', 'gradeformat', get_string('gradeformat', 'customcertelement_grade'), self::get_grade_format_options());
$mform->addElement('select', 'gradeformat', get_string('gradeformat', 'customcertelement_grade'),
self::get_grade_format_options());
$mform->setType('gradeformat', PARAM_INT);
$mform->addHelpButton('gradeformat', 'gradeformat', 'customcertelement_grade');

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element gradeitemname's core interaction API.
*
* @package customcertelement_gradeitemname
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_gradeitemname;
defined('MOODLE_INTERNAL') || die();

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element image's core interaction API.
*
* @package customcertelement_image
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_image;
defined('MOODLE_INTERNAL') || die();
@ -27,6 +35,9 @@ defined('MOODLE_INTERNAL') || die();
*/
class element extends \mod_customcert\element {
/**
* @var array The file manager options.
*/
protected $filemanageroptions = array();
/**
@ -68,7 +79,8 @@ class element extends \mod_customcert\element {
\mod_customcert\element_helper::render_form_element_position($mform);
}
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $this->filemanageroptions);
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '',
$this->filemanageroptions);
}
/**
@ -237,7 +249,6 @@ class element extends \mod_customcert\element {
$context = \context_course::instance($COURSE->id);
}
// Editing existing instance - copy existing files into draft area.
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
file_prepare_draft_area($draftitemid, $context->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
@ -267,7 +278,8 @@ class element extends \mod_customcert\element {
}
}
// Loop through the files uploaded in the course context.
if ($files = $fs->get_area_files(\context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', false, 'filename', false)) {
if ($files = $fs->get_area_files(\context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', false,
'filename', false)) {
foreach ($files as $hash => $file) {
$arrfiles[$hash] = $file->get_filename();
}

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element studentname's core interaction API.
*
* @package customcertelement_studentname
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_studentname;
defined('MOODLE_INTERNAL') || die();

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element teachername's core interaction API.
*
* @package customcertelement_teachername
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_teachername;
defined('MOODLE_INTERNAL') || die();

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element text's core interaction API.
*
* @package customcertelement_text
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_text;
defined('MOODLE_INTERNAL') || die();

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element userfield's core interaction API.
*
* @package customcertelement_userfield
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_userfield;
defined('MOODLE_INTERNAL') || die();

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the customcert element userpicture's core interaction API.
*
* @package customcertelement_userpicture
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace customcertelement_userpicture;
defined('MOODLE_INTERNAL') || die();
@ -165,7 +173,8 @@ class element extends \mod_customcert\element {
// The size of the images to use in the CSS style.
$style = '';
if ($imageinfo->width === 0 && $imageinfo->height === 0) {
// Do nothing.
// Put this in so code checker doesn't complain.
$style .= '';
} else if ($imageinfo->width === 0) { // Then the height must be set.
$style .= 'width: ' . $imageinfo->height . 'mm; ';
$style .= 'height: ' . $imageinfo->height . 'mm';

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the form element for handling the colour picker.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot . '/lib/form/editor.php');
@ -25,41 +33,21 @@ require_once($CFG->dirroot . '/lib/form/editor.php');
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_customcert_colourpicker extends MoodleQuickForm_editor {
/**
* Constructor for the colour picker.
*
* @param string $elementName
* @param string $elementLabel
* @param array $attributes
*/
public function __construct($elementName = null, $elementLabel = null, $attributes = null) {
parent::__construct($elementName, $elementLabel, $attributes);
}
/**
* Old school constructor name to support earlier versions of Moodle.
*
* @param string $elementName
* @param string $elementLabel
* @param array $attributes
*/
public function MoodleQuickForm_customcert_colourpicker($elementName = null, $elementLabel = null, $attributes = null) {
self::__construct($elementName, $elementLabel, $attributes);
}
class moodlequickform_customcert_colourpicker extends moodlequickform_editor {
/**
* Sets the value of the form element
*
* @param string $value
*/
public function setValue($value) {
public function setvalue($value) {
$this->updateAttributes(array('value' => $value));
}
/**
* Gets the value of the form element
*/
public function getValue() {
public function getvalue() {
return $this->getAttribute('value');
}
@ -68,7 +56,7 @@ class MoodleQuickForm_customcert_colourpicker extends MoodleQuickForm_editor {
*
* @return string
*/
public function toHtml() {
public function tohtml() {
global $PAGE, $OUTPUT;
$PAGE->requires->js_init_call('M.util.init_colour_picker', array($this->getAttribute('id'), null));
@ -83,6 +71,12 @@ class MoodleQuickForm_customcert_colourpicker extends MoodleQuickForm_editor {
return $content;
}
/**
* Function to export the renderer data in a format that is suitable for a mustache template.
*
* @param \renderer_base $output Used to do a final render of any components that need to be rendered for export.
* @return \stdClass|array
*/
public function export_for_template(renderer_base $output) {
$context = $this->export_for_template_base($output);
$context['html'] = $this->toHtml();

View file

@ -40,7 +40,7 @@ $pageurl = new moodle_url('/mod/customcert/index.php', array('id' => $course->id
$PAGE->set_pagelayout('incourse');
$PAGE->navbar->add(get_string('modulenameplural', 'customcert'));
// Add the page view to the Moodle log
// Add the page view to the Moodle log.
$event = \mod_customcert\event\course_module_instance_list_viewed::create(array(
'context' => context_course::instance($course->id)
));
@ -72,8 +72,8 @@ foreach ($customcerts as $customcert) {
$link = html_writer::tag('a', $customcert->name, array('href' => new moodle_url('/mod/customcert/view.php',
array('id' => $customcert->coursemodule))));
} else {
$link = html_writer::tag('a', $customcert->name, array('class' => 'dimmed', 'href' =>
new moodle_url('/mod/customcert/view.php', array('id' => $customcert->coursemodule))));
$link = html_writer::tag('a', $customcert->name, array('class' => 'dimmed',
'href' => new moodle_url('/mod/customcert/view.php', array('id' => $customcert->coursemodule))));
}
// If we are at a different section then print a horizontal rule.
if ($customcert->section !== $currentsection) {

View file

@ -249,6 +249,8 @@ function customcert_pluginfile($course, $cm, $context, $filearea, $args, $forced
}
/**
* The features this activity supports.
*
* @uses FEATURE_GROUPS
* @uses FEATURE_GROUPINGS
* @uses FEATURE_GROUPMEMBERSONLY
@ -380,9 +382,9 @@ function mod_customcert_myprofile_navigation(core_user\output\myprofile\tree $tr
/**
* Handles editing the 'name' of the element in a list.
*
* @param $itemtype
* @param $itemid
* @param $newvalue
* @param string $itemtype
* @param int $itemid
* @param string $newvalue
* @return \core\output\inplace_editable
*/
function mod_customcert_inplace_editable($itemtype, $itemid, $newvalue) {

View file

@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the instance add/edit form.
*
* @package mod_customcert
* @copyright 2013 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot.'/course/moodleform_mod.php');
@ -53,7 +61,8 @@ class mod_customcert_mod_form extends moodleform_mod {
$mform->setType('requiredtime', PARAM_INT);
$mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert');
$mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'), get_string('print', 'customcert'));
$mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'),
get_string('print', 'customcert'));
$mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'customcert'));
$mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'customcert'));
$mform->addHelpButton('protection_print', 'setprotection', 'customcert');

View file

@ -60,7 +60,7 @@ $PAGE->navbar->add($str, new \action_link($link, $str));
$PAGE->navbar->add(get_string('rearrangeelements', 'customcert'));
// Include the JS we need.
$PAGE->requires->yui_module('moodle-mod_customcert-rearrange', 'M.mod_customcert.rearrange.init',
$PAGE->requires->yui_module('moodle-mod_customcert-rearrange', 'Y.M.mod_customcert.rearrange.init',
array($template->get_id(),
$page,
$elements));

View file

@ -24,13 +24,13 @@
}
#page-mod-customcert-rearrange .element:before {
content: "";
display: block;
background-image: url([[pix:mod_customcert|target]]);
background-repeat: no-repeat;
width: 100%;
height: 9px;
content: "";
display: block;
float: left;
height: 9px;
width: 100%;
}
#page-mod-customcert-rearrange .element:hover {
@ -53,9 +53,9 @@
}
#page-mod-customcert-rearrange #pdf {
clear: both;
border-style: solid;
border-width: 1px;
clear: both;
}
#page-mod-customcert-rearrange div#leftmargin {

View file

@ -1,3 +1,46 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template mod_customcert/verify_certificate_result
The certificate verification result
Classes required for JS:
* None
Data attibutes required for JS:
* All data attributes are required
Context variables required for this template:
* userprofileurl The URL to the user's profile
* userfullname The fullname of the user
* courseurl The URL of the course
* coursefullname The full name of the course
* certificatename The name of the certificate
Example context (json):
{
"userprofileurl": "http://www.example.com",
"userfullname": "Mark Smith",
"courseurl": "http://www.example.com",
"coursefullname": "Computing 101",
"certificatename": "Ability to write 'Hello world' in Java."
}
}}
<ul class="list-unstyled unstyled">
<li><strong>Fullname:</strong> <a href="{{{userprofileurl}}}">{{userfullname}}</a></li>
<li><strong>Course:</strong> <a href="{{{courseurl}}}">{{coursefullname}}</a></li>

View file

@ -1,3 +1,37 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template mod_customcert/verify_certificate_results
The certificate verification results page
Classes required for JS:
* None
Data attibutes required for JS:
* All data attributes are required
Context variables required for this template:
* None
Example context (json):
{
}
}}
{{#success}}
{{#issues}}
{{> mod_customcert/verify_certificate_result }}

View file

@ -3,7 +3,7 @@ YUI.add('moodle-mod_customcert-rearrange', function (Y, NAME) {
/**
* Rearrange elements in the custom certificate
*
* @class M.mod_customcert.rearrange.rearrange
* @class Y.M.mod_customcert.rearrange
* @constructor
*/
var Rearrange = function() {
@ -14,64 +14,64 @@ Y.extend(Rearrange, Y.Base, {
/**
* The template id.
*/
templateid : 0,
templateid: 0,
/**
* The customcert page we are displaying.
*/
page : [],
page: [],
/**
* The custom certificate elements to display.
*/
elements : [],
elements: [],
/**
* Store the X coordinates of the top left of the pdf div.
*/
pdfx : 0,
pdfx: 0,
/**
* Store the Y coordinates of the top left of the pdf div.
*/
pdfy : 0,
pdfy: 0,
/**
* Store the width of the pdf div.
*/
pdfwidth : 0,
pdfwidth: 0,
/**
* Store the height of the pdf div.
*/
pdfheight : 0,
pdfheight: 0,
/**
* Store the location of the element before we move.
*/
elementxy : 0,
elementxy: 0,
/**
* Store the left boundary of the pdf div.
*/
pdfleftboundary : 0,
pdfleftboundary: 0,
/**
* Store the right boundary of the pdf div.
*/
pdfrightboundary : 0,
pdfrightboundary: 0,
/**
* The number of pixels in a mm.
*/
pixelsinmm : 3.779527559055, // '3.779528'.
pixelsinmm: 3.779527559055, // 3.779528.
/**
* Initialise.
*
* @param params
* @param {Array} params
*/
initializer : function(params) {
initializer: function(params) {
// Set the course module id.
this.templateid = params[0];
// Set the page.
@ -96,14 +96,14 @@ Y.extend(Rearrange, Y.Base, {
this.pdfrightboundary -= parseInt(this.page.rightmargin * this.pixelsinmm, 10);
}
this.set_positions();
this.create_events();
this.setpositions();
this.createevents();
},
/**
* Sets the current position of the elements.
*/
set_positions : function() {
setpositions: function() {
// Go through the elements and set their positions.
for (var key in this.elements) {
var element = this.elements[key];
@ -117,10 +117,10 @@ Y.extend(Rearrange, Y.Base, {
}
switch (element.refpoint) {
case '1': // Top-center
case '1': // Top-center.
posx -= nodewidth / 2;
break;
case '2': // Top-right
case '2': // Top-right.
posx = posx - nodewidth + 2;
break;
}
@ -133,15 +133,15 @@ Y.extend(Rearrange, Y.Base, {
/**
* Creates the JS events for changing element positions.
*/
create_events : function() {
createevents: function() {
// Trigger a save event when save button is pushed.
Y.one('.savepositionsbtn [type=submit]').on('click', function(e) {
this.save_positions(e);
this.savepositions(e);
}, this);
// Trigger a save event when apply button is pushed.
Y.one('.applypositionsbtn [type=submit]').on('click', function(e) {
this.save_positions(e);
this.savepositions(e);
e.preventDefault();
}, this);
@ -161,7 +161,7 @@ Y.extend(Rearrange, Y.Base, {
// if not, set it back to where it was.
del.on('drag:end', function() {
var node = del.get('currentNode');
if (this.is_out_of_bounds(node)) {
if (this.isoutofbounds(node)) {
node.setXY(this.elementxy);
}
}, this);
@ -170,10 +170,10 @@ Y.extend(Rearrange, Y.Base, {
/**
* Returns true if any part of the element is placed outside of the PDF div, false otherwise.
*
* @param node
* @param {Node} node
* @returns {boolean}
*/
is_out_of_bounds : function(node) {
isoutofbounds: function(node) {
// Get the width and height of the node.
var nodewidth = parseFloat(node.getComputedStyle('width'));
var nodeheight = parseFloat(node.getComputedStyle('height'));
@ -200,9 +200,9 @@ Y.extend(Rearrange, Y.Base, {
/**
* Perform an AJAX call and save the positions of the elements.
*
* @param e
* @param {Event} e
*/
save_positions : function(e) {
savepositions: function(e) {
// The parameters to send the AJAX call.
var params = {
tid: this.templateid,
@ -222,10 +222,10 @@ Y.extend(Rearrange, Y.Base, {
var nodewidth = parseFloat(node.getComputedStyle('width'));
switch (refpoint) {
case '1': // Top-center
case '1': // Top-center.
posx += nodewidth / 2;
break;
case '2': // Top-right
case '2': // Top-right.
posx += nodewidth;
break;
}
@ -246,18 +246,18 @@ Y.extend(Rearrange, Y.Base, {
data: params,
on: {
failure: function(tid, response) {
this.ajax_failure(response);
this.ajaxfailure(response);
},
success: function() {
var formNode = e.currentTarget.ancestor('form', true);
var baseUrl = formNode.getAttribute('action');
var pageinput = formNode.one('[name=pid]');
var formnode = e.currentTarget.ancestor('form', true);
var baseurl = formnode.getAttribute('action');
var pageinput = formnode.one('[name=pid]');
if (pageinput) {
var pageid = pageinput.get('value');
window.location = baseUrl + '?pid=' + pageid;
window.location = baseurl + '?pid=' + pageid;
} else {
var templateid = formNode.one('[name=tid]').get('value');
window.location = baseUrl + '?tid=' + templateid;
var templateid = formnode.one('[name=tid]').get('value');
window.location = baseurl + '?tid=' + templateid;
}
}
},
@ -270,10 +270,10 @@ Y.extend(Rearrange, Y.Base, {
/**
* Handles any failures during an AJAX call.
*
* @param response
* @param {XMLHttpRequest} response
* @returns {M.core.exception}
*/
ajax_failure : function(response) {
ajaxfailure: function(response) {
var e = {
name: response.status + ' ' + response.statusText,
message: response.responseText
@ -282,10 +282,9 @@ Y.extend(Rearrange, Y.Base, {
}
});
M.mod_customcert = M.mod_customcert || {};
M.mod_customcert.rearrange = M.mod_customcert.rearrange || {};
M.mod_customcert.rearrange.init = function(templateid, page, elements) {
Y.namespace('M.mod_customcert.rearrange').init = function(templateid, page, elements) {
new Rearrange(templateid, page, elements);
};
}, '@VERSION@', {"requires": ["dd-delegate", "dd-drag"]});

View file

@ -1 +1 @@
YUI.add("moodle-mod_customcert-rearrange",function(e,t){var n=function(){n.superclass.constructor.apply(this,[arguments])};e.extend(n,e.Base,{templateid:0,page:[],elements:[],pdfx:0,pdfy:0,pdfwidth:0,pdfheight:0,elementxy:0,pdfleftboundary:0,pdfrightboundary:0,pixelsinmm:3.779527559055,initializer:function(t){this.templateid=t[0],this.page=t[1],this.elements=t[2],this.pdfx=e.one("#pdf").getX(),this.pdfy=e.one("#pdf").getY(),this.pdfwidth=parseFloat(e.one("#pdf").getComputedStyle("width")),this.pdfheight=parseFloat(e.one("#pdf").getComputedStyle("height")),this.pdfleftboundary=this.pdfx,this.page.leftmargin&&(this.pdfleftboundary+=parseInt(this.page.leftmargin*this.pixelsinmm,10)),this.pdfrightboundary=this.pdfx+this.pdfwidth,this.page.rightmargin&&(this.pdfrightboundary-=parseInt(this.page.rightmargin*this.pixelsinmm,10)),this.set_positions(),this.create_events()},set_positions:function(){for(var t in this.elements){var n=this.elements[t],r=this.pdfx+n.posx*this.pixelsinmm,i=this.pdfy+n.posy*this.pixelsinmm,s=parseFloat(e.one("#element-"+n.id).getComputedStyle("width")),o=n.width*this.pixelsinmm;o&&s>o&&(s=o);switch(n.refpoint){case"1":r-=s/2;break;case"2":r=r-s+2}e.one("#element-"+n.id).setX(r),e.one("#element-"+n.id).setY(i)}},create_events:function(){e.one(".savepositionsbtn [type=submit]").on("click",function(e){this.save_positions(e)},this),e.one(".applypositionsbtn [type=submit]").on("click",function(e){this.save_positions(e),e.preventDefault()},this);var t=new e.DD.Delegate({container:"#pdf",nodes:".element"});t.on("drag:start",function(){var e=t.get("currentNode");this.elementxy=e.getXY()},this),t.on("drag:end",function(){var e=t.get("currentNode");this.is_out_of_bounds(e)&&e.setXY(this.elementxy)},this)},is_out_of_bounds:function(e){var t=parseFloat(e.getComputedStyle("width")),n=parseFloat(e.getComputedStyle("height")),r=e.getX(),i=r+t,s=e.getY(),o=s+n;return r<this.pdfleftboundary||i>this.pdfrightboundary?!0:s<this.pdfy||o>this.pdfy+this.pdfheight?!0:!1},save_positions:function(t){var n={tid:this.templateid,values:[]};for(var r in this.elements){var i=this.elements[r],s=e.one("#element-"+i.id),o=s.getX()-this.pdfx,u=s.getY()-this.pdfy,a=s.getData("refpoint"),f=parseFloat(s.getComputedStyle("width"));switch(a){case"1":o+=f/2;break;case"2":o+=f}n.values.push({id:i.id,posx:Math.round(parseFloat(o/this.pixelsinmm)),posy:Math.round(parseFloat(u/this.pixelsinmm))})}n.values=JSON.stringify(n.values),e.io(M.cfg.wwwroot+"/mod/customcert/ajax.php",{method:"POST",data:n,on:{failure:function(e,t){this.ajax_failure(t)},success:function(){var e=t.currentTarget.ancestor("form",!0),n=e.getAttribute("action"),r=e.one("[name=pid]");if(r){var i=r.get("value");window.location=n+"?pid="+i}else{var s=e.one("[name=tid]").get("value");window.location=n+"?tid="+s}}},context:this}),t.preventDefault()},ajax_failure:function(e){var t={name:e.status+" "+e.statusText,message:e.responseText};return new M.core.exception(t)}}),M.mod_customcert=M.mod_customcert||{},M.mod_customcert.rearrange=M.mod_customcert.rearrange||{},M.mod_customcert.rearrange.init=function(e,t,r){new n(e,t,r)}},"@VERSION@",{requires:["dd-delegate","dd-drag"]});
YUI.add("moodle-mod_customcert-rearrange",function(e,t){var n=function(){n.superclass.constructor.apply(this,[arguments])};e.extend(n,e.Base,{templateid:0,page:[],elements:[],pdfx:0,pdfy:0,pdfwidth:0,pdfheight:0,elementxy:0,pdfleftboundary:0,pdfrightboundary:0,pixelsinmm:3.779527559055,initializer:function(t){this.templateid=t[0],this.page=t[1],this.elements=t[2],this.pdfx=e.one("#pdf").getX(),this.pdfy=e.one("#pdf").getY(),this.pdfwidth=parseFloat(e.one("#pdf").getComputedStyle("width")),this.pdfheight=parseFloat(e.one("#pdf").getComputedStyle("height")),this.pdfleftboundary=this.pdfx,this.page.leftmargin&&(this.pdfleftboundary+=parseInt(this.page.leftmargin*this.pixelsinmm,10)),this.pdfrightboundary=this.pdfx+this.pdfwidth,this.page.rightmargin&&(this.pdfrightboundary-=parseInt(this.page.rightmargin*this.pixelsinmm,10)),this.setpositions(),this.createevents()},setpositions:function(){for(var t in this.elements){var n=this.elements[t],r=this.pdfx+n.posx*this.pixelsinmm,i=this.pdfy+n.posy*this.pixelsinmm,s=parseFloat(e.one("#element-"+n.id).getComputedStyle("width")),o=n.width*this.pixelsinmm;o&&s>o&&(s=o);switch(n.refpoint){case"1":r-=s/2;break;case"2":r=r-s+2}e.one("#element-"+n.id).setX(r),e.one("#element-"+n.id).setY(i)}},createevents:function(){e.one(".savepositionsbtn [type=submit]").on("click",function(e){this.savepositions(e)},this),e.one(".applypositionsbtn [type=submit]").on("click",function(e){this.savepositions(e),e.preventDefault()},this);var t=new e.DD.Delegate({container:"#pdf",nodes:".element"});t.on("drag:start",function(){var e=t.get("currentNode");this.elementxy=e.getXY()},this),t.on("drag:end",function(){var e=t.get("currentNode");this.isoutofbounds(e)&&e.setXY(this.elementxy)},this)},isoutofbounds:function(e){var t=parseFloat(e.getComputedStyle("width")),n=parseFloat(e.getComputedStyle("height")),r=e.getX(),i=r+t,s=e.getY(),o=s+n;return r<this.pdfleftboundary||i>this.pdfrightboundary?!0:s<this.pdfy||o>this.pdfy+this.pdfheight?!0:!1},savepositions:function(t){var n={tid:this.templateid,values:[]};for(var r in this.elements){var i=this.elements[r],s=e.one("#element-"+i.id),o=s.getX()-this.pdfx,u=s.getY()-this.pdfy,a=s.getData("refpoint"),f=parseFloat(s.getComputedStyle("width"));switch(a){case"1":o+=f/2;break;case"2":o+=f}n.values.push({id:i.id,posx:Math.round(parseFloat(o/this.pixelsinmm)),posy:Math.round(parseFloat(u/this.pixelsinmm))})}n.values=JSON.stringify(n.values),e.io(M.cfg.wwwroot+"/mod/customcert/ajax.php",{method:"POST",data:n,on:{failure:function(e,t){this.ajaxfailure(t)},success:function(){var e=t.currentTarget.ancestor("form",!0),n=e.getAttribute("action"),r=e.one("[name=pid]");if(r){var i=r.get("value");window.location=n+"?pid="+i}else{var s=e.one("[name=tid]").get("value");window.location=n+"?tid="+s}}},context:this}),t.preventDefault()},ajaxfailure:function(e){var t={name:e.status+" "+e.statusText,message:e.responseText};return new M.core.exception(t)}}),e.namespace("M.mod_customcert.rearrange").init=function(e,t,r){new n(e,t,r)}},"@VERSION@",{requires:["dd-delegate","dd-drag"]});

View file

@ -3,7 +3,7 @@ YUI.add('moodle-mod_customcert-rearrange', function (Y, NAME) {
/**
* Rearrange elements in the custom certificate
*
* @class M.mod_customcert.rearrange.rearrange
* @class Y.M.mod_customcert.rearrange
* @constructor
*/
var Rearrange = function() {
@ -14,64 +14,64 @@ Y.extend(Rearrange, Y.Base, {
/**
* The template id.
*/
templateid : 0,
templateid: 0,
/**
* The customcert page we are displaying.
*/
page : [],
page: [],
/**
* The custom certificate elements to display.
*/
elements : [],
elements: [],
/**
* Store the X coordinates of the top left of the pdf div.
*/
pdfx : 0,
pdfx: 0,
/**
* Store the Y coordinates of the top left of the pdf div.
*/
pdfy : 0,
pdfy: 0,
/**
* Store the width of the pdf div.
*/
pdfwidth : 0,
pdfwidth: 0,
/**
* Store the height of the pdf div.
*/
pdfheight : 0,
pdfheight: 0,
/**
* Store the location of the element before we move.
*/
elementxy : 0,
elementxy: 0,
/**
* Store the left boundary of the pdf div.
*/
pdfleftboundary : 0,
pdfleftboundary: 0,
/**
* Store the right boundary of the pdf div.
*/
pdfrightboundary : 0,
pdfrightboundary: 0,
/**
* The number of pixels in a mm.
*/
pixelsinmm : 3.779527559055, // '3.779528'.
pixelsinmm: 3.779527559055, // 3.779528.
/**
* Initialise.
*
* @param params
* @param {Array} params
*/
initializer : function(params) {
initializer: function(params) {
// Set the course module id.
this.templateid = params[0];
// Set the page.
@ -96,14 +96,14 @@ Y.extend(Rearrange, Y.Base, {
this.pdfrightboundary -= parseInt(this.page.rightmargin * this.pixelsinmm, 10);
}
this.set_positions();
this.create_events();
this.setpositions();
this.createevents();
},
/**
* Sets the current position of the elements.
*/
set_positions : function() {
setpositions: function() {
// Go through the elements and set their positions.
for (var key in this.elements) {
var element = this.elements[key];
@ -117,10 +117,10 @@ Y.extend(Rearrange, Y.Base, {
}
switch (element.refpoint) {
case '1': // Top-center
case '1': // Top-center.
posx -= nodewidth / 2;
break;
case '2': // Top-right
case '2': // Top-right.
posx = posx - nodewidth + 2;
break;
}
@ -133,15 +133,15 @@ Y.extend(Rearrange, Y.Base, {
/**
* Creates the JS events for changing element positions.
*/
create_events : function() {
createevents: function() {
// Trigger a save event when save button is pushed.
Y.one('.savepositionsbtn [type=submit]').on('click', function(e) {
this.save_positions(e);
this.savepositions(e);
}, this);
// Trigger a save event when apply button is pushed.
Y.one('.applypositionsbtn [type=submit]').on('click', function(e) {
this.save_positions(e);
this.savepositions(e);
e.preventDefault();
}, this);
@ -161,7 +161,7 @@ Y.extend(Rearrange, Y.Base, {
// if not, set it back to where it was.
del.on('drag:end', function() {
var node = del.get('currentNode');
if (this.is_out_of_bounds(node)) {
if (this.isoutofbounds(node)) {
node.setXY(this.elementxy);
}
}, this);
@ -170,10 +170,10 @@ Y.extend(Rearrange, Y.Base, {
/**
* Returns true if any part of the element is placed outside of the PDF div, false otherwise.
*
* @param node
* @param {Node} node
* @returns {boolean}
*/
is_out_of_bounds : function(node) {
isoutofbounds: function(node) {
// Get the width and height of the node.
var nodewidth = parseFloat(node.getComputedStyle('width'));
var nodeheight = parseFloat(node.getComputedStyle('height'));
@ -200,9 +200,9 @@ Y.extend(Rearrange, Y.Base, {
/**
* Perform an AJAX call and save the positions of the elements.
*
* @param e
* @param {Event} e
*/
save_positions : function(e) {
savepositions: function(e) {
// The parameters to send the AJAX call.
var params = {
tid: this.templateid,
@ -222,10 +222,10 @@ Y.extend(Rearrange, Y.Base, {
var nodewidth = parseFloat(node.getComputedStyle('width'));
switch (refpoint) {
case '1': // Top-center
case '1': // Top-center.
posx += nodewidth / 2;
break;
case '2': // Top-right
case '2': // Top-right.
posx += nodewidth;
break;
}
@ -246,18 +246,18 @@ Y.extend(Rearrange, Y.Base, {
data: params,
on: {
failure: function(tid, response) {
this.ajax_failure(response);
this.ajaxfailure(response);
},
success: function() {
var formNode = e.currentTarget.ancestor('form', true);
var baseUrl = formNode.getAttribute('action');
var pageinput = formNode.one('[name=pid]');
var formnode = e.currentTarget.ancestor('form', true);
var baseurl = formnode.getAttribute('action');
var pageinput = formnode.one('[name=pid]');
if (pageinput) {
var pageid = pageinput.get('value');
window.location = baseUrl + '?pid=' + pageid;
window.location = baseurl + '?pid=' + pageid;
} else {
var templateid = formNode.one('[name=tid]').get('value');
window.location = baseUrl + '?tid=' + templateid;
var templateid = formnode.one('[name=tid]').get('value');
window.location = baseurl + '?tid=' + templateid;
}
}
},
@ -270,10 +270,10 @@ Y.extend(Rearrange, Y.Base, {
/**
* Handles any failures during an AJAX call.
*
* @param response
* @param {XMLHttpRequest} response
* @returns {M.core.exception}
*/
ajax_failure : function(response) {
ajaxfailure: function(response) {
var e = {
name: response.status + ' ' + response.statusText,
message: response.responseText
@ -282,10 +282,9 @@ Y.extend(Rearrange, Y.Base, {
}
});
M.mod_customcert = M.mod_customcert || {};
M.mod_customcert.rearrange = M.mod_customcert.rearrange || {};
M.mod_customcert.rearrange.init = function(templateid, page, elements) {
Y.namespace('M.mod_customcert.rearrange').init = function(templateid, page, elements) {
new Rearrange(templateid, page, elements);
};
}, '@VERSION@', {"requires": ["dd-delegate", "dd-drag"]});

View file

@ -1,7 +1,7 @@
/**
* Rearrange elements in the custom certificate
*
* @class M.mod_customcert.rearrange.rearrange
* @class Y.M.mod_customcert.rearrange
* @constructor
*/
var Rearrange = function() {
@ -12,64 +12,64 @@ Y.extend(Rearrange, Y.Base, {
/**
* The template id.
*/
templateid : 0,
templateid: 0,
/**
* The customcert page we are displaying.
*/
page : [],
page: [],
/**
* The custom certificate elements to display.
*/
elements : [],
elements: [],
/**
* Store the X coordinates of the top left of the pdf div.
*/
pdfx : 0,
pdfx: 0,
/**
* Store the Y coordinates of the top left of the pdf div.
*/
pdfy : 0,
pdfy: 0,
/**
* Store the width of the pdf div.
*/
pdfwidth : 0,
pdfwidth: 0,
/**
* Store the height of the pdf div.
*/
pdfheight : 0,
pdfheight: 0,
/**
* Store the location of the element before we move.
*/
elementxy : 0,
elementxy: 0,
/**
* Store the left boundary of the pdf div.
*/
pdfleftboundary : 0,
pdfleftboundary: 0,
/**
* Store the right boundary of the pdf div.
*/
pdfrightboundary : 0,
pdfrightboundary: 0,
/**
* The number of pixels in a mm.
*/
pixelsinmm : 3.779527559055, // '3.779528'.
pixelsinmm: 3.779527559055, // 3.779528.
/**
* Initialise.
*
* @param params
* @param {Array} params
*/
initializer : function(params) {
initializer: function(params) {
// Set the course module id.
this.templateid = params[0];
// Set the page.
@ -94,14 +94,14 @@ Y.extend(Rearrange, Y.Base, {
this.pdfrightboundary -= parseInt(this.page.rightmargin * this.pixelsinmm, 10);
}
this.set_positions();
this.create_events();
this.setpositions();
this.createevents();
},
/**
* Sets the current position of the elements.
*/
set_positions : function() {
setpositions: function() {
// Go through the elements and set their positions.
for (var key in this.elements) {
var element = this.elements[key];
@ -115,10 +115,10 @@ Y.extend(Rearrange, Y.Base, {
}
switch (element.refpoint) {
case '1': // Top-center
case '1': // Top-center.
posx -= nodewidth / 2;
break;
case '2': // Top-right
case '2': // Top-right.
posx = posx - nodewidth + 2;
break;
}
@ -131,15 +131,15 @@ Y.extend(Rearrange, Y.Base, {
/**
* Creates the JS events for changing element positions.
*/
create_events : function() {
createevents: function() {
// Trigger a save event when save button is pushed.
Y.one('.savepositionsbtn [type=submit]').on('click', function(e) {
this.save_positions(e);
this.savepositions(e);
}, this);
// Trigger a save event when apply button is pushed.
Y.one('.applypositionsbtn [type=submit]').on('click', function(e) {
this.save_positions(e);
this.savepositions(e);
e.preventDefault();
}, this);
@ -159,7 +159,7 @@ Y.extend(Rearrange, Y.Base, {
// if not, set it back to where it was.
del.on('drag:end', function() {
var node = del.get('currentNode');
if (this.is_out_of_bounds(node)) {
if (this.isoutofbounds(node)) {
node.setXY(this.elementxy);
}
}, this);
@ -168,10 +168,10 @@ Y.extend(Rearrange, Y.Base, {
/**
* Returns true if any part of the element is placed outside of the PDF div, false otherwise.
*
* @param node
* @param {Node} node
* @returns {boolean}
*/
is_out_of_bounds : function(node) {
isoutofbounds: function(node) {
// Get the width and height of the node.
var nodewidth = parseFloat(node.getComputedStyle('width'));
var nodeheight = parseFloat(node.getComputedStyle('height'));
@ -198,9 +198,9 @@ Y.extend(Rearrange, Y.Base, {
/**
* Perform an AJAX call and save the positions of the elements.
*
* @param e
* @param {Event} e
*/
save_positions : function(e) {
savepositions: function(e) {
// The parameters to send the AJAX call.
var params = {
tid: this.templateid,
@ -220,10 +220,10 @@ Y.extend(Rearrange, Y.Base, {
var nodewidth = parseFloat(node.getComputedStyle('width'));
switch (refpoint) {
case '1': // Top-center
case '1': // Top-center.
posx += nodewidth / 2;
break;
case '2': // Top-right
case '2': // Top-right.
posx += nodewidth;
break;
}
@ -244,18 +244,18 @@ Y.extend(Rearrange, Y.Base, {
data: params,
on: {
failure: function(tid, response) {
this.ajax_failure(response);
this.ajaxfailure(response);
},
success: function() {
var formNode = e.currentTarget.ancestor('form', true);
var baseUrl = formNode.getAttribute('action');
var pageinput = formNode.one('[name=pid]');
var formnode = e.currentTarget.ancestor('form', true);
var baseurl = formnode.getAttribute('action');
var pageinput = formnode.one('[name=pid]');
if (pageinput) {
var pageid = pageinput.get('value');
window.location = baseUrl + '?pid=' + pageid;
window.location = baseurl + '?pid=' + pageid;
} else {
var templateid = formNode.one('[name=tid]').get('value');
window.location = baseUrl + '?tid=' + templateid;
var templateid = formnode.one('[name=tid]').get('value');
window.location = baseurl + '?tid=' + templateid;
}
}
},
@ -268,10 +268,10 @@ Y.extend(Rearrange, Y.Base, {
/**
* Handles any failures during an AJAX call.
*
* @param response
* @param {XMLHttpRequest} response
* @returns {M.core.exception}
*/
ajax_failure : function(response) {
ajaxfailure: function(response) {
var e = {
name: response.status + ' ' + response.statusText,
message: response.responseText
@ -280,8 +280,6 @@ Y.extend(Rearrange, Y.Base, {
}
});
M.mod_customcert = M.mod_customcert || {};
M.mod_customcert.rearrange = M.mod_customcert.rearrange || {};
M.mod_customcert.rearrange.init = function(templateid, page, elements) {
Y.namespace('M.mod_customcert.rearrange').init = function(templateid, page, elements) {
new Rearrange(templateid, page, elements);
};