1 function deplie_arbre(){
2 tree
= jQuery('#articles_tous');
3 jQuery('ul:hidden',tree
).siblings('img.expandImage').each(function(){jQuery(this).bascule()});
6 tree
= jQuery('#articles_tous');
7 jQuery('#articles_tous ul').hide();
8 jQuery('img.expandImage', tree
).attr('src',img_deplierhaut
);
10 function annuler_deplacement(){
11 liste
= jQuery("#deplacements").text();
12 tableau
= liste
.split("\n");
13 if (tableau
.length
>0){
14 action
= tableau
[tableau
.length
-1];
15 tab
= action
.split(":");
16 jQuery("#"+tab
[2]).insertion(tab
[0],jQuery("#"+tab
[0]).parent().attr('id'));
18 jQuery("#deplacements").html(tableau
.join("\n"));
19 if (tableau
.length
==0) jQuery("#cancel").hide();
20 if (tableau
.length
==0) jQuery("#apply").hide();
24 jQuery
.fn
.set_expandImage = function(){
25 jQuery('ul:hidden',jQuery(this)).parent().prepend('<img src="'+img_deplierhaut
+'" class="expandImage" />');
26 jQuery('ul:visible',jQuery(this)).parent().prepend('<img src="'+img_deplierbas
+'" class="expandImage" />');
27 jQuery('img.expandImage', jQuery(this)).click(function (){jQuery(this).bascule();});
32 jQuery
.fn
.deplie = function(){
34 jQuery(this).siblings('img.expandImage').eq(0).attr('src',img_deplierbas
);
35 jQuery(this).children('li').children('a.ajax').each(function(){
36 jQuery(this).before("<div>"+ajax_image_searching
+"</div>");
37 var id
= jQuery(this).parent().parent().attr('id');
38 jQuery(this).parent().parent().load(jQuery(this).attr('href'),function(){jQuery("#"+id
).set_expandImage().set_droppables();jQuery
.recallDroppables();});
41 jQuery
.recallDroppables();
45 jQuery
.fn
.bascule = function() {
46 subbranch
= jQuery(this).siblings('ul').eq(0);
47 if (subbranch
.is(':hidden')) {
49 jQuery(this).attr('src',img_deplierbas
);
50 subbranch
.children('li').children('a.ajax').each(function(){
51 jQuery(this).before("<div>"+ajax_image_searching
+"</div>");
52 var id
= jQuery(this).parent().parent().attr('id');
53 jQuery(this).parent().parent().load(jQuery(this).attr('href'),function(){jQuery("#"+id
).set_expandImage().set_droppables();});
57 jQuery(this).attr('src',img_deplierhaut
);
61 jQuery
.fn
.insertion = function(dragged
,oldParent
){
62 subbranch
= jQuery(this).children('ul').eq(0);
63 if (subbranch
.size() == 0) {
64 jQuery(this).prepend('<img src="'+img_deplierbas
+'" width="16" height="16" class="expandImage" />');
65 id
= jQuery(this).attr('id');
66 id
= id
.split("-"); id
=id
[1]
67 jQuery(this).append("<ul id='ul"+id
+"' ></ul>");
68 jQuery(this).children('img.expandImage').click(function (){jQuery(this).bascule();});
69 subbranch
= jQuery(this).children('ul').eq(0);
71 if((dragged
.is('li.art')) && (subbranch
.children('li.rub').length
>0)){
72 subbranch
.end().children('li.rub').eq(0).before(dragged
);
75 subbranch
.end().append(dragged
);
77 if (subbranch
.is(':hidden')){
81 oldBranches
= jQuery('li', oldParent
);
82 if (oldBranches
.size() == 0) {
83 oldParent
.siblings('img.expandImage').remove();
84 oldParent
.end().remove();
86 dragged
.draggable( 'destroy' );
87 jQuery(this).set_droppables();
90 jQuery
.fn
.set_droppables = function(){
91 jQuery('span.holder',jQuery(this)).droppable(
95 activeClass
: 'fakeClass',
96 tolerance
: 'pointer',
97 over : function(event
,ui
)
99 jQuery(this).parent().addClass('selected');
100 if (!this.expanded
) {
101 subbranch
= jQuery(this).siblings('ul').eq(0);
102 if (subbranch
.is(':hidden')){
103 subbranch
.pause(1000).deplie();
104 this.expanded
= true;
108 out : function(event
,ui
)
110 jQuery(this).parent().removeClass('selected');
112 subbranch
= jQuery(this).siblings('ul').eq(0);
118 this.expanded
= false;
120 drop : function(event
,ui
)
122 jQuery(this).parent().removeClass('selected');
123 subbranch
= jQuery(this).siblings('ul').eq(0);
126 var target
=jQuery(this).parent().attr('id');
127 var quoi
=jQuery(ui
.draggable
).attr('id');
128 var source
=jQuery(ui
.draggable
).parent().parent().attr('id'); // il faut stocker l'id du li car le ul peut avoir disparu au moment du cancel
129 action
=quoi
+":"+target
+":"+source
;
130 var dep
= jQuery("#deplacements");
131 dep
.html(dep
.text()+"\n"+action
);
132 jQuery("#apply").show();
133 jQuery("#cancel").show();
134 jQuery(this).parent().insertion(jQuery(ui
.draggable
),jQuery(ui
.draggable
).parent());
138 jQuery('li.treeItem',jQuery(this)).draggable(
150 jQuery('#articles_tous').set_expandImage();
151 jQuery('#articles_tous').set_droppables();