on-demand release 4.0dev+
[moodle.git] / calendar / amd / build / modal_event_form.min.js
CommitLineData
acd9d982 1define ("core_calendar/modal_event_form",["jquery","core_form/events","core/str","core/notification","core/templates","core/custom_interaction_events","core/modal","core/modal_registry","core/fragment","core_calendar/events","core_calendar/repository"],function(a,b,c,d,e,f,g,h,i,j,k){var l=!1,m={SAVE_BUTTON:"[data-action=\"save\"]",LOADING_ICON_CONTAINER:"[data-region=\"loading-icon-container\"]"},n=function(a){g.call(this,a);this.eventId=null;this.startTime=null;this.courseId=null;this.categoryId=null;this.contextId=null;this.reloadingBody=!1;this.reloadingTitle=!1;this.saveButton=this.getFooter().find(m.SAVE_BUTTON)};n.TYPE="core_calendar-modal_event_form";n.prototype=Object.create(g.prototype);n.prototype.constructor=n;n.prototype.setContextId=function(a){this.contextId=a};n.prototype.getContextId=function(){return this.contextId};n.prototype.setCourseId=function(a){this.courseId=a};n.prototype.getCourseId=function(){return this.courseId};n.prototype.setCategoryId=function(a){this.categoryId=a};n.prototype.getCategoryId=function(){return this.categoryId};n.prototype.hasCourseId=function(){return null!==this.courseId};n.prototype.hasCategoryId=function(){return null!==this.categoryId};n.prototype.setEventId=function(a){this.eventId=a};n.prototype.getEventId=function(){return this.eventId};n.prototype.hasEventId=function(){return null!==this.eventId};n.prototype.setStartTime=function(a){this.startTime=a};n.prototype.getStartTime=function(){return this.startTime};n.prototype.hasStartTime=function(){return null!==this.startTime};n.prototype.getForm=function(){return this.getBody().find("form")};n.prototype.disableButtons=function(){this.saveButton.prop("disabled",!0)};n.prototype.enableButtons=function(){this.saveButton.prop("disabled",!1)};n.prototype.reloadTitleContent=function(){if(this.reloadingTitle){return this.titlePromise}this.reloadingTitle=!0;if(this.hasEventId()){this.titlePromise=c.get_string("editevent","calendar")}else{this.titlePromise=c.get_string("newevent","calendar")}this.titlePromise.then(function(a){this.setTitle(a);return a}.bind(this)).always(function(){this.reloadingTitle=!1}.bind(this)).fail(d.exception);return this.titlePromise};n.prototype.reloadBodyContent=function(a){if(this.reloadingBody){return this.bodyPromise}this.reloadingBody=!0;this.disableButtons();var b={};if(this.hasEventId()){b.eventid=this.getEventId()}if(this.hasStartTime()){b.starttime=this.getStartTime()}if(this.hasCourseId()){b.courseid=this.getCourseId()}if(this.hasCategoryId()){b.categoryid=this.getCategoryId()}if("undefined"!=typeof a){b.formdata=a}this.bodyPromise=i.loadFragment("calendar","event_form",this.getContextId(),b);this.setBody(this.bodyPromise);this.bodyPromise.then(function(){this.enableButtons()}.bind(this)).fail(d.exception).always(function(){this.reloadingBody=!1}.bind(this)).fail(d.exception);return this.bodyPromise};n.prototype.reloadAllContent=function(){return a.when(this.reloadTitleContent(),this.reloadBodyContent())};n.prototype.show=function(){this.reloadAllContent();g.prototype.show.call(this)};n.prototype.hide=function(){g.prototype.hide.call(this);this.setEventId(null);this.setStartTime(null);this.setCourseId(null);this.setCategoryId(null)};n.prototype.getFormData=function(){return this.getForm().serialize()};n.prototype.save=function(){var b,c=this.saveButton.find(m.LOADING_ICON_CONTAINER);b=this.getForm().find("[aria-invalid=\"true\"]");if(b.length){b.first().focus();return Promise.resolve()}c.removeClass("hidden");this.disableButtons();var e=this.getFormData();return k.submitCreateUpdateForm(e).then(function(b){if(b.validationerror){this.reloadBodyContent(e)}else{var c=this.hasEventId();this.hide();if(c){a("body").trigger(j.updated,[b.event])}else{a("body").trigger(j.created,[b.event])}}}.bind(this)).always(function(){c.addClass("hidden");this.enableButtons()}.bind(this)).fail(d.exception)};n.prototype.registerEventListeners=function(){g.prototype.registerEventListeners.call(this);this.getModal().on(f.events.activate,m.SAVE_BUTTON,function(a,b){this.getForm().submit();b.originalEvent.preventDefault();a.stopPropagation()}.bind(this));this.getModal().on("submit",function(a){b.notifyFormSubmittedByJavascript(this.getForm()[0]);this.save();a.preventDefault();a.stopPropagation()}.bind(this))};if(!l){h.register(n.TYPE,n,"calendar/modal_event_form");l=!0}return n});
195ea448 2//# sourceMappingURL=modal_event_form.min.js.map