Show More
@@ -1,1498 +1,1506 | |||
|
1 | 1 | /** |
|
2 | 2 | RhodeCode JS Files |
|
3 | 3 | **/ |
|
4 | 4 | |
|
5 | 5 | if (typeof console == "undefined" || typeof console.log == "undefined"){ |
|
6 | 6 | console = { log: function() {} } |
|
7 | 7 | } |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | var str_repeat = function(i, m) { |
|
11 | 11 | for (var o = []; m > 0; o[--m] = i); |
|
12 | 12 | return o.join(''); |
|
13 | 13 | }; |
|
14 | 14 | |
|
15 | 15 | /** |
|
16 | 16 | * INJECT .format function into String |
|
17 | 17 | * Usage: "My name is {0} {1}".format("Johny","Bravo") |
|
18 | 18 | * Return "My name is Johny Bravo" |
|
19 | 19 | * Inspired by https://gist.github.com/1049426 |
|
20 | 20 | */ |
|
21 | 21 | String.prototype.format = function() { |
|
22 | 22 | |
|
23 | 23 | function format() { |
|
24 | 24 | var str = this; |
|
25 | 25 | var len = arguments.length+1; |
|
26 | 26 | var safe = undefined; |
|
27 | 27 | var arg = undefined; |
|
28 | 28 | |
|
29 | 29 | // For each {0} {1} {n...} replace with the argument in that position. If |
|
30 | 30 | // the argument is an object or an array it will be stringified to JSON. |
|
31 | 31 | for (var i=0; i < len; arg = arguments[i++]) { |
|
32 | 32 | safe = typeof arg === 'object' ? JSON.stringify(arg) : arg; |
|
33 | 33 | str = str.replace(RegExp('\\{'+(i-1)+'\\}', 'g'), safe); |
|
34 | 34 | } |
|
35 | 35 | return str; |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | // Save a reference of what may already exist under the property native. |
|
39 | 39 | // Allows for doing something like: if("".format.native) { /* use native */ } |
|
40 | 40 | format.native = String.prototype.format; |
|
41 | 41 | |
|
42 | 42 | // Replace the prototype property |
|
43 | 43 | return format; |
|
44 | 44 | |
|
45 | 45 | }(); |
|
46 | 46 | |
|
47 | 47 | String.prototype.strip = function(char) { |
|
48 | 48 | if(char === undefined){ |
|
49 | 49 | char = '\\s'; |
|
50 | 50 | } |
|
51 | 51 | return this.replace(new RegExp('^'+char+'+|'+char+'+$','g'), ''); |
|
52 | 52 | } |
|
53 | 53 | String.prototype.lstrip = function(char) { |
|
54 | 54 | if(char === undefined){ |
|
55 | 55 | char = '\\s'; |
|
56 | 56 | } |
|
57 | 57 | return this.replace(new RegExp('^'+char+'+'),''); |
|
58 | 58 | } |
|
59 | 59 | String.prototype.rstrip = function(char) { |
|
60 | 60 | if(char === undefined){ |
|
61 | 61 | char = '\\s'; |
|
62 | 62 | } |
|
63 | 63 | return this.replace(new RegExp(''+char+'+$'),''); |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | /** |
|
67 | 67 | * SmartColorGenerator |
|
68 | 68 | * |
|
69 | 69 | *usage:: |
|
70 | 70 | * var CG = new ColorGenerator(); |
|
71 | 71 | * var col = CG.getColor(key); //returns array of RGB |
|
72 | 72 | * 'rgb({0})'.format(col.join(',') |
|
73 | 73 | * |
|
74 | 74 | * @returns {ColorGenerator} |
|
75 | 75 | */ |
|
76 | 76 | var ColorGenerator = function(){ |
|
77 | 77 | this.GOLDEN_RATIO = 0.618033988749895; |
|
78 | 78 | this.CURRENT_RATIO = 0.22717784590367374 // this can be random |
|
79 | 79 | this.HSV_1 = 0.75;//saturation |
|
80 | 80 | this.HSV_2 = 0.95; |
|
81 | 81 | this.color; |
|
82 | 82 | this.cacheColorMap = {}; |
|
83 | 83 | }; |
|
84 | 84 | |
|
85 | 85 | ColorGenerator.prototype = { |
|
86 | 86 | getColor:function(key){ |
|
87 | 87 | if(this.cacheColorMap[key] !== undefined){ |
|
88 | 88 | return this.cacheColorMap[key]; |
|
89 | 89 | } |
|
90 | 90 | else{ |
|
91 | 91 | this.cacheColorMap[key] = this.generateColor(); |
|
92 | 92 | return this.cacheColorMap[key]; |
|
93 | 93 | } |
|
94 | 94 | }, |
|
95 | 95 | _hsvToRgb:function(h,s,v){ |
|
96 | 96 | if (s == 0.0) |
|
97 | 97 | return [v, v, v]; |
|
98 | 98 | i = parseInt(h * 6.0) |
|
99 | 99 | f = (h * 6.0) - i |
|
100 | 100 | p = v * (1.0 - s) |
|
101 | 101 | q = v * (1.0 - s * f) |
|
102 | 102 | t = v * (1.0 - s * (1.0 - f)) |
|
103 | 103 | i = i % 6 |
|
104 | 104 | if (i == 0) |
|
105 | 105 | return [v, t, p] |
|
106 | 106 | if (i == 1) |
|
107 | 107 | return [q, v, p] |
|
108 | 108 | if (i == 2) |
|
109 | 109 | return [p, v, t] |
|
110 | 110 | if (i == 3) |
|
111 | 111 | return [p, q, v] |
|
112 | 112 | if (i == 4) |
|
113 | 113 | return [t, p, v] |
|
114 | 114 | if (i == 5) |
|
115 | 115 | return [v, p, q] |
|
116 | 116 | }, |
|
117 | 117 | generateColor:function(){ |
|
118 | 118 | this.CURRENT_RATIO = this.CURRENT_RATIO+this.GOLDEN_RATIO; |
|
119 | 119 | this.CURRENT_RATIO = this.CURRENT_RATIO %= 1; |
|
120 | 120 | HSV_tuple = [this.CURRENT_RATIO, this.HSV_1, this.HSV_2] |
|
121 | 121 | RGB_tuple = this._hsvToRgb(HSV_tuple[0],HSV_tuple[1],HSV_tuple[2]); |
|
122 | 122 | function toRgb(v){ |
|
123 | 123 | return ""+parseInt(v*256) |
|
124 | 124 | } |
|
125 | 125 | return [toRgb(RGB_tuple[0]),toRgb(RGB_tuple[1]),toRgb(RGB_tuple[2])]; |
|
126 | 126 | |
|
127 | 127 | } |
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | |
|
131 | 131 | |
|
132 | 132 | |
|
133 | 133 | |
|
134 | 134 | /** |
|
135 | 135 | * GLOBAL YUI Shortcuts |
|
136 | 136 | */ |
|
137 | 137 | var YUC = YAHOO.util.Connect; |
|
138 | 138 | var YUD = YAHOO.util.Dom; |
|
139 | 139 | var YUE = YAHOO.util.Event; |
|
140 | 140 | var YUQ = YAHOO.util.Selector.query; |
|
141 | 141 | |
|
142 | 142 | // defines if push state is enabled for this browser ? |
|
143 | 143 | var push_state_enabled = Boolean( |
|
144 | 144 | window.history && window.history.pushState && window.history.replaceState |
|
145 | 145 | && !( /* disable for versions of iOS before version 4.3 (8F190) */ |
|
146 | 146 | (/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i).test(navigator.userAgent) |
|
147 | 147 | /* disable for the mercury iOS browser, or at least older versions of the webkit engine */ |
|
148 | 148 | || (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent) |
|
149 | 149 | ) |
|
150 | 150 | ); |
|
151 | 151 | |
|
152 | 152 | var _run_callbacks = function(callbacks){ |
|
153 | 153 | if (callbacks !== undefined){ |
|
154 | 154 | var _l = callbacks.length; |
|
155 | 155 | for (var i=0;i<_l;i++){ |
|
156 | 156 | var func = callbacks[i]; |
|
157 | 157 | if(typeof(func)=='function'){ |
|
158 | 158 | try{ |
|
159 | 159 | func(); |
|
160 | 160 | }catch (err){}; |
|
161 | 161 | } |
|
162 | 162 | } |
|
163 | 163 | } |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | /** |
|
167 | 167 | * Partial Ajax Implementation |
|
168 | 168 | * |
|
169 | 169 | * @param url: defines url to make partial request |
|
170 | 170 | * @param container: defines id of container to input partial result |
|
171 | 171 | * @param s_call: success callback function that takes o as arg |
|
172 | 172 | * o.tId |
|
173 | 173 | * o.status |
|
174 | 174 | * o.statusText |
|
175 | 175 | * o.getResponseHeader[ ] |
|
176 | 176 | * o.getAllResponseHeaders |
|
177 | 177 | * o.responseText |
|
178 | 178 | * o.responseXML |
|
179 | 179 | * o.argument |
|
180 | 180 | * @param f_call: failure callback |
|
181 | 181 | * @param args arguments |
|
182 | 182 | */ |
|
183 | 183 | function ypjax(url,container,s_call,f_call,args){ |
|
184 | 184 | var method='GET'; |
|
185 | 185 | if(args===undefined){ |
|
186 | 186 | args=null; |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | // Set special header for partial ajax == HTTP_X_PARTIAL_XHR |
|
190 | 190 | YUC.initHeader('X-PARTIAL-XHR',true); |
|
191 | 191 | |
|
192 | 192 | // wrapper of passed callback |
|
193 | 193 | var s_wrapper = (function(o){ |
|
194 | 194 | return function(o){ |
|
195 | 195 | YUD.get(container).innerHTML=o.responseText; |
|
196 | 196 | YUD.setStyle(container,'opacity','1.0'); |
|
197 | 197 | //execute the given original callback |
|
198 | 198 | if (s_call !== undefined){ |
|
199 | 199 | s_call(o); |
|
200 | 200 | } |
|
201 | 201 | } |
|
202 | 202 | })() |
|
203 | 203 | YUD.setStyle(container,'opacity','0.3'); |
|
204 | 204 | YUC.asyncRequest(method,url,{ |
|
205 | 205 | success:s_wrapper, |
|
206 | 206 | failure:function(o){ |
|
207 | 207 | console.log(o); |
|
208 | 208 | YUD.get(container).innerHTML='ERROR '+o.status; |
|
209 | 209 | YUD.setStyle(container,'opacity','1.0'); |
|
210 | 210 | YUD.setStyle(container,'color','red'); |
|
211 | 211 | } |
|
212 | 212 | },args); |
|
213 | 213 | |
|
214 | 214 | }; |
|
215 | 215 | |
|
216 | 216 | var ajaxPOST = function(url,postData,success) { |
|
217 | 217 | // Set special header for ajax == HTTP_X_PARTIAL_XHR |
|
218 | 218 | YUC.initHeader('X-PARTIAL-XHR',true); |
|
219 | 219 | |
|
220 | 220 | var toQueryString = function(o) { |
|
221 | 221 | if(typeof o !== 'object') { |
|
222 | 222 | return false; |
|
223 | 223 | } |
|
224 | 224 | var _p, _qs = []; |
|
225 | 225 | for(_p in o) { |
|
226 | 226 | _qs.push(encodeURIComponent(_p) + '=' + encodeURIComponent(o[_p])); |
|
227 | 227 | } |
|
228 | 228 | return _qs.join('&'); |
|
229 | 229 | }; |
|
230 | 230 | |
|
231 | 231 | var sUrl = url; |
|
232 | 232 | var callback = { |
|
233 | 233 | success: success, |
|
234 | 234 | failure: function (o) { |
|
235 | 235 | alert("error"); |
|
236 | 236 | }, |
|
237 | 237 | }; |
|
238 | 238 | var postData = toQueryString(postData); |
|
239 | 239 | var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData); |
|
240 | 240 | return request; |
|
241 | 241 | }; |
|
242 | 242 | |
|
243 | 243 | |
|
244 | 244 | /** |
|
245 | 245 | * tooltip activate |
|
246 | 246 | */ |
|
247 | 247 | var tooltip_activate = function(){ |
|
248 | 248 | function toolTipsId(){ |
|
249 | 249 | var ids = []; |
|
250 | 250 | var tts = YUQ('.tooltip'); |
|
251 | 251 | for (var i = 0; i < tts.length; i++) { |
|
252 | 252 | // if element doesn't not have and id |
|
253 | 253 | // autogenerate one for tooltip |
|
254 | 254 | if (!tts[i].id){ |
|
255 | 255 | tts[i].id='tt'+((i*100)+tts.length); |
|
256 | 256 | } |
|
257 | 257 | ids.push(tts[i].id); |
|
258 | 258 | } |
|
259 | 259 | return ids |
|
260 | 260 | }; |
|
261 | 261 | var myToolTips = new YAHOO.widget.Tooltip("tooltip", { |
|
262 | 262 | context: [[toolTipsId()],"tl","bl",null,[0,5]], |
|
263 | 263 | monitorresize:false, |
|
264 | 264 | xyoffset :[0,0], |
|
265 | 265 | autodismissdelay:300000, |
|
266 | 266 | hidedelay:5, |
|
267 | 267 | showdelay:20, |
|
268 | 268 | }); |
|
269 | 269 | }; |
|
270 | 270 | |
|
271 | 271 | /** |
|
272 | 272 | * show more |
|
273 | 273 | */ |
|
274 | 274 | var show_more_event = function(){ |
|
275 | 275 | YUE.on(YUD.getElementsByClassName('show_more'),'click',function(e){ |
|
276 | 276 | var el = e.target; |
|
277 | 277 | YUD.setStyle(YUD.get(el.id.substring(1)),'display',''); |
|
278 | 278 | YUD.setStyle(el.parentNode,'display','none'); |
|
279 | 279 | }); |
|
280 | 280 | }; |
|
281 | 281 | |
|
282 | 282 | |
|
283 | 283 | /** |
|
284 | 284 | * Quick filter widget |
|
285 | 285 | * |
|
286 | 286 | * @param target: filter input target |
|
287 | 287 | * @param nodes: list of nodes in html we want to filter. |
|
288 | 288 | * @param display_element function that takes current node from nodes and |
|
289 | 289 | * does hide or show based on the node |
|
290 | 290 | * |
|
291 | 291 | */ |
|
292 | 292 | var q_filter = function(target,nodes,display_element){ |
|
293 | 293 | |
|
294 | 294 | var nodes = nodes; |
|
295 | 295 | var q_filter_field = YUD.get(target); |
|
296 | 296 | var F = YAHOO.namespace(target); |
|
297 | 297 | |
|
298 | 298 | YUE.on(q_filter_field,'click',function(){ |
|
299 | 299 | q_filter_field.value = ''; |
|
300 | 300 | }); |
|
301 | 301 | |
|
302 | 302 | YUE.on(q_filter_field,'keyup',function(e){ |
|
303 | 303 | clearTimeout(F.filterTimeout); |
|
304 | 304 | F.filterTimeout = setTimeout(F.updateFilter,600); |
|
305 | 305 | }); |
|
306 | 306 | |
|
307 | 307 | F.filterTimeout = null; |
|
308 | 308 | |
|
309 | 309 | var show_node = function(node){ |
|
310 | 310 | YUD.setStyle(node,'display','') |
|
311 | 311 | } |
|
312 | 312 | var hide_node = function(node){ |
|
313 | 313 | YUD.setStyle(node,'display','none'); |
|
314 | 314 | } |
|
315 | 315 | |
|
316 | 316 | F.updateFilter = function() { |
|
317 | 317 | // Reset timeout |
|
318 | 318 | F.filterTimeout = null; |
|
319 | 319 | |
|
320 | 320 | var obsolete = []; |
|
321 | 321 | |
|
322 | 322 | var req = q_filter_field.value.toLowerCase(); |
|
323 | 323 | |
|
324 | 324 | var l = nodes.length; |
|
325 | 325 | var i; |
|
326 | 326 | var showing = 0; |
|
327 | 327 | |
|
328 | 328 | for (i=0;i<l;i++ ){ |
|
329 | 329 | var n = nodes[i]; |
|
330 | 330 | var target_element = display_element(n) |
|
331 | 331 | if(req && n.innerHTML.toLowerCase().indexOf(req) == -1){ |
|
332 | 332 | hide_node(target_element); |
|
333 | 333 | } |
|
334 | 334 | else{ |
|
335 | 335 | show_node(target_element); |
|
336 | 336 | showing+=1; |
|
337 | 337 | } |
|
338 | 338 | } |
|
339 | 339 | |
|
340 | 340 | // if repo_count is set update the number |
|
341 | 341 | var cnt = YUD.get('repo_count'); |
|
342 | 342 | if(cnt){ |
|
343 | 343 | YUD.get('repo_count').innerHTML = showing; |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | } |
|
347 | 347 | }; |
|
348 | 348 | |
|
349 | 349 | var tableTr = function(cls,body){ |
|
350 | 350 | var tr = document.createElement('tr'); |
|
351 | 351 | YUD.addClass(tr, cls); |
|
352 | 352 | |
|
353 | 353 | |
|
354 | 354 | var cont = new YAHOO.util.Element(body); |
|
355 | 355 | var comment_id = fromHTML(body).children[0].id.split('comment-')[1]; |
|
356 | 356 | tr.id = 'comment-tr-{0}'.format(comment_id); |
|
357 | 357 | tr.innerHTML = '<td class="lineno-inline new-inline"></td>'+ |
|
358 | 358 | '<td class="lineno-inline old-inline"></td>'+ |
|
359 | 359 | '<td>{0}</td>'.format(body); |
|
360 | 360 | return tr; |
|
361 | 361 | }; |
|
362 | 362 | |
|
363 | 363 | /** comments **/ |
|
364 | 364 | var removeInlineForm = function(form) { |
|
365 | 365 | form.parentNode.removeChild(form); |
|
366 | 366 | }; |
|
367 | 367 | |
|
368 | 368 | var createInlineForm = function(parent_tr, f_path, line) { |
|
369 | 369 | var tmpl = YUD.get('comment-inline-form-template').innerHTML; |
|
370 | 370 | tmpl = tmpl.format(f_path, line); |
|
371 | 371 | var form = tableTr('comment-form-inline',tmpl) |
|
372 | 372 | |
|
373 | 373 | // create event for hide button |
|
374 | 374 | form = new YAHOO.util.Element(form); |
|
375 | 375 | var form_hide_button = new YAHOO.util.Element(form.getElementsByClassName('hide-inline-form')[0]); |
|
376 | 376 | form_hide_button.on('click', function(e) { |
|
377 | 377 | var newtr = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode; |
|
378 | 378 | if(YUD.hasClass(newtr.nextElementSibling,'inline-comments-button')){ |
|
379 | 379 | YUD.setStyle(newtr.nextElementSibling,'display',''); |
|
380 | 380 | } |
|
381 | 381 | removeInlineForm(newtr); |
|
382 | 382 | YUD.removeClass(parent_tr, 'form-open'); |
|
383 | 383 | |
|
384 | 384 | }); |
|
385 | 385 | |
|
386 | 386 | return form |
|
387 | 387 | }; |
|
388 | 388 | |
|
389 | 389 | /** |
|
390 | 390 | * Inject inline comment for on given TR this tr should be always an .line |
|
391 | 391 | * tr containing the line. Code will detect comment, and always put the comment |
|
392 | 392 | * block at the very bottom |
|
393 | 393 | */ |
|
394 | 394 | var injectInlineForm = function(tr){ |
|
395 | 395 | if(!YUD.hasClass(tr, 'line')){ |
|
396 | 396 | return |
|
397 | 397 | } |
|
398 | 398 | var submit_url = AJAX_COMMENT_URL; |
|
399 | 399 | var _td = tr.getElementsByClassName('code')[0]; |
|
400 | 400 | if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context') || YUD.hasClass(_td,'no-comment')){ |
|
401 | 401 | return |
|
402 | 402 | } |
|
403 | 403 | YUD.addClass(tr,'form-open'); |
|
404 | 404 | var node = tr.parentNode.parentNode.parentNode.getElementsByClassName('full_f_path')[0]; |
|
405 | 405 | var f_path = YUD.getAttribute(node,'path'); |
|
406 | 406 | var lineno = getLineNo(tr); |
|
407 | 407 | var form = createInlineForm(tr, f_path, lineno, submit_url); |
|
408 | 408 | |
|
409 | 409 | var parent = tr; |
|
410 | 410 | while (1){ |
|
411 | 411 | var n = parent.nextElementSibling; |
|
412 | 412 | // next element are comments ! |
|
413 | 413 | if(YUD.hasClass(n,'inline-comments')){ |
|
414 | 414 | parent = n; |
|
415 | 415 | } |
|
416 | 416 | else{ |
|
417 | 417 | break; |
|
418 | 418 | } |
|
419 | 419 | } |
|
420 | 420 | YUD.insertAfter(form,parent); |
|
421 | 421 | |
|
422 | 422 | var f = YUD.get(form); |
|
423 | 423 | |
|
424 | 424 | var overlay = f.getElementsByClassName('overlay')[0]; |
|
425 | 425 | var _form = f.getElementsByClassName('inline-form')[0]; |
|
426 | 426 | |
|
427 | 427 | form.on('submit',function(e){ |
|
428 | 428 | YUE.preventDefault(e); |
|
429 | 429 | |
|
430 | 430 | //ajax submit |
|
431 | 431 | var text = YUD.get('text_'+lineno).value; |
|
432 | 432 | var postData = { |
|
433 | 433 | 'text':text, |
|
434 | 434 | 'f_path':f_path, |
|
435 | 435 | 'line':lineno |
|
436 | 436 | }; |
|
437 | 437 | |
|
438 | 438 | if(lineno === undefined){ |
|
439 | 439 | alert('missing line !'); |
|
440 | 440 | return |
|
441 | 441 | } |
|
442 | 442 | if(f_path === undefined){ |
|
443 | 443 | alert('missing file path !'); |
|
444 | 444 | return |
|
445 | 445 | } |
|
446 | 446 | |
|
447 | 447 | if(text == ""){ |
|
448 | 448 | return |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | var success = function(o){ |
|
452 | 452 | YUD.removeClass(tr, 'form-open'); |
|
453 | 453 | removeInlineForm(f); |
|
454 | 454 | var json_data = JSON.parse(o.responseText); |
|
455 | 455 | renderInlineComment(json_data); |
|
456 | 456 | }; |
|
457 | 457 | |
|
458 | 458 | if (YUD.hasClass(overlay,'overlay')){ |
|
459 | 459 | var w = _form.offsetWidth; |
|
460 | 460 | var h = _form.offsetHeight; |
|
461 | 461 | YUD.setStyle(overlay,'width',w+'px'); |
|
462 | 462 | YUD.setStyle(overlay,'height',h+'px'); |
|
463 | 463 | } |
|
464 | 464 | YUD.addClass(overlay, 'submitting'); |
|
465 | 465 | |
|
466 | 466 | ajaxPOST(submit_url, postData, success); |
|
467 | 467 | }); |
|
468 | 468 | |
|
469 | 469 | setTimeout(function(){ |
|
470 | 470 | // callbacks |
|
471 | 471 | tooltip_activate(); |
|
472 | 472 | MentionsAutoComplete('text_'+lineno, 'mentions_container_'+lineno, |
|
473 | 473 | _USERS_AC_DATA, _GROUPS_AC_DATA); |
|
474 | 474 | YUD.get('text_'+lineno).focus(); |
|
475 | 475 | },10) |
|
476 | 476 | }; |
|
477 | 477 | |
|
478 | 478 | var deleteComment = function(comment_id){ |
|
479 | 479 | var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__',comment_id); |
|
480 | 480 | var postData = {'_method':'delete'}; |
|
481 | 481 | var success = function(o){ |
|
482 | 482 | var n = YUD.get('comment-tr-'+comment_id); |
|
483 | 483 | var root = n.previousElementSibling.previousElementSibling; |
|
484 | 484 | n.parentNode.removeChild(n); |
|
485 | 485 | |
|
486 | 486 | // scann nodes, and attach add button to last one |
|
487 | 487 | placeAddButton(root); |
|
488 | 488 | } |
|
489 | 489 | ajaxPOST(url,postData,success); |
|
490 | 490 | } |
|
491 | 491 | |
|
492 | 492 | |
|
493 | 493 | var createInlineAddButton = function(tr){ |
|
494 | 494 | |
|
495 | 495 | var label = TRANSLATION_MAP['add another comment']; |
|
496 | 496 | |
|
497 | 497 | var html_el = document.createElement('div'); |
|
498 | 498 | YUD.addClass(html_el, 'add-comment'); |
|
499 | 499 | html_el.innerHTML = '<span class="ui-btn">{0}</span>'.format(label); |
|
500 | 500 | |
|
501 | 501 | var add = new YAHOO.util.Element(html_el); |
|
502 | 502 | add.on('click', function(e) { |
|
503 | 503 | injectInlineForm(tr); |
|
504 | 504 | }); |
|
505 | 505 | return add; |
|
506 | 506 | }; |
|
507 | 507 | |
|
508 | 508 | var getLineNo = function(tr) { |
|
509 | 509 | var line; |
|
510 | 510 | var o = tr.children[0].id.split('_'); |
|
511 | 511 | var n = tr.children[1].id.split('_'); |
|
512 | 512 | |
|
513 | 513 | if (n.length >= 2) { |
|
514 | 514 | line = n[n.length-1]; |
|
515 | 515 | } else if (o.length >= 2) { |
|
516 | 516 | line = o[o.length-1]; |
|
517 | 517 | } |
|
518 | 518 | |
|
519 | 519 | return line |
|
520 | 520 | }; |
|
521 | 521 | |
|
522 | 522 | var placeAddButton = function(target_tr){ |
|
523 | 523 | if(!target_tr){ |
|
524 | 524 | return |
|
525 | 525 | } |
|
526 | 526 | var last_node = target_tr; |
|
527 | 527 | //scann |
|
528 | 528 | while (1){ |
|
529 | 529 | var n = last_node.nextElementSibling; |
|
530 | 530 | // next element are comments ! |
|
531 | 531 | if(YUD.hasClass(n,'inline-comments')){ |
|
532 | 532 | last_node = n; |
|
533 | 533 | //also remove the comment button from previos |
|
534 | 534 | var comment_add_buttons = last_node.getElementsByClassName('add-comment'); |
|
535 | 535 | for(var i=0;i<comment_add_buttons.length;i++){ |
|
536 | 536 | var b = comment_add_buttons[i]; |
|
537 | 537 | b.parentNode.removeChild(b); |
|
538 | 538 | } |
|
539 | 539 | } |
|
540 | 540 | else{ |
|
541 | 541 | break; |
|
542 | 542 | } |
|
543 | 543 | } |
|
544 | 544 | |
|
545 | 545 | var add = createInlineAddButton(target_tr); |
|
546 | 546 | // get the comment div |
|
547 | 547 | var comment_block = last_node.getElementsByClassName('comment')[0]; |
|
548 | 548 | // attach add button |
|
549 | 549 | YUD.insertAfter(add,comment_block); |
|
550 | 550 | } |
|
551 | 551 | |
|
552 | 552 | /** |
|
553 | 553 | * Places the inline comment into the changeset block in proper line position |
|
554 | 554 | */ |
|
555 | 555 | var placeInline = function(target_container,lineno,html){ |
|
556 | 556 | var lineid = "{0}_{1}".format(target_container,lineno); |
|
557 | 557 | var target_line = YUD.get(lineid); |
|
558 | 558 | var comment = new YAHOO.util.Element(tableTr('inline-comments',html)) |
|
559 | 559 | |
|
560 | 560 | // check if there are comments already ! |
|
561 | 561 | var parent = target_line.parentNode; |
|
562 | 562 | var root_parent = parent; |
|
563 | 563 | while (1){ |
|
564 | 564 | var n = parent.nextElementSibling; |
|
565 | 565 | // next element are comments ! |
|
566 | 566 | if(YUD.hasClass(n,'inline-comments')){ |
|
567 | 567 | parent = n; |
|
568 | 568 | } |
|
569 | 569 | else{ |
|
570 | 570 | break; |
|
571 | 571 | } |
|
572 | 572 | } |
|
573 | 573 | // put in the comment at the bottom |
|
574 | 574 | YUD.insertAfter(comment,parent); |
|
575 | 575 | |
|
576 | 576 | // scann nodes, and attach add button to last one |
|
577 | 577 | placeAddButton(root_parent); |
|
578 | 578 | |
|
579 | 579 | return target_line; |
|
580 | 580 | } |
|
581 | 581 | |
|
582 | 582 | /** |
|
583 | 583 | * make a single inline comment and place it inside |
|
584 | 584 | */ |
|
585 | 585 | var renderInlineComment = function(json_data){ |
|
586 | 586 | try{ |
|
587 | 587 | var html = json_data['rendered_text']; |
|
588 | 588 | var lineno = json_data['line_no']; |
|
589 | 589 | var target_id = json_data['target_id']; |
|
590 | 590 | placeInline(target_id, lineno, html); |
|
591 | 591 | |
|
592 | 592 | }catch(e){ |
|
593 | 593 | console.log(e); |
|
594 | 594 | } |
|
595 | 595 | } |
|
596 | 596 | |
|
597 | 597 | /** |
|
598 | 598 | * Iterates over all the inlines, and places them inside proper blocks of data |
|
599 | 599 | */ |
|
600 | 600 | var renderInlineComments = function(file_comments){ |
|
601 | 601 | for (f in file_comments){ |
|
602 | 602 | // holding all comments for a FILE |
|
603 | 603 | var box = file_comments[f]; |
|
604 | 604 | |
|
605 | 605 | var target_id = YUD.getAttribute(box,'target_id'); |
|
606 | 606 | // actually comments with line numbers |
|
607 | 607 | var comments = box.children; |
|
608 | 608 | for(var i=0; i<comments.length; i++){ |
|
609 | 609 | var data = { |
|
610 | 610 | 'rendered_text': comments[i].outerHTML, |
|
611 | 611 | 'line_no': YUD.getAttribute(comments[i],'line'), |
|
612 | 612 | 'target_id': target_id |
|
613 | 613 | } |
|
614 | 614 | renderInlineComment(data); |
|
615 | 615 | } |
|
616 | 616 | } |
|
617 | 617 | } |
|
618 | 618 | |
|
619 | 619 | |
|
620 | 620 | var fileBrowserListeners = function(current_url, node_list_url, url_base){ |
|
621 | 621 | |
|
622 | 622 | var current_url_branch = +"?branch=__BRANCH__"; |
|
623 | 623 | var url = url_base; |
|
624 | 624 | var node_url = node_list_url; |
|
625 | 625 | |
|
626 | 626 | YUE.on('stay_at_branch','click',function(e){ |
|
627 | 627 | if(e.target.checked){ |
|
628 | 628 | var uri = current_url_branch; |
|
629 | 629 | uri = uri.replace('__BRANCH__',e.target.value); |
|
630 | 630 | window.location = uri; |
|
631 | 631 | } |
|
632 | 632 | else{ |
|
633 | 633 | window.location = current_url; |
|
634 | 634 | } |
|
635 | 635 | }) |
|
636 | 636 | |
|
637 | 637 | var n_filter = YUD.get('node_filter'); |
|
638 | 638 | var F = YAHOO.namespace('node_filter'); |
|
639 | 639 | |
|
640 | 640 | F.filterTimeout = null; |
|
641 | 641 | var nodes = null; |
|
642 | 642 | |
|
643 | 643 | F.initFilter = function(){ |
|
644 | 644 | YUD.setStyle('node_filter_box_loading','display',''); |
|
645 | 645 | YUD.setStyle('search_activate_id','display','none'); |
|
646 | 646 | YUD.setStyle('add_node_id','display','none'); |
|
647 | 647 | YUC.initHeader('X-PARTIAL-XHR',true); |
|
648 | 648 | YUC.asyncRequest('GET',url,{ |
|
649 | 649 | success:function(o){ |
|
650 | 650 | nodes = JSON.parse(o.responseText).nodes; |
|
651 | 651 | YUD.setStyle('node_filter_box_loading','display','none'); |
|
652 | 652 | YUD.setStyle('node_filter_box','display',''); |
|
653 | 653 | n_filter.focus(); |
|
654 | 654 | if(YUD.hasClass(n_filter,'init')){ |
|
655 | 655 | n_filter.value = ''; |
|
656 | 656 | YUD.removeClass(n_filter,'init'); |
|
657 | 657 | } |
|
658 | 658 | }, |
|
659 | 659 | failure:function(o){ |
|
660 | 660 | console.log('failed to load'); |
|
661 | 661 | } |
|
662 | 662 | },null); |
|
663 | 663 | } |
|
664 | 664 | |
|
665 | 665 | F.updateFilter = function(e) { |
|
666 | 666 | |
|
667 | 667 | return function(){ |
|
668 | 668 | // Reset timeout |
|
669 | 669 | F.filterTimeout = null; |
|
670 | 670 | var query = e.target.value.toLowerCase(); |
|
671 | 671 | var match = []; |
|
672 | 672 | var matches = 0; |
|
673 | 673 | var matches_max = 20; |
|
674 | 674 | if (query != ""){ |
|
675 | 675 | for(var i=0;i<nodes.length;i++){ |
|
676 | 676 | |
|
677 | 677 | var pos = nodes[i].name.toLowerCase().indexOf(query) |
|
678 | 678 | if(query && pos != -1){ |
|
679 | 679 | |
|
680 | 680 | matches++ |
|
681 | 681 | //show only certain amount to not kill browser |
|
682 | 682 | if (matches > matches_max){ |
|
683 | 683 | break; |
|
684 | 684 | } |
|
685 | 685 | |
|
686 | 686 | var n = nodes[i].name; |
|
687 | 687 | var t = nodes[i].type; |
|
688 | 688 | var n_hl = n.substring(0,pos) |
|
689 | 689 | +"<b>{0}</b>".format(n.substring(pos,pos+query.length)) |
|
690 | 690 | +n.substring(pos+query.length) |
|
691 | 691 | match.push('<tr><td><a class="browser-{0}" href="{1}">{2}</a></td><td colspan="5"></td></tr>'.format(t,node_url.replace('__FPATH__',n),n_hl)); |
|
692 | 692 | } |
|
693 | 693 | if(match.length >= matches_max){ |
|
694 | 694 | match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format(_TM['search truncated'])); |
|
695 | 695 | } |
|
696 | 696 | } |
|
697 | 697 | } |
|
698 | 698 | if(query != ""){ |
|
699 | 699 | YUD.setStyle('tbody','display','none'); |
|
700 | 700 | YUD.setStyle('tbody_filtered','display',''); |
|
701 | 701 | |
|
702 | 702 | if (match.length==0){ |
|
703 | 703 | match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format(_TM['no matching files'])); |
|
704 | 704 | } |
|
705 | 705 | |
|
706 | 706 | YUD.get('tbody_filtered').innerHTML = match.join(""); |
|
707 | 707 | } |
|
708 | 708 | else{ |
|
709 | 709 | YUD.setStyle('tbody','display',''); |
|
710 | 710 | YUD.setStyle('tbody_filtered','display','none'); |
|
711 | 711 | } |
|
712 | 712 | |
|
713 | 713 | } |
|
714 | 714 | }; |
|
715 | 715 | |
|
716 | 716 | YUE.on(YUD.get('filter_activate'),'click',function(){ |
|
717 | 717 | F.initFilter(); |
|
718 | 718 | }) |
|
719 | 719 | YUE.on(n_filter,'click',function(){ |
|
720 | 720 | if(YUD.hasClass(n_filter,'init')){ |
|
721 | 721 | n_filter.value = ''; |
|
722 | 722 | YUD.removeClass(n_filter,'init'); |
|
723 | 723 | } |
|
724 | 724 | }); |
|
725 | 725 | YUE.on(n_filter,'keyup',function(e){ |
|
726 | 726 | clearTimeout(F.filterTimeout); |
|
727 | 727 | F.filterTimeout = setTimeout(F.updateFilter(e),600); |
|
728 | 728 | }); |
|
729 | 729 | }; |
|
730 | 730 | |
|
731 | 731 | |
|
732 | 732 | var initCodeMirror = function(textAreadId,resetUrl){ |
|
733 | 733 | var myCodeMirror = CodeMirror.fromTextArea(YUD.get(textAreadId),{ |
|
734 | 734 | mode: "null", |
|
735 | 735 | lineNumbers:true |
|
736 | 736 | }); |
|
737 | 737 | YUE.on('reset','click',function(e){ |
|
738 | 738 | window.location=resetUrl |
|
739 | 739 | }); |
|
740 | 740 | |
|
741 | 741 | YUE.on('file_enable','click',function(){ |
|
742 | 742 | YUD.setStyle('editor_container','display',''); |
|
743 | 743 | YUD.setStyle('upload_file_container','display','none'); |
|
744 | 744 | YUD.setStyle('filename_container','display',''); |
|
745 | 745 | }); |
|
746 | 746 | |
|
747 | 747 | YUE.on('upload_file_enable','click',function(){ |
|
748 | 748 | YUD.setStyle('editor_container','display','none'); |
|
749 | 749 | YUD.setStyle('upload_file_container','display',''); |
|
750 | 750 | YUD.setStyle('filename_container','display','none'); |
|
751 | 751 | }); |
|
752 | 752 | }; |
|
753 | 753 | |
|
754 | 754 | |
|
755 | 755 | |
|
756 | 756 | var getIdentNode = function(n){ |
|
757 | 757 | //iterate thru nodes untill matched interesting node ! |
|
758 | 758 | |
|
759 | 759 | if (typeof n == 'undefined'){ |
|
760 | 760 | return -1 |
|
761 | 761 | } |
|
762 | 762 | |
|
763 | 763 | if(typeof n.id != "undefined" && n.id.match('L[0-9]+')){ |
|
764 | 764 | return n |
|
765 | 765 | } |
|
766 | 766 | else{ |
|
767 | 767 | return getIdentNode(n.parentNode); |
|
768 | 768 | } |
|
769 | 769 | }; |
|
770 | 770 | |
|
771 | 771 | var getSelectionLink = function(selection_link_label) { |
|
772 | 772 | return function(){ |
|
773 | 773 | //get selection from start/to nodes |
|
774 | 774 | if (typeof window.getSelection != "undefined") { |
|
775 | 775 | s = window.getSelection(); |
|
776 | 776 | |
|
777 | 777 | from = getIdentNode(s.anchorNode); |
|
778 | 778 | till = getIdentNode(s.focusNode); |
|
779 | 779 | |
|
780 | 780 | f_int = parseInt(from.id.replace('L','')); |
|
781 | 781 | t_int = parseInt(till.id.replace('L','')); |
|
782 | 782 | |
|
783 | 783 | if (f_int > t_int){ |
|
784 | 784 | //highlight from bottom |
|
785 | 785 | offset = -35; |
|
786 | 786 | ranges = [t_int,f_int]; |
|
787 | 787 | |
|
788 | 788 | } |
|
789 | 789 | else{ |
|
790 | 790 | //highligth from top |
|
791 | 791 | offset = 35; |
|
792 | 792 | ranges = [f_int,t_int]; |
|
793 | 793 | } |
|
794 | 794 | |
|
795 | 795 | if (ranges[0] != ranges[1]){ |
|
796 | 796 | if(YUD.get('linktt') == null){ |
|
797 | 797 | hl_div = document.createElement('div'); |
|
798 | 798 | hl_div.id = 'linktt'; |
|
799 | 799 | } |
|
800 | 800 | anchor = '#L'+ranges[0]+'-'+ranges[1]; |
|
801 | 801 | hl_div.innerHTML = ''; |
|
802 | 802 | l = document.createElement('a'); |
|
803 | 803 | l.href = location.href.substring(0,location.href.indexOf('#'))+anchor; |
|
804 | 804 | l.innerHTML = selection_link_label; |
|
805 | 805 | hl_div.appendChild(l); |
|
806 | 806 | |
|
807 | 807 | YUD.get('body').appendChild(hl_div); |
|
808 | 808 | |
|
809 | 809 | xy = YUD.getXY(till.id); |
|
810 | 810 | |
|
811 | 811 | YUD.addClass('linktt','yui-tt'); |
|
812 | 812 | YUD.setStyle('linktt','top',xy[1]+offset+'px'); |
|
813 | 813 | YUD.setStyle('linktt','left',xy[0]+'px'); |
|
814 | 814 | YUD.setStyle('linktt','visibility','visible'); |
|
815 | 815 | } |
|
816 | 816 | else{ |
|
817 | 817 | YUD.setStyle('linktt','visibility','hidden'); |
|
818 | 818 | } |
|
819 | 819 | } |
|
820 | 820 | } |
|
821 | 821 | }; |
|
822 | 822 | |
|
823 | 823 | var deleteNotification = function(url, notification_id,callbacks){ |
|
824 | 824 | var callback = { |
|
825 | 825 | success:function(o){ |
|
826 | 826 | var obj = YUD.get(String("notification_"+notification_id)); |
|
827 | 827 | if(obj.parentNode !== undefined){ |
|
828 | 828 | obj.parentNode.removeChild(obj); |
|
829 | 829 | } |
|
830 | 830 | _run_callbacks(callbacks); |
|
831 | 831 | }, |
|
832 | 832 | failure:function(o){ |
|
833 | 833 | alert("error"); |
|
834 | 834 | }, |
|
835 | 835 | }; |
|
836 | 836 | var postData = '_method=delete'; |
|
837 | 837 | var sUrl = url.replace('__NOTIFICATION_ID__',notification_id); |
|
838 | 838 | var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, |
|
839 | 839 | callback, postData); |
|
840 | 840 | }; |
|
841 | 841 | |
|
842 | 842 | var readNotification = function(url, notification_id,callbacks){ |
|
843 | 843 | var callback = { |
|
844 | 844 | success:function(o){ |
|
845 | 845 | var obj = YUD.get(String("notification_"+notification_id)); |
|
846 | 846 | YUD.removeClass(obj, 'unread'); |
|
847 | 847 | var r_button = obj.children[0].getElementsByClassName('read-notification')[0] |
|
848 | 848 | |
|
849 | 849 | if(r_button.parentNode !== undefined){ |
|
850 | 850 | r_button.parentNode.removeChild(r_button); |
|
851 | 851 | } |
|
852 | 852 | _run_callbacks(callbacks); |
|
853 | 853 | }, |
|
854 | 854 | failure:function(o){ |
|
855 | 855 | alert("error"); |
|
856 | 856 | }, |
|
857 | 857 | }; |
|
858 | 858 | var postData = '_method=put'; |
|
859 | 859 | var sUrl = url.replace('__NOTIFICATION_ID__',notification_id); |
|
860 | 860 | var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, |
|
861 | 861 | callback, postData); |
|
862 | 862 | }; |
|
863 | 863 | |
|
864 | 864 | /** MEMBERS AUTOCOMPLETE WIDGET **/ |
|
865 | 865 | |
|
866 | 866 | var MembersAutoComplete = function (users_list, groups_list) { |
|
867 | 867 | var myUsers = users_list; |
|
868 | 868 | var myGroups = groups_list; |
|
869 | 869 | |
|
870 | 870 | // Define a custom search function for the DataSource of users |
|
871 | 871 | var matchUsers = function (sQuery) { |
|
872 | 872 | // Case insensitive matching |
|
873 | 873 | var query = sQuery.toLowerCase(); |
|
874 | 874 | var i = 0; |
|
875 | 875 | var l = myUsers.length; |
|
876 | 876 | var matches = []; |
|
877 | 877 | |
|
878 | 878 | // Match against each name of each contact |
|
879 | 879 | for (; i < l; i++) { |
|
880 | 880 | contact = myUsers[i]; |
|
881 | 881 | if (((contact.fname+"").toLowerCase().indexOf(query) > -1) || |
|
882 | 882 | ((contact.lname+"").toLowerCase().indexOf(query) > -1) || |
|
883 | 883 | ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) { |
|
884 | 884 | matches[matches.length] = contact; |
|
885 | 885 | } |
|
886 | 886 | } |
|
887 | 887 | return matches; |
|
888 | 888 | }; |
|
889 | 889 | |
|
890 | 890 | // Define a custom search function for the DataSource of usersGroups |
|
891 | 891 | var matchGroups = function (sQuery) { |
|
892 | 892 | // Case insensitive matching |
|
893 | 893 | var query = sQuery.toLowerCase(); |
|
894 | 894 | var i = 0; |
|
895 | 895 | var l = myGroups.length; |
|
896 | 896 | var matches = []; |
|
897 | 897 | |
|
898 | 898 | // Match against each name of each contact |
|
899 | 899 | for (; i < l; i++) { |
|
900 | 900 | matched_group = myGroups[i]; |
|
901 | 901 | if (matched_group.grname.toLowerCase().indexOf(query) > -1) { |
|
902 | 902 | matches[matches.length] = matched_group; |
|
903 | 903 | } |
|
904 | 904 | } |
|
905 | 905 | return matches; |
|
906 | 906 | }; |
|
907 | 907 | |
|
908 | 908 | //match all |
|
909 | 909 | var matchAll = function (sQuery) { |
|
910 | 910 | u = matchUsers(sQuery); |
|
911 | 911 | g = matchGroups(sQuery); |
|
912 | 912 | return u.concat(g); |
|
913 | 913 | }; |
|
914 | 914 | |
|
915 | 915 | // DataScheme for members |
|
916 | 916 | var memberDS = new YAHOO.util.FunctionDataSource(matchAll); |
|
917 | 917 | memberDS.responseSchema = { |
|
918 | 918 | fields: ["id", "fname", "lname", "nname", "grname", "grmembers", "gravatar_lnk"] |
|
919 | 919 | }; |
|
920 | 920 | |
|
921 | 921 | // DataScheme for owner |
|
922 | 922 | var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers); |
|
923 | 923 | ownerDS.responseSchema = { |
|
924 | 924 | fields: ["id", "fname", "lname", "nname", "gravatar_lnk"] |
|
925 | 925 | }; |
|
926 | 926 | |
|
927 | 927 | // Instantiate AutoComplete for perms |
|
928 | 928 | var membersAC = new YAHOO.widget.AutoComplete("perm_new_member_name", "perm_container", memberDS); |
|
929 | 929 | membersAC.useShadow = false; |
|
930 | 930 | membersAC.resultTypeList = false; |
|
931 | membersAC.animVert = false; | |
|
932 | membersAC.animHoriz = false; | |
|
933 | membersAC.animSpeed = 0.1; | |
|
931 | 934 | |
|
932 | 935 | // Instantiate AutoComplete for owner |
|
933 | 936 | var ownerAC = new YAHOO.widget.AutoComplete("user", "owner_container", ownerDS); |
|
934 | 937 | ownerAC.useShadow = false; |
|
935 | 938 | ownerAC.resultTypeList = false; |
|
936 | ||
|
939 | ownerAC.animVert = false; | |
|
940 | ownerAC.animHoriz = false; | |
|
941 | ownerAC.animSpeed = 0.1; | |
|
937 | 942 | |
|
938 | 943 | // Helper highlight function for the formatter |
|
939 | 944 | var highlightMatch = function (full, snippet, matchindex) { |
|
940 | 945 | return full.substring(0, matchindex) |
|
941 | 946 | + "<span class='match'>" |
|
942 | 947 | + full.substr(matchindex, snippet.length) |
|
943 | 948 | + "</span>" + full.substring(matchindex + snippet.length); |
|
944 | 949 | }; |
|
945 | 950 | |
|
946 | 951 | // Custom formatter to highlight the matching letters |
|
947 | 952 | var custom_formatter = function (oResultData, sQuery, sResultMatch) { |
|
948 | 953 | var query = sQuery.toLowerCase(); |
|
949 | 954 | var _gravatar = function(res, em, group){ |
|
950 | 955 | if (group !== undefined){ |
|
951 | 956 | em = '/images/icons/group.png' |
|
952 | 957 | } |
|
953 | 958 | tmpl = '<div class="ac-container-wrap"><img class="perm-gravatar-ac" src="{0}"/>{1}</div>' |
|
954 | 959 | return tmpl.format(em,res) |
|
955 | 960 | } |
|
956 | 961 | // group |
|
957 | 962 | if (oResultData.grname != undefined) { |
|
958 | 963 | var grname = oResultData.grname; |
|
959 | 964 | var grmembers = oResultData.grmembers; |
|
960 | 965 | var grnameMatchIndex = grname.toLowerCase().indexOf(query); |
|
961 | 966 | var grprefix = "{0}: ".format(_TM['Group']); |
|
962 | 967 | var grsuffix = " (" + grmembers + " )"; |
|
963 | 968 | var grsuffix = " ({0} {1})".format(grmembers, _TM['members']); |
|
964 | 969 | |
|
965 | 970 | if (grnameMatchIndex > -1) { |
|
966 | 971 | return _gravatar(grprefix + highlightMatch(grname, query, grnameMatchIndex) + grsuffix,null,true); |
|
967 | 972 | } |
|
968 | 973 | return _gravatar(grprefix + oResultData.grname + grsuffix, null,true); |
|
969 | 974 | // Users |
|
970 | 975 | } else if (oResultData.nname != undefined) { |
|
971 | 976 | var fname = oResultData.fname || ""; |
|
972 | 977 | var lname = oResultData.lname || ""; |
|
973 | 978 | var nname = oResultData.nname; |
|
974 | 979 | |
|
975 | 980 | // Guard against null value |
|
976 | 981 | var fnameMatchIndex = fname.toLowerCase().indexOf(query), |
|
977 | 982 | lnameMatchIndex = lname.toLowerCase().indexOf(query), |
|
978 | 983 | nnameMatchIndex = nname.toLowerCase().indexOf(query), |
|
979 | 984 | displayfname, displaylname, displaynname; |
|
980 | 985 | |
|
981 | 986 | if (fnameMatchIndex > -1) { |
|
982 | 987 | displayfname = highlightMatch(fname, query, fnameMatchIndex); |
|
983 | 988 | } else { |
|
984 | 989 | displayfname = fname; |
|
985 | 990 | } |
|
986 | 991 | |
|
987 | 992 | if (lnameMatchIndex > -1) { |
|
988 | 993 | displaylname = highlightMatch(lname, query, lnameMatchIndex); |
|
989 | 994 | } else { |
|
990 | 995 | displaylname = lname; |
|
991 | 996 | } |
|
992 | 997 | |
|
993 | 998 | if (nnameMatchIndex > -1) { |
|
994 | 999 | displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")"; |
|
995 | 1000 | } else { |
|
996 | 1001 | displaynname = nname ? "(" + nname + ")" : ""; |
|
997 | 1002 | } |
|
998 | 1003 | |
|
999 | 1004 | return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk); |
|
1000 | 1005 | } else { |
|
1001 | 1006 | return ''; |
|
1002 | 1007 | } |
|
1003 | 1008 | }; |
|
1004 | 1009 | membersAC.formatResult = custom_formatter; |
|
1005 | 1010 | ownerAC.formatResult = custom_formatter; |
|
1006 | 1011 | |
|
1007 | 1012 | var myHandler = function (sType, aArgs) { |
|
1008 | 1013 | |
|
1009 | 1014 | var myAC = aArgs[0]; // reference back to the AC instance |
|
1010 | 1015 | var elLI = aArgs[1]; // reference to the selected LI element |
|
1011 | 1016 | var oData = aArgs[2]; // object literal of selected item's result data |
|
1012 | 1017 | //fill the autocomplete with value |
|
1013 | 1018 | if (oData.nname != undefined) { |
|
1014 | 1019 | //users |
|
1015 | 1020 | myAC.getInputEl().value = oData.nname; |
|
1016 | 1021 | YUD.get('perm_new_member_type').value = 'user'; |
|
1017 | 1022 | } else { |
|
1018 | 1023 | //groups |
|
1019 | 1024 | myAC.getInputEl().value = oData.grname; |
|
1020 | 1025 | YUD.get('perm_new_member_type').value = 'users_group'; |
|
1021 | 1026 | } |
|
1022 | 1027 | }; |
|
1023 | 1028 | |
|
1024 | 1029 | membersAC.itemSelectEvent.subscribe(myHandler); |
|
1025 | 1030 | if(ownerAC.itemSelectEvent){ |
|
1026 | 1031 | ownerAC.itemSelectEvent.subscribe(myHandler); |
|
1027 | 1032 | } |
|
1028 | 1033 | |
|
1029 | 1034 | return { |
|
1030 | 1035 | memberDS: memberDS, |
|
1031 | 1036 | ownerDS: ownerDS, |
|
1032 | 1037 | membersAC: membersAC, |
|
1033 | 1038 | ownerAC: ownerAC, |
|
1034 | 1039 | }; |
|
1035 | 1040 | } |
|
1036 | 1041 | |
|
1037 | 1042 | |
|
1038 | 1043 | var MentionsAutoComplete = function (divid, cont, users_list, groups_list) { |
|
1039 | 1044 | var myUsers = users_list; |
|
1040 | 1045 | var myGroups = groups_list; |
|
1041 | 1046 | |
|
1042 | 1047 | // Define a custom search function for the DataSource of users |
|
1043 | 1048 | var matchUsers = function (sQuery) { |
|
1044 | 1049 | var org_sQuery = sQuery; |
|
1045 | 1050 | if(this.mentionQuery == null){ |
|
1046 | 1051 | return [] |
|
1047 | 1052 | } |
|
1048 | 1053 | sQuery = this.mentionQuery; |
|
1049 | 1054 | // Case insensitive matching |
|
1050 | 1055 | var query = sQuery.toLowerCase(); |
|
1051 | 1056 | var i = 0; |
|
1052 | 1057 | var l = myUsers.length; |
|
1053 | 1058 | var matches = []; |
|
1054 | 1059 | |
|
1055 | 1060 | // Match against each name of each contact |
|
1056 | 1061 | for (; i < l; i++) { |
|
1057 | 1062 | contact = myUsers[i]; |
|
1058 | 1063 | if (((contact.fname+"").toLowerCase().indexOf(query) > -1) || |
|
1059 | 1064 | ((contact.lname+"").toLowerCase().indexOf(query) > -1) || |
|
1060 | 1065 | ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) { |
|
1061 | 1066 | matches[matches.length] = contact; |
|
1062 | 1067 | } |
|
1063 | 1068 | } |
|
1064 | 1069 | return matches |
|
1065 | 1070 | }; |
|
1066 | 1071 | |
|
1067 | 1072 | //match all |
|
1068 | 1073 | var matchAll = function (sQuery) { |
|
1069 | 1074 | u = matchUsers(sQuery); |
|
1070 | 1075 | return u |
|
1071 | 1076 | }; |
|
1072 | 1077 | |
|
1073 | 1078 | // DataScheme for owner |
|
1074 | 1079 | var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers); |
|
1075 | 1080 | |
|
1076 | 1081 | ownerDS.responseSchema = { |
|
1077 | 1082 | fields: ["id", "fname", "lname", "nname", "gravatar_lnk"] |
|
1078 | 1083 | }; |
|
1079 | 1084 | |
|
1080 | 1085 | // Instantiate AutoComplete for mentions |
|
1081 | 1086 | var ownerAC = new YAHOO.widget.AutoComplete(divid, cont, ownerDS); |
|
1082 | 1087 | ownerAC.useShadow = false; |
|
1083 | 1088 | ownerAC.resultTypeList = false; |
|
1084 | 1089 | ownerAC.suppressInputUpdate = true; |
|
1090 | ownerAC.animVert = false; | |
|
1091 | ownerAC.animHoriz = false; | |
|
1092 | ownerAC.animSpeed = 0.1; | |
|
1085 | 1093 | |
|
1086 | 1094 | // Helper highlight function for the formatter |
|
1087 | 1095 | var highlightMatch = function (full, snippet, matchindex) { |
|
1088 | 1096 | return full.substring(0, matchindex) |
|
1089 | 1097 | + "<span class='match'>" |
|
1090 | 1098 | + full.substr(matchindex, snippet.length) |
|
1091 | 1099 | + "</span>" + full.substring(matchindex + snippet.length); |
|
1092 | 1100 | }; |
|
1093 | 1101 | |
|
1094 | 1102 | // Custom formatter to highlight the matching letters |
|
1095 | 1103 | ownerAC.formatResult = function (oResultData, sQuery, sResultMatch) { |
|
1096 | 1104 | var org_sQuery = sQuery; |
|
1097 | 1105 | if(this.dataSource.mentionQuery != null){ |
|
1098 | 1106 | sQuery = this.dataSource.mentionQuery; |
|
1099 | 1107 | } |
|
1100 | 1108 | |
|
1101 | 1109 | var query = sQuery.toLowerCase(); |
|
1102 | 1110 | var _gravatar = function(res, em, group){ |
|
1103 | 1111 | if (group !== undefined){ |
|
1104 | 1112 | em = '/images/icons/group.png' |
|
1105 | 1113 | } |
|
1106 | 1114 | tmpl = '<div class="ac-container-wrap"><img class="perm-gravatar-ac" src="{0}"/>{1}</div>' |
|
1107 | 1115 | return tmpl.format(em,res) |
|
1108 | 1116 | } |
|
1109 | 1117 | if (oResultData.nname != undefined) { |
|
1110 | 1118 | var fname = oResultData.fname || ""; |
|
1111 | 1119 | var lname = oResultData.lname || ""; |
|
1112 | 1120 | var nname = oResultData.nname; |
|
1113 | 1121 | |
|
1114 | 1122 | // Guard against null value |
|
1115 | 1123 | var fnameMatchIndex = fname.toLowerCase().indexOf(query), |
|
1116 | 1124 | lnameMatchIndex = lname.toLowerCase().indexOf(query), |
|
1117 | 1125 | nnameMatchIndex = nname.toLowerCase().indexOf(query), |
|
1118 | 1126 | displayfname, displaylname, displaynname; |
|
1119 | 1127 | |
|
1120 | 1128 | if (fnameMatchIndex > -1) { |
|
1121 | 1129 | displayfname = highlightMatch(fname, query, fnameMatchIndex); |
|
1122 | 1130 | } else { |
|
1123 | 1131 | displayfname = fname; |
|
1124 | 1132 | } |
|
1125 | 1133 | |
|
1126 | 1134 | if (lnameMatchIndex > -1) { |
|
1127 | 1135 | displaylname = highlightMatch(lname, query, lnameMatchIndex); |
|
1128 | 1136 | } else { |
|
1129 | 1137 | displaylname = lname; |
|
1130 | 1138 | } |
|
1131 | 1139 | |
|
1132 | 1140 | if (nnameMatchIndex > -1) { |
|
1133 | 1141 | displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")"; |
|
1134 | 1142 | } else { |
|
1135 | 1143 | displaynname = nname ? "(" + nname + ")" : ""; |
|
1136 | 1144 | } |
|
1137 | 1145 | |
|
1138 | 1146 | return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk); |
|
1139 | 1147 | } else { |
|
1140 | 1148 | return ''; |
|
1141 | 1149 | } |
|
1142 | 1150 | }; |
|
1143 | 1151 | |
|
1144 | 1152 | if(ownerAC.itemSelectEvent){ |
|
1145 | 1153 | ownerAC.itemSelectEvent.subscribe(function (sType, aArgs) { |
|
1146 | 1154 | |
|
1147 | 1155 | var myAC = aArgs[0]; // reference back to the AC instance |
|
1148 | 1156 | var elLI = aArgs[1]; // reference to the selected LI element |
|
1149 | 1157 | var oData = aArgs[2]; // object literal of selected item's result data |
|
1150 | 1158 | //fill the autocomplete with value |
|
1151 | 1159 | if (oData.nname != undefined) { |
|
1152 | 1160 | //users |
|
1153 | 1161 | //Replace the mention name with replaced |
|
1154 | 1162 | var re = new RegExp(); |
|
1155 | 1163 | var org = myAC.getInputEl().value; |
|
1156 | 1164 | var chunks = myAC.dataSource.chunks |
|
1157 | 1165 | // replace middle chunk(the search term) with actuall match |
|
1158 | 1166 | chunks[1] = chunks[1].replace('@'+myAC.dataSource.mentionQuery, |
|
1159 | 1167 | '@'+oData.nname+' '); |
|
1160 | 1168 | myAC.getInputEl().value = chunks.join('') |
|
1161 | 1169 | YUD.get(myAC.getInputEl()).focus(); // Y U NO WORK !? |
|
1162 | 1170 | } else { |
|
1163 | 1171 | //groups |
|
1164 | 1172 | myAC.getInputEl().value = oData.grname; |
|
1165 | 1173 | YUD.get('perm_new_member_type').value = 'users_group'; |
|
1166 | 1174 | } |
|
1167 | 1175 | }); |
|
1168 | 1176 | } |
|
1169 | 1177 | |
|
1170 | 1178 | // in this keybuffer we will gather current value of search ! |
|
1171 | 1179 | // since we need to get this just when someone does `@` then we do the |
|
1172 | 1180 | // search |
|
1173 | 1181 | ownerAC.dataSource.chunks = []; |
|
1174 | 1182 | ownerAC.dataSource.mentionQuery = null; |
|
1175 | 1183 | |
|
1176 | 1184 | ownerAC.get_mention = function(msg, max_pos) { |
|
1177 | 1185 | var org = msg; |
|
1178 | 1186 | var re = new RegExp('(?:^@|\s@)([a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+)$') |
|
1179 | 1187 | var chunks = []; |
|
1180 | 1188 | |
|
1181 | 1189 | |
|
1182 | 1190 | // cut first chunk until curret pos |
|
1183 | 1191 | var to_max = msg.substr(0, max_pos); |
|
1184 | 1192 | var at_pos = Math.max(0,to_max.lastIndexOf('@')-1); |
|
1185 | 1193 | var msg2 = to_max.substr(at_pos); |
|
1186 | 1194 | |
|
1187 | 1195 | chunks.push(org.substr(0,at_pos))// prefix chunk |
|
1188 | 1196 | chunks.push(msg2) // search chunk |
|
1189 | 1197 | chunks.push(org.substr(max_pos)) // postfix chunk |
|
1190 | 1198 | |
|
1191 | 1199 | // clean up msg2 for filtering and regex match |
|
1192 | 1200 | var msg2 = msg2.lstrip(' ').lstrip('\n'); |
|
1193 | 1201 | |
|
1194 | 1202 | if(re.test(msg2)){ |
|
1195 | 1203 | var unam = re.exec(msg2)[1]; |
|
1196 | 1204 | return [unam, chunks]; |
|
1197 | 1205 | } |
|
1198 | 1206 | return [null, null]; |
|
1199 | 1207 | }; |
|
1200 | 1208 | ownerAC.textboxKeyUpEvent.subscribe(function(type, args){ |
|
1201 | 1209 | |
|
1202 | 1210 | var ac_obj = args[0]; |
|
1203 | 1211 | var currentMessage = args[1]; |
|
1204 | 1212 | var currentCaretPosition = args[0]._elTextbox.selectionStart; |
|
1205 | 1213 | |
|
1206 | 1214 | var unam = ownerAC.get_mention(currentMessage, currentCaretPosition); |
|
1207 | 1215 | var curr_search = null; |
|
1208 | 1216 | if(unam[0]){ |
|
1209 | 1217 | curr_search = unam[0]; |
|
1210 | 1218 | } |
|
1211 | 1219 | |
|
1212 | 1220 | ownerAC.dataSource.chunks = unam[1]; |
|
1213 | 1221 | ownerAC.dataSource.mentionQuery = curr_search; |
|
1214 | 1222 | |
|
1215 | 1223 | }) |
|
1216 | 1224 | |
|
1217 | 1225 | return { |
|
1218 | 1226 | ownerDS: ownerDS, |
|
1219 | 1227 | ownerAC: ownerAC, |
|
1220 | 1228 | }; |
|
1221 | 1229 | } |
|
1222 | 1230 | |
|
1223 | 1231 | |
|
1224 | 1232 | /** |
|
1225 | 1233 | * QUICK REPO MENU |
|
1226 | 1234 | */ |
|
1227 | 1235 | var quick_repo_menu = function(){ |
|
1228 | 1236 | YUE.on(YUQ('.quick_repo_menu'),'mouseenter',function(e){ |
|
1229 | 1237 | var menu = e.currentTarget.firstElementChild.firstElementChild; |
|
1230 | 1238 | if(YUD.hasClass(menu,'hidden')){ |
|
1231 | 1239 | YUD.replaceClass(e.currentTarget,'hidden', 'active'); |
|
1232 | 1240 | YUD.replaceClass(menu, 'hidden', 'active'); |
|
1233 | 1241 | } |
|
1234 | 1242 | }) |
|
1235 | 1243 | YUE.on(YUQ('.quick_repo_menu'),'mouseleave',function(e){ |
|
1236 | 1244 | var menu = e.currentTarget.firstElementChild.firstElementChild; |
|
1237 | 1245 | if(YUD.hasClass(menu,'active')){ |
|
1238 | 1246 | YUD.replaceClass(e.currentTarget, 'active', 'hidden'); |
|
1239 | 1247 | YUD.replaceClass(menu, 'active', 'hidden'); |
|
1240 | 1248 | } |
|
1241 | 1249 | }) |
|
1242 | 1250 | }; |
|
1243 | 1251 | |
|
1244 | 1252 | |
|
1245 | 1253 | /** |
|
1246 | 1254 | * TABLE SORTING |
|
1247 | 1255 | */ |
|
1248 | 1256 | |
|
1249 | 1257 | // returns a node from given html; |
|
1250 | 1258 | var fromHTML = function(html){ |
|
1251 | 1259 | var _html = document.createElement('element'); |
|
1252 | 1260 | _html.innerHTML = html; |
|
1253 | 1261 | return _html; |
|
1254 | 1262 | } |
|
1255 | 1263 | var get_rev = function(node){ |
|
1256 | 1264 | var n = node.firstElementChild.firstElementChild; |
|
1257 | 1265 | |
|
1258 | 1266 | if (n===null){ |
|
1259 | 1267 | return -1 |
|
1260 | 1268 | } |
|
1261 | 1269 | else{ |
|
1262 | 1270 | out = n.firstElementChild.innerHTML.split(':')[0].replace('r',''); |
|
1263 | 1271 | return parseInt(out); |
|
1264 | 1272 | } |
|
1265 | 1273 | } |
|
1266 | 1274 | |
|
1267 | 1275 | var get_name = function(node){ |
|
1268 | 1276 | var name = node.firstElementChild.children[2].innerHTML; |
|
1269 | 1277 | return name |
|
1270 | 1278 | } |
|
1271 | 1279 | var get_group_name = function(node){ |
|
1272 | 1280 | var name = node.firstElementChild.children[1].innerHTML; |
|
1273 | 1281 | return name |
|
1274 | 1282 | } |
|
1275 | 1283 | var get_date = function(node){ |
|
1276 | 1284 | var date_ = YUD.getAttribute(node.firstElementChild,'date'); |
|
1277 | 1285 | return date_ |
|
1278 | 1286 | } |
|
1279 | 1287 | |
|
1280 | 1288 | var get_age = function(node){ |
|
1281 | 1289 | console.log(node); |
|
1282 | 1290 | return node |
|
1283 | 1291 | } |
|
1284 | 1292 | |
|
1285 | 1293 | var revisionSort = function(a, b, desc, field) { |
|
1286 | 1294 | |
|
1287 | 1295 | var a_ = fromHTML(a.getData(field)); |
|
1288 | 1296 | var b_ = fromHTML(b.getData(field)); |
|
1289 | 1297 | |
|
1290 | 1298 | // extract revisions from string nodes |
|
1291 | 1299 | a_ = get_rev(a_) |
|
1292 | 1300 | b_ = get_rev(b_) |
|
1293 | 1301 | |
|
1294 | 1302 | var comp = YAHOO.util.Sort.compare; |
|
1295 | 1303 | var compState = comp(a_, b_, desc); |
|
1296 | 1304 | return compState; |
|
1297 | 1305 | }; |
|
1298 | 1306 | var ageSort = function(a, b, desc, field) { |
|
1299 | 1307 | var a_ = fromHTML(a.getData(field)); |
|
1300 | 1308 | var b_ = fromHTML(b.getData(field)); |
|
1301 | 1309 | |
|
1302 | 1310 | // extract name from table |
|
1303 | 1311 | a_ = get_date(a_) |
|
1304 | 1312 | b_ = get_date(b_) |
|
1305 | 1313 | |
|
1306 | 1314 | var comp = YAHOO.util.Sort.compare; |
|
1307 | 1315 | var compState = comp(a_, b_, desc); |
|
1308 | 1316 | return compState; |
|
1309 | 1317 | }; |
|
1310 | 1318 | |
|
1311 | 1319 | var nameSort = function(a, b, desc, field) { |
|
1312 | 1320 | var a_ = fromHTML(a.getData(field)); |
|
1313 | 1321 | var b_ = fromHTML(b.getData(field)); |
|
1314 | 1322 | |
|
1315 | 1323 | // extract name from table |
|
1316 | 1324 | a_ = get_name(a_) |
|
1317 | 1325 | b_ = get_name(b_) |
|
1318 | 1326 | |
|
1319 | 1327 | var comp = YAHOO.util.Sort.compare; |
|
1320 | 1328 | var compState = comp(a_, b_, desc); |
|
1321 | 1329 | return compState; |
|
1322 | 1330 | }; |
|
1323 | 1331 | |
|
1324 | 1332 | var permNameSort = function(a, b, desc, field) { |
|
1325 | 1333 | var a_ = fromHTML(a.getData(field)); |
|
1326 | 1334 | var b_ = fromHTML(b.getData(field)); |
|
1327 | 1335 | // extract name from table |
|
1328 | 1336 | |
|
1329 | 1337 | a_ = a_.children[0].innerHTML; |
|
1330 | 1338 | b_ = b_.children[0].innerHTML; |
|
1331 | 1339 | |
|
1332 | 1340 | var comp = YAHOO.util.Sort.compare; |
|
1333 | 1341 | var compState = comp(a_, b_, desc); |
|
1334 | 1342 | return compState; |
|
1335 | 1343 | }; |
|
1336 | 1344 | |
|
1337 | 1345 | var groupNameSort = function(a, b, desc, field) { |
|
1338 | 1346 | var a_ = fromHTML(a.getData(field)); |
|
1339 | 1347 | var b_ = fromHTML(b.getData(field)); |
|
1340 | 1348 | |
|
1341 | 1349 | // extract name from table |
|
1342 | 1350 | a_ = get_group_name(a_) |
|
1343 | 1351 | b_ = get_group_name(b_) |
|
1344 | 1352 | |
|
1345 | 1353 | var comp = YAHOO.util.Sort.compare; |
|
1346 | 1354 | var compState = comp(a_, b_, desc); |
|
1347 | 1355 | return compState; |
|
1348 | 1356 | }; |
|
1349 | 1357 | var dateSort = function(a, b, desc, field) { |
|
1350 | 1358 | var a_ = fromHTML(a.getData(field)); |
|
1351 | 1359 | var b_ = fromHTML(b.getData(field)); |
|
1352 | 1360 | |
|
1353 | 1361 | // extract name from table |
|
1354 | 1362 | a_ = get_date(a_) |
|
1355 | 1363 | b_ = get_date(b_) |
|
1356 | 1364 | |
|
1357 | 1365 | var comp = YAHOO.util.Sort.compare; |
|
1358 | 1366 | var compState = comp(a_, b_, desc); |
|
1359 | 1367 | return compState; |
|
1360 | 1368 | }; |
|
1361 | 1369 | |
|
1362 | 1370 | |
|
1363 | 1371 | |
|
1364 | 1372 | /* Multi selectors */ |
|
1365 | 1373 | |
|
1366 | 1374 | var MultiSelectWidget = function(selected_id, available_id, form_id){ |
|
1367 | 1375 | |
|
1368 | 1376 | |
|
1369 | 1377 | //definition of containers ID's |
|
1370 | 1378 | var selected_container = selected_id; |
|
1371 | 1379 | var available_container = available_id; |
|
1372 | 1380 | |
|
1373 | 1381 | //temp container for selected storage. |
|
1374 | 1382 | var cache = new Array(); |
|
1375 | 1383 | var av_cache = new Array(); |
|
1376 | 1384 | var c = YUD.get(selected_container); |
|
1377 | 1385 | var ac = YUD.get(available_container); |
|
1378 | 1386 | |
|
1379 | 1387 | //get only selected options for further fullfilment |
|
1380 | 1388 | for(var i = 0;node =c.options[i];i++){ |
|
1381 | 1389 | if(node.selected){ |
|
1382 | 1390 | //push selected to my temp storage left overs :) |
|
1383 | 1391 | cache.push(node); |
|
1384 | 1392 | } |
|
1385 | 1393 | } |
|
1386 | 1394 | |
|
1387 | 1395 | //get all available options to cache |
|
1388 | 1396 | for(var i = 0;node =ac.options[i];i++){ |
|
1389 | 1397 | //push selected to my temp storage left overs :) |
|
1390 | 1398 | av_cache.push(node); |
|
1391 | 1399 | } |
|
1392 | 1400 | |
|
1393 | 1401 | //fill available only with those not in choosen |
|
1394 | 1402 | ac.options.length=0; |
|
1395 | 1403 | tmp_cache = new Array(); |
|
1396 | 1404 | |
|
1397 | 1405 | for(var i = 0;node = av_cache[i];i++){ |
|
1398 | 1406 | var add = true; |
|
1399 | 1407 | for(var i2 = 0;node_2 = cache[i2];i2++){ |
|
1400 | 1408 | if(node.value == node_2.value){ |
|
1401 | 1409 | add=false; |
|
1402 | 1410 | break; |
|
1403 | 1411 | } |
|
1404 | 1412 | } |
|
1405 | 1413 | if(add){ |
|
1406 | 1414 | tmp_cache.push(new Option(node.text, node.value, false, false)); |
|
1407 | 1415 | } |
|
1408 | 1416 | } |
|
1409 | 1417 | |
|
1410 | 1418 | for(var i = 0;node = tmp_cache[i];i++){ |
|
1411 | 1419 | ac.options[i] = node; |
|
1412 | 1420 | } |
|
1413 | 1421 | |
|
1414 | 1422 | function prompts_action_callback(e){ |
|
1415 | 1423 | |
|
1416 | 1424 | var choosen = YUD.get(selected_container); |
|
1417 | 1425 | var available = YUD.get(available_container); |
|
1418 | 1426 | |
|
1419 | 1427 | //get checked and unchecked options from field |
|
1420 | 1428 | function get_checked(from_field){ |
|
1421 | 1429 | //temp container for storage. |
|
1422 | 1430 | var sel_cache = new Array(); |
|
1423 | 1431 | var oth_cache = new Array(); |
|
1424 | 1432 | |
|
1425 | 1433 | for(var i = 0;node = from_field.options[i];i++){ |
|
1426 | 1434 | if(node.selected){ |
|
1427 | 1435 | //push selected fields :) |
|
1428 | 1436 | sel_cache.push(node); |
|
1429 | 1437 | } |
|
1430 | 1438 | else{ |
|
1431 | 1439 | oth_cache.push(node) |
|
1432 | 1440 | } |
|
1433 | 1441 | } |
|
1434 | 1442 | |
|
1435 | 1443 | return [sel_cache,oth_cache] |
|
1436 | 1444 | } |
|
1437 | 1445 | |
|
1438 | 1446 | //fill the field with given options |
|
1439 | 1447 | function fill_with(field,options){ |
|
1440 | 1448 | //clear firtst |
|
1441 | 1449 | field.options.length=0; |
|
1442 | 1450 | for(var i = 0;node = options[i];i++){ |
|
1443 | 1451 | field.options[i]=new Option(node.text, node.value, |
|
1444 | 1452 | false, false); |
|
1445 | 1453 | } |
|
1446 | 1454 | |
|
1447 | 1455 | } |
|
1448 | 1456 | //adds to current field |
|
1449 | 1457 | function add_to(field,options){ |
|
1450 | 1458 | for(var i = 0;node = options[i];i++){ |
|
1451 | 1459 | field.appendChild(new Option(node.text, node.value, |
|
1452 | 1460 | false, false)); |
|
1453 | 1461 | } |
|
1454 | 1462 | } |
|
1455 | 1463 | |
|
1456 | 1464 | // add action |
|
1457 | 1465 | if (this.id=='add_element'){ |
|
1458 | 1466 | var c = get_checked(available); |
|
1459 | 1467 | add_to(choosen,c[0]); |
|
1460 | 1468 | fill_with(available,c[1]); |
|
1461 | 1469 | } |
|
1462 | 1470 | // remove action |
|
1463 | 1471 | if (this.id=='remove_element'){ |
|
1464 | 1472 | var c = get_checked(choosen); |
|
1465 | 1473 | add_to(available,c[0]); |
|
1466 | 1474 | fill_with(choosen,c[1]); |
|
1467 | 1475 | } |
|
1468 | 1476 | // add all elements |
|
1469 | 1477 | if(this.id=='add_all_elements'){ |
|
1470 | 1478 | for(var i=0; node = available.options[i];i++){ |
|
1471 | 1479 | choosen.appendChild(new Option(node.text, |
|
1472 | 1480 | node.value, false, false)); |
|
1473 | 1481 | } |
|
1474 | 1482 | available.options.length = 0; |
|
1475 | 1483 | } |
|
1476 | 1484 | //remove all elements |
|
1477 | 1485 | if(this.id=='remove_all_elements'){ |
|
1478 | 1486 | for(var i=0; node = choosen.options[i];i++){ |
|
1479 | 1487 | available.appendChild(new Option(node.text, |
|
1480 | 1488 | node.value, false, false)); |
|
1481 | 1489 | } |
|
1482 | 1490 | choosen.options.length = 0; |
|
1483 | 1491 | } |
|
1484 | 1492 | |
|
1485 | 1493 | } |
|
1486 | 1494 | |
|
1487 | 1495 | YUE.addListener(['add_element','remove_element', |
|
1488 | 1496 | 'add_all_elements','remove_all_elements'],'click', |
|
1489 | 1497 | prompts_action_callback) |
|
1490 | 1498 | if (form_id !== undefined) { |
|
1491 | 1499 | YUE.addListener(form_id,'submit',function(){ |
|
1492 | 1500 | var choosen = YUD.get(selected_container); |
|
1493 | 1501 | for (var i = 0; i < choosen.options.length; i++) { |
|
1494 | 1502 | choosen.options[i].selected = 'selected'; |
|
1495 | 1503 | } |
|
1496 | 1504 | }); |
|
1497 | 1505 | } |
|
1498 | 1506 | } No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now