Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"rearrange-area.min.js","sources":["../src/rearrange-area.js"],"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 <http://www.gnu.org/licenses/>.\n\n/**\n * AMD module used when rearranging a custom certificate.\n *\n * @module     mod_customcert/rearrange-area\n * @copyright  2016 Mark Nelson <markn@moodle.com>\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                                '<div id=\\'elementcontent\\'></div>',\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"],"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","this","_editElement","bind","event","elementid","currentTarget","id","substr","contextid","attr","params","loadFragment","done","html","js","get_string","title","use","_editElementDialogueConfig","undefined","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","call","methodname","args","inputs","serializeArray","values","init"],"mappings":";;;;;;;AAsBAA,uCAAO,CAAC,SAAU,WAAY,gBAAiB,0BAA2B,oBAClE,WAAY,iBAAkB,cAC9B,SAASC,EAAGC,EAAGC,SAAUC,SAAUC,aAAcC,IAAKC,SAAUC,UAOxDC,cAAgB,SAASC,eACpBC,MAAQV,EAAES,eACVE,qBAGTH,cAAcI,UAAUC,6BAA+B,EACvDL,cAAcI,UAAUE,+BAAiC,EACzDN,cAAcI,UAAUG,8BAAgC,EACxDP,cAAcI,UAAUI,WAAa,eAErCR,cAAcI,UAAUD,WAAa,g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