You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
7.1 KiB

define(["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();a&&(l.SECTIONLI=a)});var m=function(a){var b;return g.use("moodle-course-util",function(c){b=c.Moodle.core_course.util.cm.getId(c.Node(a.get(0)))}),b},n=function(a){var b;return g.use("moodle-course-util",function(c){b=c.Moodle.core_course.util.cm.getName(c.Node(a.get(0)))}),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));return c.show(),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));return c.show(),c}return null},q=function(a){var b=M.util.add_lightbox(g,g.Node(a.get(0)));return b.show(),b},r=function(a,b,c){window.setTimeout(function(){a.removeClass(k.EDITINPROGRESS),b&&b.hide()},c)},s=function(a,b){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)}),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+"]";"groupsseparate"!==c&&"groupsvisible"!==c&&"groupsnone"!==c||(e="[data-action=groupsseparate],[data-action=groupsvisible],[data-action=groupsnone]"),d.find(e).is(":visible")?d.find(e).focus():d.find(l.MENU).find(l.TOGGLE).focus()},v=function(b){var c=a("a:visible"),d=!1,e=null;return c.each(function(){if(a.contains(b[0],this))d=!0;else if(d)return e=this,!1}),e},w=function(c,e,f){var g,h=f.attr("data-action"),i=o(c),j=b.call([{methodname:"core_course_edit_module",args:{id:e,action:h,sectionreturn:f.attr("data-sectionreturn")?f.attr("data-sectionreturn"):0}}],!0);"duplicate"===h&&(g=q(f.closest(l.SECTIONLI))),a.when.apply(a,j).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")),0===b&&(u(a(this).attr("id"),h),d=null)}),d&&d.focus(),r(c,i,400),s(g,400),c.trigger(a.Event("coursemoduleedited",{ajaxreturn:b,action:h}))}).fail(function(b){r(c,i),s(g);var e=a.Event("coursemoduleeditfailed",{exception:b,action:h});c.trigger(e),e.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){var c={type:a,name:f};e.get_strings([{key:"confirm"},{key:null===f?"deletechecktype":"deletechecktypename",param:c},{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){var k=[{key:f,component:g}];return e.get_strings(k).then(function(d){return a.find("span.menu-action-text").html(d[0]),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")):(b.removeClass("hidden"),A(c,"i/hide","hidefromothers","format_"+e,null,null,"hide")),void 0!==d.modules)for(var g in d.modules)C(d.modules[g]);void 0!==d.section_availability&&b.find(".section_av