MDL-67264 core_course: Activity chooser new feature
[moodle.git] / course / amd / build / actions.min.js
1 define ("core_course/actions",["jquery","core/ajax","core/templates","core/notification","core/str","core/url","core/yui","core/modal_factory","core/modal_events","core/key_codes"],function(a,b,c,d,e,f,g,h,i,j){var k={EDITINPROGRESS:"editinprogress",SECTIONDRAGGABLE:"sectiondraggable",EDITINGMOVE:"editing_move"},l={ACTIVITYLI:"li.activity",ACTIONAREA:".actions",ACTIVITYACTION:"a.cm-edit-action",MENU:".moodle-actionmenu[data-enhance=moodle-core-actionmenu]",TOGGLE:".toggle-display,.dropdown-toggle",SECTIONLI:"li.section",SECTIONACTIONMENU:".section_action_menu",ADDSECTIONS:"#changenumsections [data-add-sections]"};g.use("moodle-course-coursebase",function(){var a=M.course.format.get_section_selector();if(a){l.SECTIONLI=a}});var m=function(a){var b;g.use("moodle-course-util",function(c){b=c.Moodle.core_course.util.cm.getId(c.Node(a.get(0)))});return b},n=function(a){var b;g.use("moodle-course-util",function(c){b=c.Moodle.core_course.util.cm.getName(c.Node(a.get(0)))});return b},o=function(a){a.addClass(k.EDITINPROGRESS);var b=a.find(l.ACTIONAREA).get(0);if(b){var c=M.util.add_spinner(g,g.Node(b));c.show();return c}return null},p=function(a){a.addClass(k.EDITINPROGRESS);var b=a.find(l.SECTIONACTIONMENU).get(0);if(b){var c=M.util.add_spinner(g,g.Node(b));c.show();return c}return null},q=function(a){var b=M.util.add_lightbox(g,g.Node(a.get(0)));b.show();return b},r=function(a,b,c){window.setTimeout(function(){a.removeClass(k.EDITINPROGRESS);if(b){b.hide()}},c)},s=function(a,b){if(a){window.setTimeout(function(){a.hide()},b)}},t=function(a){g.use("moodle-course-coursebase",function(){M.course.coursebase.invoke_function("setup_for_resource","#"+a)});if(M.core.actionmenu&&M.core.actionmenu.newDOMNode){M.core.actionmenu.newDOMNode(g.one("#"+a))}},u=function(b,c){var d=a("#"+b),e="[data-action="+c+"]";if("groupsseparate"===c||"groupsvisible"===c||"groupsnone"===c){e="[data-action=groupsseparate],[data-action=groupsvisible],[data-action=groupsnone]"}if(d.find(e).is(":visible")){d.find(e).focus()}else{d.find(l.MENU).find(l.TOGGLE).focus()}},v=function(b){var c=a("a:visible"),d=!1,e=null;c.each(function(){if(a.contains(b[0],this)){d=!0}else if(d){e=this;return!1}});return e},w=function(c,e,f){var g=f.attr("data-action"),h=o(c),i=b.call([{methodname:"core_course_edit_module",args:{id:e,action:g,sectionreturn:f.attr("data-sectionreturn")?f.attr("data-sectionreturn"):0}}],!0),j;if("duplicate"===g){j=q(f.closest(l.SECTIONLI))}a.when.apply(a,i).done(function(b){var d=v(c);c.replaceWith(b);a("<div>"+b+"</div>").find(l.ACTIVITYLI).each(function(b){t(a(this).attr("id"));if(0===b){u(a(this).attr("id"),g);d=null}});if(d){d.focus()}r(c,h,400);s(j,400);c.trigger(a.Event("coursemoduleedited",{ajaxreturn:b,action:g}))}).fail(function(b){r(c,h);s(j);var f=a.Event("coursemoduleeditfailed",{exception:b,action:g});c.trigger(f);if(!f.isDefaultPrevented()){d.exception(b)}})},x=function(c,d,e){var f=o(c),g=b.call([{methodname:"core_course_get_module",args:{id:d,sectionreturn:e}}],!0);a.when.apply(a,g).done(function(a){r(c,f,400);C(a)}).fail(function(){r(c,f)})},y=function(a,b){var c=a.attr("class").match(/modtype_([^\s]*)/)[1],f=n(a);e.get_string("pluginname",c).done(function(a){e.get_strings([{key:"confirm"},{key:null===f?"deletechecktype":"deletechecktypename",param:{type:a,name:f}},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],b)})})},z=function(a,b){e.get_strings([{key:"confirm"},{key:"yes"},{key:"no"}]).done(function(c){d.confirm(c[0],a,c[1],c[2],b)})},A=function(a,b,f,g,h,i,j){return e.get_strings([{key:f,component:g}]).then(function(d){a.find("span.menu-action-text").html(d[0]);return c.renderPix(b,"core")}).then(function(b){a.find(".icon").replaceWith(b);a.attr("data-action",j)}).catch(d.exception)},B=function(b,c,d,e){var f=c.attr("data-action");if("hide"===f||"show"===f){if("hide"===f){b.addClass("hidden");A(c,"i/show","showfromothers","format_"+e,null,null,"show")}else{b.removeClass("hidden");A(c,"i/hide","hidefromothers","format_"+e,null,null,"hide")}if(d.modules!==void 0){for(var g in d.modules){C(d.modules[g])}}if(d.section_availability!==void 0){b.find(".section_availability").first().replaceWith(d.section_availability)}}else if("setmarker"===f){var h=a(l.SECTIONLI+".current"),i=h.find(l.SECTIONACTIONMENU+" a[data-action=removemarker]");h.removeClass("current");A(i,"i/marker","highlight","core","markthistopic","core","setmarker");b.addClass("current");A(c,"i/marked","highlightoff","core","markedthistopic","core","removemarker")}else if("removemarker"===f){b.removeClass("current");A(c,"i/marker","highlight","core","markthistopic","core","setmarker")}},C=function(b){a("<div>"+b+"</div>").find(l.ACTIVITYLI).each(function(){var c=a(this).attr("id");a(l.ACTIVITYLI+"#"+c).replaceWith(b);t(c)})},D=function(c,e,f,g){var h=f.attr("data-action"),i=f.attr("data-sectionreturn")?f.attr("data-sectionreturn"):0,j=p(c),k=b.call([{methodname:"core_course_edit_section",args:{id:e,action:h,sectionreturn:i}}],!0),m=q(c);a.when.apply(a,k).done(function(b){var d=a.parseJSON(b);r(c,j);s(m);c.find(l.SECTIONACTIONMENU).find(l.TOGGLE).focus();var i=a.Event("coursesectionedited",{ajaxreturn:d,action:h});c.trigger(i);if(!i.isDefaultPrevented()){B(c,f,d,g)}}).fail(function(b){r(c,j);s(m);var f=a.Event("coursesectioneditfailed",{exception:b,action:h});c.trigger(f);if(!f.isDefaultPrevented()){d.exception(b)}})};g.use("moodle-course-coursebase",function(){M.course.coursebase.register_module({set_visibility_resource_ui:function set_visibility_resource_ui(b){var c=a(b.element.getDOMNode()),d=m(c);if(d){var e=c.find("."+k.EDITINGMOVE).attr("data-sectionreturn");x(c,d,e)}}})});return{initCoursePage:function initCoursePage(b){a("body").on("click keypress",l.ACTIVITYLI+" "+l.ACTIVITYACTION+"[data-action]",function(b){if("keypress"===b.type&&13!==b.keyCode){return}var c=a(this),d=c.closest(l.ACTIVITYLI),e=c.attr("data-action"),f=m(d);switch(e){case"moveleft":case"moveright":case"delete":case"duplicate":case"hide":case"stealth":case"show":case"groupsseparate":case"groupsvisible":case"groupsnone":break;default:return;}if(!f){return}b.preventDefault();if("delete"===e){y(d,function(){w(d,f,c)})}else{w(d,f,c)}});a("body").on("click keypress",l.SECTIONLI+" "+l.SECTIONACTIONMENU+"[data-sectionid] a[data-action]",function(c){if("keypress"===c.type&&13!==c.keyCode){return}var d=a(this),e=d.closest(l.SECTIONLI),f=d.closest(l.SECTIONACTIONMENU).attr("data-sectionid");c.preventDefault();if(d.attr("data-confirm")){z(d.attr("data-confirm"),function(){D(e,f,d,b)})}else{D(e,f,d,b)}});e.get_string("numberweeks").done(function(b){var c=a(l.ADDSECTIONS),d=c.attr("data-add-sections"),e=c.attr("new-sections"),f=a("<div><label for=\"add_section_numsections\"></label> <input id=\"add_section_numsections\" type=\"number\" min=\"1\" max=\""+e+"\" value=\"1\"></div>");f.find("label").html(b);h.create({title:d,type:h.types.SAVE_CANCEL,body:f.html()},c).done(function(b){var e=a(b.getBody()).find("#add_section_numsections"),f=function(){if(""+parseInt(e.val())===e.val()&&1<=parseInt(e.val())){document.location=c.attr("href")+"&numsections="+parseInt(e.val())}};b.setSaveButtonText(d);b.getRoot().on(i.shown,function(){e.focus().select().on("keydown",function(a){if(a.keyCode===j.enter){f()}})});b.getRoot().on(i.save,function(a){a.preventDefault();f()})})})},replaceSectionActionItem:function replaceSectionActionItem(a,b,c,d,e,f,g,h){var i=a.find(l.SECTIONACTIONMENU+" "+b);A(i,c,d,e,f,g,h)}}});
2 //# sourceMappingURL=actions.min.js.map