AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"newchild.min.js","sources":["../src/newchild.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 * The newchild component.\n *\n * This is a drop target for moving a category to an as-yet-nonexistant child list under another category.\n *\n * @module qbank_managecategories/newchild\n * @class qbank_managecategories
/newchild\n */\n\nimport {BaseComponent, DragDrop} from 'core/reactive';\nimport {categorymanager} from 'qbank_managecategories/categorymanager';\nimport Tooltip from 'theme_boost/bootstrap/tooltip';\n\nexport default class extends BaseComponent {\n create(descriptor) {\n this.name = descriptor.element.id;\n this.selectors = {\n NEW_CHILD: '.qbank_managecategories-newchild',\n CATEGORY_ID: id => `#category-${id}`\n };\n this.classes = {\n DROP_TARGET: 'qbank_managecategories-droptarget',\n };\n this.ids = {\n CATEGORY: id => `category-${id}`,\n };\n }\n\n stateReady() {\n this.dragdrop = new DragDrop(this);\n }\n\n destroy() {\n // The draggable element must be unregistered.\n if (this.dragdrop !== undefined) {\n this.dragdrop.unregister();\n this.dragdrop = undefined;\n }\n }\n\n /**\n * Static method to create a component instance form the m
ustache template.\n *\n * @param {string} target the DOM main element or its ID\n * @param {object} selectors optional css selector overrides\n * @return {Component}\n */\n static init(target, selectors) {\n const targetElement = document.querySelector(target);\n return new this({\n element: targetElement,\n selectors,\n reactive: categorymanager,\n });\n }\n\n /**\n * Cannot drop a category as a new child of its own descendant.\n *\n * @param {Object} dropData\n * @return {boolean}\n */\n validateDropData(dropData) {\n if (this.getElement().closest(this.selectors.CATEGORY_ID(dropData.id))) {\n return false;\n }\n return true;\n }\n\n showDropZone(dropData, event) {\n const dropTarget = event.target.closest(this.selectors.NEW_CHILD);\n dropTarget.classList.add(this.classes.DROP_TARGET);\n Tooltip.getOrCreateInstance(dropTarget).show();\n }\n\n
hideDropZone(dropData, event) {\n const dropTarget = event.target.closest(this.selectors.NEW_CHILD);\n dropTarget.classList.remove(this.classes.DROP_TARGET);\n Tooltip.getOrCreateInstance(dropTarget).hide();\n }\n\n drop(dropData, event) {\n const dropTarget = event.target.closest(this.selectors.NEW_CHILD);\n\n if (!dropTarget) {\n return;\n }\n\n const source = document.getElementById(this.ids.CATEGORY(dropData.id));\n\n if (!source) {\n return;\n }\n\n const targetParentId = dropTarget.dataset.parent;\n\n // Insert the category as the first child of the new parent.\n categorymanager.moveCategory(dropData.id, targetParentId);\n }\n\n /**\n * Watch for categories moving to a new parent.\n *\n * @return {Array} A list of watchers.\n */\n getWatchers() {\n return [\n // Watch for any category having its parent changed.\n {watch: `categories.pa
rent:updated`, handler: this.checkNewChild},\n ];\n }\n\n /**\n * If an element now has this category as the parent, remove this new child target.\n *\n * @param {Object} args\n * @param {Element} args.element\n */\n checkNewChild({element}) {\n if (element.parent === parseInt(this.element.dataset.parent)) {\n this.remove();\n }\n }\n}\n"],"names":["BaseComponent","create","descriptor","name","element","id","selectors","NEW_CHILD","CATEGORY_ID","classes","DROP_TARGET","ids","CATEGORY","stateReady","dragdrop","DragDrop","this","destroy","undefined","unregister","target","document","querySelector","reactive","categorymanager","validateDropData","dropData","getElement","closest","showDropZone","event","dropTarget","classList","add","getOrCreateInstance","show","hideDropZone","remove","hide","drop","getElementById","targetParentId","dataset","parent","moveCategory","getWatchers","watch","handler","checkNewChild","parseInt"],"mappings":"+WA4B6BA,wBAC
zBC,OAAOC,iBACEC,KAAOD,WAAWE,QAAQC,QAC1BC,UAAY,CACbC,UAAW,mCACXC,YAAaH,wBAAmBA,UAE/BI,QAAU,CACXC,YAAa,0CAEZC,IAAM,CACPC,SAAUP,uBAAkBA,KAIpCQ,kBACSC,SAAW,IAAIC,mBAASC,MAGjCC,eAE0BC,IAAlBF,KAAKF,gBACAA,SAASK,kBACTL,cAAWI,eAWZE,OAAQd,kBAET,IAAIU,KAAK,CACZZ,QAFkBiB,SAASC,cAAcF,QAGzCd,UAAAA,UACAiB,SAAUC,mCAUlBC,iBAAiBC,iBACTV,KAAKW,aAAaC,QAAQZ,KAAKV,UAAUE,YAAYkB,SAASrB,KAMtEwB,aAAaH,SAAUI,aACbC,WAAaD,MAAMV,OAAOQ,QAAQZ,KAAKV,UAAUC,WACvDwB,WAAWC,UAAUC,IAAIjB,KAAKP,QAAQC,8BAC9BwB,oBAAoBH,YAAYI,OAG5CC,aAAaV,SAAUI,aACbC,WAAaD,MAAMV,OAAOQ,QAAQZ,KAAKV,UAAUC,WACvDwB,WAAWC,UAAUK,OAAOrB,KAAKP,QAAQC,8BACjCwB,oBAAoBH,YAAYO,OAG5CC,KAAKb,SAAUI,aACLC,WAAaD,MAAMV,OAAOQ,QAAQZ,KAAKV,UAAUC,eAElDwB,sBAIUV,SAASmB,eAAexB,KAAKL,IAAIC,SAASc,SAASrB,kBAM5DoC,eAAiBV,WAAWW,QAAQC,wCAG1BC,aAAalB,SAASrB,GAAIoC,gBAQ9CI,oBACW,CAEH,CAACC,kCAAoCC,QAAS/B,KAAKgC,gBAU3DA,wBAAc5C,QAACA,cACPA,QAAQuC,SAAWM,SAASjC,KAAKZ,QAAQsC,QAAQC,cAC5CN"}