1 | |
---|
2 | function coreBlocks(opt, keys, token, initValues) |
---|
3 | { |
---|
4 | var options = { |
---|
5 | ajaxUrl:'plugins/AMenuManager/amm_ajax.php' |
---|
6 | }, |
---|
7 | translatedKeys= { |
---|
8 | g002_ok:'g002_ok', |
---|
9 | g002_cancel:'g002_cancel', |
---|
10 | g002_loading: 'g002_loading', |
---|
11 | g002_editoflink : 'g002_editoflink', |
---|
12 | g002_createoflink : 'g002_createoflink' |
---|
13 | }, |
---|
14 | properties = { |
---|
15 | id:'', |
---|
16 | token:token, |
---|
17 | resetValues: |
---|
18 | { |
---|
19 | 'piwigo':[], |
---|
20 | 'cancel':[] |
---|
21 | } |
---|
22 | }, |
---|
23 | |
---|
24 | /** |
---|
25 | * display tab content |
---|
26 | */ |
---|
27 | displayTabContent = function (tab) |
---|
28 | { |
---|
29 | switch(tab) |
---|
30 | { |
---|
31 | case 'position': |
---|
32 | $('#containerPos').css('display', 'block'); |
---|
33 | $('#containerMenu').css('display', 'none'); |
---|
34 | break; |
---|
35 | case 'blocksContent': |
---|
36 | $('#containerPos').css('display', 'none'); |
---|
37 | $('#containerMenu').css('display', 'block'); |
---|
38 | break; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * reset values |
---|
44 | * @param String mode : 'piwigo' (piwigo default value) or 'cancel' (restore previous settings) |
---|
45 | */ |
---|
46 | reset = function(mode) |
---|
47 | { |
---|
48 | $('#iConfigState').hide(); |
---|
49 | |
---|
50 | for(var i=0;i<properties.resetValues[mode].length;i++) |
---|
51 | { |
---|
52 | var access=resetValues[mode][i].visibility.split('/'), |
---|
53 | accessUsers=access[0].split(','), |
---|
54 | accessGroup=access[1].split(','); |
---|
55 | |
---|
56 | $("#menu_"+resetValues[mode][i].block).get(0).appendChild($("#i"+resetValues[mode][i].id).get(0)); |
---|
57 | |
---|
58 | $("#i"+resetValues[mode][i].id).find('input.visibilityUser').each( |
---|
59 | function () |
---|
60 | { |
---|
61 | $(this).attr('checked', $.inArray($(this).attr('value'), accessUsers)==-1); |
---|
62 | } |
---|
63 | ); |
---|
64 | |
---|
65 | $("#i"+resetValues[mode][i].id).find('input.visibilityGroup').each( |
---|
66 | function () |
---|
67 | { |
---|
68 | $(this).attr('checked', $.inArray($(this).attr('value'), accessGroup)==-1); |
---|
69 | } |
---|
70 | ); |
---|
71 | } |
---|
72 | }, |
---|
73 | |
---|
74 | /** |
---|
75 | * submit config |
---|
76 | */ |
---|
77 | submit = function () |
---|
78 | { |
---|
79 | if(!checkValidity()) return(false); |
---|
80 | |
---|
81 | displayProcessing(true); |
---|
82 | |
---|
83 | // build datas |
---|
84 | var datas = { |
---|
85 | menuItems: {}, |
---|
86 | blocks: {} |
---|
87 | }, |
---|
88 | order=0; |
---|
89 | |
---|
90 | $('#containerMenu ul.categoryUl li.categoryLi').each( |
---|
91 | function () |
---|
92 | { |
---|
93 | var visibilityUser=[] |
---|
94 | visibilityGroup=[]; |
---|
95 | |
---|
96 | $(this).find('input.visibilityUser:not(:checked)').each( |
---|
97 | function () |
---|
98 | { |
---|
99 | visibilityUser.push($(this).attr('value')); |
---|
100 | } |
---|
101 | ); |
---|
102 | $(this).find('input.visibilityGroup:not(:checked)').each( |
---|
103 | function () |
---|
104 | { |
---|
105 | visibilityGroup.push($(this).attr('value')); |
---|
106 | } |
---|
107 | ); |
---|
108 | |
---|
109 | datas.menuItems[this.id.substr(1)]={ |
---|
110 | order:order, |
---|
111 | container:$(this).parent().parent().attr('id').substr(14), |
---|
112 | visibilityUser:visibilityUser, |
---|
113 | visibilityGroup:visibilityGroup |
---|
114 | }; |
---|
115 | order++; |
---|
116 | } |
---|
117 | ); |
---|
118 | |
---|
119 | order=0; |
---|
120 | $('ul.menuUl li.menuListItem').each( |
---|
121 | function () |
---|
122 | { |
---|
123 | var id=$(this).attr('blockid'), |
---|
124 | visibilityUser=$(this).find('div.menuListUsers').inputList('value'), |
---|
125 | visibilityGroup=$(this).find('div.menuListGroups').inputList('value'); |
---|
126 | |
---|
127 | datas.blocks[id]={ |
---|
128 | id:id, |
---|
129 | order:order, |
---|
130 | users:visibilityUser, |
---|
131 | groups:visibilityGroup |
---|
132 | }; |
---|
133 | |
---|
134 | order++; |
---|
135 | } |
---|
136 | ); |
---|
137 | |
---|
138 | $.ajax( |
---|
139 | { |
---|
140 | type: "POST", |
---|
141 | url: options.ajaxUrl, |
---|
142 | async: true, |
---|
143 | data: { ajaxfct:"admin.coreBlocks.setConfig", token:properties.token, datas:datas }, |
---|
144 | success: |
---|
145 | function(msg) |
---|
146 | { |
---|
147 | displayProcessing(false); |
---|
148 | |
---|
149 | returned=msg.split('!'); |
---|
150 | |
---|
151 | if(returned[0]=='OK') |
---|
152 | { |
---|
153 | properties.resetValues.cancel=[]; |
---|
154 | for(var id in datas.items) |
---|
155 | { |
---|
156 | properties.resetValues.cancel.push( |
---|
157 | { |
---|
158 | id:id, |
---|
159 | block:datas.items[id].container, |
---|
160 | order:datas.items[id].order, |
---|
161 | visibility:datas.items[id].visibility |
---|
162 | } |
---|
163 | ); |
---|
164 | } |
---|
165 | |
---|
166 | $('#iConfigState') |
---|
167 | .html(returned[1]) |
---|
168 | .removeClass('errors') |
---|
169 | .addClass('infos') |
---|
170 | .css('display', 'block'); |
---|
171 | } |
---|
172 | else |
---|
173 | { |
---|
174 | $('#iConfigState') |
---|
175 | .html(returned[1]) |
---|
176 | .removeClass('infos') |
---|
177 | .addClass('errors') |
---|
178 | .css('display', 'block'); |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | ); |
---|
183 | }, |
---|
184 | |
---|
185 | /** |
---|
186 | * check validity of form |
---|
187 | */ |
---|
188 | checkValidity = function () |
---|
189 | { |
---|
190 | $('.error').removeClass('error'); |
---|
191 | ok=true; |
---|
192 | return(ok); |
---|
193 | }, |
---|
194 | |
---|
195 | /** |
---|
196 | * display or hide the processing flower |
---|
197 | */ |
---|
198 | displayProcessing = function (visible) |
---|
199 | { |
---|
200 | if(visible) |
---|
201 | { |
---|
202 | $('#iBDProcessing').css("display", "block"); |
---|
203 | } |
---|
204 | else |
---|
205 | { |
---|
206 | $('#iBDProcessing').css("display", "none"); |
---|
207 | } |
---|
208 | }, |
---|
209 | |
---|
210 | init = function (initValues) |
---|
211 | { |
---|
212 | properties.resetValues=initValues.resetValues; |
---|
213 | |
---|
214 | $("#containerMenu").sortable( |
---|
215 | { |
---|
216 | connectWith: '.connectedSortable', |
---|
217 | cursor: 'move', |
---|
218 | opacity:0.6, |
---|
219 | items: 'li:not(.menuItemDisabled)', |
---|
220 | tolerance:'pointer', |
---|
221 | start: function () |
---|
222 | { |
---|
223 | $('#iConfigState').hide(); |
---|
224 | } |
---|
225 | } |
---|
226 | ); |
---|
227 | |
---|
228 | $('#containerMenu ul.categoryUl li.categoryLi img.visibilitySwitch').bind('click', |
---|
229 | function () |
---|
230 | { |
---|
231 | $('#'+$(this).parent().parent().attr('id')+'_visibility').toggle(); |
---|
232 | $('#iConfigState').hide(); |
---|
233 | } |
---|
234 | ); |
---|
235 | |
---|
236 | $("ul.menuUl").sortable( |
---|
237 | { |
---|
238 | connectWith: '.connectedSortable', |
---|
239 | axis: "y", |
---|
240 | cursor: 'move', |
---|
241 | opacity:0.6, |
---|
242 | items: 'li.connectedSortable', |
---|
243 | tolerance:'pointer', |
---|
244 | start: function () |
---|
245 | { |
---|
246 | $('#iConfigState').hide(); |
---|
247 | } |
---|
248 | } |
---|
249 | ); |
---|
250 | |
---|
251 | $('ul.menuUl li div.menuListUsers, ul.menuUl li div.menuListGroups').inputList( |
---|
252 | { |
---|
253 | listMaxHeight:300, |
---|
254 | multiple:true, |
---|
255 | popupMode:'mouseout', |
---|
256 | returnMode:'notSelected', |
---|
257 | change: function () |
---|
258 | { |
---|
259 | $('#iConfigState').hide(); |
---|
260 | } |
---|
261 | } |
---|
262 | ).inputList('value', ':invert'); |
---|
263 | |
---|
264 | |
---|
265 | displayTabContent(initValues.tab); |
---|
266 | }; |
---|
267 | |
---|
268 | this.reset = function (mode) { reset(mode); }; |
---|
269 | this.submit = function () { submit(); }; |
---|
270 | this.displayTabContent = function (tab) { displayTabContent(tab); }; |
---|
271 | |
---|
272 | init(initValues); |
---|
273 | } |
---|
274 | |
---|
275 | |
---|