define("local_treestudyplan/page-edit-plan",["exports","core/str","core/ajax","core/notification","./vue","./studyplan-editor-components","./treestudyplan-components","./modedit-modal","./debugger","./string-helper","./studyplan-processor","./downloader","./portal-vue","./bootstrap-vue","./vue-easy-dnd"],(function(_exports,_str,_ajax,_notification,_vue,_studyplanEditorComponents,_treestudyplanComponents,_modeditModal,_debugger,_stringHelper,_studyplanProcessor,_downloader,_portalVue,_bootstrapVue,_vueEasyDnd){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(_contextid,categoryid){(void 0===_contextid||!Number.isInteger(_contextid)||_contextid<1)&&(_contextid=1);void 0!==categoryid&&Number.isInteger(categoryid)||(categoryid=0);var app=new _vue.default({el:"#root",data:{create:{studyplan:{name:"",shortname:"",description:"",slots:4,startdate:"2020-08-01",enddate:"",context:_contextid,aggregation:"bistate",aggregation_config:""}},toolbox:{right:!0},activestudyplan:null,loadingstudyplan:!1,studyplans:[],frameworks:[],badges:[],courses:[],text:strings.studyplan,usedcontexts:[]},created:function(){this.$root.$on("studyplanRemoved",(function(studyplan){app.activestudyplan==studyplan&&(app.activestudyplan=null);var index=null;for(var idx in app.studyplans)if(app.studyplans[idx].id==studyplan.id){index=idx;break}index&&app.studyplans.splice(index,1)}))},mounted:function(){(0,_ajax.call)([{methodname:"local_treestudyplan_list_studyplans",args:{context_id:_contextid}}])[0].done((function(response){var timingval={future:0,present:1,past:2};response.sort((function(a,b){var timinga=_treestudyplanComponents.default.studyplanTiming(a),timingb=_treestudyplanComponents.default.studyplanTiming(b),t=timingval[timinga]-timingval[timingb];return 0==t&&0==(t=new Date(b.startdate).getTime()-new Date(a.startdate).getTime())&&(t=a.name.localeCompare(b.name)),t})),app.studyplans=response;var hash=location.hash.replace("#","");if(hash)for(var 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:function(){return this.activestudyplan&&this.activestudyplan.name?this.activestudyplan.name:this.text.studyplan_select_placeholder},contextid:function(){return _contextid},filterComponentType:function(){return{item:!0,component:!1,span:1,type:"filter"}}},methods:{closeStudyplan:function(){app.activestudyplan=null,location.hash=""},movedStudyplan:function(plan,from,to){var params=new URLSearchParams(location.search);params.delete("categoryid"),params.set("contextid",to),window.location.search=params.toString()},onStudyPlanCreated:function(newstudyplan){app.studyplans.push(newstudyplan),app.selectStudyplan(newstudyplan)},switchContext:function(ctx){var params=new URLSearchParams(location.search);params.set("categoryid",ctx.id),window.location.search=params.toString()},selectStudyplan:function(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,!0),debug.info("studyplan processed"),app.loadingstudyplan=!1,location.hash=app.activestudyplan.id})).fail((function(error){_notification.default.exception(error),app.loadingstudyplan=!1}))},import_studyplan:function(){(0,_downloader.upload)((function(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:function(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)}}})},_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(_portalVue.default),_vue.default.use(_bootstrapVue.default),_vue.default.use(_treestudyplanComponents.default),_vue.default.use(_studyplanEditorComponents.default),_vue.default.use(_modeditModal.default),_vue.default.component("drag",_vueEasyDnd.Drag),_vue.default.component("drop",_vueEasyDnd.Drop),_vue.default.component("drop-list",_vueEasyDnd.DropList);var debug=new _debugger.default("treestudyplan");debug.enable();var strings=(0,_stringHelper.load_strings)({studyplan:{studyplan_select_placeholder:"studyplan_select_placeholder"}})})); //# sourceMappingURL=page-edit-plan.min.js.map