Current Path : /var/www/ljmtc/cbt/mod/grouptool/amd/build/ |
Current File : /var/www/ljmtc/cbt/mod/grouptool/amd/build/sortlist.min.js |
define ("mod_grouptool/sortlist",["jquery","jqueryui","core/ajax","core/templates","core/str","core/log","core/notification"],function(a,b,c,d,e,f,g){var h=function(){this.cmid=0};h.prototype.updateCheckboxes=function(b,c){var d="";a("select[name=\"classes[]\"] option:selected").each(function(b,c){if(""!==d){d+=", "}d+=".class"+a(c).val()});var e=a(d);b.preventDefault();switch(c){case"select":e.prop("checked",!0);break;case"deselect":e.prop("checked",!1);break;case"toggle":e.each(function(b,c){if(a(c).prop("checked")){a(c).prop("checked",!1)}else{a(c).prop("checked",!0)}});break;default:f.info("Undefined new checkbox state!","grouptool");break;}};h.prototype.dragStartHandler=function(a,b){var c=b.helper;c.find("a[data-movedown], a[data-moveup]").css("visibility","visible")};h.prototype.dragEndHandler=function(b){var e=[],h=a(".mod_grouptool_sortlist_body .mod_grouptool_sortlist_entry");h.find("a[data-movedown], a[data-moveup]").css("visibility","visible");h.first().find("a[data-moveup]").css("visibility","hidden");h.last().find("a[data-movedown]").css("visibility","hidden");h.each(function(b){a(this).attr("order",b+1);a(this).find("input[name=\"order["+a(this).data("id")+"]\"]").val(b+1);e.push({groupid:a(this).data("id"),order:b+1})});var i=c.call([{methodname:"mod_grouptool_reorder_groups",args:{cmid:b.data.cmid,order:e},fail:g.exception}]);i[0].then(function(b){var c={message:"",extraclasses:"infonode"},e="core/notification_success",h=5000;if(b.error){e="core/notification_error";c.message=b.error;h=60000;f.info("AJAX Call to reorder groups successfull\nError ocured:"+b.error+"\n"+status,"grouptool");d.render(e,c).then(function(b){var c=a(b);c.hide(0);a("table.drag_list").before(c);c.slideDown(600,function(){window.setTimeout(function(){c.slideUp(600,function(){c.remove()})},h)});return this}).fail(g.exception)}else{c.message=b.message;f.info("AJAX Call to reorder groups successfull\n"+b.message+"\n"+status,"grouptool")}return this}).fail(g.exception)};h.prototype.moveDown=function(b){var d=a(b.target),e=d.closest(".mod_grouptool_sortlist_entry"),h=d.closest(".mod_grouptool_sortlist_entry").next(".mod_grouptool_sortlist_entry"),i=e.data("order"),j=h.data("order");b.preventDefault();b.stopPropagation();var k=c.call([{methodname:"mod_grouptool_swap_groups",args:{cmid:b.data.cmid,a:e.data("id"),b:h.data("id")},fail:g.exception}]);k[0].then(function(a){if(a.error){g.exception(a.error)}else{h.after(e.clone(!0));e.replaceWith(h);e.data("order",j);e.find("input[name=\"order["+e.data("id")+"]\"]").val(j);h.data("order",i);h.find("input[name=\"order["+h.data("id")+"]\"]").val(i);f.info(a.message)}return this}).fail(g.exception)};h.prototype.moveUp=function(b){var d=a(b.target),e=d.closest(".mod_grouptool_sortlist_entry"),h=d.closest(".mod_grouptool_sortlist_entry").prev(".mod_grouptool_sortlist_entry"),i=e.data("order"),j=h.data("order");b.preventDefault();b.stopPropagation();var k=c.call([{methodname:"mod_grouptool_swap_groups",args:{cmid:b.data.cmid,a:e.data("id"),b:h.data("id")},fail:g.exception}]);k[0].then(function(a){if(a.error){g.exception(a.error)}else{h.before(e.clone(!0));e.replaceWith(h);e.data("order",j);e.find("input[name=\"order["+e.data("id")+"]\"]").val(j);h.data("order",i);h.find("input[name=\"order["+h.data("id")+"]\"]").val(i);f.info(a.message)}return this}).fail(g.exception)};var i=new h;i.initializer=function(b){i.cmid=b;f.info("Initialize Grouptool sortlist","grouptool");a(".path-mod-grouptool .mod_grouptool_sortlist .mod_grouptool_sortlist_body").sortable({containment:".mod_grouptool_sortlist .mod_grouptool_sortlist_body",cursor:"move",delay:150,handle:"[data-drag]",items:" .mod_grouptool_sortlist_entry",opacity:.5,helper:"clone",axis:"y",start:i.dragStartHandler,stop:function stop(a){a.data=i;i.dragEndHandler(a)}});var c=a(".path-mod-grouptool .mod_grouptool_sortlist tr[data-id] [data-drag]");a(".path-mod-grouptool .mod_grouptool_sortlist tr .js_invisible").removeClass("js_invisible");c.removeClass("js_invisible");c.css("cursor","pointer");var d=a(".path-mod-grouptool .mod_grouptool_sortlist");d.on("click","tr[data-id] a[data-movedown]",this,i.moveDown);d.on("click","tr[data-id] a[data-moveup]",this,i.moveUp);var e=a("button[name=\"do_class_action\"]");if(e){require(["mod_grouptool/multiseltoggle"],function(b){var c=a("select[name=\"classes[]\"]");b.enable(c.get()[0])});e.on("click",function(b){var c="";a("input[name=\"class_action\"]").each(function(d,e){if(!0===a(e).prop("checked")){c=a(e).val();f.info("Update checkboxes '"+c+"'!");i.updateCheckboxes(b,c)}})})}else{f.info("No sortlist controller found!","grouptool")}a(".simple_select_all").on("click",function(b){f.info("Bind select-all handler!","grouptool");b.preventDefault();b.stopPropagation();a(".class0").prop("checked",!0)});a(".simple_select_none").on("click",function(b){f.info("Bind deselect-all handler!","grouptool");b.preventDefault();b.stopPropagation();a(".class0").prop("checked",!1)})};return i}); //# sourceMappingURL=sortlist.min.js.map