From 9ea484cf0bce2e54ce476885f5126e681e8d5207 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Thu, 20 Aug 2020 06:34:54 +1000 Subject: [PATCH] Issue #370: Support right to left certificates --- amd/build/rearrange-area.min.js | 2 +- amd/build/rearrange-area.min.js.map | 2 +- amd/src/rearrange-area.js | 27 ++++++++++++++++--- backup/moodle2/backup_customcert_stepslib.php | 2 +- classes/edit_form.php | 12 +++++++++ classes/template.php | 3 +++ db/install.xml | 9 ++++--- db/upgrade.php | 15 +++++++++++ edit.php | 2 ++ lang/en/customcert.php | 8 ++++-- rearrange.php | 8 +++--- styles.css | 22 +++++++++++++++ version.php | 2 +- .../moodle-mod_customcert-rearrange-debug.js | 22 +++++++++++++-- .../moodle-mod_customcert-rearrange-min.js | 2 +- .../moodle-mod_customcert-rearrange.js | 22 +++++++++++++-- yui/src/rearrange/js/rearrange.js | 22 +++++++++++++-- 17 files changed, 158 insertions(+), 24 deletions(-) diff --git a/amd/build/rearrange-area.min.js b/amd/build/rearrange-area.min.js index 36faa3a0..90018c53 100644 --- a/amd/build/rearrange-area.min.js +++ b/amd/build/rearrange-area.min.js @@ -1,2 +1,2 @@ -define ("mod_customcert/rearrange-area",["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,f,g,h,i){var j=function(b){this._node=a(b);this._setEvents()};j.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0;j.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1;j.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2;j.prototype.PIXELSINMM=3.779527559055;j.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))};j.prototype._editElement=function(a){var e=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid");c.loadFragment("mod_customcert","editelement",h,{elementid:e}).done(function(a,c){g.get_string("editelement","mod_customcert").done(function(f){b.use("moodle-core-formchangechecker",function(){new d(f,"
",this._editElementDialogueConfig.bind(this,e,a,c),void 0,!0)}.bind(this))}.bind(this))}.bind(this)).fail(f.exception)};j.prototype._editElementDialogueConfig=function(b,c,d,g){h.replaceNode("#elementcontent",c,d);this._setPositionInForm(b);var i=a(g.getContent());i.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),e=parseInt(a("#id_refpoint").val()),f="";if(e==this.CUSTOMCERT_REF_POINT_TOPLEFT){f="refpoint-left"}else if(e==this.CUSTOMCERT_REF_POINT_TOPCENTER){f="refpoint-center"}else if(e==this.CUSTOMCERT_REF_POINT_TOPRIGHT){f="refpoint-right"}d.empty().append(c);d.removeClass();d.addClass("element "+f);d.attr("data-refpoint",e);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,e,h,i);g.close()}.bind(this))}.bind(this)).fail(f.exception);c.preventDefault()}.bind(this));i.on("click","#id_cancel",function(a){g.close();a.preventDefault()})};j.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;if(h&&g>h){g=h}switch(c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=g/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-g+2;break;}f.setX(d);f.setY(e)};j.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;break;}g=Math.round(parseFloat(g/this.PIXELSINMM));h=Math.round(parseFloat(h/this.PIXELSINMM));d.val(g);e.val(h)}};j.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=i.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]};j.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=i.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]};return{init:function init(a){new j(a)}}}); +define ("mod_customcert/rearrange-area",["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,f,g,h,i){var j=function(b){this._node=a(b);this._setEvents()};j.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0;j.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1;j.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2;j.prototype.PIXELSINMM=3.779527559055;j.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))};j.prototype._editElement=function(a){var e=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid");c.loadFragment("mod_customcert","editelement",h,{elementid:e}).done(function(a,c){g.get_string("editelement","mod_customcert").done(function(f){b.use("moodle-core-formchangechecker",function(){new d(f,"
",this._editElementDialogueConfig.bind(this,e,a,c),void 0,!0)}.bind(this))}.bind(this))}.bind(this)).fail(f.exception)};j.prototype._editElementDialogueConfig=function(b,c,d,g){h.replaceNode("#elementcontent",c,d);this._setPositionInForm(b);var i=a(g.getContent());i.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),e=parseInt(a("#id_refpoint").val()),f="";if(e==this.CUSTOMCERT_REF_POINT_TOPLEFT){f="refpoint-left"}else if(e==this.CUSTOMCERT_REF_POINT_TOPCENTER){f="refpoint-center"}else if(e==this.CUSTOMCERT_REF_POINT_TOPRIGHT){f="refpoint-right"}d.empty().append(c);d.removeClass();d.addClass("element "+f);d.attr("data-refpoint",e);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,e,h,i);g.close()}.bind(this))}.bind(this)).fail(f.exception);c.preventDefault()}.bind(this));i.on("click","#id_cancel",function(a){g.close();a.preventDefault()})};j.prototype._setPosition=function(a,c,d,e){var f=b.one("#element-"+a),g="rtl"===b.one("#pdf").getComputedStyle("direction");if(g){d=b.one("#pdf").getX()+parseFloat(b.one("#pdf").getComputedStyle("width"))-d*this.PIXELSINMM}else{d=b.one("#pdf").getX()+d*this.PIXELSINMM}e=b.one("#pdf").getY()+e*this.PIXELSINMM;var h=parseFloat(f.getComputedStyle("width")),i=f.width*this.PIXELSINMM;if(i&&h>i){h=i}switch(c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=h/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-h;break;}f.setX(d);f.setY(e)};j.prototype._setPositionInForm=function(c){var d=a("#editelementform #id_posx"),e=a("#editelementform #id_posy"),f="rtl"===b.one("#pdf").getComputedStyle("direction");if(d.length&&e.length){var g=b.one("#element-"+c),h=g.getX()-b.one("#pdf").getX(),i=g.getY()-b.one("#pdf").getY(),j=parseInt(g.getData("refpoint")),k=parseFloat(g.getComputedStyle("width"));if(f){h=b.one("#pdf").getX()+parseFloat(b.one("#pdf").getComputedStyle("width"))-g.getX()}switch(j){case this.CUSTOMCERT_REF_POINT_TOPCENTER:if(f){h-=k/2}else{h+=k/2}break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:if(f){h-=k}else{h+=k}break;}h=Math.round(parseFloat(h/this.PIXELSINMM));i=Math.round(parseFloat(i/this.PIXELSINMM));d.val(h);e.val(i)}};j.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=i.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]};j.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=i.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]};return{init:function init(a){new j(a)}}}); //# sourceMappingURL=rearrange-area.min.js.map diff --git a/amd/build/rearrange-area.min.js.map b/amd/build/rearrange-area.min.js.map index 45761be7..742287c7 100644 --- a/amd/build/rearrange-area.min.js.map +++ b/amd/build/rearrange-area.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/rearrange-area.js"],"names":["define","$","Y","fragment","Dialogue","notification","str","template","ajax","RearrangeArea","selector","_node","_setEvents","prototype","CUSTOMCERT_REF_POINT_TOPLEFT","CUSTOMCERT_REF_POINT_TOPCENTER","CUSTOMCERT_REF_POINT_TOPRIGHT","PIXELSINMM","on","_editElement","bind","event","elementid","currentTarget","id","substr","contextid","attr","loadFragment","done","html","js","get_string","title","use","_editElementDialogueConfig","fail","exception","popup","replaceNode","_setPositionInForm","body","getContent","e","M","core_formchangechecker","reset_form_dirty_state","_saveElement","then","_getElementHTML","elementNode","find","refpoint","parseInt","val","refpointClass","empty","append","removeClass","addClass","posx","posy","_setPosition","close","preventDefault","element","one","getX","getY","nodewidth","parseFloat","getComputedStyle","maxwidth","width","setX","setY","posxelement","posyelement","length","getData","Math","round","templateid","promises","call","methodname","args","inputs","serializeArray","values","init"],"mappings":"AAuBAA,OAAM,iCAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,eAAvB,CAAwC,yBAAxC,CAAmE,mBAAnE,CACC,UADD,CACa,gBADb,CAC+B,WAD/B,CAAD,CAEE,SAASC,CAAT,CAAYC,CAAZ,CAAeC,CAAf,CAAyBC,CAAzB,CAAmCC,CAAnC,CAAiDC,CAAjD,CAAsDC,CAAtD,CAAgEC,CAAhE,CAAsE,CAOlE,GAAIC,CAAAA,CAAa,CAAG,SAASC,CAAT,CAAmB,CACnC,KAAKC,KAAL,CAAaV,CAAC,CAACS,CAAD,CAAd,CACA,KAAKE,UAAL,EACH,CAHD,CAKAH,CAAa,CAACI,SAAd,CAAwBC,4BAAxB,CAAuD,CAAv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CAAmB,CACrB,GAAID,CAAAA,CAAJ,CAAkBC,CAAlB,CACH,CAHE,CAKV,CA5LH,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * AMD module used when rearranging a custom certificate.\n *\n * @module mod_customcert/rearrange-area\n * @package mod_customcert\n * @copyright 2016 Mark Nelson \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/notification',\n 'core/str', 'core/templates', 'core/ajax'],\n function($, Y, fragment, Dialogue, notification, str, template, ajax) {\n\n /**\n * RearrangeArea class.\n *\n * @param {String} selector The rearrange PDF selector\n */\n var RearrangeArea = function(selector) {\n this._node = $(selector);\n this._setEvents();\n };\n\n RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPLEFT = 0;\n RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPCENTER = 1;\n RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT = 2;\n RearrangeArea.prototype.PIXELSINMM = 3.779527559055;\n\n RearrangeArea.prototype._setEvents = function() {\n this._node.on('click', '.element', this._editElement.bind(this));\n };\n\n RearrangeArea.prototype._editElement = function(event) {\n var elementid = event.currentTarget.id.substr(8);\n var contextid = this._node.attr('data-contextid');\n var params = {\n 'elementid': elementid\n };\n\n fragment.loadFragment('mod_customcert', 'editelement', contextid, params).done(function(html, js) {\n str.get_string('editelement', 'mod_customcert').done(function(title) {\n Y.use('moodle-core-formchangechecker', function() {\n new Dialogue(\n title,\n '
',\n this._editElementDialogueConfig.bind(this, elementid, html, js),\n undefined,\n true\n );\n }.bind(this));\n }.bind(this));\n }.bind(this)).fail(notification.exception);\n };\n\n RearrangeArea.prototype._editElementDialogueConfig = function(elementid, html, js, popup) {\n // Place the content in the dialogue.\n template.replaceNode('#elementcontent', html, js);\n\n // We may have dragged the element changing it's position.\n // Ensure the form has the current up-to-date location.\n this._setPositionInForm(elementid);\n\n // Add events for when we save, close and cancel the page.\n var body = $(popup.getContent());\n body.on('click', '#id_submitbutton', function(e) {\n // Do not want to ask the user if they wish to stay on page after saving.\n M.core_formchangechecker.reset_form_dirty_state();\n // Save the data.\n this._saveElement(elementid).then(function() {\n // Update the DOM to reflect the adjusted value.\n this._getElementHTML(elementid).done(function(html) {\n var elementNode = this._node.find('#element-' + elementid);\n var refpoint = parseInt($('#id_refpoint').val());\n var refpointClass = '';\n if (refpoint == this.CUSTOMCERT_REF_POINT_TOPLEFT) {\n refpointClass = 'refpoint-left';\n } else if (refpoint == this.CUSTOMCERT_REF_POINT_TOPCENTER) {\n refpointClass = 'refpoint-center';\n } else if (refpoint == this.CUSTOMCERT_REF_POINT_TOPRIGHT) {\n refpointClass = 'refpoint-right';\n }\n elementNode.empty().append(html);\n // Update the ref point.\n elementNode.removeClass();\n elementNode.addClass('element ' + refpointClass);\n elementNode.attr('data-refpoint', refpoint);\n // Move the element.\n var posx = $('#editelementform #id_posx').val();\n var posy = $('#editelementform #id_posy').val();\n this._setPosition(elementid, refpoint, posx, posy);\n // All done.\n popup.close();\n }.bind(this));\n }.bind(this)).fail(notification.exception);\n e.preventDefault();\n }.bind(this));\n\n body.on('click', '#id_cancel', function(e) {\n popup.close();\n e.preventDefault();\n });\n };\n\n RearrangeArea.prototype._setPosition = function(elementid, refpoint, posx, posy) {\n var element = Y.one('#element-' + elementid);\n\n posx = Y.one('#pdf').getX() + posx * this.PIXELSINMM;\n posy = Y.one('#pdf').getY() + posy * this.PIXELSINMM;\n var nodewidth = parseFloat(element.getComputedStyle('width'));\n var maxwidth = element.width * this.PIXELSINMM;\n\n if (maxwidth && (nodewidth > maxwidth)) {\n nodewidth = maxwidth;\n }\n\n switch (refpoint) {\n case this.CUSTOMCERT_REF_POINT_TOPCENTER:\n posx -= nodewidth / 2;\n break;\n case this.CUSTOMCERT_REF_POINT_TOPRIGHT:\n posx = posx - nodewidth + 2;\n break;\n }\n\n element.setX(posx);\n element.setY(posy);\n };\n\n RearrangeArea.prototype._setPositionInForm = function(elementid) {\n var posxelement = $('#editelementform #id_posx');\n var posyelement = $('#editelementform #id_posy');\n\n if (posxelement.length && posyelement.length) {\n var element = Y.one('#element-' + elementid);\n var posx = element.getX() - Y.one('#pdf').getX();\n var posy = element.getY() - Y.one('#pdf').getY();\n var refpoint = parseInt(element.getData('refpoint'));\n var nodewidth = parseFloat(element.getComputedStyle('width'));\n\n switch (refpoint) {\n case this.CUSTOMCERT_REF_POINT_TOPCENTER:\n posx += nodewidth / 2;\n break;\n case this.CUSTOMCERT_REF_POINT_TOPRIGHT:\n posx += nodewidth;\n break;\n }\n\n posx = Math.round(parseFloat(posx / this.PIXELSINMM));\n posy = Math.round(parseFloat(posy / this.PIXELSINMM));\n\n posxelement.val(posx);\n posyelement.val(posy);\n }\n };\n\n RearrangeArea.prototype._getElementHTML = function(elementid) {\n // Get the variables we need.\n var templateid = this._node.attr('data-templateid');\n\n // Call the web service to get the updated element.\n var promises = ajax.call([{\n methodname: 'mod_customcert_get_element_html',\n args: {\n templateid: templateid,\n elementid: elementid\n }\n }]);\n\n // Return the promise.\n return promises[0];\n };\n\n RearrangeArea.prototype._saveElement = function(elementid) {\n // Get the variables we need.\n var templateid = this._node.attr('data-templateid');\n var inputs = $('#editelementform').serializeArray();\n\n // Call the web service to save the element.\n var promises = ajax.call([{\n methodname: 'mod_customcert_save_element',\n args: {\n templateid: templateid,\n elementid: elementid,\n values: inputs\n }\n }]);\n\n // Return the promise.\n return promises[0];\n };\n\n return {\n init: function(selector) {\n new RearrangeArea(selector);\n }\n };\n }\n );\n"],"file":"rearrange-area.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/rearrange-area.js"],"names":["define","$","Y","fragment","Dialogue","notification","str","template","ajax","RearrangeArea","selector","_node","_setEvents","prototype","CUSTOMCERT_REF_POINT_TOPLEFT","CUSTOMCERT_REF_POINT_TOPCENTER","CUSTOMCERT_REF_POINT_TOPRIGHT","PIXELSINMM","on","_editElement","bind","event","elementid","currentTarget","id","substr","contextid","attr","loadFragment","done","html","js","get_string","title","use","_editElementDialogueConfig","fail","exception","popup","replaceNode","_setPositionInForm","body","getContent","e","M","core_formchangechecker","reset_form_dirty_state","_saveElement","then","_getElementHTML","elementNode","find","refpoint","parseInt","val","refpointClass","empty","append","removeClass","addClass","posx","posy","_setPosition","close","preventDefault","element","one","isRtl","getComputedStyle","getX","parseFloat","getY","nodewidth","maxwidth","width","setX","setY","posxelement","posyelement","length","getData","Math","round","templateid","promises","call","methodname","args","inputs","serializeArray","values","init"],"mappings":"AAuBAA,OAAM,iCAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,eAAvB,CAAwC,yBAAxC,CAAmE,mBAAnE,CACC,UADD,CACa,gBADb,CAC+B,WAD/B,CAAD,CAEE,SAASC,CAAT,CAAYC,CAAZ,CAAeC,CAAf,CAAyBC,CAAzB,CAAmCC,CAAnC,CAAiDC,CAAjD,CAAsDC,CAAtD,CAAgEC,CAAhE,CAAsE,CAOlE,GAAIC,CAAAA,CAAa,CAAG,SAASC,CAAT,CAAmB,CACnC,KAAKC,KAAL,CAAaV,CAAC,CAACS,CAAD,CAAd,CACA,KAAKE,UAAL,EACH,CAHD,CAKAH,CAAa,CAACI,SAAd,CAAwBC,4BAAxB,CAAuD,CAAvD,CACAL,CAAa,CAACI,SAAd,CAAwBE,8BAAxB,CAAyD,CAAzD,CACAN,CAAa,CAACI,SAAd,CAAwBG,6BAAxB,CAAwD,CAAxD,CACAP,CAAa,CAACI,SAAd,CAAwBI,UAAxB,CAAqC,cAArC,CAEAR,CAA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CAAD,CAAV,CAL2C,CAc1D,MAAO8D,CAAAA,CAAQ,CAAC,CAAD,CAClB,CAfD,CAiBA3E,CAAa,CAACI,SAAd,CAAwBkC,YAAxB,CAAuC,SAASzB,CAAT,CAAoB,IAEnD6D,CAAAA,CAAU,CAAG,KAAKxE,KAAL,CAAWgB,IAAX,CAAgB,iBAAhB,CAFsC,CAGnD6D,CAAM,CAAGvF,CAAC,CAAC,kBAAD,CAAD,CAAsBwF,cAAtB,EAH0C,CAMnDL,CAAQ,CAAG5E,CAAI,CAAC6E,IAAL,CAAU,CAAC,CACtBC,UAAU,CAAE,6BADU,CAEtBC,IAAI,CAAE,CACFJ,UAAU,CAAEA,CADV,CAEF7D,SAAS,CAAEA,CAFT,CAGFoE,MAAM,CAAEF,CAHN,CAFgB,CAAD,CAAV,CANwC,CAgBvD,MAAOJ,CAAAA,CAAQ,CAAC,CAAD,CAClB,CAjBD,CAmBA,MAAO,CACHO,IAAI,CAAE,cAASjF,CAAT,CAAmB,CACrB,GAAID,CAAAA,CAAJ,CAAkBC,CAAlB,CACH,CAHE,CAKV,CA/MH,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * AMD module used when rearranging a custom certificate.\n *\n * @module mod_customcert/rearrange-area\n * @package mod_customcert\n * @copyright 2016 Mark Nelson \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/notification',\n 'core/str', 'core/templates', 'core/ajax'],\n function($, Y, fragment, Dialogue, notification, str, template, ajax) {\n\n /**\n * RearrangeArea class.\n *\n * @param {String} selector The rearrange PDF selector\n */\n var RearrangeArea = function(selector) {\n this._node = $(selector);\n this._setEvents();\n };\n\n RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPLEFT = 0;\n RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPCENTER = 1;\n RearrangeArea.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT = 2;\n RearrangeArea.prototype.PIXELSINMM = 3.779527559055;\n\n RearrangeArea.prototype._setEvents = function() {\n this._node.on('click', '.element', this._editElement.bind(this));\n };\n\n RearrangeArea.prototype._editElement = function(event) {\n var elementid = event.currentTarget.id.substr(8);\n var contextid = this._node.attr('data-contextid');\n var params = {\n 'elementid': elementid\n };\n\n fragment.loadFragment('mod_customcert', 'editelement', contextid, params).done(function(html, js) {\n str.get_string('editelement', 'mod_customcert').done(function(title) {\n Y.use('moodle-core-formchangechecker', function() {\n new Dialogue(\n title,\n '
',\n this._editElementDialogueConfig.bind(this, elementid, html, js),\n undefined,\n true\n );\n }.bind(this));\n }.bind(this));\n }.bind(this)).fail(notification.exception);\n };\n\n RearrangeArea.prototype._editElementDialogueConfig = function(elementid, html, js, popup) {\n // Place the content in the dialogue.\n template.replaceNode('#elementcontent', html, js);\n\n // We may have dragged the element changing it's position.\n // Ensure the form has the current up-to-date location.\n this._setPositionInForm(elementid);\n\n // Add events for when we save, close and cancel the page.\n var body = $(popup.getContent());\n body.on('click', '#id_submitbutton', function(e) {\n // Do not want to ask the user if they wish to stay on page after saving.\n M.core_formchangechecker.reset_form_dirty_state();\n // Save the data.\n this._saveElement(elementid).then(function() {\n // Update the DOM to reflect the adjusted value.\n this._getElementHTML(elementid).done(function(html) {\n var elementNode = this._node.find('#element-' + elementid);\n var refpoint = parseInt($('#id_refpoint').val());\n var refpointClass = '';\n if (refpoint == this.CUSTOMCERT_REF_POINT_TOPLEFT) {\n refpointClass = 'refpoint-left';\n } else if (refpoint == this.CUSTOMCERT_REF_POINT_TOPCENTER) {\n refpointClass = 'refpoint-center';\n } else if (refpoint == this.CUSTOMCERT_REF_POINT_TOPRIGHT) {\n refpointClass = 'refpoint-right';\n }\n elementNode.empty().append(html);\n // Update the ref point.\n elementNode.removeClass();\n elementNode.addClass('element ' + refpointClass);\n elementNode.attr('data-refpoint', refpoint);\n // Move the element.\n var posx = $('#editelementform #id_posx').val();\n var posy = $('#editelementform #id_posy').val();\n this._setPosition(elementid, refpoint, posx, posy);\n // All done.\n popup.close();\n }.bind(this));\n }.bind(this)).fail(notification.exception);\n e.preventDefault();\n }.bind(this));\n\n body.on('click', '#id_cancel', function(e) {\n popup.close();\n e.preventDefault();\n });\n };\n\n RearrangeArea.prototype._setPosition = function(elementid, refpoint, posx, posy) {\n var element = Y.one('#element-' + elementid);\n var isRtl = Y.one('#pdf').getComputedStyle('direction') === 'rtl';\n\n if (isRtl) {\n posx = Y.one('#pdf').getX() + parseFloat(Y.one('#pdf').getComputedStyle('width')) - posx * this.PIXELSINMM;\n } else {\n posx = Y.one('#pdf').getX() + posx * this.PIXELSINMM;\n }\n posy = Y.one('#pdf').getY() + posy * this.PIXELSINMM;\n var nodewidth = parseFloat(element.getComputedStyle('width'));\n var maxwidth = element.width * this.PIXELSINMM;\n\n if (maxwidth && (nodewidth > maxwidth)) {\n nodewidth = maxwidth;\n }\n\n switch (refpoint) {\n case this.CUSTOMCERT_REF_POINT_TOPCENTER:\n posx -= nodewidth / 2;\n break;\n case this.CUSTOMCERT_REF_POINT_TOPRIGHT:\n posx = posx - nodewidth;\n break;\n }\n\n element.setX(posx);\n element.setY(posy);\n };\n\n RearrangeArea.prototype._setPositionInForm = function(elementid) {\n var posxelement = $('#editelementform #id_posx');\n var posyelement = $('#editelementform #id_posy');\n var isRtl = Y.one('#pdf').getComputedStyle('direction') === 'rtl';\n\n if (posxelement.length && posyelement.length) {\n var element = Y.one('#element-' + elementid);\n var posx = element.getX() - Y.one('#pdf').getX();\n var posy = element.getY() - Y.one('#pdf').getY();\n var refpoint = parseInt(element.getData('refpoint'));\n var nodewidth = parseFloat(element.getComputedStyle('width'));\n\n // Recalculate posx if the page's direction is right-to-left.\n if (isRtl) {\n posx = Y.one('#pdf').getX() + parseFloat(Y.one('#pdf').getComputedStyle('width')) - element.getX();\n }\n\n switch (refpoint) {\n case this.CUSTOMCERT_REF_POINT_TOPCENTER:\n if (isRtl) {\n posx -= nodewidth / 2;\n } else {\n posx += nodewidth / 2;\n }\n break;\n case this.CUSTOMCERT_REF_POINT_TOPRIGHT:\n if (isRtl) {\n posx -= nodewidth;\n } else {\n posx += nodewidth;\n }\n break;\n }\n\n posx = Math.round(parseFloat(posx / this.PIXELSINMM));\n posy = Math.round(parseFloat(posy / this.PIXELSINMM));\n\n posxelement.val(posx);\n posyelement.val(posy);\n }\n };\n\n RearrangeArea.prototype._getElementHTML = function(elementid) {\n // Get the variables we need.\n var templateid = this._node.attr('data-templateid');\n\n // Call the web service to get the updated element.\n var promises = ajax.call([{\n methodname: 'mod_customcert_get_element_html',\n args: {\n templateid: templateid,\n elementid: elementid\n }\n }]);\n\n // Return the promise.\n return promises[0];\n };\n\n RearrangeArea.prototype._saveElement = function(elementid) {\n // Get the variables we need.\n var templateid = this._node.attr('data-templateid');\n var inputs = $('#editelementform').serializeArray();\n\n // Call the web service to save the element.\n var promises = ajax.call([{\n methodname: 'mod_customcert_save_element',\n args: {\n templateid: templateid,\n elementid: elementid,\n values: inputs\n }\n }]);\n\n // Return the promise.\n return promises[0];\n };\n\n return {\n init: function(selector) {\n new RearrangeArea(selector);\n }\n };\n }\n );\n"],"file":"rearrange-area.min.js"} \ No newline at end of file diff --git a/amd/src/rearrange-area.js b/amd/src/rearrange-area.js index ea790514..386342c6 100644 --- a/amd/src/rearrange-area.js +++ b/amd/src/rearrange-area.js @@ -117,8 +117,13 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/ RearrangeArea.prototype._setPosition = function(elementid, refpoint, posx, posy) { var element = Y.one('#element-' + elementid); + var isRtl = Y.one('#pdf').getComputedStyle('direction') === 'rtl'; - posx = Y.one('#pdf').getX() + posx * this.PIXELSINMM; + if (isRtl) { + posx = Y.one('#pdf').getX() + parseFloat(Y.one('#pdf').getComputedStyle('width')) - posx * this.PIXELSINMM; + } else { + posx = Y.one('#pdf').getX() + posx * this.PIXELSINMM; + } posy = Y.one('#pdf').getY() + posy * this.PIXELSINMM; var nodewidth = parseFloat(element.getComputedStyle('width')); var maxwidth = element.width * this.PIXELSINMM; @@ -132,7 +137,7 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/ posx -= nodewidth / 2; break; case this.CUSTOMCERT_REF_POINT_TOPRIGHT: - posx = posx - nodewidth + 2; + posx = posx - nodewidth; break; } @@ -143,6 +148,7 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/ RearrangeArea.prototype._setPositionInForm = function(elementid) { var posxelement = $('#editelementform #id_posx'); var posyelement = $('#editelementform #id_posy'); + var isRtl = Y.one('#pdf').getComputedStyle('direction') === 'rtl'; if (posxelement.length && posyelement.length) { var element = Y.one('#element-' + elementid); @@ -151,12 +157,25 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/ var refpoint = parseInt(element.getData('refpoint')); var nodewidth = parseFloat(element.getComputedStyle('width')); + // Recalculate posx if the page's direction is right-to-left. + if (isRtl) { + posx = Y.one('#pdf').getX() + parseFloat(Y.one('#pdf').getComputedStyle('width')) - element.getX(); + } + switch (refpoint) { case this.CUSTOMCERT_REF_POINT_TOPCENTER: - posx += nodewidth / 2; + if (isRtl) { + posx -= nodewidth / 2; + } else { + posx += nodewidth / 2; + } break; case this.CUSTOMCERT_REF_POINT_TOPRIGHT: - posx += nodewidth; + if (isRtl) { + posx -= nodewidth; + } else { + posx += nodewidth; + } break; } diff --git a/backup/moodle2/backup_customcert_stepslib.php b/backup/moodle2/backup_customcert_stepslib.php index e6bf6170..ee2cd4cf 100644 --- a/backup/moodle2/backup_customcert_stepslib.php +++ b/backup/moodle2/backup_customcert_stepslib.php @@ -52,7 +52,7 @@ protected function define_structure() { // The pages. $pages = new backup_nested_element('pages'); $page = new backup_nested_element('page', array('id'), array( - 'templateid', 'width', 'height', 'leftmargin', 'rightmargin', + 'templateid', 'width', 'height', 'direction', 'leftmargin', 'rightmargin', 'sequence', 'timecreated', 'timemodified')); // The elements. diff --git a/classes/edit_form.php b/classes/edit_form.php index 50f642c0..229d1912 100644 --- a/classes/edit_form.php +++ b/classes/edit_form.php @@ -126,6 +126,9 @@ public function definition_after_data() { // Set the height. $element = $mform->getElement('pageheight_' . $p->id); $element->setValue($p->height); + // Set the direction. + $element = $mform->getElement('pagedirection_' . $p->id); + $element->setValue($p->direction); // Set the left margin. $element = $mform->getElement('pageleftmargin_' . $p->id); $element->setValue($p->leftmargin); @@ -230,6 +233,15 @@ protected function add_customcert_page_elements($page) { $mform->addRule('pageheight_' . $page->id, null, 'required', null, 'client'); $mform->addHelpButton('pageheight_' . $page->id, 'height', 'customcert'); + $directions = [ + 0 => get_string('ltr', 'customcert'), + 1 => get_string('rtl', 'customcert'), + ]; + $mform->addElement('select', 'pagedirection_' . $page->id, get_string('direction', 'customcert'), $directions); + $mform->setDefault('pagedirection_' . $page->id, 'ltr'); + $mform->addRule('pagedirection_' . $page->id, null, 'required', null, 'client'); + $mform->addHelpButton('pagedirection_' . $page->id, 'direction', 'customcert'); + $mform->addElement('text', 'pageleftmargin_' . $page->id, get_string('leftmargin', 'customcert')); $mform->setType('pageleftmargin_' . $page->id, PARAM_INT); $mform->setDefault('pageleftmargin_' . $page->id, 0); diff --git a/classes/template.php b/classes/template.php index 688574b5..f63bf4bf 100644 --- a/classes/template.php +++ b/classes/template.php @@ -126,6 +126,7 @@ public function save_page($data) { // Get the name of the fields we want from the form. $width = 'pagewidth_' . $page->id; $height = 'pageheight_' . $page->id; + $direction = 'pagedirection_' . $page->id; $leftmargin = 'pageleftmargin_' . $page->id; $rightmargin = 'pagerightmargin_' . $page->id; // Create the page data to update the DB with. @@ -133,6 +134,7 @@ public function save_page($data) { $p->id = $page->id; $p->width = $data->$width; $p->height = $data->$height; + $p->direction = $data->$direction; $p->leftmargin = $data->$leftmargin; $p->rightmargin = $data->$rightmargin; $p->timemodified = $time; @@ -293,6 +295,7 @@ public function generate_pdf($preview = false, $userid = null, $return = false) $orientation = 'P'; } $pdf->AddPage($orientation, array($page->width, $page->height)); + $pdf->setRTL($page->direction); $pdf->SetMargins($page->leftmargin, 0, $page->rightmargin); // Get the elements for the page. if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) { diff --git a/db/install.xml b/db/install.xml index f6ac7966..8463e711 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -10,7 +10,7 @@ - + @@ -59,6 +59,7 @@ + @@ -76,7 +77,7 @@ - + @@ -94,4 +95,4 @@ - + \ No newline at end of file diff --git a/db/upgrade.php b/db/upgrade.php index 57d2b4fb..6603fbd8 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -166,5 +166,20 @@ function xmldb_customcert_upgrade($oldversion) { upgrade_mod_savepoint(true, 2019111803, 'customcert'); } + if ($oldversion < 2020082000) { + + // Define field direction to be added to customcert_pages. + $table = new xmldb_table('customcert_pages'); + $field = new xmldb_field('direction', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'height'); + + // Conditionally launch add field direction. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Customcert savepoint reached. + upgrade_mod_savepoint(true, 2020082000, 'customcert'); + } + return true; } diff --git a/edit.php b/edit.php index c84ca085..9416bed0 100644 --- a/edit.php +++ b/edit.php @@ -179,12 +179,14 @@ // Associate all the data from the form to the newly created page. $width = 'pagewidth_' . $pageid; $height = 'pageheight_' . $pageid; + $direction = 'pagedirection_' . $pageid; $leftmargin = 'pageleftmargin_' . $pageid; $rightmargin = 'pagerightmargin_' . $pageid; $rightmargin = 'pagerightmargin_' . $pageid; $data->$width = $data->pagewidth_0; $data->$height = $data->pageheight_0; + $data->$direction = $data->pagedirection_0; $data->$leftmargin = $data->pageleftmargin_0; $data->$rightmargin = $data->pagerightmargin_0; diff --git a/lang/en/customcert.php b/lang/en/customcert.php index ee88c2f3..fcaad7a8 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -58,6 +58,10 @@ $string['deletepageconfirm'] = 'Are you sure you want to delete this certificate page?'; $string['deletetemplateconfirm'] = 'Are you sure you want to delete this certificate template?'; $string['description'] = 'Description'; +$string['direction'] = 'Direction'; +$string['direction_help'] = 'This is the direction of the certificate PDF.'; +$string['ltr'] = 'Left to right'; +$string['rtl'] = 'Right to left'; $string['duplicate'] = 'Duplicate'; $string['duplicateconfirm'] = 'Duplicate confirmation'; $string['duplicatetemplateconfirm'] = 'Are you sure you want to duplicate this certificate template?'; @@ -137,9 +141,9 @@ $string['pluginname'] = 'Custom certificate'; $string['portrait'] = 'Portrait'; $string['posx'] = 'Position X'; -$string['posx_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the x direction.'; +$string['posx_help'] = 'This is the position in mm from the left side (or the right side, if the page\'s direction is right-to-left) of the page you wish the element\'s reference point to locate in the x direction.'; $string['posy'] = 'Position Y'; -$string['posy_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the y direction.'; +$string['posy_help'] = 'This is the position in mm from the top of the page you wish the element\'s reference point to locate in the y direction.'; $string['preventcopy'] = 'Prevent copy'; $string['preventcopy_desc'] = 'Enable protection from copy action.'; $string['preventprint'] = 'Prevent print'; diff --git a/rearrange.php b/rearrange.php index 7483953c..4cb4e64f 100644 --- a/rearrange.php +++ b/rearrange.php @@ -86,13 +86,15 @@ // Create the div that represents the PDF. $style = 'height: ' . $page->height . 'mm; line-height: normal; width: ' . $page->width . 'mm;'; +$class = $page->direction == 1 ? 'page-rtl' : 'page-ltr'; $marginstyle = 'height: ' . $page->height . 'mm; width:1px; float:left; position:relative;'; -$html .= html_writer::start_tag('div', array( +$html .= html_writer::start_tag('div', [ 'data-templateid' => $template->get_id(), 'data-contextid' => $template->get_contextid(), 'id' => 'pdf', - 'style' => $style) -); + 'style' => $style, + 'class' => $class, +]); if ($page->leftmargin) { $position = 'left:' . $page->leftmargin . 'mm;'; $html .= "
"; diff --git a/styles.css b/styles.css index 9fbe30bf..411ba12f 100644 --- a/styles.css +++ b/styles.css @@ -43,7 +43,12 @@ } #page-mod-customcert-rearrange .element.refpoint-left:before { + /*rtl:ignore*/ background-position: left top; + /*rtl:raw: + margin: -4px 4px -5px -5px; + */ + /*rtl:remove*/ margin: -4px -5px -5px -4px; } @@ -53,7 +58,12 @@ } #page-mod-customcert-rearrange .element.refpoint-right:before { + /*rtl:ignore*/ background-position: right top; + /*rtl:raw: + margin: -4px -4px -5px -5px; + */ + /*rtl:remove*/ margin: -4px -5px -5px 4px; } @@ -63,6 +73,18 @@ clear: both; } +/*rtl:ignore*/ +#page-mod-customcert-rearrange #pdf.page-ltr { + direction: ltr; + text-align: left; +} + +/*rtl:ignore*/ +#page-mod-customcert-rearrange #pdf.page-rtl { + direction: rtl; + text-align: right; +} + #page-mod-customcert-rearrange div#leftmargin { border-left: 1px dotted black; } diff --git a/version.php b/version.php index 9e05c151..21f048fc 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2019111804; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2020082000; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2019111800; // Requires this Moodle version (3.8). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; diff --git a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-debug.js b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-debug.js index 72812f34..6f5e949d 100644 --- a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-debug.js +++ b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-debug.js @@ -94,6 +94,8 @@ Y.extend(Rearrange, Y.Base, { * Sets the current position of the elements. */ setpositions: function() { + var isRtl = this.page.direction == 1; + // Go through the elements and set their positions. for (var key in this.elements) { var element = this.elements[key]; @@ -106,12 +108,17 @@ Y.extend(Rearrange, Y.Base, { nodewidth = maxwidth; } + // Recalculate posx if the page's direction is right-to-left. + if (isRtl) { + posx = this.pdfx + this.pdfwidth - element.posx * this.pixelsinmm; + } + switch (element.refpoint) { case '1': // Top-center. posx -= nodewidth / 2; break; case '2': // Top-right. - posx = posx - nodewidth + 2; + posx = posx - nodewidth; break; } @@ -227,6 +234,8 @@ Y.extend(Rearrange, Y.Base, { * @param {Event} e */ savepositions: function(e) { + var isRtl = this.page.direction == 1; + // The parameters to send the AJAX call. var params = { tid: this.templateid, @@ -245,12 +254,21 @@ Y.extend(Rearrange, Y.Base, { var nodewidth = parseFloat(node.getComputedStyle('width')); + // Recalculate posx if the page's direction is right-to-left. + if (isRtl) { + posx = this.pdfx + this.pdfwidth - node.getX(); + } + switch (refpoint) { case '1': // Top-center. posx += nodewidth / 2; break; case '2': // Top-right. - posx += nodewidth; + if (isRtl) { + posx -= nodewidth; + } else { + posx += nodewidth; + } break; } diff --git a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-min.js b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-min.js index 0e5cdc93..80318c7f 100644 --- a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-min.js +++ b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange-min.js @@ -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(e){this.templateid=e[0],this.page=e[1],this.elements=e[2],this.setPdfDimensions(),this.setBoundaries(),this.setpositions(),this.createevents(),window.addEventListener("resize",this.checkWindownResize.bind(this))},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)}},setPdfDimensions:function(){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"))},setBoundaries:function(){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))},checkWindownResize:function(){this.setPdfDimensions(),this.setBoundaries(),this.setpositions()},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 rthis.pdfrightboundary?!0:sthis.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"]}); +YUI.add("moodle-mod_customcert-rearrange",function(r,t){var s=function(){s.superclass.constructor.apply(this,[arguments])};r.extend(s,r.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.setPdfDimensions(),this.setBoundaries(),this.setpositions(),this.createevents(),window.addEventListener("resize",this.checkWindownResize.bind(this))},setpositions:function(){var t,e,i,s,n,o,a=1==this.page.direction;for(t in this.elements){switch(e=this.elements[t],i=this.pdfx+e.posx*this.pixelsinmm,s=this.pdfy+e.posy*this.pixelsinmm,n=parseFloat(r.one("#element-"+e.id).getComputedStyle("width")),(o=e.width*this.pixelsinmm)&&othis.pdfrightboundary||(othis.pdfy+this.pdfheight)},savepositions:function(o){var t,e,i,s,n,a,d,p=1==this.page.direction,h={tid:this.templateid,values:[]};for(t in this.elements){switch(e=this.elements[t],s=(i=r.one("#element-"+e.id)).getX()-this.pdfx,n=i.getY()-this.pdfy,a=i.getData("refpoint"),d=parseFloat(i.getComputedStyle("width")),p&&(s=this.pdfx+this.pdfwidth-i.getX()),a){case"1":s+=d/2;break;case"2":p?s-=d:s+=d}h.values.push({id:e.id,posx:Math.round(parseFloat(s/this.pixelsinmm)),posy:Math.round(parseFloat(n/this.pixelsinmm))})}h.values=JSON.stringify(h.values),r.io(M.cfg.wwwroot+"/mod/customcert/ajax.php",{method:"POST",data:h,on:{failure:function(t,e){this.ajaxfailure(e)},success:function(){var t,e,i=o.currentTarget.ancestor("form",!0),s=i.getAttribute("action"),n=i.one("[name=pid]");n?(t=n.get("value"),window.location=s+"?pid="+t):(e=i.one("[name=tid]").get("value"),window.location=s+"?tid="+e)}},context:this}),o.preventDefault()},ajaxfailure:function(t){var e={name:t.status+" "+t.statusText,message:t.responseText};return new M.core.exception(e)}}),r.namespace("M.mod_customcert.rearrange").init=function(t,e,i){new s(t,e,i)}},"@VERSION@",{requires:["dd-delegate","dd-drag"]}); \ No newline at end of file diff --git a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange.js b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange.js index 72812f34..6f5e949d 100644 --- a/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange.js +++ b/yui/build/moodle-mod_customcert-rearrange/moodle-mod_customcert-rearrange.js @@ -94,6 +94,8 @@ Y.extend(Rearrange, Y.Base, { * Sets the current position of the elements. */ setpositions: function() { + var isRtl = this.page.direction == 1; + // Go through the elements and set their positions. for (var key in this.elements) { var element = this.elements[key]; @@ -106,12 +108,17 @@ Y.extend(Rearrange, Y.Base, { nodewidth = maxwidth; } + // Recalculate posx if the page's direction is right-to-left. + if (isRtl) { + posx = this.pdfx + this.pdfwidth - element.posx * this.pixelsinmm; + } + switch (element.refpoint) { case '1': // Top-center. posx -= nodewidth / 2; break; case '2': // Top-right. - posx = posx - nodewidth + 2; + posx = posx - nodewidth; break; } @@ -227,6 +234,8 @@ Y.extend(Rearrange, Y.Base, { * @param {Event} e */ savepositions: function(e) { + var isRtl = this.page.direction == 1; + // The parameters to send the AJAX call. var params = { tid: this.templateid, @@ -245,12 +254,21 @@ Y.extend(Rearrange, Y.Base, { var nodewidth = parseFloat(node.getComputedStyle('width')); + // Recalculate posx if the page's direction is right-to-left. + if (isRtl) { + posx = this.pdfx + this.pdfwidth - node.getX(); + } + switch (refpoint) { case '1': // Top-center. posx += nodewidth / 2; break; case '2': // Top-right. - posx += nodewidth; + if (isRtl) { + posx -= nodewidth; + } else { + posx += nodewidth; + } break; } diff --git a/yui/src/rearrange/js/rearrange.js b/yui/src/rearrange/js/rearrange.js index 127c7ccd..4bb70f0f 100644 --- a/yui/src/rearrange/js/rearrange.js +++ b/yui/src/rearrange/js/rearrange.js @@ -92,6 +92,8 @@ Y.extend(Rearrange, Y.Base, { * Sets the current position of the elements. */ setpositions: function() { + var isRtl = this.page.direction == 1; + // Go through the elements and set their positions. for (var key in this.elements) { var element = this.elements[key]; @@ -104,12 +106,17 @@ Y.extend(Rearrange, Y.Base, { nodewidth = maxwidth; } + // Recalculate posx if the page's direction is right-to-left. + if (isRtl) { + posx = this.pdfx + this.pdfwidth - element.posx * this.pixelsinmm; + } + switch (element.refpoint) { case '1': // Top-center. posx -= nodewidth / 2; break; case '2': // Top-right. - posx = posx - nodewidth + 2; + posx = posx - nodewidth; break; } @@ -225,6 +232,8 @@ Y.extend(Rearrange, Y.Base, { * @param {Event} e */ savepositions: function(e) { + var isRtl = this.page.direction == 1; + // The parameters to send the AJAX call. var params = { tid: this.templateid, @@ -243,12 +252,21 @@ Y.extend(Rearrange, Y.Base, { var nodewidth = parseFloat(node.getComputedStyle('width')); + // Recalculate posx if the page's direction is right-to-left. + if (isRtl) { + posx = this.pdfx + this.pdfwidth - node.getX(); + } + switch (refpoint) { case '1': // Top-center. posx += nodewidth / 2; break; case '2': // Top-right. - posx += nodewidth; + if (isRtl) { + posx -= nodewidth; + } else { + posx += nodewidth; + } break; }