define("local_treestudyplan/page-coach",["exports","core/ajax","core/notification","./vue/vue","./util/debugger","./util/string-helper","./studyplan-processor","./util/date-helper","./util/browserbuttonevents","./studyplan-editor-components","./treestudyplan-components","./report-viewer-components","./modedit-modal","./portal-vue/portal-vue.esm","./bootstrap-vue/bootstrap-vue"],(function(_exports,_ajax,_notification,_vue,_debugger,_stringHelper,_studyplanProcessor,_dateHelper,_browserbuttonevents,_studyplanEditorComponents,_treestudyplanComponents,_reportViewerComponents,_modeditModal,_portalVue,_bootstrapVue){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=function(){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.coach,toolbox:{right:!0},usedcontexts:[],editmode:!1},async mounted(){(0,_ajax.call)([{methodname:"local_treestudyplan_list_coaching_studyplans",args:{}}])[0].then((function(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],!1);break}})).catch(_notification.default.exception),(0,_browserbuttonevents.addBrowserButtonEvent)(this.navChanged,this.navChanged)},computed:{},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}}},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;const self=this;self.loadingstudyplan=!0,self.associatedstudents=[],self.selectedstudent=null,self.studentstudyplan=null,(0,_ajax.call)([{methodname:"local_treestudyplan_get_studyplan_map",args:{id:studyplan.id}}])[0].then((response=>{self.activestudyplan=(0,_studyplanProcessor.processStudyplan)(response,!0),(0,_ajax.call)([{methodname:"local_treestudyplan_all_associated_grouped",args:{studyplan_id:studyplan.id}}])[0].then((function(response){self.associatedstudents=response;let foundstudent=!1;if(studentid)for(const group of self.associatedstudents)for(const student of group.users)if(student.id==studentid){foundstudent=!0,self.showStudentView(student);break}if(!foundstudent)for(const group of self.associatedstudents)for(const student of group.users){foundstudent=!0,self.showStudentView(student);break}foundstudent||(app.selected.studentid=0,updatehash&&(window.location.hash=app.activestudyplan.id),self.displayedstudyplan=self.activestudyplan,self.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.activestudyplan.id}}])[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((function(error){_notification.default.exception(error),app.loadingstudyplan=!1}))):this.showOverview(updatehash)},showOverview(){let updatehash=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];debug.info("Switch to overview",updatehash),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),_studyplanEditorComponents=_interopRequireDefault(_studyplanEditorComponents),_treestudyplanComponents=_interopRequireDefault(_treestudyplanComponents),_reportViewerComponents=_interopRequireDefault(_reportViewerComponents),_modeditModal=_interopRequireDefault(_modeditModal),_portalVue=_interopRequireDefault(_portalVue),_bootstrapVue=_interopRequireDefault(_bootstrapVue),_vue.default.use(_studyplanEditorComponents.default),_vue.default.use(_treestudyplanComponents.default),_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("treestudyplancoach"),strings=(0,_stringHelper.loadStrings)({coach:{}})})); //# sourceMappingURL=page-coach.min.js.map