moodle_local_treestudyplan/amd/build/page-edit-plan.min.js.map
2024-03-25 23:42:40 +01:00

1 line
15 KiB
Plaintext

{"version":3,"file":"page-edit-plan.min.js","sources":["../src/page-edit-plan.js"],"sourcesContent":["/*eslint no-var: \"error\" */\n/*eslint no-unused-vars: \"off\" */\n/*eslint linebreak-style: \"off\" */\n/*eslint no-trailing-spaces: \"off\" */\n/*eslint-env es6*/\n// Put this file in path/to/plugin/amd/src\n// You can call it anything you like\n\nimport {get_string,get_strings} from 'core/str';\nimport {call} from 'core/ajax';\nimport notification from 'core/notification';\n\n//import {resetAllFormDirtyStates} from 'core_form/changechecker'; // Moodle 4.00+ only\n\nimport Vue from './vue/vue';\n\nimport EditorComponents from './studyplan-editor-components';\nVue.use(EditorComponents);\n\nimport TSComponents from './treestudyplan-components';\nVue.use(TSComponents);\n\nimport ModalComponents from './modedit-modal';\nVue.use(ModalComponents);\nimport Debugger from './util/debugger';\n\nimport {load_strings} from './util/string-helper';\nimport {ProcessStudyplan} from './studyplan-processor';\nimport {download,upload} from './downloader';\nimport {studyplanTiming} from './util/date-helper';\n\nimport PortalVue from './portal-vue/portal-vue.esm';\nVue.use(PortalVue);\nimport BootstrapVue from './bootstrap-vue/bootstrap-vue';\nVue.use(BootstrapVue);\n\n\nconst debug = new Debugger(\"treestudyplan\");\n\nlet resetAllFormDirtyStates = () => {};\nimport('core_form/changechecker').then((ns) => {\n debug.info(ns);\n if(ns.resetAllFormDirtyStates) {\n resetAllFormDirtyStates = ns.resetAllFormDirtyStates;\n }\n}).catch(()=>{});\n\n\n\nlet strings = load_strings({\n studyplan: {\n studyplan_select_placeholder: 'studyplan_select_placeholder',\n },\n});\n\n/**\n * Initialize the Page\n * @param {int} contextid The context we should attempt to work in (1:1 related to the category)\n * @param {int} categoryid The category we shoud attempt to work in (1:1 related to the context)\n * @param {object} options Options to be passed to this script\n */\nexport function init(contextid,categoryid,options) {\n // Make sure the id's are numeric and integer\n if(undefined === contextid || !Number.isInteger(Number(contextid)) || contextid < 1 ){ contextid = 1;}\n else { contextid = Number(contextid);} // ensure a numeric value instead of string\n if(undefined === categoryid || !Number.isInteger(Number(categoryid))){ categoryid = 0;}\n else { categoryid = Number(categoryid);} // ensure a numeric value instead of string\n\n debug.info(\"options\",options);\n if ( options !== null && typeof options === 'object' && !Array.isArray(options) ) {\n if ( !options.defaultAggregation ) {\n options.defaultAggregation = \"core\";\n }\n \n } else {\n options = { defaultAggregation: \"core\"};\n }\n\n // Setup the initial Vue app for this page\n let app = new Vue({\n el: '#root',\n data: {\n create: {\n studyplan: {\n name: '',\n shortname: '',\n description: '',\n idnumber: '',\n slots : 4,\n startdate: '2020-08-01',\n enddate: '',\n context: contextid,\n aggregation: options.defaultAggregation,\n aggregation_config: '',\n }\n },\n\n activestudyplan: null,\n activepage: null,\n loadingstudyplan: false,\n studyplans: [],\n\n text: strings.studyplan,\n usedcontexts: [],\n },\n created() {\n this.$root.$on('studyplanRemoved',(studyplan)=>{\n\n if(app.activestudyplan == studyplan){\n app.activestudyplan = null;\n }\n\n // remove studyplan from index list\n let index = null;\n for(let idx in app.studyplans){\n if(app.studyplans[idx].id == studyplan.id){\n index = idx;\n break;\n }\n }\n if(index){\n app.studyplans.splice(index, 1);\n }\n\n });\n },\n mounted() {\n this.initialize();\n },\n computed: {\n dropdown_title(){\n if(this.activestudyplan && this.activestudyplan.name){\n return this.activestudyplan.name;\n }\n else{\n return this.text.studyplan_select_placeholder;\n }\n },\n contextid(){\n return contextid;\n },\n\n },\n methods: {\n initialize() {\n call([{\n methodname: 'local_treestudyplan_list_studyplans',\n args: { context_id: contextid}\n }])[0].then(function(response){\n const timingval = { future: 0, present: 1, past: 2, };\n response.sort((a,b) => {\n const timinga = studyplanTiming(a);\n const timingb = studyplanTiming(b);\n \n let t = timingval[timinga] - timingval[timingb];\n if(t == 0){\n // sort by start date if timing is equal\n t = new Date(b.startdate).getTime() - new Date(a.startdate).getTime();\n \n if (t == 0) {\n // sort by name if timing is equal\n t = a.name.localeCompare(b.name);\n }\n }\n return t;\n });\n app.studyplans = response;\n \n // load studyplan from hash if applicable\n const hash = location.hash.replace('#','');\n if(hash){\n const id = hash;\n app.selectStudyplan(id);\n }\n }).catch(notification.exception);\n\n call([{\n methodname: 'local_treestudyplan_list_available_categories',\n args: { operation: 'edit', refcontext_id: contextid}\n }])[0].then(function(response){\n app.usedcontexts = response;\n }).catch(notification.exception);\n },\n closeStudyplan() {\n app.activestudyplan = null;\n window.location.hash = '';\n },\n movedStudyplan(plan,from,to) {\n // reload the page in the new context (needed, since a number of links are not reactive in the page)\n const params = new URLSearchParams(location.search);\n params.delete('categoryid');\n params.set(\"contextid\", to);\n setTimeout(() => {\n // Reload page in a timeout to give other form javasccript the change to remove the beforeunload handler.\n window.location.search = params.toString();\n },50);\n },\n onStudyPlanCreated(newstudyplan){\n if (newstudyplan.context_id != contextid) {\n // Study plan has changed context id - reload page into new context id and show the plan\n const params = new URLSearchParams(location.search);\n params.delete('categoryid');\n params.set(\"contextid\", newstudyplan.context_id);\n // Make sure the form is no longer dirty before reloading the page - avoid beforeunload handler triggering.\n resetAllFormDirtyStates();\n window.location = window.location.pathname + \"?\" + params.toString() + \"#\" + newstudyplan.id;\n } else {\n app.studyplans.push(newstudyplan);\n app.selectStudyplan(newstudyplan.id);\n }\n },\n switchContext(ctxid){\n const params = new URLSearchParams(location.search);\n params.delete('categoryid');\n params.set('contextid', ctxid);\n setTimeout(() => {\n // Reload page in a timeout to give other form javasccript the change to remove the beforeunload handler.\n window.location.href = window.location.pathname + \"?\" + params.toString();\n },50);\n },\n selectStudyplan(studyplanid){\n // fetch studyplan\n app.loadingstudyplan = true;\n app.activestudyplan = null;\n call([{\n methodname: 'local_treestudyplan_get_studyplan_map',\n args: { id: studyplanid}\n }])[0].then(function(response){\n app.activestudyplan = ProcessStudyplan(response);\n debug.info('studyplan processed');\n app.loadingstudyplan = false;\n window.location.hash = app.activestudyplan.id;\n }).catch(function(error){\n notification.exception(error);\n app.loadingstudyplan = false;\n });\n },\n import_studyplan(){\n const self = this;\n upload((filename,content)=>{\n call([{\n methodname: 'local_treestudyplan_import_plan',\n args: {\n content: content,\n format: \"application/json\",\n context_id: contextid,\n },\n }])[0].then(function(response){\n if(response.success){\n self.initialize();\n } else {\n debug.error(\"Import failed: \",response.msg);\n }\n\n }).catch(notification.exception);\n }, \"application/json\");\n },\n export_plan(plan,format){\n let self = this;\n if(format == undefined || ![\"json\",\"csv\"].includes(format)){\n format = \"json\";\n }\n call([{\n methodname: 'local_treestudyplan_export_plan',\n args: {\n studyplan_id: plan.id,\n format: format\n },\n }])[0].then(function(response){\n\n download(plan.shortname+\".json\",response.content,response.format);\n }).catch(notification.exception);\n },\n \n },\n });\n}\n\n"],"names":["contextid","categoryid","options","undefined","Number","isInteger","debug","info","Array","isArray","defaultAggregation","app","Vue","el","data","create","studyplan","name","shortname","description","idnumber","slots","startdate","enddate","context","aggregation","aggregation_config","activestudyplan","activepage","loadingstudyplan","studyplans","text","strings","usedcontexts","created","$root","$on","index","idx","id","splice","mounted","initialize","computed","dropdown_title","this","studyplan_select_placeholder","methods","methodname","args","context_id","then","response","timingval","future","present","past","sort","a","b","timinga","timingb","t","Date","getTime","localeCompare","hash","location","replace","selectStudyplan","catch","notification","exception","operation","refcontext_id","closeStudyplan","window","movedStudyplan","plan","from","to","params","URLSearchParams","search","delete","set","setTimeout","toString","onStudyPlanCreated","newstudyplan","resetAllFormDirtyStates","pathname","push","switchContext","ctxid","href","studyplanid","error","import_studyplan","self","filename","content","format","success","msg","export_plan","includes","studyplan_id","use","EditorComponents","TSComponents","ModalComponents","PortalVue","BootstrapVue","Debugger","ns"],"mappings":"ioBA6DqBA,UAAUC,WAAWC,SAEiDF,eAApFG,IAAcH,YAAcI,OAAOC,UAAUD,OAAOJ,aAAeA,UAAY,EAAiB,EAChFI,OAAOJ,WAEnBC,gBADJE,IAAcF,YAAeG,OAAOC,UAAUD,OAAOH,aACpCG,OAAOH,YADyD,EAGpFK,MAAMC,KAAK,UAAUL,S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