moodle_local_treestudyplan/amd/build/page-edit-plan.min.js.map
2024-06-05 22:32:18 +02:00

1 line
17 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';\nimport {addBrowserButtonEvent} from './util/browserbuttonevents';\n\nimport {loadStrings} from './util/string-helper';\nimport {processStudyplan} from './studyplan-processor';\nimport {download,upload} from './downloader';\nimport {studyplanTiming} from './util/date-helper';\nimport { premiumenabled, premiumstatus } from \"./util/premium\";\nimport mFormComponents from \"./util/mform-helper\";\nVue.use(mFormComponents);\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 = loadStrings({\n studyplan: {\n studyplan_select_placeholder: 'studyplan_select_placeholder',\n advanced_import_from_file: 'advanced_import_from_file',\n advanced_create_from_template: 'advanced_create_from_template',\n studyplan_add: \"studyplan_add\",\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 templatecount: 0,\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 addBrowserButtonEvent(this.backPressed);\n },\n beforeunmount() {\n\n },\n computed: {\n premiumenabled,\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 backPressed() {\n debug.log(\"Back button pressed\");\n if (app.activestudyplan) {\n debug.log(\"Closing studyplan\");\n this.closeStudyplan();\n }\n },\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 for(const p of app.studyplans) {\n if (p.id == id) {\n app.selectStudyplan(id);\n break;\n }\n }\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 this.refreshTemplateCount();\n },\n refreshTemplateCount(){\n call([{\n methodname: 'local_treestudyplan_count_templates',\n args: { }\n }])[0].then(function(response){\n app.templatecount = 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","templatecount","text","strings","usedcontexts","created","$root","$on","index","idx","id","splice","mounted","initialize","this","backPressed","beforeunmount","computed","premiumenabled","dropdown_title","studyplan_select_placeholder","methods","log","closeStudyplan","methodname","args","context_id","then","response","timingval","future","present","past","sort","a","b","timinga","timingb","t","Date","getTime","localeCompare","hash","location","replace","p","selectStudyplan","catch","notification","exception","operation","refcontext_id","refreshTemplateCount","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","mFormComponents","PortalVue","BootstrapVue","Debugger","ns","advanced_import_from_file","advanced_create_from_template","studyplan_add"],"mappings":"gvBAoEqBA,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,SACJ,OAAZA,SAAuC,iBAAZA,SAAyBM,MAAMC,QAAQP,SAMnEA,QAAU,CAAEQ,mBAAoB,QAL1BR,QAAQQ,qBACVR,QAAQQ,mBAAqB,YAQjCC,IAAM,IAAIC,aAAI,CACdC,GAAI,QACJC,KAAM,CACFC,OAAQ,CACJC,UAAW,CACPC,KAAM,GACNC,UAAW,GACXC,YAAa,GACbC,SAAU,GACVC,MAAQ,EACRC,UAAW,aACXC,QAAS,GACTC,QAASxB,UACTyB,YAAavB,QAAQQ,mBACrBgB,mBAAoB,KAI5BC,gBAAiB,KACjBC,WAAY,KACZC,kBAAkB,EAClBC,WAAY,GACZC,cAAe,EAEfC,KAAMC,QAAQjB,UACdkB,aAAc,IAElBC,eACSC,MAAMC,IAAI,oBAAoBrB,YAE5BL,IAAIgB,iBAAmBX,YACtBL,IAAIgB,gBAAkB,UAItBW,MAAQ,SACR,IAAIC,OAAO5B,IAAImB,cACZnB,IAAImB,WAAWS,KAAKC,IAAMxB,UAAUwB,GAAG,CACtC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