AutorÃa | Ultima modificación | Ver Log |
YUI.add("moodle-course-management",function(s,e){var i,o,r,t,n=function(){n.superclass.constructor.apply(this,arguments)};n.NAME="moodle-course-management",n.CSS_PREFIX="management",n.ATTRS={element:{setter:function(e){return e="string"==typeof e?s.one("#"+e):e}},categorylisting:{value:null},courselisting:{value:null},coursedetails:{value:null},activecategoryid:{value:null},activecourseid:{value:null},categories:{setter:function(e,t){if(s.Lang.isArray(e))return e;t=this.get(t);return t.push(e),t},value:[]},courses:{validator:function(e){return s.Lang.isArray(e)},value:[]},page:{getter:function(e,t){return null===e&&(e=this.get("element").getData(t),this.set(t,e)),e},value:null},totalpages:{getter:function(e,t){return null===e&&(e=this.get("element").getData(t),this.set(t,e)),e},value:null},totalcourses:{getter:function(e,t){return null===e&&(e=this.get("element").getData(t),this.set(t,e)),e},value:null},ajaxurl:{getter:function(e){return e=null===e?M.cfg.wwwroot+"/course/ajax/management.php":e},value:null},d
ragdrop:{value:null}},s.extend(n,s.Base,n.prototype={categoriesinit:!1,initializer:function(){this.set("element","coursecat-management");var e=this.get("element"),t=e.one("#category-listing"),i=e.one("#course-listing"),o=null,n=null;t&&(o=t.one('.listitem[data-selected="1"]')),i&&(n=i.one('.listitem[data-selected="1"]')),this.set("categorylisting",t),this.set("courselisting",i),this.set("coursedetails",e.one("#course-detail")),o&&this.set("activecategoryid",o.getData("id")),n&&this.set("activecourseid",n.getData("id")),this.initialiseCategories(t),this.initialiseCourses(),i&&this.set("dragdrop",new r({console:this}))},initialiseCategories:function(e){var t;if(!e)return!1;(t=e.one("#menumovecategoriesto"))&&t.setAttribute("disabled",!0),(t=e.one("#menuresortcategoriesby"))&&t.setAttribute("disabled",!0),(t=e.one("#menuresortcoursesby"))&&t.setAttribute("disabled",!0),e.all(".listitem[data-id]").each(function(e){this.set("categories",new i({node:e,console:this})),0},this),this.categoriesinit||(this.get("catego
rylisting").delegate("click",this.handleCategoryDelegation,"a[data-action]",this),this.get("categorylisting").delegate("click",this.handleCategoryDelegation,'input[name="bcat[]"]',this),this.get("categorylisting").delegate("change",this.handleBulkSortByaction,"#menuselectsortby",this),this.categoriesinit=!0)},initialiseCourses:function(){var e,t=this.getCategoryById(this.get("activecategoryid")),i=this.get("courselisting");if(!i)return!1;(e=i.one("#menumovecoursesto"))&&e.setAttribute("disabled",!0),i.all(".listitem[data-id]").each(function(e){this.registerCourse(new o({node:e,console:this,category:t})),0},this),i.delegate("click",this.handleCourseDelegation,"a[data-action]",this),i.delegate("click",this.handleCourseDelegation,'input[name="bc[]"]',this)},registerCourse:function(e){var t=this.get("courses");t.push(e),this.set("courses",t)},handleCourseDelegation:function(e){var t=e.currentTarget,i=t.getData("action"),t=t.ancestor(".listitem").getData("id"),t=this.getCourseById(t);t&&t.handle(i,e)},handleCateg
oryDelegation:function(e){var t=e.currentTarget,i=t.getData("action"),t=t.ancestor(".listitem").getData("id"),t=this.getCategoryById(t);t&&t.handle(i,e)},isCourseSelected:function(e){var t,i,o,n=!1;if(e&&e.get("checked"))n=!0;else for(o=(i=this.get("courses")).length,t=0;t<o;t++)if(i.hasOwnProperty(t)&&i[t].get("node").one('input[name="bc[]"]').get("checked")){n=!0;break}return n},isCategorySelected:function(e){var t,i,o,n=!1;if(e&&e.get("checked"))n=!0;else for(o=(i=this.get("categories")).length,t=0;t<o;t++)if(i.hasOwnProperty(t)&&i[t].get("node").one('input[name="bcat[]"]').get("checked")){n=!0;break}return n},handleBulkSortByaction:function(e){var t=this.get("categorylisting").one("#menuresortcategoriesby"),i=this.get("categorylisting").one("#menuresortcoursesby"),o=this.get("categorylisting").one('input[name="bulksort"]'),n=e;n?e&&e.currentTarget&&(n=e.currentTarget):n=this.get("categorylisting").one("#menuselectsortby"),n&&(this.get("categories").length<=1||!this.isCategorySelected()&&"selectedcategori
es"===n.get("options").item(n.get("selectedIndex")).getAttribute("value")?(t&&t.setAttribute("disabled",!0),i&&i.setAttribute("disabled",!0),o&&o.setAttribute("disabled",!0)):(t&&t.removeAttribute("disabled"),i&&i.removeAttribute("disabled"),o&&o.removeAttribute("disabled")))},getCategoryById:function(e){for(var t,i=this.get("categories"),o=i.length,n=0;n<o;n++)if(i.hasOwnProperty(n)&&(t=i[n]).get("categoryid")===e)return t;return!1},getCourseById:function(e){for(var t,i=this.get("courses"),o=i.length,n=0;n<o;n++)if(i.hasOwnProperty(n)&&(t=i[n]).get("courseid")===e)return t;return!1},removeCourseById:function(e){for(var t=this.get("courses"),i=t.length,o=0;o<i;o++)if(t[o].get("courseid")===e){t.splice(o,1);break}},performAjaxAction:function(e,t,i,o){var n=new s.IO;t.action=e,t.ajax="1",t.sesskey=M.cfg.sesskey,null===i&&(i=function(){}),n.send(this.get("ajaxurl"),{method:"POST",on:{complete:i},context:o,data:t,arguments:t})}}),M.course=M.course||{},M.course.management=M.course.management||{},M.course.manageme
nt.console=null,M.course.management.init=function(e){M.course.management.console=new n(e)},(r=function(e){n.superclass.constructor.apply(this,[e])}).NAME="moodle-course-management-dd",r.CSS_PREFIX="management-dd",r.ATTRS={console:{writeOnce:"initOnly"}},r.prototype={goingup:!1,lasty:null,previoussibling:null,initializer:function(){var e=this.get("console").get("element"),t=e.one("#category-listing"),i=e.one("#course-listing > .course-listing"),t=t?t.one("ul.ml"):null,o=i?i.one("ul.ml"):null,i=!!i&&i.getData("canmoveoutof"),n=i?e:o;if(!o)return!1;for(;0===n.get("scrollHeight")&&!n.compareTo(window.document.body);)n=n.get("parentNode");o.all("> li").each(function(e){this.initCourseListing(e,n)},this),o.setData("dd",new s.DD.Drop({node:o})),i&&t&&t.all("li > div").each(function(e){this.initCategoryListitem(e)},this),s.DD.DDM.on("drag:start",this.dragStart,this),s.DD.DDM.on(
"drag:end",this.dragEnd,this),s.DD.DDM.on("drag:drag",this.dragDrag,this),s.DD.DDM.on("drop:over",this.dropOver,this),s.DD.DDM.on("drop:enter",this.dropEnter,this),s.DD.DDM.on("drop:exit",this.dropExit,this),s.DD.DDM.on("drop:hit",this.dropHit,this)},initCourseListing:function(e,t){e.setData("dd",new s.DD.Drag({node:e,target:{padding:"0 0 0 20"}}).addHandle(".drag-handle").plug(s.Plugin.DDProxy,{moveOnEnd:!1,borderStyle:!1}).plug(s.Plugin.DDConstrained,{constrain2node:t}))},initCategoryListitem:function(e){e.setData("dd",new s.DD.Drop({node:e}))},dragStart:function(e){var e=e.target,t=e.get("node"),e=e.get("dragNode");t.addClass("course-being-dragged"),e.addClass("course-being-dragged-proxy").set("innerHTML",t.one("a.coursename").get("innerHTML")),this.previoussibling=t.get("previousSibling")},dragEnd:function(e){e.target.get("node").removeClass("course-being-dragged"),this.get("console").get("element").all("#category-listing li.highlight").removeClass("highlight")},dragDrag:function(e){e=e.target.lastXY[1];
e<this.lasty?this.goingup=!0:this.goingup=!1,this.lasty=e},dropOver:function(e){var t=e.drag.get("node"),i=e.drop.get("node");if("li"===i.get("tagName").toLowerCase()&&i.hasClass("listitem-course")){if(!this.goingup&&!(i=i.get("nextSibling")))return(i=e.drop.get("node")).get("parentNode").append(t),!1;i.get("parentNode").insertBefore(t,i),e.drop.sizeShim()}},dropEnter:function(e){e=e.drop.get("node");"div"===e.get("tagName").toLowerCase()&&e.ancestor("li.listitem-category").addClass("highlight")},dropExit:function(e){e=e.drop.get("node");"div"===e.get("tagName").toLowerCase()&&e.ancestor("li.listitem-category").removeClass("highlight")},dropHit:function(e){var t,i,o=e.drag.get("node"),e=e.drop.get("node"),n=null!==e.ancestor(".listitem-category"),s=!n&&e.test(".listitem-course"),r=this.get("console");if(!o.test(".listitem-course"))return!1;t=o.getData("id"),n?(n=e.ancestor(".listitem-category").getData("id"),(n=r.getCategoryById(n))&&(i=r.getCourseById(t))&&n.moveCourseTo(i)):(s||e.ancestor("#course-listing"
))&&(i=r.getCourseById(t),(s=(n=o.get("previousSibling"))&&n.getData("id")||0)!==(e=this.previoussibling?this.previoussibling.getData("id"):0)&&i.moveAfter(s,e))}},s.extend(r,s.Base,r.prototype),(t=function(){t.superclass.constructor.apply(this,arguments)}).NAME="moodle-course-management-item",t.CSS_PREFIX="management-item",t.ATTRS={node:{},console:{},itemname:{value:"item"}},s.extend(t,s.Base,t.prototype={highlighttimeout:null,checkAjaxResponse:function(e,t,i){if(200!==t.status)return!1;if(null===e||null===i)return!1;e=s.JSON.parse(t.responseText);return!1!==e.error&&new M.core.exception(e),!1!==e.outcome&&e},moveup:function(e,t,i){var o,n;if(!1===this.checkAjaxResponse(e,t,i))return!1;(t=(e=this.get("node")).previous(".listitem"))?(t.insert(e,"before"),i=t.one(" > div a.action-moveup"),n=e.one(" > div a.action-movedown"),i&&n||(o=e.one(" > div a.action-moveup"),t=t.one(" > div a.action-movedown"),i||n?n||o.insert(t,"after"):(i=s.Node.create('<a style="visibility:hidden;"> </a>'),t.replace(i),o.replace
(t),i.replace(o),i.destroy())),(o=e.one(" > div a.action-moveup"))?o.focus():(n=e.one(" > div a.action-movedown"))&&n.focus(),this.updated(!0)):window.location.reload()},movedown:function(e,t,i){var o,n;if(!1===this.checkAjaxResponse(e,t,i))return!1;(t=(e=this.get("node")).next(".listitem"))?(e.insert(t,"before"),i=t.one(" > div a.action-movedown"),o=e.one(" > div a.action-moveup"),i&&o||(t=t.one(" > div a.action-moveup"),n=e.one(" > div a.action-movedown"),i||o?o||n.insert(t,"before"):(i=s.Node.create('<a style="visibility:hidden;"> </a>'),t.replace(i),n.replace(t),i.replace(n),i.destroy())),(n=e.one(" > div a.action-movedown"))?n.focus():(o=e.one(" > div a.action-moveup"))&&o.focus(),this.updated(!0)):window.location.reload()},show:function(e,t,i){if(!1===this.checkAjaxResponse(e,t,i))return!1;this.markVisible(),(e=this.get("node").one("a[data-action=hide]"))&&e.focus(),this.updated()},markVisible:function(){return this.get("node").setAttribute("data-visible","1"),!0},hide:function(e,t,i){if(!1===this
.checkAjaxResponse(e,t,i))return!1;this.markHidden(),(e=this.get("node").one("a[data-action=show]"))&&e.focus(),this.updated()},markHidden:function(){return this.get("node").setAttribute("data-visible","0"),!0},updated:function(e){e&&this.highlight()},highlight:function(){var e=this.get("node");e.siblings(".highlight").removeClass("highlight"),e.addClass("highlight"),this.highlighttimeout&&window.clearTimeout(this.highlighttimeout),this.highlighttimeout=window.setTimeout(function(){e.removeClass("highlight")},2500)}}),(i=function(){i.superclass.constructor.apply(this,arguments)}).NAME="moodle-course-management-category",i.CSS_PREFIX="management-category",i.ATTRS={categoryid:{getter:function(e,t){return null===e&&(e=this.get("node").getData("id"),this.set(t,e)),e},value:null,writeOnce:!0},selected:{getter:function(e,t){return null===e&&(e=this.get("node").getData(t),this.set(t,e=null===e?!1:e)),e},value:null},courses:{validator:function(e){return s.Lang.isArray(e)},value:[]}},i.prototype={initializer:function
(){this.set("itemname","category")},getName:function(){return this.get("node").one("a.categoryname").get("innerHTML")},registerCourse:function(e){var t=this.get("courses");t.push(e),this.set("courses",t)},handle:function(e,t){var i,o,n={categoryid:this.get("categoryid")},s=this.get("console").get("activecategoryid");switch(s&&s!==n.categoryid&&(n.selectedcategory=s),e){case"moveup":t.preventDefault(),this.get("console").performAjaxAction("movecategoryup",n,this.moveup,this);break;case"movedown":t.preventDefault(),this.get("console").performAjaxAction("movecategorydown",n,this.movedown,this);break;case"show":t.preventDefault(),this.get("console").performAjaxAction("showcategory",n,this.show,this);break;case"hide":t.preventDefault(),this.get("console").performAjaxAction("hidecategory",n,this.hide,this);break;case"expand":t.preventDefault(),"0"===this.get("node").getData(
"expanded")&&(this.get("node").setAttribute("data-expanded","1").setData("expanded","true"),this.get("console").performAjaxAction("getsubcategorieshtml",n,this.loadSubcategories,this)),this.expand();break;case"collapse":t.preventDefault(),this.collapse();break;case"select":(o=(i=this.get("console")).get("categorylisting").one("#menumovecategoriesto"))&&(i.isCategorySelected(t.currentTarget)&&1<i.get("categories").length?o.removeAttribute("disabled"):o.setAttribute("disabled",!0),i.handleBulkSortByaction());break;default:return!1}},expand:function(){var e=this.get("node"),o=e.one("a[data-action=expand]"),t=e.one("ul[role=group]");e.removeClass("collapsed").setAttribute("aria-expanded","true"),o.setAttribute("data-action","collapse").setAttrs({title:M.util.get_string("collapsecategory","moodle",this.getName())}),require(["core/str","core/templates","core/notification"],function(e,t,i){e.get_string("collapse","core").then(function(e){return t.renderPix("t/switch_minus","core",e)}).then(function(e){return e=s.No
de.create(e).addClass("tree-icon").getDOMNode().outerHTML,o.set("innerHTML",e)}).fail(i.exception)}),t&&t.setAttribute("aria-hidden","false"),this.get("console").performAjaxAction("expandcategory",{categoryid:this.get("categoryid")},null,this)},collapse:function(){var e=this.get("node"),o=e.one("a[data-action=collapse]"),t=e.one("ul[role=group]");e.addClass("collapsed").setAttribute("aria-expanded","false"),o.setAttribute("data-action","expand").setAttrs({title:M.util.get_string("expandcategory","moodle",this.getName())}),require(["core/str","core/templates","core/notification"],function(e,t,i){e.get_string("expand","core").then(function(e){return t.renderPix("t/switch_plus","core",e)}).then(function(e){return e=s.Node.create(e).addClass("tree-icon").getDOMNode().outerHTML,o.set("innerHTML",e)}).fail(i.exception)}),t&&t.setAttribute("aria-hidden","true"),this.get("console").performAjaxAction("collapsecategory",{categoryid:this.get("categoryid")},null,this)},loadSubcategories:function(e,t,i){var e=this.checkA
jaxResponse(e,t,i),t=this.get("node"),i=this.get("console");return!1!==e&&(t.append(e.html),i.initialiseCategories(t),M.core&&M.core.actionmenu&&M.core.actionmenu.newDOMNode&&M.core.actionmenu.newDOMNode(t),e=t.one("ul[role=group]"),i=t.one("a[data-action=collapse]"),e&&i&&i.setAttribute("aria-controls",e.generateID()),!0)},moveCourseTo:function(t){require(["core/notification"],function(e){e.saveCancelPromise(M.util.get_string("confirmation","admin"),M.util.get_string("confirmcoursemove","moodle",{course:t.getName(),category:this.getName()}),M.util.get_string("move","moodle")).then(function(){this.get("console").performAjaxAction("movecourseintocategory",{courseid:t.get("courseid"),categoryid:this.get("categoryid")},this.completeMoveCourse,this)}.bind(this))["catch"](function(){})}.bind(this))},completeMoveCourse:function(e,t,i){var o,n,e=this.checkAjaxResponse(e,t,i),t=this.get("console");return!1!==e&&(!!(i=t.getCourseById(i.courseid))&&(this.highlight(),i&&(e.paginationtotals&&(n=t.get("courselisting").on
e(".listing-pagination-totals"))&&n.set("innerHTML",e.paginationtotals),"undefined"!==e.totalcatcourses&&(n=this.get("node").one(".course-count span"))&&n.set("innerHTML",n.get("innerHTML").replace(/^\d+/,e.totalcatcourses)),"undefined"!=typeof e.fromcatcoursecount&&(o=t.get("activecategoryid"),(o=t.getCategoryById(o))&&(n=o.get("node").one(".course-count span"))&&n.set("innerHTML",n.get("innerHTML").replace(/^\d+/,e.fromcatcoursecount))),i.remove()),!0))},show:function(e,t,i){e=this.checkAjaxResponse(e,t,i);if(!1===e)return!1;this.markVisible(),(t=this.get("node").one("a[data-action=hide]"))&&t.focus(),e.categoryvisibility&&this.updateChildVisibility(e.categoryvisibility),e.coursevisibility&&this.updateCourseVisiblity(e.coursevisibility),this.updated()},hide:function(e,t,i){e=this.checkAjaxResponse(e,t,i);if(!1===e)return!1;this.markHidden(),(t=this.get("node").one("a[data-action=show]"))&&t.focus(),e.categoryvisibility&&this.updateChildVisibility(e.categoryvisibility),e.coursevisibility&&this.updateCourseV
isiblity(e.coursevisibility),this.updated()},updateCourseVisiblity:function(e){var t,i,o=this.get("console");try{for(t in e)"object"==typeof e[t]&&(i=o.getCourseById(e[t].id))&&("1"===e[t].visible?i.markVisible():i.markHidden())}catch(n){}return this},updateChildVisibility:function(e){var t,i,o=this.get("console");try{for(t in e)"object"==typeof e[t]&&(i=o.getCategoryById(e[t].id))&&("1"===e[t].visible?i.markVisible():i.markHidden())}catch(n){}return this}},s.extend(i,t,i.prototype),(o=function(){o.superclass.constructor.apply(this,arguments)}).NAME="moodle-course-management-course",o.CSS_PREFIX="management-course",o.ATTRS={courseid:{},selected:{getter:function(e,t){return null===e&&(e=this.get("node").getData(t),this.set(t,e)),e},value:null},node:{},console:{writeOnce:"initOnly"},category:{writeOnce:"initOnly"}},o.prototype={initializer:function(){var e=this.get("node"),t=this.get("category");this.set("courseid",e.getData("id")),t&&t.registerCourse&&t.registerCourse(this),this.set("itemname","course")},getN
ame:function(){return this.get("node").one("a.coursename").get("innerHTML")},handle:function(e,t){var i,o,n=this.get("console"),s={courseid:this.get("courseid")};switch(e){case"moveup":t.halt(),n.performAjaxAction("movecourseup",s,this.moveup,this);break;case"movedown":t.halt(),n.performAjaxAction("movecoursedown",s,this.movedown,this);break;case"show":t.halt(),n.performAjaxAction("showcourse",s,this.show,this);break;case"hide":t.halt(),n.performAjaxAction("hidecourse",s,this.hide,this);break;case"select":(o=(i=this.get("console")).get("courselisting").one("#menumovecoursesto"))&&(i.isCourseSelected(t.currentTarget)?o.removeAttribute("disabled"):o.setAttribute("disabled",!0));break;default:return!1}},remove:function(){this.get("console").removeCourseById(this.get("courseid")),this.get("node").remove()},moveAfter:function(e,t){var i=this.get("console"),e={courseid:this.get(
"courseid"),moveafter:e,previous:t};i.performAjaxAction("movecourseafter",e,this.moveAfterResponse,this)},moveAfterResponse:function(e,t,i){var e=this.checkAjaxResponse(e,t,i),t=this.get("node");if(!1===e)return(e=t.ancestor("ul").one("li[data-id="+i.previous+"]"))?e.insertAfter(t,"after"):t.ancestor("ul").one("li").insert(t,"before"),!1;this.highlight()}},s.extend(o,t,o.prototype)},"@VERSION@",{requires:["base","node","io-base","moodle-core-notification-exception","json-parse","dd-constrain","dd-proxy","dd-drop","dd-delegate","node-event-delegate"]});