src/pyams_skin/resources/js/myams-tree.min.js
changeset 489 63ea9a94bd47
parent 486 48b7cea0d903
child 494 6ca0da3caede
equal deleted inserted replaced
488:efdf19b8f453 489:63ea9a94bd47
     1 !function(a,e){var t=e.MyAMS;t.tree={switchTableNode:function(){function e(t){a('tr[data-ams-tree-node-parent-id="'+t+'"]').each(function(){var t=a(this);e(t.data("ams-tree-node-id")),t.remove()})}var s=a(this),r=a("i.switch",s),n=s.parents("tr").first(),d=n.parents("table").first();if(r.hasClass("fa-minus-square-o"))e(n.data("ams-tree-node-id")),r.removeClass("fa-minus-square-o").addClass("fa-plus-square-o");else{var o=n.data("ams-location")||d.data("ams-location")||"",i=n.data("ams-tree-nodes-target")||d.data("ams-tree-nodes-target")||"get-tree-nodes.json",l=n.data("ams-element-name");r.removeClass("fa-plus-square-o").addClass("fa-cog fa-spin"),t.ajax.post(o+"/"+l+"/"+i,{can_sort:!a("td.sorter",n).is(":empty")},function(e,s){if(e.length>0){for(var o=n,i=0;i<e.length;i++){var l=a(e[i]);l.insertAfter(o).addClass("no-drag-handle"),t.initContent(l),o=l}d.hasClass("table-dnd")&&d.tableDnDUpdate()}r.removeClass("fa-cog fa-spin").addClass("fa-minus-square-o")})}},switchTree:function(){var e=a(this),s=a("i.switch",e),r=a(this).parents("table").first(),n=r.data("ams-tree-node-id");if(s.hasClass("fa-minus-square-o"))a("tr[data-ams-tree-node-parent-id]").filter('tr[data-ams-tree-node-parent-id!="'+n+'"]').remove(),a("i.switch",r).removeClass("fa-minus-square-o").addClass("fa-plus-square-o");else{var d=a("tbody tr",r).first(),o=r.data("ams-location")||"",i=r.data("ams-tree-nodes-target")||"get-tree.json";s.removeClass("fa-plus-square-o").addClass("fa-cog fa-spin"),t.ajax.post(o+"/"+i,{can_sort:!a("td.sorter",d).is(":empty")},function(e,n){a("tr[data-ams-tree-node-id]",r).remove();for(var d=null,o=0;o<e.length;o++){var i=a(e[o]);null===d?i.appendTo(a("tbody",r)):i.insertAfter(d),i.addClass("no-drag-handle"),t.initContent(i),d=i}r.hasClass("table-dnd")&&r.tableDnDUpdate(),a("i.switch",r).removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),s.removeClass("fa-cog fa-spin").addClass("fa-minus-square-o")})}},sortTree:function(e,s){var r=a(e).data(),n=r.amsTabledndDropTarget;if(n){(s=a(s)).data("ams-disabled-handlers","click");try{var d=s.parents("table").first().data("ams-tree-node-id"),o=s.data("ams-tree-node-id"),i=s.data("ams-tree-node-parent-id"),l=s.prev("tr");if(l.exists()){var f=l.data("ams-tree-node-id"),m=a(".switch",l);if(m.hasClass("fa-minus-square-o"))if(i===f)var u="reorder";else u="reparent";else u=i===(f=l.data("ams-tree-node-parent-id"))?"reorder":"reparent"}else m=null,u=i===(f=d)?"reorder":"reparent";var p=t.getFunctionByName(n);if("function"==typeof p)p.call(table,e,v);else{if(!n.startsWith(window.location.protocol)){var c=r.amsLocation;c&&(n=c+"/"+n)}var v={action:u,child:o,parent:f,order:JSON.stringify(a("tr[data-ams-tree-node-id]").listattr("data-ams-tree-node-id")),can_sort:!a("td.sorter",s).is(":empty")};t.ajax.post(n,v,function(e){function r(e){a('tr[data-ams-tree-node-parent-id="'+e+'"]').each(function(){var e=a(this);r(e.attr("data-ams-tree-node-id")),e.remove()})}if(e.status)t.ajax.handleJSON(e);else{var n=a(s).parents("tbody").first();if(r(o),"reparent"===v.action){r(f),s.remove();for(var d=a('tr[data-ams-tree-node-id="'+f+'"]'),i=0;i<e.length;i++){var l=a(e[i]);d.exists()?l.insertAfter(d).addClass("no-drag-handle"):l.prependTo(n).addClass("no-drag-handle"),t.initContent(l),d=l}}a("tr").parents("table").tableDnDUpdate()}})}}finally{setTimeout(function(){a(s).removeData("ams-disabled-handlers")},50)}}return!1}}}(jQuery,this);
     1 !function(a,e){var t=e.MyAMS;t.tree={switchTableNode:function(){function e(t){a('tr[data-ams-tree-node-parent-id="'+t+'"]').each(function(){var t=a(this);e(t.data("ams-tree-node-id")),t.remove()})}var s=a(this),r=a("i.switch",s),n=s.parents("tr").first(),d=n.parents("table").first();if(r.hasClass("fa-minus-square-o"))e(n.data("ams-tree-node-id")),r.removeClass("fa-minus-square-o").addClass("fa-plus-square-o");else{var o=n.data("ams-location")||d.data("ams-location")||"",i=n.data("ams-tree-nodes-target")||d.data("ams-tree-nodes-target")||"get-tree-nodes.json",l=n.data("ams-element-name");r.removeClass("fa-plus-square-o").addClass("fa-cog fa-spin"),t.ajax&&t.ajax.post(o+"/"+l+"/"+i,{can_sort:!a("td.sorter",n).is(":empty")},function(e,s){if(e.length>0){for(var o=n,i=0;i<e.length;i++){var l=a(e[i]);l.insertAfter(o).addClass("no-drag-handle"),t.initContent&&t.initContent(l),o=l}d.hasClass("table-dnd")&&d.tableDnDUpdate()}r.removeClass("fa-cog fa-spin").addClass("fa-minus-square-o")})}},switchTree:function(){var e=a(this),s=a("i.switch",e),r=a(this).parents("table").first(),n=r.data("ams-tree-node-id");if(s.hasClass("fa-minus-square-o"))a("tr[data-ams-tree-node-parent-id]").filter('tr[data-ams-tree-node-parent-id!="'+n+'"]').remove(),a("i.switch",r).removeClass("fa-minus-square-o").addClass("fa-plus-square-o");else{var d=a("tbody tr",r).first(),o=r.data("ams-location")||"",i=r.data("ams-tree-nodes-target")||"get-tree.json";s.removeClass("fa-plus-square-o").addClass("fa-cog fa-spin"),t.ajax&&t.ajax.post(o+"/"+i,{can_sort:!a("td.sorter",d).is(":empty")},function(e,n){a("tr[data-ams-tree-node-id]",r).remove();for(var d=null,o=0;o<e.length;o++){var i=a(e[o]);null===d?i.appendTo(a("tbody",r)):i.insertAfter(d),i.addClass("no-drag-handle"),t.initContent&&t.initContent(i),d=i}r.hasClass("table-dnd")&&r.tableDnDUpdate(),a("i.switch",r).removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),s.removeClass("fa-cog fa-spin").addClass("fa-minus-square-o")})}},sortTree:function(e,s){var r=a(e).data(),n=r.amsTabledndDropTarget;if(n){(s=a(s)).data("ams-disabled-handlers","click");try{var d=s.parents("table").first().data("ams-tree-node-id"),o=s.data("ams-tree-node-id"),i=s.data("ams-tree-node-parent-id"),l=s.prev("tr");if(l.exists()){var f=l.data("ams-tree-node-id"),m=a(".switch",l);if(m.hasClass("fa-minus-square-o"))if(i===f)var u="reorder";else u="reparent";else u=i===(f=l.data("ams-tree-node-parent-id"))?"reorder":"reparent"}else m=null,u=i===(f=d)?"reorder":"reparent";var p=t.getFunctionByName(n);if("function"==typeof p)p.call(table,e,v);else{if(!n.startsWith(window.location.protocol)){var c=r.amsLocation;c&&(n=c+"/"+n)}var v={action:u,child:o,parent:f,order:JSON.stringify(a("tr[data-ams-tree-node-id]").listattr("data-ams-tree-node-id")),can_sort:!a("td.sorter",s).is(":empty")};t.ajax&&t.ajax.post(n,v,function(e){function r(e){a('tr[data-ams-tree-node-parent-id="'+e+'"]').each(function(){var e=a(this);r(e.attr("data-ams-tree-node-id")),e.remove()})}if(e.status)t.ajax.handleJSON(e);else{var n=a(s).parents("tbody").first();if(r(o),"reparent"===v.action){r(f),s.remove();for(var d=a('tr[data-ams-tree-node-id="'+f+'"]'),i=0;i<e.length;i++){var l=a(e[i]);d.exists()?l.insertAfter(d).addClass("no-drag-handle"):l.prependTo(n).addClass("no-drag-handle"),t.initContent&&t.initContent(l),d=l}}a("tr").parents("table").tableDnDUpdate()}})}}finally{setTimeout(function(){a(s).removeData("ams-disabled-handlers")},50)}}return!1}}}(jQuery,this);