%PDF- %PDF-
Direktori : /home/vacivi36/ava/reportbuilder/amd/build/local/editor/ |
Current File : /home/vacivi36/ava/reportbuilder/amd/build/local/editor/conditions.min.js.map |
{"version":3,"file":"conditions.min.js","sources":["../../../src/local/editor/conditions.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 * Report builder conditions editor\n *\n * @module core_reportbuilder/local/editor/conditions\n * @copyright 2021 Paul Holden <paulh@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport $ from 'jquery';\nimport CustomEvents from 'core/custom_interaction_events';\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport 'core/inplace_editable';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport {prefetchStrings} from 'core/prefetch';\nimport SortableList from 'core/sortable_list';\nimport {get_string as getString} from 'core/str';\nimport Templates from 'core/templates';\nimport {add as addToast} from 'core/toast';\nimport DynamicForm from 'core_form/dynamicform';\nimport * as reportEvents from 'core_reportbuilder/local/events';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {addCondition, deleteCondition, reorderCondition, resetConditions} from 'core_reportbuilder/local/repository/conditions';\n\n/**\n * Reload conditions settings region\n *\n * @param {Element} reportElement\n * @param {Object} templateContext\n * @return {Promise}\n */\nconst reloadSettingsConditionsRegion = (reportElement, templateContext) => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reload');\n const settingsConditionsRegion = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n\n return Templates.renderForPromise('core_reportbuilder/local/settings/conditions', {conditions: templateContext})\n .then(({html, js}) => {\n Templates.replaceNode(settingsConditionsRegion, html, js + templateContext.javascript);\n\n initConditionsForm();\n\n // Re-focus the add condition element after reloading the region.\n const reportAddCondition = reportElement.querySelector(reportSelectors.actions.reportAddCondition);\n reportAddCondition?.focus();\n\n return pendingPromise.resolve();\n });\n};\n\n/**\n * Initialise conditions form, must be called on each init because the form container is re-created when switching editor modes\n */\nconst initConditionsForm = () => {\n CustomEvents.define(reportSelectors.actions.reportAddCondition, [CustomEvents.events.accessibleChange]);\n\n // Handle dynamic conditions form.\n const reportElement = document.querySelector(reportSelectors.regions.report);\n const conditionFormContainer = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n if (!conditionFormContainer) {\n return;\n }\n const conditionForm = new DynamicForm(conditionFormContainer, '\\\\core_reportbuilder\\\\form\\\\condition');\n\n // Submit report conditions.\n conditionForm.addEventListener(conditionForm.events.FORM_SUBMITTED, event => {\n event.preventDefault();\n\n getString('conditionsapplied', 'core_reportbuilder')\n .then(addToast)\n .catch(Notification.exception);\n\n // After the form has been submitted, we should trigger report table reload.\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n });\n\n // Reset report conditions.\n conditionForm.addEventListener(conditionForm.events.NOSUBMIT_BUTTON_PRESSED, event => {\n event.preventDefault();\n\n Notification.saveCancelPromise(\n getString('resetconditions', 'core_reportbuilder'),\n getString('resetconditionsconfirm', 'core_reportbuilder'),\n getString('resetall', 'core_reportbuilder'),\n {triggerElement: event.detail}\n ).then(() => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reset');\n\n return resetConditions(reportElement.dataset.reportId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => addToast(getString('conditionsreset', 'core_reportbuilder')))\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }).catch(() => {\n return;\n });\n });\n};\n\n/**\n * Initialise module, prefetch all required strings\n *\n * @param {Boolean} initialized Ensure we only add our listeners once\n */\nexport const init = initialized => {\n prefetchStrings('core_reportbuilder', [\n 'conditionadded',\n 'conditiondeleted',\n 'conditionmoved',\n 'conditionsapplied',\n 'conditionsreset',\n 'deletecondition',\n 'deleteconditionconfirm',\n 'resetall',\n 'resetconditions',\n 'resetconditionsconfirm',\n ]);\n\n prefetchStrings('core', [\n 'delete',\n ]);\n\n initConditionsForm();\n if (initialized) {\n return;\n }\n\n // Add condition to report. Use custom events helper to ensure consistency across platforms.\n $(document).on(CustomEvents.events.accessibleChange, reportSelectors.actions.reportAddCondition, event => {\n const reportAddCondition = event.target.closest(reportSelectors.actions.reportAddCondition);\n if (reportAddCondition) {\n event.preventDefault();\n\n // Check if dropdown is closed with no condition selected.\n if (reportAddCondition.selectedIndex === 0) {\n return;\n }\n\n const reportElement = reportAddCondition.closest(reportSelectors.regions.report);\n const pendingPromise = new Pending('core_reportbuilder/conditions:add');\n\n addCondition(reportElement.dataset.reportId, reportAddCondition.value)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionadded', 'core_reportbuilder',\n reportAddCondition.options[reportAddCondition.selectedIndex].text))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n });\n\n document.addEventListener('click', event => {\n\n // Remove condition from report.\n const reportRemoveCondition = event.target.closest(reportSelectors.actions.reportRemoveCondition);\n if (reportRemoveCondition) {\n event.preventDefault();\n\n const reportElement = reportRemoveCondition.closest(reportSelectors.regions.report);\n const conditionContainer = reportRemoveCondition.closest(reportSelectors.regions.activeCondition);\n const conditionName = conditionContainer.dataset.conditionName;\n\n Notification.saveCancelPromise(\n getString('deletecondition', 'core_reportbuilder', conditionName),\n getString('deleteconditionconfirm', 'core_reportbuilder', conditionName),\n getString('delete', 'core'),\n {triggerElement: reportRemoveCondition}\n ).then(() => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:remove');\n\n return deleteCondition(reportElement.dataset.reportId, conditionContainer.dataset.conditionId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => addToast(getString('conditiondeleted', 'core_reportbuilder', conditionName)))\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }).catch(() => {\n return;\n });\n }\n });\n\n // Initialize sortable list to handle active conditions moving (note JQuery dependency, see MDL-72293 for resolution).\n var activeConditionsSortableList = new SortableList(`${reportSelectors.regions.activeConditions}`,\n {isHorizontal: false});\n activeConditionsSortableList.getElementName = element => Promise.resolve(element.data('conditionName'));\n\n $(document).on(SortableList.EVENTS.DROP, reportSelectors.regions.activeCondition, (event, info) => {\n if (info.positionChanged) {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reorder');\n const reportElement = event.target.closest(reportSelectors.regions.report);\n const conditionId = info.element.data('conditionId');\n const conditionPosition = info.element.data('conditionPosition');\n\n // Select target position, if moving to the end then count number of element siblings.\n let targetConditionPosition = info.targetNextElement.data('conditionPosition') || info.element.siblings().length + 2;\n if (targetConditionPosition > conditionPosition) {\n targetConditionPosition--;\n }\n\n reorderCondition(reportElement.dataset.reportId, conditionId, targetConditionPosition)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionmoved', 'core_reportbuilder', info.element.data('conditionName')))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n });\n};\n"],"names":["reloadSettingsConditionsRegion","reportElement","templateContext","pendingPromise","Pending","settingsConditionsRegion","querySelector","reportSelectors","regions","settingsConditions","Templates","renderForPromise","conditions","then","_ref","html","js","replaceNode","javascript","initConditionsForm","reportAddCondition","actions","focus","resolve","define","CustomEvents","events","accessibleChange","document","report","conditionFormContainer","conditionForm","DynamicForm","addEventListener","FORM_SUBMITTED","event","preventDefault","addToast","catch","Notification","exception","reportEvents","tableReload","NOSUBMIT_BUTTON_PRESSED","saveCancelPromise","triggerElement","detail","dataset","reportId","data","initialized","on","target","closest","selectedIndex","value","options","text","reportRemoveCondition","conditionContainer","activeCondition","conditionName","conditionId","SortableList","activeConditions","isHorizontal","getElementName","element","Promise","EVENTS","DROP","info","positionChanged","conditionPosition","targetConditionPosition","targetNextElement","siblings","length"],"mappings":"qqEAgDMA,+BAAiC,CAACC,cAAeC,yBAC7CC,eAAiB,IAAIC,iBAAQ,wCAC7BC,yBAA2BJ,cAAcK,cAAcC,gBAAgBC,QAAQC,2BAE9EC,mBAAUC,iBAAiB,+CAAgD,CAACC,WAAYV,kBAC1FW,MAAKC,WAACC,KAACA,KAADC,GAAOA,4BACAC,YAAYZ,yBAA0BU,KAAMC,GAAKd,gBAAgBgB,YAE3EC,2BAGMC,mBAAqBnB,cAAcK,cAAcC,gBAAgBc,QAAQD,2BAC/EA,MAAAA,oBAAAA,mBAAoBE,QAEbnB,eAAeoB,cAO5BJ,mBAAqB,wCACVK,OAAOjB,gBAAgBc,QAAQD,mBAAoB,CAACK,mCAAaC,OAAOC,yBAG/E1B,cAAgB2B,SAAStB,cAAcC,gBAAgBC,QAAQqB,QAC/DC,uBAAyB7B,cAAcK,cAAcC,gBAAgBC,QAAQC,wBAC9EqB,oCAGCC,cAAgB,IAAIC,qBAAYF,uBAAwB,yCAG9DC,cAAcE,iBAAiBF,cAAcL,OAAOQ,gBAAgBC,QAChEA,MAAMC,qCAEI,oBAAqB,sBAC1BvB,KAAKwB,YACLC,MAAMC,sBAAaC,+CAGVC,aAAaC,YAAa,GAAIzC,kBAIhD8B,cAAcE,iBAAiBF,cAAcL,OAAOiB,yBAAyBR,QACzEA,MAAMC,uCAEOQ,mBACT,mBAAU,kBAAmB,uBAC7B,mBAAU,yBAA0B,uBACpC,mBAAU,WAAY,sBACtB,CAACC,eAAgBV,MAAMW,SACzBjC,MAAK,WACGV,eAAiB,IAAIC,iBAAQ,8CAE5B,+BAAg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