src/pyams_skin/resources/js/myams-tree.min.js
changeset 436 4ee52103327c
child 456 c09f55f777fa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_skin/resources/js/myams-tree.min.js	Wed Oct 17 17:55:33 2018 +0200
@@ -0,0 +1,1 @@
+!function(a,e){var t=e.MyAMS,s=t;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 r=a(this),n=a("i.switch",r),d=r.parents("tr").first(),o=d.parents("table").first();if(n.hasClass("fa-minus-square-o"))e(d.data("ams-tree-node-id")),n.removeClass("fa-minus-square-o").addClass("fa-plus-square-o");else{var i=d.data("ams-location")||o.data("ams-location")||"",l=d.data("ams-tree-nodes-target")||o.data("ams-tree-nodes-target")||"get-tree-nodes.json",f=d.data("ams-element-name");n.removeClass("fa-plus-square-o").addClass("fa-cog fa-spin"),t.ajax.post(i+"/"+f+"/"+l,{can_sort:!a("td.sorter",d).is(":empty")},function(e,t){if(e.length>0){for(var r=d,i=0;i<e.length;i++){var l=a(e[i]);l.insertAfter(r).addClass("no-drag-handle"),s.initContent(l),r=l}o.hasClass("table-dnd")&&o.tableDnDUpdate()}n.removeClass("fa-cog fa-spin").addClass("fa-minus-square-o")})}},switchTree:function(){var e=a(this),r=a("i.switch",e),n=a(this).parents("table").first(),d=n.data("ams-tree-node-id");if(r.hasClass("fa-minus-square-o"))a("tr[data-ams-tree-node-parent-id]").filter('tr[data-ams-tree-node-parent-id!="'+d+'"]').remove(),a("i.switch",n).removeClass("fa-minus-square-o").addClass("fa-plus-square-o");else{var o=a("tbody tr",n).first(),i=n.data("ams-location")||"",l=n.data("ams-tree-nodes-target")||"get-tree.json";r.removeClass("fa-plus-square-o").addClass("fa-cog fa-spin"),t.ajax.post(i+"/"+l,{can_sort:!a("td.sorter",o).is(":empty")},function(e,t){a("tr[data-ams-tree-node-id]",n).remove();for(var d=null,o=0;o<e.length;o++){var i=a(e[o]);null===d?i.appendTo(a("tbody",n)):i.insertAfter(d),i.addClass("no-drag-handle"),s.initContent(i),d=i}n.hasClass("table-dnd")&&n.tableDnDUpdate(),a("i.switch",n).removeClass("fa-plus-square-o").addClass("fa-minus-square-o"),r.removeClass("fa-cog fa-spin").addClass("fa-minus-square-o")})}},sortTree:function(e,t){var r=a(e).data(),n=r.amsTabledndDropTarget;if(n){(t=a(t)).data("ams-disabled-handlers","click");try{var d=t.parents("table").first().data("ams-tree-node-id"),o=t.data("ams-tree-node-id"),i=t.data("ams-tree-node-parent-id"),l=t.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=s.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",t).is(":empty")};s.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)s.ajax.handleJSON(e);else{var n=a(t).parents("tbody").first();if(r(o),"reparent"===v.action){r(f),t.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"),s.initContent(l),d=l}}a("tr").parents("table").tableDnDUpdate()}})}}finally{setTimeout(function(){a(t).removeData("ams-disabled-handlers")},50)}}return!1}}}(jQuery,this);