define("local_treestudyplan/page-view-plan",["exports","core/ajax","core/notification","./vue/vue","./util/debugger","./util/string-helper","./studyplan-processor","./util/date-helper","./util/browserbuttonevents","./report-viewer-components","./modedit-modal","./portal-vue/portal-vue.esm","./bootstrap-vue/bootstrap-vue"],(function(_exports,_ajax,_notification,_vue,_debugger,_stringHelper,_studyplanProcessor,_dateHelper,_browserbuttonevents,_reportViewerComponents,_modeditModal,_portalVue,_bootstrapVue){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(contextid,categoryid){contextid=void 0===contextid||!Number.isInteger(Number(contextid))||contextid<1?1:Number(contextid);categoryid=void 0!==categoryid&&Number.isInteger(Number(categoryid))?Number(categoryid):0;let app=new _vue.default({el:"#root",data:{selected:{planid:0,studentid:0},displayedstudyplan:null,activestudyplan:null,associatedstudents:[],selectedstudent:null,studentstudyplan:null,loadingstudyplan:!1,studyplans:[],text:strings.studyplan,toolbox:{right:!0},usedcontexts:[]},async mounted(){(0,_ajax.call)([{methodname:"local_treestudyplan_list_studyplans",args:{context_id:contextid}}])[0].then((response=>{const timingval={present:0,past:1,future:2};response.sort(((a,b)=>{const timinga=(0,_dateHelper.studyplanTiming)(a),timingb=(0,_dateHelper.studyplanTiming)(b),t=timingval[timinga]-timingval[timingb];return 0==t?a.name.localeCompare(b.name):t})),app.studyplans=response;const parts=window.location.hash.replace("#","").split("-");if(parts&&parts.length>0&&""!=parts[0])for(let idx in app.studyplans)if(app.studyplans[idx].id==parts[0]){app.selectStudyplan(app.studyplans[idx],parts[1]);break}})).catch(_notification.default.exception),(0,_ajax.call)([{methodname:"local_treestudyplan_list_available_categories",args:{operation:"view",refcontext_id:contextid}}])[0].then((response=>{const contexts=[];for(const ix in response){const cat=response[ix];(cat.studyplancount>0||cat.context_id==contextid)&&contexts.push(cat)}app.usedcontexts=contexts})).catch(_notification.default.exception),(0,_browserbuttonevents.addBrowserButtonEvent)(this.navChanged,this.navChanged)},computed:{dropdownTitle(){return this.activestudyplan&&this.activestudyplan.name?this.activestudyplan.name:this.text.studyplanSelectPlaceholder},contextid:()=>contextid},methods:{navChanged(){const hash=window.location.hash.replace("#",""),parts=hash.split("-");if(debug.log("Navigation changed",hash,parts),parts&&parts.length>0){const planid=Number(parts[0]),studentid=parts.length>1?Number(parts[1]):0;if(debug.log("Selected ids",planid,studentid,this.selected.planid,this.selected.studentid),0==planid)planid!=this.selected.planid&&this.closeStudyplan(!1);else if(this.selected.planid!=planid||0==studentid&&0!=this.selected.studentid){debug.info("Requested plan changed - loading studyplan");for(let idx in app.studyplans){const plan=this.studyplans[idx];if(Number(plan.id)==planid){this.selectStudyplan(plan,studentid,!1);break}}}else if(this.selected.studentid!=studentid)for(const group of app.associatedstudents)for(const student of group.users)if(Number(student.id)==studentid){app.showStudentView(student,!1);break}}},switchContext(ctxid){const params=new URLSearchParams(location.search);params.delete("categoryid"),params.set("contextid",ctxid),setTimeout((()=>{window.location.href=window.location.pathname+"?"+params.toString()}),50)},closeStudyplan(){let updatehash=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];app.selected.planid=0,app.selected.studentid=0,app.activestudyplan=null,app.associatedstudents=[],app.studentstudyplan=[],app.displayedstudyplan=null,updatehash&&(window.location.hash="")},selectStudyplan(studyplan,studentid){let updatehash=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];app.selected.planid=Number(studyplan.id),app.selected.studentid=studentid?Number(studentid):0,app.loadingstudyplan=!0,app.associatedstudents=[],app.selectedstudent=null,app.studentstudyplan=null,(0,_ajax.call)([{methodname:"local_treestudyplan_get_studyplan_map",args:{id:studyplan.id}}])[0].then((response=>{app.activestudyplan=(0,_studyplanProcessor.processStudyplan)(response,!0),(0,_ajax.call)([{methodname:"local_treestudyplan_all_associated_grouped",args:{studyplan_id:studyplan.id}}])[0].then((response=>{app.associatedstudents=response;let foundstudent=!1;if(studentid)for(const group of app.associatedstudents)for(const student of group.users)if(student.id==studentid){foundstudent=!0,app.showStudentView(student,updatehash);break}foundstudent||(app.selected.studentid=0,updatehash&&(window.location.hash=app.activestudyplan.id),app.displayedstudyplan=app.activestudyplan,app.loadingstudyplan=!1)})).catch(_notification.default.exception)})).catch((function(error){_notification.default.exception(error),app.loadingstudyplan=!1}))},showStudentView(student){let updatehash=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];app.selected.studentid=student?Number(student.id):0,student?(app.selectedstudent=student,app.studentstudyplan=null,app.loadingstudyplan=!0,(0,_ajax.call)([{methodname:"local_treestudyplan_get_user_studyplan",args:{userid:student.id,studyplanid:app.selected.planid}}])[0].then((response=>{app.studentstudyplan=(0,_studyplanProcessor.processStudyplan)(response,!1),app.displayedstudyplan=app.studentstudyplan,app.loadingstudyplan=!1,updatehash&&(window.location.hash=app.activestudyplan.id+"-"+student.id)})).catch((error=>{_notification.default.exception(error),app.loadingstudyplan=!1}))):this.showOverview(updatehash)},showOverview(){let updatehash=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];app.selected.studentid=0,app.selectedstudent=null,app.studentstudyplan=null,app.displayedstudyplan=app.activestudyplan,updatehash&&(window.location.hash=app.activestudyplan.id)}}})},_notification=_interopRequireDefault(_notification),_vue=_interopRequireDefault(_vue),_debugger=_interopRequireDefault(_debugger),_reportViewerComponents=_interopRequireDefault(_reportViewerComponents),_modeditModal=_interopRequireDefault(_modeditModal),_portalVue=_interopRequireDefault(_portalVue),_bootstrapVue=_interopRequireDefault(_bootstrapVue),_vue.default.use(_reportViewerComponents.default),_vue.default.use(_modeditModal.default),_vue.default.use(_portalVue.default),_vue.default.use(_bootstrapVue.default);let debug=new _debugger.default("treestudyplanviewer"),strings=(0,_stringHelper.loadStrings)({studyplan:{studyplanSelectPlaceholder:"studyplan_select_placeholder"}})})); //# sourceMappingURL=page-view-plan.min.js.map