moodle_local_treestudyplan/amd/build/page-edit-plan.min.js
2023-11-23 07:44:04 +01:00

3 lines
5.9 KiB
JavaScript

define("local_treestudyplan/page-edit-plan",["exports","core/str","core/ajax","core/notification","./vue/vue","./studyplan-editor-components","./treestudyplan-components","./modedit-modal","./util/debugger","./util/string-helper","./studyplan-processor","./downloader","./util/date-helper","./portal-vue/portal-vue.esm","./bootstrap-vue/bootstrap-vue","./vue-easy-dnd/vue-easy-dnd.esm"],(function(_exports,_str,_ajax,_notification,_vue,_studyplanEditorComponents,_treestudyplanComponents,_modeditModal,_debugger,_stringHelper,_studyplanProcessor,_downloader,_dateHelper,_portalVue,_bootstrapVue,_vueEasyDnd){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(contextid,categoryid,options){contextid=void 0===contextid||!Number.isInteger(Number(contextid))||contextid<1?1:Number(contextid);categoryid=void 0!==categoryid&&Number.isInteger(Number(categoryid))?Number(categoryid):0;debug.info("options",options),null===options||"object"!=typeof options||Array.isArray(options)?options={defaultAggregation:"core"}:options.defaultAggregation||(options.defaultAggregation="core");let app=new _vue.default({el:"#root",data:{create:{studyplan:{name:"",shortname:"",description:"",idnumber:"",slots:4,startdate:"2020-08-01",enddate:"",context:contextid,aggregation:options.defaultAggregation,aggregation_config:""}},toolbox:{shown:!1,right:!0},activestudyplan:null,loadingstudyplan:!1,studyplans:[],frameworks:[],badges:[],courses:[],text:strings.studyplan,usedcontexts:[]},created(){this.$root.$on("studyplanRemoved",(studyplan=>{app.activestudyplan==studyplan&&(app.activestudyplan=null);let index=null;for(let idx in app.studyplans)if(app.studyplans[idx].id==studyplan.id){index=idx;break}index&&app.studyplans.splice(index,1)}))},mounted(){(0,_ajax.call)([{methodname:"local_treestudyplan_list_studyplans",args:{context_id:contextid}}])[0].done((function(response){const timingval={future:0,present:1,past:2};response.sort(((a,b)=>{const timinga=(0,_dateHelper.studyplanTiming)(a),timingb=(0,_dateHelper.studyplanTiming)(b);let t=timingval[timinga]-timingval[timingb];return 0==t&&(t=new Date(b.startdate).getTime()-new Date(a.startdate).getTime(),0==t&&(t=a.name.localeCompare(b.name))),t})),app.studyplans=response;const hash=location.hash.replace("#","");if(hash)for(let idx in app.studyplans)if(app.studyplans[idx].id==hash){app.selectStudyplan(app.studyplans[idx]);break}})).fail(_notification.default.exception),(0,_ajax.call)([{methodname:"local_treestudyplan_list_badges",args:{}}])[0].done((function(response){app.badges=response})).fail(_notification.default.exception),(0,_ajax.call)([{methodname:"local_treestudyplan_map_categories",args:{root_id:categoryid}}])[0].done((function(response){app.courses=response})).fail(_notification.default.exception),(0,_ajax.call)([{methodname:"local_treestudyplan_list_used_categories",args:{operation:"edit"}}])[0].done((function(response){app.usedcontexts=response})).fail(_notification.default.exception)},computed:{dropdown_title(){return this.activestudyplan&&this.activestudyplan.name?this.activestudyplan.name:this.text.studyplan_select_placeholder},contextid:()=>contextid,filterComponentType:()=>({item:!1,component:!0,span:1,type:"filter"})},methods:{closeStudyplan(){app.activestudyplan=null,window.location.hash=""},movedStudyplan(plan,from,to){const params=new URLSearchParams(location.search);params.delete("categoryid"),params.set("contextid",to),window.location.search=params.toString()},onStudyPlanCreated(newstudyplan){app.studyplans.push(newstudyplan),app.selectStudyplan(newstudyplan)},switchContext(ctx){const params=new URLSearchParams(location.search);params.set("categoryid",ctx.id),window.location.search=params.toString()},selectStudyplan(studyplan){app.loadingstudyplan=!0,app.activestudyplan=null,(0,_ajax.call)([{methodname:"local_treestudyplan_get_studyplan_map",args:{id:studyplan.id}}])[0].done((function(response){app.activestudyplan=(0,_studyplanProcessor.ProcessStudyplan)(response),debug.info("studyplan processed"),app.loadingstudyplan=!1,window.location.hash=app.activestudyplan.id})).fail((function(error){_notification.default.exception(error),app.loadingstudyplan=!1}))},import_studyplan(){(0,_downloader.upload)(((filename,content)=>{(0,_ajax.call)([{methodname:"local_treestudyplan_import_plan",args:{content:content,format:"application/json",context_id:contextid}}])[0].done((function(response){response.success?location.reload():debug.error("Import failed: ",response.msg)})).fail(_notification.default.exception)}),"application/json")},export_plan(plan,format){null!=format&&["json","csv"].includes(format)||(format="json"),(0,_ajax.call)([{methodname:"local_treestudyplan_export_plan",args:{studyplan_id:plan.id,format:format}}])[0].done((function(response){(0,_downloader.download)(plan.shortname+".json",response.content,response.format)})).fail(_notification.default.exception)},toggletoolbox(event){debug.info(event),this.toolbox.shown=event}}})},_notification=_interopRequireDefault(_notification),_vue=_interopRequireDefault(_vue),_studyplanEditorComponents=_interopRequireDefault(_studyplanEditorComponents),_treestudyplanComponents=_interopRequireDefault(_treestudyplanComponents),_modeditModal=_interopRequireDefault(_modeditModal),_debugger=_interopRequireDefault(_debugger),_portalVue=_interopRequireDefault(_portalVue),_bootstrapVue=_interopRequireDefault(_bootstrapVue),_vue.default.use(_studyplanEditorComponents.default),_vue.default.use(_treestudyplanComponents.default),_vue.default.use(_modeditModal.default),_vue.default.use(_portalVue.default),_vue.default.use(_bootstrapVue.default),_vue.default.component("drag",_vueEasyDnd.Drag),_vue.default.component("drop",_vueEasyDnd.Drop),_vue.default.component("drop-list",_vueEasyDnd.DropList);const debug=new _debugger.default("treestudyplan");let strings=(0,_stringHelper.load_strings)({studyplan:{studyplan_select_placeholder:"studyplan_select_placeholder"}})}));
//# sourceMappingURL=page-edit-plan.min.js.map