MDL-54852 assignment: Suppress "leave page" warning after save
[moodle.git] / mod / assign / amd / build / grading_panel.min.js
1 define(["jquery","core/yui","core/notification","core/templates","core/fragment","core/ajax","core/str","mod_assign/grading_form_change_checker","mod_assign/grading_events"],function(a,b,c,d,e,f,g,h,i){var j=function(b){this._regionSelector=b,this._region=a(b),this._userCache=[],this.registerEventListeners()};return j.prototype._regionSelector=null,j.prototype._lastUserId=0,j.prototype._lastAttemptNumber=-1,j.prototype._region=null,j.prototype._niceReplaceNodeContents=function(b,c,e){var f=a.Deferred();return b.fadeOut("fast",function(){d.replaceNodeContents(b,c,e),b.fadeIn("fast",function(){f.resolve()})}),f.promise()},j.prototype._saveFormState=function(){"undefined"!=typeof window.tinyMCE&&window.tinyMCE.triggerSave();var b=a('[data-region="grading-actions-form"] [name="sendstudentnotifications"]').val();a('.gradeform [name="sendstudentnotifications"]').val(b)},j.prototype._submitForm=function(b,d){var e=a(this._region.find("form.gradeform"));a('[data-region="overlay"]').show(),e.trigger("save-form-state");var g=e.serialize(),h=this._region.attr("data-assignmentid");f.call([{methodname:"mod_assign_submit_grading_form",args:{assignmentid:h,userid:this._lastUserId,jsonformdata:JSON.stringify(g)},done:this._handleFormSubmissionResponse.bind(this,g,d),fail:c.exception}])},j.prototype._handleFormSubmissionResponse=function(d,e,f){"undefined"==typeof e&&(e=this._lastUserId),f.length?a(document).trigger("reset",[this._lastUserId,d]):(g.get_strings([{key:"changessaved",component:"core"},{key:"gradechangessaveddetail",component:"mod_assign"}]).done(function(a){c.alert(a[0],a[1])}).fail(c.exception),b.use("moodle-core-formchangechecker",function(){M.core_formchangechecker.reset_form_dirty_state()}),e==this._lastUserId?a(document).trigger("reset",e):a(document).trigger("user-changed",e)),a('[data-region="overlay"]').hide()},j.prototype._resetForm=function(b,c,d){var e=a.Event("custom");"undefined"==typeof c&&(c=this._lastUserId),this._lastUserId=0,this._refreshGradingPanel(e,c,d)},j.prototype._chooseAttempt=function(b){var d=a(b.target),e=d.data("submissions"),f=a(document.getElementById(e)),h=f.clone(),i=h.wrap(a("<form/>")).html();g.get_strings([{key:"viewadifferentattempt",component:"mod_assign"},{key:"view",component:"core"},{key:"cancel",component:"core"}]).done(function(b){c.confirm(b[0],i,b[1],b[2],function(){var b=a("input:radio[name='select-attemptnumber']:checked").val();this._refreshGradingPanel(null,this._lastUserId,"",b)}.bind(this))}.bind(this)).fail(c.exception)},j.prototype._addPopoutButtons=function(b){var e=a(b);d.render("mod_assign/popout_button",{}).done(function(a){var b=e.find('[data-fieldtype="filemanager"],[data-fieldtype="editor"],[data-fieldtype="grading"]').closest(".fitem");b.addClass("has-popout").find("label").parent().append(a),e.on("click",'[data-region="popout-button"]',this._togglePopout.bind(this))}.bind(this)).fail(c.exception)},j.prototype._togglePopout=function(b){b.preventDefault();var c=a(b.target).closest(".fitem");c.hasClass("popout")?a(".popout").removeClass("popout"):(a(".popout").removeClass("popout"),c.addClass("popout"),c.addClass("moodle-has-zindex"))},j.prototype._refreshGradingPanel=function(b,f,g,i){var j=this._region.attr("data-contextid");"undefined"==typeof g&&(g=""),"undefined"==typeof i&&(i=-1),this._lastUserId==f&&this._lastAttemptNumber==i&&""===g||(this._lastUserId=f,this._lastAttemptNumber=i,a(document).trigger("start-loading-user"),window.M.util.js_pending("mod-assign-loading-user"),d.render("mod_assign/loading",{}).done(function(b,d){this._niceReplaceNodeContents(this._region,b,d).done(function(){if(f>0){this._region.show();var b={userid:f,attemptnumber:i,jsonformdata:JSON.stringify(g)};e.loadFragment("mod_assign","gradingpanel",j,b).done(function(b,d){this._niceReplaceNodeContents(this._region,b,d).done(function(){h.saveFormState('[data-region="grade-panel"] .gradeform'),a(document).on("editor-content-restored",function(){h.saveFormState('[data-region="grade-panel"] .gradeform')}),a('[data-region="attempt-chooser"]').on("click",this._chooseAttempt.bind(this)),this._addPopoutButtons('[data-region="grade-panel"] .gradeform'),a(document).trigger("finish-loading-user"),window.M.util.js_complete("mod-assign-loading-user")}.bind(this)).fail(c.exception)}.bind(this)).fail(c.exception)}else{this._region.hide();var d=a('[data-region="review-panel"]');d.length&&this._niceReplaceNodeContents(d,"",""),a(document).trigger("finish-loading-user"),window.M.util.js_complete("mod-assign-loading-user")}}.bind(this))}.bind(this)).fail(c.exception))},j.prototype.getPanelElement=function(){return a('[data-region="grade-panel"]')},j.prototype.collapsePanel=function(){this.getPanelElement().addClass("collapsed")},j.prototype.expandPanel=function(){this.getPanelElement().removeClass("collapsed")},j.prototype.registerEventListeners=function(){var b=a(document);b.on("user-changed",this._refreshGradingPanel.bind(this)),b.on("save-changes",this._submitForm.bind(this)),b.on("reset",this._resetForm.bind(this)),b.on("save-form-state",this._saveFormState.bind(this)),b.on(i.COLLAPSE_GRADE_PANEL,function(){this.collapsePanel()}.bind(this)),b.on(i.COLLAPSE_REVIEW_PANEL,function(){this.expandPanel()}.bind(this)),b.on(i.EXPAND_GRADE_PANEL,function(){this.expandPanel()}.bind(this))},j});