{"version":3,"file":"edit.min.js","sources":["https:\/\/kundenportal.comm-unity.at\/local\/wb_faq\/amd\/src\/edit.js"],"sourcesContent":["\n\/\/ 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 * @package local_wunderbyte_table\n * @copyright Wunderbyte GmbH \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\n\nimport ModalForm from 'core_form\/modalform';\nimport ModalFactory from 'core\/modal_factory';\nimport ModalEvents from 'core\/modal_events';\nimport {get_string as getString, get_strings as getStrings} from 'core\/str';\nimport {showSuccessNotification, showErrorNotification} from 'local_wb_faq\/notifications';\nimport {deleteEntry, toggleVisibility} from 'local_wb_faq\/admin';\nimport {reloadData} from 'local_wb_faq\/faq';\n\nconst SELECTORS = {\n GROUPSUBMIT: '[data-action=\"groupSubmit\"]'\n};\n\n\/**\n * Gets called from mustache template.\n *\n *\/\nexport const init = () => {\n\n \/\/ Find all container.\n const containers = document.querySelectorAll('.local_wb_faq_container');\n\n containers.forEach(element => {\n if (!element.dataset.initialized) {\n element.addEventListener('click', editModalListener);\n element.dataset.initialized = true;\n }\n });\n};\n\n\/**\n * Modal listener to open the edit Modals.\n * @param {*} event\n *\/\nconst editModalListener = event => {\n\n let button = event.target;\n\n if (button.tagName.toLowerCase() === 'i') {\n button = button.parentElement;\n }\n\n if (button.classList.contains('local_wb_faq_edit_question')) {\n\n openEditQuestionsModal(event);\n\n } else if (button.classList.contains('local_wb_faq_delete_question')) {\n\n confirmDeleteEntry(event);\n } else if (button.classList.contains('local_wb_faq_toggle_entry_visibility')) {\n\n confirmToggleVisibility(event);\n } else if (button.classList.contains('local_wb_faq_toggle_category_visibility')) {\n\n confirmToggleVisibility(event);\n } else if (button.classList.contains('local_wb_faq_edit_category')) {\n\n openEditCategoriesModal(event);\n\n } else if (button.classList.contains('local_wb_faq_delete_category')) {\n\n confirmDeleteEntry(event);\n }\n};\n\n\/**\n * Opens the Modal to edit questions.\n * @param {*} event the click event\n *\/\n function openEditQuestionsModal(event) {\n\n let button = event.target;\n let entryid = 0;\n let parentid = 0;\n let uid = 0;\n\n if (button.tagName.toLowerCase() !== 'a') {\n button = button.parentElement;\n }\n\n if (button.dataset.id) {\n entryid = button.dataset.id;\n }\n\n if (button.dataset.faqroot) {\n parentid = button.dataset.faqroot;\n }\n\n if (button.dataset.uid) {\n uid = button.dataset.uid;\n }\n\n const modalForm = new ModalForm({\n\n \/\/ Name of the class where form is defined (must extend \\core_form\\dynamic_form):\n formClass: \"local_wb_faq\\\\form\\\\editQuestionForm\",\n \/\/ Add as many arguments as you need, they will be passed to the form:\n args: {\n 'id': entryid,\n 'type': 1,\n 'nobuttons': true,\n 'parentid': parentid\n },\n \/\/ Pass any configuration settings to the modal dialogue, for example, the title:\n modalConfig: {title: getString('addquestion', 'local_wb_faq')},\n \/\/ DOM element that should get the focus after the modal dialogue is closed:\n returnFocus: button\n });\n\n \/\/ Listen to events if you want to execute something on form submit.\n \/\/ Event detail will contain everything the process() function returned:\n modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, (e) => {\n\n e.preventDefault();\n\n showSuccessNotification();\n if (uid) {\n reloadData(uid, parentid);\n } else {\n window.location.reload();\n }\n });\n\n \/\/ Show the form.\n modalForm.show().then(() => {\n\n return;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n\n showErrorNotification();\n });\n}\n\n\/**\n * Opens the Modal to edit questions.\n * @param {*} event the click event\n *\/\n function openEditCategoriesModal(event) {\n\n let button = event.target;\n let entryid = 0;\n let parentid = 0;\n let uid = 0;\n\n if (button.tagName.toLowerCase() !== 'a') {\n button = button.parentElement;\n }\n\n if (button.dataset.id) {\n entryid = button.dataset.id;\n }\n\n if (button.dataset.faqroot) {\n parentid = button.dataset.faqroot;\n }\n\n if (button.dataset.uid) {\n uid = button.dataset.uid;\n }\n\n const modalForm = new ModalForm({\n\n \/\/ Name of the class where form is defined (must extend \\core_form\\dynamic_form):\n formClass: \"local_wb_faq\\\\form\\\\editCategoriesForm\",\n \/\/ Add as many arguments as you need, they will be passed to the form:\n args: {\n 'id': entryid,\n 'type': 0,\n 'nobuttons': true,\n 'parentid': parentid\n },\n \/\/ Pass any configuration settings to the modal dialogue, for example, the title:\n modalConfig: {title: getString('addcategory', 'local_wb_faq')},\n \/\/ DOM element that should get the focus after the modal dialogue is closed:\n returnFocus: button\n });\n\n modalForm.addEventListener('change', e => {\n\n if (e.target.dataset.onChangeAction == \"reloadForm\") {\n const button = document.querySelector(SELECTORS.GROUPSUBMIT);\n modalForm.processNoSubmitButton(button);\n }\n });\n\n \/\/ Listen to events if you want to execute something on form submit.\n \/\/ Event detail will contain everything the process() function returned:\n modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, (e) => {\n\n e.preventDefault();\n\n showSuccessNotification();\n if (uid) {\n reloadData(uid, parentid);\n } else {\n window.location.reload();\n }\n });\n\n \/\/ Show the form.\n modalForm.show().then(() => {\n\n return;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n\n showErrorNotification();\n });\n}\n\n\/**\n * @param {*} event\n *\/\n export function confirmDeleteEntry(event) {\n\n let button = event.target;\n let entryid = 0;\n\n \/\/ We assume we delete a question.\n if (!((button.tagName.toLowerCase() == 'a')\n || (button.tagName.toLowerCase() == 'button'))) {\n button = button.parentElement;\n }\n \/\/ No difference at the moment between deleting question or category, but there could be.\n if (button.classList.contains('local_wb_faq_delete_question')) {\n if (button.dataset.id) {\n entryid = button.dataset.id;\n }\n } else if (button.classList.contains('local_wb_faq_delete_category')) {\n if (button.dataset.id) {\n entryid = button.dataset.id;\n }\n } else if (button.dataset\n && button.dataset.action\n && button.dataset.action == 'delete') {\n\n entryid = button.dataset.targetid;\n } else {\n return;\n }\n\n getStrings([\n {key: 'confirmdeleteentrytitle', component: 'local_wb_faq'},\n {key: 'confirmdeleteentrybody', component: 'local_wb_faq'},\n {key: 'confirmdeleteentry', component: 'local_wb_faq'}\n ]\n ).then(strings => {\n\n ModalFactory.create({type: ModalFactory.types.SAVE_CANCEL}).then(modal => {\n\n modal.setTitle(strings[0]);\n modal.setBody(strings[1]);\n modal.setSaveButtonText(strings[2]);\n modal.getRoot().on(ModalEvents.save, function() {\n\n \/\/ Looking for the question.\n let entry = button.closest('li.accordion-item');\n let elementid = 0;\n\n \/\/ We need to be looking for the category, not a question.\n if (!entry) {\n entry = button.closest('[data-action=\"goto\"]');\n\n if (!entry) {\n \/\/ If we still don't find the entry, we are in admin mode.\n entry = event.target.closest('tr');\n elementid = button.dataset.targetid;\n } else {\n elementid = entry.dataset.targetid;\n }\n } else {\n elementid = entry.dataset.id;\n }\n\n \/\/ This is to verify that we've actually found the right dom element.\n if (elementid == entryid) {\n entry.remove();\n \/\/ Todo: We should react only on a success response from delete.\n deleteEntry(entryid);\n showSuccessNotification();\n }\n });\n\n modal.show();\n return modal;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n\n showErrorNotification();\n });\n return true;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n\n showErrorNotification();\n });\n}\n\n\/**\n * @param {*} event\n *\/\n export function confirmToggleVisibility(event) {\n\n let button = event.target;\n let entryid = 0;\n\n \/\/ We assume we delete a question.\n if (button.tagName.toLowerCase() !== 'a') {\n button = button.parentElement;\n }\n\n \/\/ No difference at the moment between deleting question or category, but there could be.\n if (button.classList.contains('local_wb_faq_toggle_entry_visibility')) {\n if (button.dataset.id) {\n entryid = button.dataset.id;\n }\n } else if (button.classList.contains('local_wb_faq_toggle_category_visibility')) {\n if (button.dataset.id) {\n entryid = button.dataset.id;\n }\n } else {\n return;\n }\n\n getStrings([\n {key: 'confirmtogglevisibilitytitle', component: 'local_wb_faq'},\n {key: 'confirmtogglevisibilitybody', component: 'local_wb_faq'},\n {key: 'confirmtogglevisibility', component: 'local_wb_faq'}\n ]\n ).then(strings => {\n\n ModalFactory.create({type: ModalFactory.types.SAVE_CANCEL}).then(modal => {\n\n modal.setTitle(strings[0]);\n modal.setBody(strings[1]);\n modal.setSaveButtonText(strings[2]);\n modal.getRoot().on(ModalEvents.save, function() {\n\n \/\/ Looking for the question.\n let entry = button.closest('li.accordion-item');\n let elementid = 0;\n\n \/\/ We need to be looking for the category, not a question.\n if (!entry) {\n entry = button.closest('[data-action=\"goto\"]');\n elementid = entry.dataset.targetid;\n } else {\n elementid = entry.dataset.id;\n }\n\n \/\/ This is to verify that we've actually found the right dom element.\n if (elementid == entryid) {\n \/\/ Todo: We should react only on a success response from delete.\n toggleVisibility(entryid);\n\n let ielement = button.querySelector('i.toggle-visibility');\n\n if (ielement) {\n if (ielement.classList.contains('fa-eye-slash')) {\n ielement.classList.replace('fa-eye-slash', 'fa-eye');\n } else {\n ielement.classList.replace('fa-eye', 'fa-eye-slash');\n }\n showSuccessNotification();\n window.location.reload();\n } else {\n window.location.reload();\n }\n\n\n\n }\n });\n\n modal.show();\n return modal;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n\n showErrorNotification();\n });\n return true;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n\n showErrorNotification();\n });\n}"],"names":["SELECTORS","document","querySelectorAll","forEach","element","dataset","initialized","addEventListener","editModalListener","event","button","target","tagName","toLowerCase","parentElement","classList","contains","entryid","parentid","uid","id","faqroot","modalForm","ModalForm","formClass","args","modalConfig","title","returnFocus","events","FORM_SUBMITTED","e","preventDefault","window","location","reload","show","then","catch","console","log","openEditQuestionsModal","confirmDeleteEntry","confirmToggleVisibility","onChangeAction","querySelector","processNoSubmitButton","openEditCategoriesModal","action","targetid","key","component","strings","create","type","ModalFactory","types","SAVE_CANCEL","modal","setTitle","setBody","setSaveButtonText","getRoot","on","ModalEvents","save","entry","closest","elementid","remove","ielement","replace"],"mappings":";;;;;wVA+BMA,sBACW,4CAOG,KAGGC,SAASC,iBAAiB,2BAElCC,SAAQC,UACVA,QAAQC,QAAQC,cACjBF,QAAQG,iBAAiB,QAASC,mBAClCJ,QAAQC,QAAQC,aAAc,aASpCE,kBAAoBC,YAElBC,OAASD,MAAME,OAEkB,MAAjCD,OAAOE,QAAQC,gBACfH,OAASA,OAAOI,eAGhBJ,OAAOK,UAAUC,SAAS,uCA2BDP,WAEzBC,OAASD,MAAME,OACfM,QAAU,EACVC,SAAW,EACXC,IAAM,EAE2B,MAAjCT,OAAOE,QAAQC,gBACfH,OAASA,OAAOI,eAGhBJ,OAAOL,QAAQe,KACfH,QAAUP,OAAOL,QAAQe,IAGzBV,OAAOL,QAAQgB,UACfH,SAAWR,OAAOL,QAAQgB,SAG1BX,OAAOL,QAAQc,MACfA,IAAMT,OAAOL,QAAQc,WAGnBG,UAAY,IAAIC,mBAAU,CAG5BC,UAAW,uCAEXC,KAAM,IACIR,aACE,aACK,WACDC,UAGhBQ,YAAa,CAACC,OAAO,mBAAU,cAAe,iBAE9CC,YAAalB,SAKjBY,UAAUf,iBAAiBe,UAAUO,OAAOC,gBAAiBC,IAEzDA,EAAEC,8DAGEb,wBACWA,IAAKD,UAEhBe,OAAOC,SAASC,YAKxBb,UAAUc,OAAOC,MAAK,SAGnBC,OAAMP,IAELQ,QAAQC,IAAIT,iDArFZU,CAAuBhC,OAEhBC,OAAOK,UAAUC,SAAS,gCAEjC0B,mBAAmBjC,OACZC,OAAOK,UAAUC,SAAS,yCAG1BN,OAAOK,UAAUC,SAAS,2CADjC2B,wBAAwBlC,OAIjBC,OAAOK,UAAUC,SAAS,uCAoFPP,WAE1BC,OAASD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