Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"form-field.min.js","sources":["../src/form-field.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 * A module that enables the setting of form field values on the client side.\n *\n * @module     mod_lti/form-field\n * @copyright  2016 Jun Pataleta <jun@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since      3.2\n */\ndefine(['jquery'],\n    function($) {\n        /**\n         * Form field class.\n         *\n         * @param {string} name Field name.\n         * @param {number} type The field type.\n         * @param {boolean} resetIfUndefined Flag to reset the field to the default value if undefined in the return data.\n         * @param {string|number|boolean} defaultValue The default value to use for the field.\n         * @constructor\n         */\n        var FormField = function(name, type, resetIfUndefined, defaultValue) {\n            this.name = name;\n            this.id = 'id_' + this.name;\n            this.selector = '#' + this.id;\n            this.type = type;\n            this.resetIfUndefined = resetIfUndefined;\n            this.defaultValue = defaultValue;\n        };\n\n        /**\n         * Form field types.\n         *\n         * @type {{TEXT: number, SELECT: number, CHECKBOX: number, EDITOR: number}}\n         */\n        FormField.TYPES = {\n            TEXT: 1,\n            SELECT: 2,\n            CHECKBOX: 3,\n            EDITOR: 4\n        };\n\n        /**\n         * Sets the values for a form field.\n         *\n         * @param {string|boolean|number} value The value to be set into the field.\n         */\n        FormField.prototype.setFieldValue = function(value) {\n            if (value === null) {\n                if (this.resetIfUndefined) {\n                    value = this.defaultValue;\n                } else {\n                    // No need set the field value if value is null and there's no need to reset the field.\n                    return;\n                }\n            }\n\n            switch (this.type) {\n                case FormField.TYPES.CHECKBOX:\n                    if (value) {\n                        $(this.selector).prop('checked', true);\n                    } else {\n                        $(this.selector).prop('checked', false);\n                    }\n                    break;\n                case FormField.TYPES.EDITOR:\n                    if (typeof value.text !== 'undefined') {\n                        /* global tinyMCE:false */\n\n                        // Set text in editor's editable content, if applicable.\n                        // Check if it is an Atto editor.\n                        var attoEditor = $(this.selector + 'editable');\n                        if (attoEditor.length) {\n                            attoEditor.html(value.text);\n                        } else if (typeof tinyMCE !== 'undefined') {\n                            // If the editor is not Atto, try to fallback to TinyMCE.\n                            if (tinyMCE.majorVersion == \"3\") {\n                                // Tiny 3.\n                                tinyMCE.execInstanceCommand(this.id, 'mceInsertContent', false, value.text);\n                            } else {\n                                // Tiny 4+.\n                                tinyMCE.get(this.id).setContent(value.text);\n                            }\n                        }\n\n                        // Set text to actual editor text area.\n                        $(this.selector).val(value.text);\n                    }\n                    break;\n                default:\n                    $(this.selector).val(value);\n                    break;\n            }\n        };\n\n        return FormField;\n    }\n);\n"],"names":["define","$","FormField","name","type","resetIfUndefined","defaultValue","id","this","selector","TYPES","TEXT","SELECT","CHECKBOX","EDITOR","prototype","setFieldValue","value","prop","text","attoEditor","length","html","tinyMCE","majorVersion","execInstanceCommand","get","setContent","val"],"mappings":";;;;;;;;AAuBAA,4BAAO,CAAC,WACJ,SAASC,OAUDC,UAAY,SAASC,KAAMC,KAAMC,iBAAkBC,mBAC9CH,KAAOA,UACPI,GAAK,MAAQC,KAAKL,UAClBM,SAAW,IAAMD,KAAKD,QACtBH,KAAOA,UACPC,iBAAmBA,sBACnBC,aAAeA,qBAQxBJ,UAAUQ,MAAQ,CACdC,KAAM,EACNC,OAAQ,EACRC,SAAU,EACVC,OAAQ,GAQZZ,UAAUa,UAAUC,cAAgB,SAASC,UAC3B,OAAVA,MAAgB,KACZT,KAAKH,wBACLY,MAAQT,KAAKF,oBAObE,KAAKJ,WACJF,UAAUQ,MAAMG,SACbI,MACAhB,EAAEO,KAAKC,UAAUS,KAAK,WAAW,GAEjCjB,EAAEO,KAAKC,UAAUS,KAAK,WAAW,cAGpChB,UAAUQ,MAAMI,eACS,IAAfG,MAAME,KAAsB,KAK/BC,WAAanB,EAAEO,KAAKC,SAAW,YAC/BW,WAAWC,OACXD,WAAWE,KAAKL,MAAME,MACI,oBAAZI,UAEc,KAAxBA,QAAQC,aAERD,QAAQE,oBAAoBjB,KAAKD,GAAI,oBAAoB,EAAOU,MAAME,MAGtEI,QAAQG,IAAIlB,KAAKD,IAAIoB,WAAWV,MAAME,OAK9ClB,EAAEO,KAAKC,UAAUmB,IAAIX,MAAME,oBAI/BlB,EAAEO,KAAKC,UAAUmB,IAAIX,SAK1Bf"}