[SPIP] ~maj 3.0.10 --> 3.0.14
[lhc/web/www.git] / www / plugins-dist / forum / prive / javascript / actiongroup.js
1 var actiongroup={
2 checkedItems:{},
3 countchecked:0,
4 countCurrent:0
5 }
6 /**
7 * Position fixe lors du scroll
8 */
9 actiongroup.followScroll = function(){
10 var container = $("#actiongroup").parents('.box.raccourcis');
11 var limite = container.offset().top;
12 $(window).scroll(function() {
13 if($(this).scrollTop() > limite)
14 container.css({'position': 'fixed', 'top': 0, 'width': container.width()+'px'});
15 if($(this).scrollTop() < limite)
16 container.css({'position': 'static', 'width': 'auto'});
17 });
18 }
19 /**
20 * Vider completement la selection
21 */
22 actiongroup.emptySelection = function(){
23 actiongroup.checkedItems={};
24 actiongroup.countchecked=0;
25 actiongroup.unselectAll();
26 }
27 /**
28 * Selectionner les items de la page
29 */
30 actiongroup.selectAll = function(sel){
31 sel = sel || document;
32 $('input.actiongroup',sel)
33 .attr('checked',true)
34 .each(function(){
35 actiongroup.updateChecklist($(this).attr('value'),true,false);
36 });
37 actiongroup.updateChecklist(0,false);
38 }
39 /**
40 * Deselectionner les items de la page
41 */
42 actiongroup.unselectAll = function(sel){
43 sel = sel || document;
44 $('input.actiongroup',sel)
45 .attr('checked',false)
46 .each(function(){
47 actiongroup.updateChecklist($(this).attr('value'),false,false);
48 });
49 actiongroup.updateChecklist(0,false);
50 }
51 /**
52 * Mettre a jour la listes des donnees et la boite html #actiongroup
53 * consecutivement
54 * @param int value
55 * @param bool checked
56 * @param bool|void update_status
57 */
58 actiongroup.updateChecklist = function(value,checked,update_status){
59 if (checked && !(actiongroup.checkedItems[value] || false))
60 actiongroup.countchecked++;
61 if (!checked && (actiongroup.checkedItems[value] || false))
62 actiongroup.countchecked--;
63 actiongroup.checkedItems[value]=checked;
64 if (update_status || typeof update_status=="undefined") {
65 jQuery.spip.log(actiongroup.countchecked);
66 if (actiongroup.countchecked==0){
67 $('#actiongroup .shortcut.empty,#actiongroup .shortcut.unselectall')
68 .addClass('hidden');
69 $('#actiongroup .shortcut.selectall')
70 .removeClass('hidden');
71 $('#actiongroup .status .zero')
72 .show()
73 .siblings(':visible')
74 .hide();
75 $('#actiongroup .action')
76 .addClass('hidden');
77 if ($(".checkable").length)
78 $('#actiongroup').closest('.box:hidden').show('fast');
79 else
80 $('#actiongroup').closest('.box:visible').hide('fast');
81 }
82 else {
83 $('#actiongroup .action')
84 .removeClass('hidden');
85 if (actiongroup.countchecked==1)
86 $('#actiongroup .status .one')
87 .show()
88 .siblings(':visible')
89 .hide();
90 else{
91 $('#actiongroup .status .many b')
92 .html(actiongroup.countchecked);
93 $('#actiongroup .status .many')
94 .show()
95 .siblings(':visible')
96 .hide();
97 }
98 var checked = $('input.actiongroup:checked').length;
99 if (checked)
100 $('#actiongroup .shortcut.unselectall')
101 .removeClass('hidden');
102 else
103 $('#actiongroup .shortcut.unselectall')
104 .addClass('hidden');
105 if (actiongroup.countchecked>checked)
106 $('#actiongroup .shortcut.empty')
107 .removeClass('hidden');
108 else
109 $('#actiongroup .shortcut.empty')
110 .addClass('hidden');
111 if (actiongroup.countCurrent>checked)
112 $('#actiongroup .shortcut.selectall')
113 .removeClass('hidden');
114 else
115 $('#actiongroup .shortcut.selectall')
116 .addClass('hidden');
117 }
118 $('#actiongroup')
119 .siblings('.success:visible')
120 .hide('slow');
121 }
122 }
123 /**
124 * Remettre a jour les checkbox du html a partir de la liste en memoire
125 * apres un chargement ajax par exemple
126 */
127 actiongroup.updateHtmlFromChecklist = function(){
128 actiongroup.countCurrent = $('input.actiongroup')
129 .each(function(){
130 $(this)
131 .attr('checked',actiongroup.checkedItems[$(this).attr('value')] || false);
132 })
133 .length;
134 // forcer la mise a jour des messages
135 actiongroup.updateChecklist(0,false);
136 }
137 /**
138 * Activer le traitement par lot sur une liste d'items
139 * @param node
140 * @param type
141 */
142 actiongroup.activate = function(sel){
143 $(sel)
144 .not('.checkable')
145 .each(function(){
146 var id = parseInt($(this).attr('data-id'));
147 if (id)
148 $(this)
149 .append("<input type='checkbox' name='actiongroup[]' class='actiongroup checkbox' value='"+id+"'/>");
150 })
151 .click(function(){
152 var check = $('input.actiongroup',this);
153 check
154 .prop('checked',!check.prop('checked'))
155 .trigger('change');
156 })
157 .addClass('checkable')
158 .find('input.actiongroup, form, a')
159 .click(function(e){
160 e.stopPropagation();
161 })
162 .filter('input.actiongroup')
163 .change(function(){
164 actiongroup.updateChecklist($(this).attr('value'),$(this).prop('checked'));
165 });
166
167 $('#actiongroup .action')
168 .unbind('click')
169 .click(function(){
170 var href=$(this).attr('data-href');
171 var ids = [];
172 for(var id in actiongroup.checkedItems)
173 if (actiongroup.checkedItems[id])
174 ids.push(id);
175 jQuery.spip.log(href);
176 jQuery.spip.log(ids);
177 if (href && ids.length) {
178 $('#actiongroup')
179 .siblings('.success')
180 .hide()
181 .parent()
182 .animateLoading();
183 $.ajax({
184 url: href,
185 data: {"ids":ids},
186 onAjaxLoad:false,
187 success: function(){
188 // vider le cache car on a fait une operation en base
189 jQuery.spip.preloaded_urls = {};
190 // recharger le bloc de la selection
191 $(sel).eq(0).ajaxReload();
192 actiongroup.checkedItems={};
193 actiongroup.countchecked=0;
194 actiongroup.countCurrent=0;
195 actiongroup.updateChecklist(0,false);
196 $('#actiongroup')
197 .css('opacity','1.0')
198 .siblings()
199 .css('opacity','1.0')
200 .filter('.success')
201 .show()
202 .parent().find('.image_loading').remove();
203 }
204 });
205 }
206 });
207 actiongroup.updateHtmlFromChecklist();
208 actiongroup.followScroll();
209 }