on-demand release 4.0dev+
[moodle.git] / mod / assign / amd / build / grading_panel.min.js
1 define ("mod_assign/grading_panel",["jquery","core/yui","core/notification","core/templates","core/fragment","core/ajax","core/str","mod_assign/grading_form_change_checker","mod_assign/grading_events","core_form/events","core/toast","core_form/changechecker"],function(a,b,c,d,e,f,g,h,i,j,k,l){var m=function(b){this._regionSelector=b;this._region=a(b);this._userCache=[];this.registerEventListeners()};m.prototype._regionSelector=null;m.prototype._lastUserId=0;m.prototype._lastAttemptNumber=-1;m.prototype._region=null;m.prototype.nextUserId=null;m.prototype.nextUser=!1;m.prototype._niceReplaceNodeContents=function(b,c,e){var f=a.Deferred();b.fadeOut("fast",function(){d.replaceNodeContents(b,c,e);b.fadeIn("fast",function(){f.resolve()})});return f.promise()};m.prototype._saveFormState=function(){var b=a("[data-region=\"grading-actions-form\"] [name=\"sendstudentnotifications\"]").prop("checked");a(".gradeform [name=\"sendstudentnotifications\"]").val(b)};m.prototype._submitForm=function(b,d,e){var g=document.querySelector(".comment-area");if(g){var h=g.querySelector(".db > textarea");if(""!==h.value){var i=g.querySelector(".fd a[id^=\"comment-action-post-\"]");i.click()}}var k=a(this._region.find("form.gradeform"));a("[data-region=\"overlay\"]").show();l.markFormSubmitted(k[0]);k.trigger("save-form-state");j.notifyFormSubmittedByJavascript(k[0]);var m=k.serialize(),n=this._region.attr("data-assignmentid");f.call([{methodname:"mod_assign_submit_grading_form",args:{assignmentid:n,userid:this._lastUserId,jsonformdata:JSON.stringify(m)},done:this._handleFormSubmissionResponse.bind(this,m,d,e),fail:c.exception}])};m.prototype._handleFormSubmissionResponse=function(b,d,e,f){if("undefined"==typeof d){d=this._lastUserId}if(f.length){a(document).trigger("reset",[this._lastUserId,b])}else{g.get_string("gradechangessaveddetail","mod_assign").then(function(a){k.add(a);return a}).catch(c.exception);var h=a(this._region.find("form.gradeform"));l.resetFormDirtyState(h[0]);if(d==this._lastUserId){a(document).trigger("reset",d)}else if(e){a(document).trigger("done-saving-show-next",!0)}else{a(document).trigger("user-changed",d)}}a("[data-region=\"overlay\"]").hide()};m.prototype._resetForm=function(b,c,d){var e=a.Event("custom");if("undefined"==typeof c){c=this._lastUserId}this._lastUserId=0;this._refreshGradingPanel(e,c,d)};m.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)};m.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)};m.prototype._togglePopout=function(b){b.preventDefault();var c=a(b.target).closest(".fitem");if(c.hasClass("popout")){a(".popout").removeClass("popout")}else{a(".popout").removeClass("popout");c.addClass("popout");c.addClass("moodle-has-zindex")}};m.prototype._refreshGradingPanel=function(b,f,g,i){var j=this._region.attr("data-contextid");if("undefined"==typeof g){g=""}if("undefined"==typeof i){i=-1}if(this._lastUserId==f&&this._lastAttemptNumber==i&&""===g){return}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(0<f){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);a("[data-region=\"review-panel\"]").show()}else{this._region.hide();a("[data-region=\"review-panel\"]").hide();a(document).trigger("finish-loading-user");window.M.util.js_complete("mod-assign-loading-user")}}.bind(this))}.bind(this)).fail(c.exception)};m.prototype._getNextUser=function(a,b){this.nextUserId=b.nextUserId;this.nextUser=b.nextUser};m.prototype._handleSaveAndShowNext=function(){this._submitForm(null,this.nextUserId,this.nextUser)};m.prototype.getPanelElement=function(){return a("[data-region=\"grade-panel\"]")};m.prototype.collapsePanel=function(){this.getPanelElement().addClass("collapsed")};m.prototype.expandPanel=function(){this.getPanelElement().removeClass("collapsed")};m.prototype.registerEventListeners=function(){var b=a(document),c=a(this._region);c.on("submit","form",function(a){a.preventDefault()});b.on("next-user",this._getNextUser.bind(this));b.on("user-changed",this._refreshGradingPanel.bind(this));b.on("save-changes",this._submitForm.bind(this));b.on("save-and-show-next",this._handleSaveAndShowNext.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))};return m});
2 //# sourceMappingURL=grading_panel.min.js.map