moodle-block_mytreestudyplan/amd/build/leveleditor.min.js

1 line
No EOL
2.2 KiB
JavaScript

define(["jquery","block_gradelevel/jquery.animate-shadow","core/str","core/ajax","block_gradelevel/jscolor","block_gradelevel/handlers","block_gradelevel/debugger"],function(e,t,l,a,n,i,o){let d=new o("leveleditor");d.enable();let r=null,s=null,c={init:function(){s=e("table#level_config"),(r=Number(s.attr("data-skill")))||0===r||"0"===r?(e(document).on("input","input[type=number].uint",function(t){let l=e(this);l.val()<0&&l.val(0)}),e("a[data-action=addlevel]").on("click",function(e){c.add_levelrow(-255,"","7F7F7F")}),e("button[data-action=savechanges]").on("click",c.submit),e("button[data-action=resetlevels]").on("click",c.resetlevels)):d.error("Cannot find configured skill id")},add_levelrow:function(t,l,a){let i=e("<tr data-rowid='"+t+"'><td><input data-name='points' type='number' class='uint' value='"+l+"'></td><td><input type='text' data-name='color' class='jscolor' value='"+a+"'></td></tr>");i.find("input.jscolor").each(function(){new n(this)}),s.find("tbody").append(i)},refresh:function(){d.info("Attempting to refresh"),a.call([{methodname:"block_gradelevel_list_levels",args:{skill_id:r}}])[0].done(c.success_refill_table).fail(c.fail_report_exception)},submit:function(t){let l=[];e("table#level_config").find("tbody tr[data-rowid]").each(function(){let t=e(this),a={id:Number(t.attr("data-rowid")),points:t.find("input[data-name=points]").val(),badgecolor:t.find("input[data-name=color]").val()};""===a.points&&(a.points=-255),a.points=Number(a.points),l.push(a)}),a.call([{methodname:"block_gradelevel_submit_levels",args:{skill_id:r,levels:l}}])[0].done(c.success_refill_table).fail(i.fail_report_exception)},resetlevels:function(t){let l=[];e("table#level_config").find("tbody tr[data-rowid]").each(function(){let t=e(this),a={id:Number(t.attr("data-rowid")),points:-255,badgecolor:""};l.push(a)}),a.call([{methodname:"block_gradelevel_submit_levels",args:{skill_id:r,levels:l}}])[0].done(c.success_refill_table).fail(i.fail_report_exception)},success_refill_table:function(e){let t=s.find("tbody");t.empty();for(let t in e){let l=e[t];c.add_levelrow(l.id,l.points,l.badgecolor)}t.find("input[data-name='points']").animate({boxShadow:"0px 0px 5px 3px #3FDFCF"},400).delay(200).animate({boxShadow:"none"},800)}};return c});