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