Your IP : 192.168.165.1


Current Path : C:/xampp/htdocs/moodle/admin/tool/lp/amd/build/
Upload File :
Current File : C:/xampp/htdocs/moodle/admin/tool/lp/amd/build/competencypicker.min.js.map

{"version":3,"sources":["../src/competencypicker.js"],"names":["define","$","Notification","Ajax","Templates","Dialogue","Str","Tree","Pending","Picker","pageContextId","singleFramework","pageContextIncludes","multiSelect","self","_eventNode","_frameworks","_reset","_pageContextId","_pageContextIncludes","_multiSelect","_frameworkId","_singleFramework","prototype","_competencies","_disallowedCompetencyIDs","_popup","_searchText","_selectedCompetencies","_onlyVisible","_afterRender","tree","_find","show","on","evt","params","selected","preventDefault","validIds","each","index","item","compId","data","valid","i","id","push","length","attr","removeAttr","change","e","target","val","_loadCompetencies","then","_refresh","bind","catch","exception","click","always","close","pendingPromise","_trigger","competencyIds","competencyId","resolve","currentItems","slice","node","toggleItem","updateFocus","display","when","get_string","_render","title","render","_fetchCompetencies","frameworkId","searchText","call","methodname","args","searchtext","competencyframeworkid","done","competencies","addCompetencyChildren","parent","parentid","haschildren","children","comp","fail","selector","getContent","find","_getFramework","fid","frm","f","_loadFrameworks","promise","framework","sort","context","contextid","includes","onlyvisible","frameworks","type","handler","_preRender","html","replaceWith","search","setDisallowedCompetencyIDs","ids","trigger"],"mappings":"AA2BAA,OAAM,4BAAC,CAAC,QAAD,CACC,mBADD,CAEC,WAFD,CAGC,gBAHD,CAIC,kBAJD,CAKC,UALD,CAMC,cAND,CAOC,cAPD,CAAD,CASE,SAASC,CAAT,CAAYC,CAAZ,CAA0BC,CAA1B,CAAgCC,CAAhC,CAA2CC,CAA3C,CAAqDC,CAArD,CAA0DC,CAA1D,CAAgEC,CAAhE,CAAyE,CAS7E,GAAIC,CAAAA,CAAM,CAAG,SAASC,CAAT,CAAwBC,CAAxB,CAAyCC,CAAzC,CAA8DC,CAA9D,CAA2E,CACpF,GAAIC,CAAAA,CAAI,CAAG,IAAX,CACAA,CAAI,CAACC,UAAL,CAAkBd,CAAC,CAAC,aAAD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CAGV4F,UAAU,CAAEnG,CAAI,CAACE,WAHP,CAIVuG,MAAM,CAAEzG,CAAI,CAACa,WAJH,CAKVhB,eAAe,CAAEG,CAAI,CAACQ,gBALZ,CAAd,CAQA,MAAOlB,CAAAA,CAAS,CAAC4E,MAAV,CAAiB,2BAAjB,CAA8C6B,CAA9C,CACV,CArBM,CAsBV,CAxBD,CAiCApG,CAAM,CAACc,SAAP,CAAiBN,MAAjB,CAA0B,UAAW,CACjC,KAAKO,aAAL,CAAqB,EAArB,CACA,KAAKC,wBAAL,CAAgC,EAAhC,CACA,KAAKC,MAAL,CAAc,IAAd,CACA,KAAKC,WAAL,CAAmB,EAAnB,CACA,KAAKC,qBAAL,CAA6B,EAChC,CAND,CAgBAnB,CAAM,CAACc,SAAP,CAAiBiG,0BAAjB,CAA8C,SAASC,CAAT,CAAc,CACxD,KAAKhG,wBAAL,CAAgCgG,CACnC,CAFD,CAWAhH,CAAM,CAACc,SAAP,CAAiB2C,QAAjB,CAA4B,SAASgD,CAAT,CAAetE,CAAf,CAAqB,CAC7C,KAAK7B,UAAL,CAAgB2G,OAAhB,CAAwBR,CAAxB,CAA8B,CAACtE,CAAD,CAA9B,CACH,CAFD,CAIA,MAAqDnC,CAAAA,CAExD,CA7bK,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 <http://www.gnu.org/licenses/>.\n\n/**\n * Competency picker.\n *\n * To handle 'save' events use: picker.on('save')\n * This will receive a object with either a single 'competencyId', or an array in 'competencyIds'\n * depending on the value of multiSelect.\n *\n * @package    tool_lp\n * @copyright  2015 Frédéric Massart - FMCorz.net\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery',\n        'core/notification',\n        'core/ajax',\n        'core/templates',\n        'tool_lp/dialogue',\n        'core/str',\n        'tool_lp/tree',\n        'core/pending'\n        ],\n        function($, Notification, Ajax, Templates, Dialogue, Str, Tree, Pending) {\n\n    /**\n     * Competency picker class.\n     * @param {Number} pageContextId The page context ID.\n     * @param {Number|false} singleFramework The ID of the framework when limited to one.\n     * @param {String} pageContextIncludes One of 'children', 'parents', 'self'.\n     * @param {Boolean} multiSelect Support multi-select in the tree.\n     */\n    var Picker = function(pageContextId, singleFramework, pageContextIncludes, multiSelect) {\n        var self = this;\n        self._eventNode = $('<div></div>');\n        self._frameworks = [];\n        self._reset();\n\n        self._pageContextId = pageContextId;\n        self._pageContextIncludes = pageContextIncludes || 'children';\n        self._multiSelect = (typeof multiSelect === 'undefined' || multiSelect === true);\n        if (singleFramework) {\n            self._frameworkId = singleFramework;\n            self._singleFramework = true;\n        }\n    };\n\n    /** @type {Array} The competencies fetched. */\n    Picker.prototype._competencies = null;\n    /** @type {Array} The competencies that cannot be picked. */\n    Picker.prototype._disallowedCompetencyIDs = null;\n    /** @type {Node} The node we attach the events to. */\n    Picker.prototype._eventNode = null;\n    /** @type {Array} The list of frameworks fetched. */\n    Picker.prototype._frameworks = null;\n    /** @type {Number} The current framework ID. */\n    Picker.prototype._frameworkId = null;\n    /** @type {Number} The page context ID. */\n    Picker.prototype._pageContextId = null;\n    /** @type {Number} Relevant contexts inclusion. */\n    Picker.prototype._pageContextIncludes = null;\n    /** @type {Dialogue} The reference to the dialogue. */\n    Picker.prototype._popup = null;\n    /** @type {String} The string we filter the competencies with. */\n    Picker.prototype._searchText = '';\n    /** @type {Object} The competency that was selected. */\n    Picker.prototype._selectedCompetencies = null;\n    /** @type {Boolean} Whether we can browse frameworks or not. */\n    Picker.prototype._singleFramework = false;\n    /** @type {Boolean} Do we allow multi select? */\n    Picker.prototype._multiSelect = true;\n    /** @type {Boolean} Do we allow to display hidden framework? */\n    Picker.prototype._onlyVisible = true;\n\n    /**\n     * Hook to executed after the view is rendered.\n     *\n     * @method _afterRender\n     */\n    Picker.prototype._afterRender = function() {\n        var self = this;\n\n        // Initialise the tree.\n        var tree = new Tree(self._find('[data-enhance=linktree]'), self._multiSelect);\n\n        // To prevent jiggling we only show the tree after it is enhanced.\n        self._find('[data-enhance=linktree]').show();\n\n        tree.on('selectionchanged', function(evt, params) {\n            var selected = params.selected;\n            evt.preventDefault();\n            var validIds = [];\n            $.each(selected, function(index, item) {\n                var compId = $(item).data('id'),\n                    valid = true;\n\n                if (typeof compId === 'undefined') {\n                    // Do not allow picking nodes with no id.\n                    valid = false;\n                } else {\n                    $.each(self._disallowedCompetencyIDs, function(i, id) {\n                        if (id == compId) {\n                            valid = false;\n                        }\n                    });\n                }\n                if (valid) {\n                    validIds.push(compId);\n                }\n            });\n\n            self._selectedCompetencies = validIds;\n\n            // TODO Implement disabling of nodes in the tree module somehow.\n            if (!self._selectedCompetencies.length) {\n                self._find('[data-region=\"competencylinktree\"] [data-action=\"add\"]').attr('disabled', 'disabled');\n            } else {\n                self._find('[data-region=\"competencylinktree\"] [data-action=\"add\"]').removeAttr('disabled');\n            }\n        });\n\n        // Add listener for framework change.\n        if (!self._singleFramework) {\n            self._find('[data-action=\"chooseframework\"]').change(function(e) {\n                self._frameworkId = $(e.target).val();\n                self._loadCompetencies().then(self._refresh.bind(self)).catch(Notification.exception);\n            });\n        }\n\n        // Add listener for search.\n        self._find('[data-region=\"filtercompetencies\"] button').click(function(e) {\n            e.preventDefault();\n            $(e.target).attr('disabled', 'disabled');\n            self._searchText = self._find('[data-region=\"filtercompetencies\"] input').val() || '';\n            return self._refresh().always(function() {\n                $(e.target).removeAttr('disabled');\n            });\n        });\n\n        // Add listener for cancel.\n        self._find('[data-region=\"competencylinktree\"] [data-action=\"cancel\"]').click(function(e) {\n            e.preventDefault();\n            self.close();\n        });\n\n        // Add listener for add.\n        self._find('[data-region=\"competencylinktree\"] [data-action=\"add\"]').click(function(e) {\n            e.preventDefault();\n            var pendingPromise = new Pending();\n            if (!self._selectedCompetencies.length) {\n                return;\n            }\n\n            if (self._multiSelect) {\n                self._trigger('save', {competencyIds: self._selectedCompetencies});\n            } else {\n                // We checked above that the array has at least one value.\n                self._trigger('save', {competencyId: self._selectedCompetencies[0]});\n            }\n\n            // The dialogue here is a YUI dialogue and doesn't support Promises at all.\n            // However, it is typically synchronous so this shoudl suffice.\n            self.close();\n            pendingPromise.resolve();\n        });\n\n        // The list of selected competencies will be modified while looping (because of the listeners above).\n        var currentItems = self._selectedCompetencies.slice(0);\n\n        $.each(currentItems, function(index, id) {\n            var node = self._find('[data-id=' + id + ']');\n            if (node.length) {\n                tree.toggleItem(node);\n                tree.updateFocus(node);\n            }\n        });\n\n    };\n\n    /**\n     * Close the dialogue.\n     *\n     * @method close\n     */\n    Picker.prototype.close = function() {\n        var self = this;\n        self._popup.close();\n        self._reset();\n    };\n\n    /**\n     * Opens the picker.\n     *\n     * @method display\n     * @return {Promise}\n     */\n    Picker.prototype.display = function() {\n        var self = this;\n        return $.when(Str.get_string('competencypicker', 'tool_lp'), self._render())\n        .then(function(title, render) {\n            self._popup = new Dialogue(\n                title,\n                render[0],\n                self._afterRender.bind(self)\n            );\n            return;\n        }).catch(Notification.exception);\n    };\n\n    /**\n     * Fetch the competencies.\n     *\n     * @param {Number} frameworkId The frameworkId.\n     * @param {String} searchText Limit the competencies to those matching the text.\n     * @method _fetchCompetencies\n     * @return {Promise}\n     */\n    Picker.prototype._fetchCompetencies = function(frameworkId, searchText) {\n        var self = this;\n\n        return Ajax.call([\n            {methodname: 'core_competency_search_competencies', args: {\n                searchtext: searchText,\n                competencyframeworkid: frameworkId\n            }}\n        ])[0].done(function(competencies) {\n          /**\n           * @param {Object} parent\n           * @param {Array} competencies\n           */\n            function addCompetencyChildren(parent, competencies) {\n                for (var i = 0; i < competencies.length; i++) {\n                    if (competencies[i].parentid == parent.id) {\n                        parent.haschildren = true;\n                        competencies[i].children = [];\n                        competencies[i].haschildren = false;\n                        parent.children[parent.children.length] = competencies[i];\n                        addCompetencyChildren(competencies[i], competencies);\n                    }\n                }\n            }\n\n            // Expand the list of competencies into a tree.\n            var i, comp;\n            var tree = [];\n            for (i = 0; i < competencies.length; i++) {\n                comp = competencies[i];\n                if (comp.parentid == \"0\") { // Loose check for now, because WS returns a string.\n                    comp.children = [];\n                    comp.haschildren = 0;\n                    tree[tree.length] = comp;\n                    addCompetencyChildren(comp, competencies);\n                }\n            }\n\n            self._competencies = tree;\n\n        }).fail(Notification.exception);\n    };\n\n    /**\n     * Find a node in the dialogue.\n     *\n     * @param {String} selector\n     * @return {JQuery}\n     * @method _find\n     */\n    Picker.prototype._find = function(selector) {\n        return $(this._popup.getContent()).find(selector);\n    };\n\n    /**\n     * Convenience method to get a framework object.\n     *\n     * @param {Number} fid The framework ID.\n     * @return {Object}\n     * @method _getFramework\n     */\n    Picker.prototype._getFramework = function(fid) {\n        var frm;\n        $.each(this._frameworks, function(i, f) {\n            if (f.id == fid) {\n                frm = f;\n                return;\n            }\n        });\n        return frm;\n    };\n\n    /**\n     * Load the competencies.\n     *\n     * @method _loadCompetencies\n     * @return {Promise}\n     */\n    Picker.prototype._loadCompetencies = function() {\n        return this._fetchCompetencies(this._frameworkId, this._searchText);\n    };\n\n    /**\n     * Load the frameworks.\n     *\n     * @method _loadFrameworks\n     * @return {Promise}\n     */\n    Picker.prototype._loadFrameworks = function() {\n        var promise,\n            self = this;\n\n        // Quit early because we already have the data.\n        if (self._frameworks.length > 0) {\n            return $.when();\n        }\n\n        if (self._singleFramework) {\n            promise = Ajax.call([\n                {methodname: 'core_competency_read_competency_framework', args: {\n                    id: this._frameworkId\n                }}\n            ])[0].then(function(framework) {\n                return [framework];\n            });\n        } else {\n            promise = Ajax.call([\n                {methodname: 'core_competency_list_competency_frameworks', args: {\n                    sort: 'shortname',\n                    context: {contextid: self._pageContextId},\n                    includes: self._pageContextIncludes,\n                    onlyvisible: self._onlyVisible\n                }}\n            ])[0];\n        }\n\n        return promise.done(function(frameworks) {\n            self._frameworks = frameworks;\n        }).fail(Notification.exception);\n    };\n\n    /**\n     * Register an event listener.\n     *\n     * @param {String} type The event type.\n     * @param {Function} handler The event listener.\n     * @method on\n     */\n    Picker.prototype.on = function(type, handler) {\n        this._eventNode.on(type, handler);\n    };\n\n    /**\n     * Hook to executed before render.\n     *\n     * @method _preRender\n     * @return {Promise}\n     */\n    Picker.prototype._preRender = function() {\n        var self = this;\n        return self._loadFrameworks().then(function() {\n            if (!self._frameworkId && self._frameworks.length > 0) {\n                self._frameworkId = self._frameworks[0].id;\n            }\n\n            // We could not set a framework ID, that probably means there are no frameworks accessible.\n            if (!self._frameworkId) {\n                self._frameworks = [];\n                return $.when();\n            }\n\n            return self._loadCompetencies();\n        });\n    };\n\n    /**\n     * Refresh the view.\n     *\n     * @method _refresh\n     * @return {Promise}\n     */\n    Picker.prototype._refresh = function() {\n        var self = this;\n        return self._render().then(function(html) {\n            self._find('[data-region=\"competencylinktree\"]').replaceWith(html);\n            self._afterRender();\n            return;\n        });\n    };\n\n    /**\n     * Render the dialogue.\n     *\n     * @method _render\n     * @return {Promise}\n     */\n    Picker.prototype._render = function() {\n        var self = this;\n        return self._preRender().then(function() {\n\n            if (!self._singleFramework) {\n                $.each(self._frameworks, function(i, framework) {\n                    if (framework.id == self._frameworkId) {\n                        framework.selected = true;\n                    } else {\n                        framework.selected = false;\n                    }\n                });\n            }\n\n            var context = {\n                competencies: self._competencies,\n                framework: self._getFramework(self._frameworkId),\n                frameworks: self._frameworks,\n                search: self._searchText,\n                singleFramework: self._singleFramework,\n            };\n\n            return Templates.render('tool_lp/competency_picker', context);\n        });\n    };\n\n    /**\n     * Reset the dialogue properties.\n     *\n     * This does not reset everything, just enough to reset the UI.\n     *\n     * @method _reset\n     */\n    Picker.prototype._reset = function() {\n        this._competencies = [];\n        this._disallowedCompetencyIDs = [];\n        this._popup = null;\n        this._searchText = '';\n        this._selectedCompetencies = [];\n    };\n\n    /**\n     * Set what competencies cannot be picked.\n     *\n     * This needs to be set after reset/close.\n     *\n     * @param {Number[]} ids The IDs.\n     * @method _setDisallowedCompetencyIDs\n     */\n    Picker.prototype.setDisallowedCompetencyIDs = function(ids) {\n        this._disallowedCompetencyIDs = ids;\n    };\n\n    /**\n     * Trigger an event.\n     *\n     * @param {String} type The type of event.\n     * @param {Object} data The data to pass to the listeners.\n     * @method _reset\n     */\n    Picker.prototype._trigger = function(type, data) {\n        this._eventNode.trigger(type, [data]);\n    };\n\n    return /** @alias module:tool_lp/competencypicker */ Picker;\n\n});\n"],"file":"competencypicker.min.js"}