##// END OF EJS Templates
journal: don't show "error" popup when navigating away from page while lazy info is loading...
Mads Kiilerich -
r3553:72c89171 beta
parent child Browse files
Show More
@@ -1,2173 +1,2175 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 /**
90 90 * SmartColorGenerator
91 91 *
92 92 *usage::
93 93 * var CG = new ColorGenerator();
94 94 * var col = CG.getColor(key); //returns array of RGB
95 95 * 'rgb({0})'.format(col.join(',')
96 96 *
97 97 * @returns {ColorGenerator}
98 98 */
99 99 var ColorGenerator = function(){
100 100 this.GOLDEN_RATIO = 0.618033988749895;
101 101 this.CURRENT_RATIO = 0.22717784590367374 // this can be random
102 102 this.HSV_1 = 0.75;//saturation
103 103 this.HSV_2 = 0.95;
104 104 this.color;
105 105 this.cacheColorMap = {};
106 106 };
107 107
108 108 ColorGenerator.prototype = {
109 109 getColor:function(key){
110 110 if(this.cacheColorMap[key] !== undefined){
111 111 return this.cacheColorMap[key];
112 112 }
113 113 else{
114 114 this.cacheColorMap[key] = this.generateColor();
115 115 return this.cacheColorMap[key];
116 116 }
117 117 },
118 118 _hsvToRgb:function(h,s,v){
119 119 if (s == 0.0)
120 120 return [v, v, v];
121 121 i = parseInt(h * 6.0)
122 122 f = (h * 6.0) - i
123 123 p = v * (1.0 - s)
124 124 q = v * (1.0 - s * f)
125 125 t = v * (1.0 - s * (1.0 - f))
126 126 i = i % 6
127 127 if (i == 0)
128 128 return [v, t, p]
129 129 if (i == 1)
130 130 return [q, v, p]
131 131 if (i == 2)
132 132 return [p, v, t]
133 133 if (i == 3)
134 134 return [p, q, v]
135 135 if (i == 4)
136 136 return [t, p, v]
137 137 if (i == 5)
138 138 return [v, p, q]
139 139 },
140 140 generateColor:function(){
141 141 this.CURRENT_RATIO = this.CURRENT_RATIO+this.GOLDEN_RATIO;
142 142 this.CURRENT_RATIO = this.CURRENT_RATIO %= 1;
143 143 HSV_tuple = [this.CURRENT_RATIO, this.HSV_1, this.HSV_2]
144 144 RGB_tuple = this._hsvToRgb(HSV_tuple[0],HSV_tuple[1],HSV_tuple[2]);
145 145 function toRgb(v){
146 146 return ""+parseInt(v*256)
147 147 }
148 148 return [toRgb(RGB_tuple[0]),toRgb(RGB_tuple[1]),toRgb(RGB_tuple[2])];
149 149
150 150 }
151 151 }
152 152
153 153 /**
154 154 * PyRoutesJS
155 155 *
156 156 * Usage pyroutes.url('mark_error_fixed',{"error_id":error_id}) // /mark_error_fixed/<error_id>
157 157 */
158 158 var pyroutes = (function() {
159 159 // access global map defined in special file pyroutes
160 160 var matchlist = PROUTES_MAP;
161 161 var sprintf = (function() {
162 162 function get_type(variable) {
163 163 return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase();
164 164 }
165 165 function str_repeat(input, multiplier) {
166 166 for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */}
167 167 return output.join('');
168 168 }
169 169
170 170 var str_format = function() {
171 171 if (!str_format.cache.hasOwnProperty(arguments[0])) {
172 172 str_format.cache[arguments[0]] = str_format.parse(arguments[0]);
173 173 }
174 174 return str_format.format.call(null, str_format.cache[arguments[0]], arguments);
175 175 };
176 176
177 177 str_format.format = function(parse_tree, argv) {
178 178 var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length;
179 179 for (i = 0; i < tree_length; i++) {
180 180 node_type = get_type(parse_tree[i]);
181 181 if (node_type === 'string') {
182 182 output.push(parse_tree[i]);
183 183 }
184 184 else if (node_type === 'array') {
185 185 match = parse_tree[i]; // convenience purposes only
186 186 if (match[2]) { // keyword argument
187 187 arg = argv[cursor];
188 188 for (k = 0; k < match[2].length; k++) {
189 189 if (!arg.hasOwnProperty(match[2][k])) {
190 190 throw(sprintf('[sprintf] property "%s" does not exist', match[2][k]));
191 191 }
192 192 arg = arg[match[2][k]];
193 193 }
194 194 }
195 195 else if (match[1]) { // positional argument (explicit)
196 196 arg = argv[match[1]];
197 197 }
198 198 else { // positional argument (implicit)
199 199 arg = argv[cursor++];
200 200 }
201 201
202 202 if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) {
203 203 throw(sprintf('[sprintf] expecting number but found %s', get_type(arg)));
204 204 }
205 205 switch (match[8]) {
206 206 case 'b': arg = arg.toString(2); break;
207 207 case 'c': arg = String.fromCharCode(arg); break;
208 208 case 'd': arg = parseInt(arg, 10); break;
209 209 case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break;
210 210 case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break;
211 211 case 'o': arg = arg.toString(8); break;
212 212 case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break;
213 213 case 'u': arg = Math.abs(arg); break;
214 214 case 'x': arg = arg.toString(16); break;
215 215 case 'X': arg = arg.toString(16).toUpperCase(); break;
216 216 }
217 217 arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg);
218 218 pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' ';
219 219 pad_length = match[6] - String(arg).length;
220 220 pad = match[6] ? str_repeat(pad_character, pad_length) : '';
221 221 output.push(match[5] ? arg + pad : pad + arg);
222 222 }
223 223 }
224 224 return output.join('');
225 225 };
226 226
227 227 str_format.cache = {};
228 228
229 229 str_format.parse = function(fmt) {
230 230 var _fmt = fmt, match = [], parse_tree = [], arg_names = 0;
231 231 while (_fmt) {
232 232 if ((match = /^[^\x25]+/.exec(_fmt)) !== null) {
233 233 parse_tree.push(match[0]);
234 234 }
235 235 else if ((match = /^\x25{2}/.exec(_fmt)) !== null) {
236 236 parse_tree.push('%');
237 237 }
238 238 else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) {
239 239 if (match[2]) {
240 240 arg_names |= 1;
241 241 var field_list = [], replacement_field = match[2], field_match = [];
242 242 if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
243 243 field_list.push(field_match[1]);
244 244 while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
245 245 if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {
246 246 field_list.push(field_match[1]);
247 247 }
248 248 else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) {
249 249 field_list.push(field_match[1]);
250 250 }
251 251 else {
252 252 throw('[sprintf] huh?');
253 253 }
254 254 }
255 255 }
256 256 else {
257 257 throw('[sprintf] huh?');
258 258 }
259 259 match[2] = field_list;
260 260 }
261 261 else {
262 262 arg_names |= 2;
263 263 }
264 264 if (arg_names === 3) {
265 265 throw('[sprintf] mixing positional and named placeholders is not (yet) supported');
266 266 }
267 267 parse_tree.push(match);
268 268 }
269 269 else {
270 270 throw('[sprintf] huh?');
271 271 }
272 272 _fmt = _fmt.substring(match[0].length);
273 273 }
274 274 return parse_tree;
275 275 };
276 276
277 277 return str_format;
278 278 })();
279 279
280 280 var vsprintf = function(fmt, argv) {
281 281 argv.unshift(fmt);
282 282 return sprintf.apply(null, argv);
283 283 };
284 284 return {
285 285 'url': function(route_name, params) {
286 286 var result = route_name;
287 287 if (typeof(params) != 'object'){
288 288 params = {};
289 289 }
290 290 if (matchlist.hasOwnProperty(route_name)) {
291 291 var route = matchlist[route_name];
292 292 // param substitution
293 293 for(var i=0; i < route[1].length; i++) {
294 294
295 295 if (!params.hasOwnProperty(route[1][i]))
296 296 throw new Error(route[1][i] + ' missing in "' + route_name + '" route generation');
297 297 }
298 298 result = sprintf(route[0], params);
299 299
300 300 var ret = [];
301 301 //extra params => GET
302 302 for(param in params){
303 303 if (route[1].indexOf(param) == -1){
304 304 ret.push(encodeURIComponent(param) + "=" + encodeURIComponent(params[param]));
305 305 }
306 306 }
307 307 var _parts = ret.join("&");
308 308 if(_parts){
309 309 result = result +'?'+ _parts
310 310 }
311 311 }
312 312
313 313 return result;
314 314 },
315 315 'register': function(route_name, route_tmpl, req_params) {
316 316 if (typeof(req_params) != 'object') {
317 317 req_params = [];
318 318 }
319 319 //fix escape
320 320 route_tmpl = unescape(route_tmpl);
321 321 keys = [];
322 322 for (o in req_params){
323 323 keys.push(req_params[o])
324 324 }
325 325 matchlist[route_name] = [
326 326 route_tmpl,
327 327 keys
328 328 ]
329 329 },
330 330 '_routes': function(){
331 331 return matchlist;
332 332 }
333 333 }
334 334 })();
335 335
336 336
337 337
338 338 /**
339 339 * GLOBAL YUI Shortcuts
340 340 */
341 341 var YUC = YAHOO.util.Connect;
342 342 var YUD = YAHOO.util.Dom;
343 343 var YUE = YAHOO.util.Event;
344 344 var YUQ = YAHOO.util.Selector.query;
345 345
346 346 // defines if push state is enabled for this browser ?
347 347 var push_state_enabled = Boolean(
348 348 window.history && window.history.pushState && window.history.replaceState
349 349 && !( /* disable for versions of iOS before version 4.3 (8F190) */
350 350 (/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i).test(navigator.userAgent)
351 351 /* disable for the mercury iOS browser, or at least older versions of the webkit engine */
352 352 || (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent)
353 353 )
354 354 );
355 355
356 356 var _run_callbacks = function(callbacks){
357 357 if (callbacks !== undefined){
358 358 var _l = callbacks.length;
359 359 for (var i=0;i<_l;i++){
360 360 var func = callbacks[i];
361 361 if(typeof(func)=='function'){
362 362 try{
363 363 func();
364 364 }catch (err){};
365 365 }
366 366 }
367 367 }
368 368 }
369 369
370 370 /**
371 371 * Partial Ajax Implementation
372 372 *
373 373 * @param url: defines url to make partial request
374 374 * @param container: defines id of container to input partial result
375 375 * @param s_call: success callback function that takes o as arg
376 376 * o.tId
377 377 * o.status
378 378 * o.statusText
379 379 * o.getResponseHeader[ ]
380 380 * o.getAllResponseHeaders
381 381 * o.responseText
382 382 * o.responseXML
383 383 * o.argument
384 384 * @param f_call: failure callback
385 385 * @param args arguments
386 386 */
387 387 function ypjax(url,container,s_call,f_call,args){
388 388 var method='GET';
389 389 if(args===undefined){
390 390 args=null;
391 391 }
392 392
393 393 // Set special header for partial ajax == HTTP_X_PARTIAL_XHR
394 394 YUC.initHeader('X-PARTIAL-XHR',true);
395 395
396 396 // wrapper of passed callback
397 397 var s_wrapper = (function(o){
398 398 return function(o){
399 399 YUD.get(container).innerHTML=o.responseText;
400 400 YUD.setStyle(container,'opacity','1.0');
401 401 //execute the given original callback
402 402 if (s_call !== undefined){
403 403 s_call(o);
404 404 }
405 405 }
406 406 })()
407 407 YUD.setStyle(container,'opacity','0.3');
408 408 YUC.asyncRequest(method,url,{
409 409 success:s_wrapper,
410 410 failure:function(o){
411 411 console.log(o);
412 412 YUD.get(container).innerHTML='<span class="error_red">ERROR: {0}</span>'.format(o.status);
413 413 YUD.setStyle(container,'opacity','1.0');
414 414 },
415 415 cache:false
416 416 },args);
417 417
418 418 };
419 419
420 420 var ajaxGET = function(url,success) {
421 421 // Set special header for ajax == HTTP_X_PARTIAL_XHR
422 422 YUC.initHeader('X-PARTIAL-XHR',true);
423 423
424 424 var sUrl = url;
425 425 var callback = {
426 426 success: success,
427 427 failure: function (o) {
428 alert("error");
428 if (o.status != 0) {
429 alert("error: " + o.statusText);
430 };
429 431 },
430 432 };
431 433
432 434 var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
433 435 return request;
434 436 };
435 437
436 438
437 439
438 440 var ajaxPOST = function(url,postData,success) {
439 441 // Set special header for ajax == HTTP_X_PARTIAL_XHR
440 442 YUC.initHeader('X-PARTIAL-XHR',true);
441 443
442 444 var toQueryString = function(o) {
443 445 if(typeof o !== 'object') {
444 446 return false;
445 447 }
446 448 var _p, _qs = [];
447 449 for(_p in o) {
448 450 _qs.push(encodeURIComponent(_p) + '=' + encodeURIComponent(o[_p]));
449 451 }
450 452 return _qs.join('&');
451 453 };
452 454
453 455 var sUrl = url;
454 456 var callback = {
455 457 success: success,
456 458 failure: function (o) {
457 459 alert("error");
458 460 },
459 461 };
460 462 var postData = toQueryString(postData);
461 463 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
462 464 return request;
463 465 };
464 466
465 467
466 468 /**
467 469 * tooltip activate
468 470 */
469 471 var tooltip_activate = function(){
470 472 yt = YAHOO.yuitip.main;
471 473 YUE.onDOMReady(yt.init);
472 474 };
473 475
474 476 /**
475 477 * show more
476 478 */
477 479 var show_more_event = function(){
478 480 YUE.on(YUD.getElementsByClassName('show_more'),'click',function(e){
479 481 var el = e.target;
480 482 YUD.setStyle(YUD.get(el.id.substring(1)),'display','');
481 483 YUD.setStyle(el.parentNode,'display','none');
482 484 });
483 485 };
484 486
485 487 /**
486 488 * show changeset tooltip
487 489 */
488 490 var show_changeset_tooltip = function(){
489 491 YUE.on(YUD.getElementsByClassName('lazy-cs'), 'mouseover', function(e){
490 492 var target = e.currentTarget;
491 493 var rid = YUD.getAttribute(target,'raw_id');
492 494 var repo_name = YUD.getAttribute(target,'repo_name');
493 495 var ttid = 'tt-'+rid;
494 496 var success = function(o){
495 497 var json = JSON.parse(o.responseText);
496 498 YUD.addClass(target,'tooltip')
497 499 YUD.setAttribute(target, 'title',json['message']);
498 500 YAHOO.yuitip.main.show_yuitip(e, target);
499 501 }
500 502 if(rid && !YUD.hasClass(target, 'tooltip')){
501 503 YUD.setAttribute(target,'id',ttid);
502 504 YUD.setAttribute(target, 'title',_TM['loading...']);
503 505 YAHOO.yuitip.main.set_listeners(target);
504 506 YAHOO.yuitip.main.show_yuitip(e, target);
505 507 var url = pyroutes.url('changeset_info', {"repo_name":repo_name, "revision": rid});
506 508 ajaxGET(url, success)
507 509 }
508 510 });
509 511 };
510 512
511 513 var onSuccessFollow = function(target){
512 514 var f = YUD.get(target);
513 515 var f_cnt = YUD.get('current_followers_count');
514 516
515 517 if(YUD.hasClass(f, 'follow')){
516 518 f.setAttribute('class','following');
517 519 f.setAttribute('title',_TM['Stop following this repository']);
518 520
519 521 if(f_cnt){
520 522 var cnt = Number(f_cnt.innerHTML)+1;
521 523 f_cnt.innerHTML = cnt;
522 524 }
523 525 }
524 526 else{
525 527 f.setAttribute('class','follow');
526 528 f.setAttribute('title',_TM['Start following this repository']);
527 529 if(f_cnt){
528 530 var cnt = Number(f_cnt.innerHTML)-1;
529 531 f_cnt.innerHTML = cnt;
530 532 }
531 533 }
532 534 }
533 535
534 536 var toggleFollowingUser = function(target,fallows_user_id,token,user_id){
535 537 args = 'follows_user_id='+fallows_user_id;
536 538 args+= '&amp;auth_token='+token;
537 539 if(user_id != undefined){
538 540 args+="&amp;user_id="+user_id;
539 541 }
540 542 YUC.asyncRequest('POST',TOGGLE_FOLLOW_URL,{
541 543 success:function(o){
542 544 onSuccessFollow(target);
543 545 }
544 546 },args);
545 547 return false;
546 548 }
547 549
548 550 var toggleFollowingRepo = function(target,fallows_repo_id,token,user_id){
549 551
550 552 args = 'follows_repo_id='+fallows_repo_id;
551 553 args+= '&amp;auth_token='+token;
552 554 if(user_id != undefined){
553 555 args+="&amp;user_id="+user_id;
554 556 }
555 557 YUC.asyncRequest('POST',TOGGLE_FOLLOW_URL,{
556 558 success:function(o){
557 559 onSuccessFollow(target);
558 560 }
559 561 },args);
560 562 return false;
561 563 }
562 564
563 565 var showRepoSize = function(target, repo_name, token){
564 566 var args= 'auth_token='+token;
565 567
566 568 if(!YUD.hasClass(target, 'loaded')){
567 569 YUD.get(target).innerHTML = _TM['Loading ...'];
568 570 var url = pyroutes.url('repo_size', {"repo_name":repo_name});
569 571 YUC.asyncRequest('POST',url,{
570 572 success:function(o){
571 573 YUD.get(target).innerHTML = JSON.parse(o.responseText);
572 574 YUD.addClass(target, 'loaded');
573 575 }
574 576 },args);
575 577 }
576 578 return false;
577 579 }
578 580
579 581 /**
580 582 * TOOLTIP IMPL.
581 583 */
582 584 YAHOO.namespace('yuitip');
583 585 YAHOO.yuitip.main = {
584 586
585 587 $: YAHOO.util.Dom.get,
586 588
587 589 bgColor: '#000',
588 590 speed: 0.3,
589 591 opacity: 0.9,
590 592 offset: [15,15],
591 593 useAnim: false,
592 594 maxWidth: 600,
593 595 add_links: false,
594 596 yuitips: [],
595 597
596 598 set_listeners: function(tt){
597 599 YUE.on(tt, 'mouseover', yt.show_yuitip, tt);
598 600 YUE.on(tt, 'mousemove', yt.move_yuitip, tt);
599 601 YUE.on(tt, 'mouseout', yt.close_yuitip, tt);
600 602 },
601 603
602 604 init: function(){
603 605 yt.tipBox = yt.$('tip-box');
604 606 if(!yt.tipBox){
605 607 yt.tipBox = document.createElement('div');
606 608 document.body.appendChild(yt.tipBox);
607 609 yt.tipBox.id = 'tip-box';
608 610 }
609 611
610 612 YUD.setStyle(yt.tipBox, 'display', 'none');
611 613 YUD.setStyle(yt.tipBox, 'position', 'absolute');
612 614 if(yt.maxWidth !== null){
613 615 YUD.setStyle(yt.tipBox, 'max-width', yt.maxWidth+'px');
614 616 }
615 617
616 618 var yuitips = YUD.getElementsByClassName('tooltip');
617 619
618 620 if(yt.add_links === true){
619 621 var links = document.getElementsByTagName('a');
620 622 var linkLen = links.length;
621 623 for(i=0;i<linkLen;i++){
622 624 yuitips.push(links[i]);
623 625 }
624 626 }
625 627
626 628 var yuiLen = yuitips.length;
627 629
628 630 for(i=0;i<yuiLen;i++){
629 631 yt.set_listeners(yuitips[i]);
630 632 }
631 633 },
632 634
633 635 show_yuitip: function(e, el){
634 636 YUE.stopEvent(e);
635 637 if(el.tagName.toLowerCase() === 'img'){
636 638 yt.tipText = el.alt ? el.alt : '';
637 639 } else {
638 640 yt.tipText = el.title ? el.title : '';
639 641 }
640 642
641 643 if(yt.tipText !== ''){
642 644 // save org title
643 645 YUD.setAttribute(el, 'tt_title', yt.tipText);
644 646 // reset title to not show org tooltips
645 647 YUD.setAttribute(el, 'title', '');
646 648
647 649 yt.tipBox.innerHTML = yt.tipText;
648 650 YUD.setStyle(yt.tipBox, 'display', 'block');
649 651 if(yt.useAnim === true){
650 652 YUD.setStyle(yt.tipBox, 'opacity', '0');
651 653 var newAnim = new YAHOO.util.Anim(yt.tipBox,
652 654 {
653 655 opacity: { to: yt.opacity }
654 656 }, yt.speed, YAHOO.util.Easing.easeOut
655 657 );
656 658 newAnim.animate();
657 659 }
658 660 }
659 661 },
660 662
661 663 move_yuitip: function(e, el){
662 664 YUE.stopEvent(e);
663 665 var movePos = YUE.getXY(e);
664 666 YUD.setStyle(yt.tipBox, 'top', (movePos[1] + yt.offset[1]) + 'px');
665 667 YUD.setStyle(yt.tipBox, 'left', (movePos[0] + yt.offset[0]) + 'px');
666 668 },
667 669
668 670 close_yuitip: function(e, el){
669 671 YUE.stopEvent(e);
670 672
671 673 if(yt.useAnim === true){
672 674 var newAnim = new YAHOO.util.Anim(yt.tipBox,
673 675 {
674 676 opacity: { to: 0 }
675 677 }, yt.speed, YAHOO.util.Easing.easeOut
676 678 );
677 679 newAnim.animate();
678 680 } else {
679 681 YUD.setStyle(yt.tipBox, 'display', 'none');
680 682 }
681 683 YUD.setAttribute(el,'title', YUD.getAttribute(el, 'tt_title'));
682 684 }
683 685 }
684 686
685 687 /**
686 688 * Quick filter widget
687 689 *
688 690 * @param target: filter input target
689 691 * @param nodes: list of nodes in html we want to filter.
690 692 * @param display_element function that takes current node from nodes and
691 693 * does hide or show based on the node
692 694 *
693 695 */
694 696 var q_filter = function(target,nodes,display_element){
695 697
696 698 var nodes = nodes;
697 699 var q_filter_field = YUD.get(target);
698 700 var F = YAHOO.namespace(target);
699 701
700 702 YUE.on(q_filter_field,'click',function(){
701 703 q_filter_field.value = '';
702 704 });
703 705
704 706 YUE.on(q_filter_field,'keyup',function(e){
705 707 clearTimeout(F.filterTimeout);
706 708 F.filterTimeout = setTimeout(F.updateFilter,600);
707 709 });
708 710
709 711 F.filterTimeout = null;
710 712
711 713 var show_node = function(node){
712 714 YUD.setStyle(node,'display','')
713 715 }
714 716 var hide_node = function(node){
715 717 YUD.setStyle(node,'display','none');
716 718 }
717 719
718 720 F.updateFilter = function() {
719 721 // Reset timeout
720 722 F.filterTimeout = null;
721 723
722 724 var obsolete = [];
723 725
724 726 var req = q_filter_field.value.toLowerCase();
725 727
726 728 var l = nodes.length;
727 729 var i;
728 730 var showing = 0;
729 731
730 732 for (i=0;i<l;i++ ){
731 733 var n = nodes[i];
732 734 var target_element = display_element(n)
733 735 if(req && n.innerHTML.toLowerCase().indexOf(req) == -1){
734 736 hide_node(target_element);
735 737 }
736 738 else{
737 739 show_node(target_element);
738 740 showing+=1;
739 741 }
740 742 }
741 743
742 744 // if repo_count is set update the number
743 745 var cnt = YUD.get('repo_count');
744 746 if(cnt){
745 747 YUD.get('repo_count').innerHTML = showing;
746 748 }
747 749
748 750 }
749 751 };
750 752
751 753 var tableTr = function(cls, body){
752 754 var _el = document.createElement('div');
753 755 var cont = new YAHOO.util.Element(body);
754 756 var comment_id = fromHTML(body).children[0].id.split('comment-')[1];
755 757 var id = 'comment-tr-{0}'.format(comment_id);
756 758 var _html = ('<table><tbody><tr id="{0}" class="{1}">'+
757 759 '<td class="lineno-inline new-inline"></td>'+
758 760 '<td class="lineno-inline old-inline"></td>'+
759 761 '<td>{2}</td>'+
760 762 '</tr></tbody></table>').format(id, cls, body);
761 763 _el.innerHTML = _html;
762 764 return _el.children[0].children[0].children[0];
763 765 };
764 766
765 767 /** comments **/
766 768 var removeInlineForm = function(form) {
767 769 form.parentNode.removeChild(form);
768 770 };
769 771
770 772 var createInlineForm = function(parent_tr, f_path, line) {
771 773 var tmpl = YUD.get('comment-inline-form-template').innerHTML;
772 774 tmpl = tmpl.format(f_path, line);
773 775 var form = tableTr('comment-form-inline',tmpl)
774 776
775 777 // create event for hide button
776 778 form = new YAHOO.util.Element(form);
777 779 var form_hide_button = new YAHOO.util.Element(YUD.getElementsByClassName('hide-inline-form',null,form)[0]);
778 780 form_hide_button.on('click', function(e) {
779 781 var newtr = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode;
780 782 if(YUD.hasClass(newtr.nextElementSibling,'inline-comments-button')){
781 783 YUD.setStyle(newtr.nextElementSibling,'display','');
782 784 }
783 785 removeInlineForm(newtr);
784 786 YUD.removeClass(parent_tr, 'form-open');
785 787 YUD.removeClass(parent_tr, 'hl-comment');
786 788
787 789 });
788 790
789 791 return form
790 792 };
791 793
792 794 /**
793 795 * Inject inline comment for on given TR this tr should be always an .line
794 796 * tr containing the line. Code will detect comment, and always put the comment
795 797 * block at the very bottom
796 798 */
797 799 var injectInlineForm = function(tr){
798 800 if(!YUD.hasClass(tr, 'line')){
799 801 return
800 802 }
801 803 var submit_url = AJAX_COMMENT_URL;
802 804 var _td = YUD.getElementsByClassName('code',null,tr)[0];
803 805 if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context') || YUD.hasClass(_td,'no-comment')){
804 806 return
805 807 }
806 808 YUD.addClass(tr,'form-open');
807 809 YUD.addClass(tr,'hl-comment');
808 810 var node = YUD.getElementsByClassName('full_f_path',null,tr.parentNode.parentNode.parentNode)[0];
809 811 var f_path = YUD.getAttribute(node,'path');
810 812 var lineno = getLineNo(tr);
811 813 var form = createInlineForm(tr, f_path, lineno, submit_url);
812 814
813 815 var parent = tr;
814 816 while (1){
815 817 var n = parent.nextElementSibling;
816 818 // next element are comments !
817 819 if(YUD.hasClass(n,'inline-comments')){
818 820 parent = n;
819 821 }
820 822 else{
821 823 break;
822 824 }
823 825 }
824 826 YUD.insertAfter(form,parent);
825 827 var f = YUD.get(form);
826 828 var overlay = YUD.getElementsByClassName('overlay',null,f)[0];
827 829 var _form = YUD.getElementsByClassName('inline-form',null,f)[0];
828 830
829 831 YUE.on(YUD.get(_form), 'submit',function(e){
830 832 YUE.preventDefault(e);
831 833
832 834 //ajax submit
833 835 var text = YUD.get('text_'+lineno).value;
834 836 var postData = {
835 837 'text':text,
836 838 'f_path':f_path,
837 839 'line':lineno
838 840 };
839 841
840 842 if(lineno === undefined){
841 843 alert('missing line !');
842 844 return
843 845 }
844 846 if(f_path === undefined){
845 847 alert('missing file path !');
846 848 return
847 849 }
848 850
849 851 if(text == ""){
850 852 return
851 853 }
852 854
853 855 var success = function(o){
854 856 YUD.removeClass(tr, 'form-open');
855 857 removeInlineForm(f);
856 858 var json_data = JSON.parse(o.responseText);
857 859 renderInlineComment(json_data);
858 860 };
859 861
860 862 if (YUD.hasClass(overlay,'overlay')){
861 863 var w = _form.offsetWidth;
862 864 var h = _form.offsetHeight;
863 865 YUD.setStyle(overlay,'width',w+'px');
864 866 YUD.setStyle(overlay,'height',h+'px');
865 867 }
866 868 YUD.addClass(overlay, 'submitting');
867 869
868 870 ajaxPOST(submit_url, postData, success);
869 871 });
870 872
871 873 setTimeout(function(){
872 874 // callbacks
873 875 tooltip_activate();
874 876 MentionsAutoComplete('text_'+lineno, 'mentions_container_'+lineno,
875 877 _USERS_AC_DATA, _GROUPS_AC_DATA);
876 878 var _e = YUD.get('text_'+lineno);
877 879 if(_e){
878 880 _e.focus();
879 881 }
880 882 },10)
881 883 };
882 884
883 885 var deleteComment = function(comment_id){
884 886 var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__',comment_id);
885 887 var postData = {'_method':'delete'};
886 888 var success = function(o){
887 889 var n = YUD.get('comment-tr-'+comment_id);
888 890 var root = prevElementSibling(prevElementSibling(n));
889 891 n.parentNode.removeChild(n);
890 892
891 893 // scann nodes, and attach add button to last one
892 894 placeAddButton(root);
893 895 }
894 896 ajaxPOST(url,postData,success);
895 897 }
896 898
897 899 var createInlineAddButton = function(tr){
898 900
899 901 var label = TRANSLATION_MAP['Add another comment'];
900 902
901 903 var html_el = document.createElement('div');
902 904 YUD.addClass(html_el, 'add-comment');
903 905 html_el.innerHTML = '<span class="ui-btn">{0}</span>'.format(label);
904 906
905 907 var add = new YAHOO.util.Element(html_el);
906 908 add.on('click', function(e) {
907 909 injectInlineForm(tr);
908 910 });
909 911 return add;
910 912 };
911 913
912 914 var getLineNo = function(tr) {
913 915 var line;
914 916 var o = tr.children[0].id.split('_');
915 917 var n = tr.children[1].id.split('_');
916 918
917 919 if (n.length >= 2) {
918 920 line = n[n.length-1];
919 921 } else if (o.length >= 2) {
920 922 line = o[o.length-1];
921 923 }
922 924
923 925 return line
924 926 };
925 927
926 928 var placeAddButton = function(target_tr){
927 929 if(!target_tr){
928 930 return
929 931 }
930 932 var last_node = target_tr;
931 933 //scann
932 934 while (1){
933 935 var n = last_node.nextElementSibling;
934 936 // next element are comments !
935 937 if(YUD.hasClass(n,'inline-comments')){
936 938 last_node = n;
937 939 //also remove the comment button from previous
938 940 var comment_add_buttons = YUD.getElementsByClassName('add-comment',null,last_node);
939 941 for(var i=0;i<comment_add_buttons.length;i++){
940 942 var b = comment_add_buttons[i];
941 943 b.parentNode.removeChild(b);
942 944 }
943 945 }
944 946 else{
945 947 break;
946 948 }
947 949 }
948 950
949 951 var add = createInlineAddButton(target_tr);
950 952 // get the comment div
951 953 var comment_block = YUD.getElementsByClassName('comment',null,last_node)[0];
952 954 // attach add button
953 955 YUD.insertAfter(add,comment_block);
954 956 }
955 957
956 958 /**
957 959 * Places the inline comment into the changeset block in proper line position
958 960 */
959 961 var placeInline = function(target_container,lineno,html){
960 962 var lineid = "{0}_{1}".format(target_container,lineno);
961 963 var target_line = YUD.get(lineid);
962 964 var comment = new YAHOO.util.Element(tableTr('inline-comments',html))
963 965
964 966 // check if there are comments already !
965 967 var parent = target_line.parentNode;
966 968 var root_parent = parent;
967 969 while (1){
968 970 var n = parent.nextElementSibling;
969 971 // next element are comments !
970 972 if(YUD.hasClass(n,'inline-comments')){
971 973 parent = n;
972 974 }
973 975 else{
974 976 break;
975 977 }
976 978 }
977 979 // put in the comment at the bottom
978 980 YUD.insertAfter(comment,parent);
979 981
980 982 // scann nodes, and attach add button to last one
981 983 placeAddButton(root_parent);
982 984
983 985 return target_line;
984 986 }
985 987
986 988 /**
987 989 * make a single inline comment and place it inside
988 990 */
989 991 var renderInlineComment = function(json_data){
990 992 try{
991 993 var html = json_data['rendered_text'];
992 994 var lineno = json_data['line_no'];
993 995 var target_id = json_data['target_id'];
994 996 placeInline(target_id, lineno, html);
995 997
996 998 }catch(e){
997 999 console.log(e);
998 1000 }
999 1001 }
1000 1002
1001 1003 /**
1002 1004 * Iterates over all the inlines, and places them inside proper blocks of data
1003 1005 */
1004 1006 var renderInlineComments = function(file_comments){
1005 1007 for (f in file_comments){
1006 1008 // holding all comments for a FILE
1007 1009 var box = file_comments[f];
1008 1010
1009 1011 var target_id = YUD.getAttribute(box,'target_id');
1010 1012 // actually comments with line numbers
1011 1013 var comments = box.children;
1012 1014 for(var i=0; i<comments.length; i++){
1013 1015 var data = {
1014 1016 'rendered_text': comments[i].outerHTML,
1015 1017 'line_no': YUD.getAttribute(comments[i],'line'),
1016 1018 'target_id': target_id
1017 1019 }
1018 1020 renderInlineComment(data);
1019 1021 }
1020 1022 }
1021 1023 }
1022 1024
1023 1025 var fileBrowserListeners = function(current_url, node_list_url, url_base){
1024 1026 var current_url_branch = +"?branch=__BRANCH__";
1025 1027
1026 1028 YUE.on('stay_at_branch','click',function(e){
1027 1029 if(e.target.checked){
1028 1030 var uri = current_url_branch;
1029 1031 uri = uri.replace('__BRANCH__',e.target.value);
1030 1032 window.location = uri;
1031 1033 }
1032 1034 else{
1033 1035 window.location = current_url;
1034 1036 }
1035 1037 })
1036 1038
1037 1039 var n_filter = YUD.get('node_filter');
1038 1040 var F = YAHOO.namespace('node_filter');
1039 1041
1040 1042 F.filterTimeout = null;
1041 1043 var nodes = null;
1042 1044
1043 1045 F.initFilter = function(){
1044 1046 YUD.setStyle('node_filter_box_loading','display','');
1045 1047 YUD.setStyle('search_activate_id','display','none');
1046 1048 YUD.setStyle('add_node_id','display','none');
1047 1049 YUC.initHeader('X-PARTIAL-XHR',true);
1048 1050 YUC.asyncRequest('GET', node_list_url, {
1049 1051 success:function(o){
1050 1052 nodes = JSON.parse(o.responseText).nodes;
1051 1053 YUD.setStyle('node_filter_box_loading','display','none');
1052 1054 YUD.setStyle('node_filter_box','display','');
1053 1055 n_filter.focus();
1054 1056 if(YUD.hasClass(n_filter,'init')){
1055 1057 n_filter.value = '';
1056 1058 YUD.removeClass(n_filter,'init');
1057 1059 }
1058 1060 },
1059 1061 failure:function(o){
1060 1062 console.log('failed to load');
1061 1063 }
1062 1064 },null);
1063 1065 }
1064 1066
1065 1067 F.updateFilter = function(e) {
1066 1068
1067 1069 return function(){
1068 1070 // Reset timeout
1069 1071 F.filterTimeout = null;
1070 1072 var query = e.target.value.toLowerCase();
1071 1073 var match = [];
1072 1074 var matches = 0;
1073 1075 var matches_max = 20;
1074 1076 if (query != ""){
1075 1077 for(var i=0;i<nodes.length;i++){
1076 1078
1077 1079 var pos = nodes[i].name.toLowerCase().indexOf(query)
1078 1080 if(query && pos != -1){
1079 1081
1080 1082 matches++
1081 1083 //show only certain amount to not kill browser
1082 1084 if (matches > matches_max){
1083 1085 break;
1084 1086 }
1085 1087
1086 1088 var n = nodes[i].name;
1087 1089 var t = nodes[i].type;
1088 1090 var n_hl = n.substring(0,pos)
1089 1091 +"<b>{0}</b>".format(n.substring(pos,pos+query.length))
1090 1092 +n.substring(pos+query.length)
1091 1093 var new_url = url_base.replace('__FPATH__',n);
1092 1094 match.push('<tr><td><a class="browser-{0}" href="{1}">{2}</a></td><td colspan="5"></td></tr>'.format(t,new_url,n_hl));
1093 1095 }
1094 1096 if(match.length >= matches_max){
1095 1097 match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format(_TM['Search truncated']));
1096 1098 }
1097 1099 }
1098 1100 }
1099 1101 if(query != ""){
1100 1102 YUD.setStyle('tbody','display','none');
1101 1103 YUD.setStyle('tbody_filtered','display','');
1102 1104
1103 1105 if (match.length==0){
1104 1106 match.push('<tr><td>{0}</td><td colspan="5"></td></tr>'.format(_TM['No matching files']));
1105 1107 }
1106 1108
1107 1109 YUD.get('tbody_filtered').innerHTML = match.join("");
1108 1110 }
1109 1111 else{
1110 1112 YUD.setStyle('tbody','display','');
1111 1113 YUD.setStyle('tbody_filtered','display','none');
1112 1114 }
1113 1115
1114 1116 }
1115 1117 };
1116 1118
1117 1119 YUE.on(YUD.get('filter_activate'),'click',function(){
1118 1120 F.initFilter();
1119 1121 })
1120 1122 YUE.on(n_filter,'click',function(){
1121 1123 if(YUD.hasClass(n_filter,'init')){
1122 1124 n_filter.value = '';
1123 1125 YUD.removeClass(n_filter,'init');
1124 1126 }
1125 1127 });
1126 1128 YUE.on(n_filter,'keyup',function(e){
1127 1129 clearTimeout(F.filterTimeout);
1128 1130 F.filterTimeout = setTimeout(F.updateFilter(e),600);
1129 1131 });
1130 1132 };
1131 1133
1132 1134
1133 1135 var initCodeMirror = function(textAreadId,resetUrl){
1134 1136 var myCodeMirror = CodeMirror.fromTextArea(YUD.get(textAreadId),{
1135 1137 mode: "null",
1136 1138 lineNumbers:true
1137 1139 });
1138 1140 YUE.on('reset','click',function(e){
1139 1141 window.location=resetUrl
1140 1142 });
1141 1143
1142 1144 YUE.on('file_enable','click',function(){
1143 1145 YUD.setStyle('editor_container','display','');
1144 1146 YUD.setStyle('upload_file_container','display','none');
1145 1147 YUD.setStyle('filename_container','display','');
1146 1148 });
1147 1149
1148 1150 YUE.on('upload_file_enable','click',function(){
1149 1151 YUD.setStyle('editor_container','display','none');
1150 1152 YUD.setStyle('upload_file_container','display','');
1151 1153 YUD.setStyle('filename_container','display','none');
1152 1154 });
1153 1155 };
1154 1156
1155 1157
1156 1158
1157 1159 var getIdentNode = function(n){
1158 1160 //iterate thru nodes untill matched interesting node !
1159 1161
1160 1162 if (typeof n == 'undefined'){
1161 1163 return -1
1162 1164 }
1163 1165
1164 1166 if(typeof n.id != "undefined" && n.id.match('L[0-9]+')){
1165 1167 return n
1166 1168 }
1167 1169 else{
1168 1170 return getIdentNode(n.parentNode);
1169 1171 }
1170 1172 };
1171 1173
1172 1174 var getSelectionLink = function(e) {
1173 1175
1174 1176 //get selection from start/to nodes
1175 1177 if (typeof window.getSelection != "undefined") {
1176 1178 s = window.getSelection();
1177 1179
1178 1180 from = getIdentNode(s.anchorNode);
1179 1181 till = getIdentNode(s.focusNode);
1180 1182
1181 1183 f_int = parseInt(from.id.replace('L',''));
1182 1184 t_int = parseInt(till.id.replace('L',''));
1183 1185
1184 1186 if (f_int > t_int){
1185 1187 //highlight from bottom
1186 1188 offset = -35;
1187 1189 ranges = [t_int,f_int];
1188 1190
1189 1191 }
1190 1192 else{
1191 1193 //highligth from top
1192 1194 offset = 35;
1193 1195 ranges = [f_int,t_int];
1194 1196 }
1195 1197 // if we select more than 2 lines
1196 1198 if (ranges[0] != ranges[1]){
1197 1199 if(YUD.get('linktt') == null){
1198 1200 hl_div = document.createElement('div');
1199 1201 hl_div.id = 'linktt';
1200 1202 }
1201 1203 hl_div.innerHTML = '';
1202 1204
1203 1205 anchor = '#L'+ranges[0]+'-'+ranges[1];
1204 1206 var link = document.createElement('a');
1205 1207 link.href = location.href.substring(0,location.href.indexOf('#'))+anchor;
1206 1208 link.innerHTML = _TM['Selection link'];
1207 1209 hl_div.appendChild(link);
1208 1210 YUD.get('body').appendChild(hl_div);
1209 1211
1210 1212 xy = YUD.getXY(till.id);
1211 1213
1212 1214 YUD.addClass('linktt', 'hl-tip-box');
1213 1215 YUD.setStyle('linktt','top',xy[1]+offset+'px');
1214 1216 YUD.setStyle('linktt','left',xy[0]+'px');
1215 1217 YUD.setStyle('linktt','visibility','visible');
1216 1218
1217 1219 }
1218 1220 else{
1219 1221 YUD.setStyle('linktt','visibility','hidden');
1220 1222 }
1221 1223 }
1222 1224 };
1223 1225
1224 1226 var deleteNotification = function(url, notification_id,callbacks){
1225 1227 var callback = {
1226 1228 success:function(o){
1227 1229 var obj = YUD.get(String("notification_"+notification_id));
1228 1230 if(obj.parentNode !== undefined){
1229 1231 obj.parentNode.removeChild(obj);
1230 1232 }
1231 1233 _run_callbacks(callbacks);
1232 1234 },
1233 1235 failure:function(o){
1234 1236 alert("error");
1235 1237 },
1236 1238 };
1237 1239 var postData = '_method=delete';
1238 1240 var sUrl = url.replace('__NOTIFICATION_ID__',notification_id);
1239 1241 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl,
1240 1242 callback, postData);
1241 1243 };
1242 1244
1243 1245 var readNotification = function(url, notification_id,callbacks){
1244 1246 var callback = {
1245 1247 success:function(o){
1246 1248 var obj = YUD.get(String("notification_"+notification_id));
1247 1249 YUD.removeClass(obj, 'unread');
1248 1250 var r_button = YUD.getElementsByClassName('read-notification',null,obj.children[0])[0];
1249 1251
1250 1252 if(r_button.parentNode !== undefined){
1251 1253 r_button.parentNode.removeChild(r_button);
1252 1254 }
1253 1255 _run_callbacks(callbacks);
1254 1256 },
1255 1257 failure:function(o){
1256 1258 alert("error");
1257 1259 },
1258 1260 };
1259 1261 var postData = '_method=put';
1260 1262 var sUrl = url.replace('__NOTIFICATION_ID__',notification_id);
1261 1263 var request = YAHOO.util.Connect.asyncRequest('POST', sUrl,
1262 1264 callback, postData);
1263 1265 };
1264 1266
1265 1267 /** MEMBERS AUTOCOMPLETE WIDGET **/
1266 1268
1267 1269 var MembersAutoComplete = function (divid, cont, users_list, groups_list) {
1268 1270 var myUsers = users_list;
1269 1271 var myGroups = groups_list;
1270 1272
1271 1273 // Define a custom search function for the DataSource of users
1272 1274 var matchUsers = function (sQuery) {
1273 1275 // Case insensitive matching
1274 1276 var query = sQuery.toLowerCase();
1275 1277 var i = 0;
1276 1278 var l = myUsers.length;
1277 1279 var matches = [];
1278 1280
1279 1281 // Match against each name of each contact
1280 1282 for (; i < l; i++) {
1281 1283 contact = myUsers[i];
1282 1284 if (((contact.fname+"").toLowerCase().indexOf(query) > -1) ||
1283 1285 ((contact.lname+"").toLowerCase().indexOf(query) > -1) ||
1284 1286 ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
1285 1287 matches[matches.length] = contact;
1286 1288 }
1287 1289 }
1288 1290 return matches;
1289 1291 };
1290 1292
1291 1293 // Define a custom search function for the DataSource of userGroups
1292 1294 var matchGroups = function (sQuery) {
1293 1295 // Case insensitive matching
1294 1296 var query = sQuery.toLowerCase();
1295 1297 var i = 0;
1296 1298 var l = myGroups.length;
1297 1299 var matches = [];
1298 1300
1299 1301 // Match against each name of each contact
1300 1302 for (; i < l; i++) {
1301 1303 matched_group = myGroups[i];
1302 1304 if (matched_group.grname.toLowerCase().indexOf(query) > -1) {
1303 1305 matches[matches.length] = matched_group;
1304 1306 }
1305 1307 }
1306 1308 return matches;
1307 1309 };
1308 1310
1309 1311 //match all
1310 1312 var matchAll = function (sQuery) {
1311 1313 u = matchUsers(sQuery);
1312 1314 g = matchGroups(sQuery);
1313 1315 return u.concat(g);
1314 1316 };
1315 1317
1316 1318 // DataScheme for members
1317 1319 var memberDS = new YAHOO.util.FunctionDataSource(matchAll);
1318 1320 memberDS.responseSchema = {
1319 1321 fields: ["id", "fname", "lname", "nname", "grname", "grmembers", "gravatar_lnk"]
1320 1322 };
1321 1323
1322 1324 // DataScheme for owner
1323 1325 var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers);
1324 1326 ownerDS.responseSchema = {
1325 1327 fields: ["id", "fname", "lname", "nname", "gravatar_lnk"]
1326 1328 };
1327 1329
1328 1330 // Instantiate AutoComplete for perms
1329 1331 var membersAC = new YAHOO.widget.AutoComplete(divid, cont, memberDS);
1330 1332 membersAC.useShadow = false;
1331 1333 membersAC.resultTypeList = false;
1332 1334 membersAC.animVert = false;
1333 1335 membersAC.animHoriz = false;
1334 1336 membersAC.animSpeed = 0.1;
1335 1337
1336 1338 // Instantiate AutoComplete for owner
1337 1339 var ownerAC = new YAHOO.widget.AutoComplete("user", "owner_container", ownerDS);
1338 1340 ownerAC.useShadow = false;
1339 1341 ownerAC.resultTypeList = false;
1340 1342 ownerAC.animVert = false;
1341 1343 ownerAC.animHoriz = false;
1342 1344 ownerAC.animSpeed = 0.1;
1343 1345
1344 1346 // Helper highlight function for the formatter
1345 1347 var highlightMatch = function (full, snippet, matchindex) {
1346 1348 return full.substring(0, matchindex)
1347 1349 + "<span class='match'>"
1348 1350 + full.substr(matchindex, snippet.length)
1349 1351 + "</span>" + full.substring(matchindex + snippet.length);
1350 1352 };
1351 1353
1352 1354 // Custom formatter to highlight the matching letters
1353 1355 var custom_formatter = function (oResultData, sQuery, sResultMatch) {
1354 1356 var query = sQuery.toLowerCase();
1355 1357 var _gravatar = function(res, em, group){
1356 1358 if (group !== undefined){
1357 1359 em = '/images/icons/group.png'
1358 1360 }
1359 1361 tmpl = '<div class="ac-container-wrap"><img class="perm-gravatar-ac" src="{0}"/>{1}</div>'
1360 1362 return tmpl.format(em,res)
1361 1363 }
1362 1364 // group
1363 1365 if (oResultData.grname != undefined) {
1364 1366 var grname = oResultData.grname;
1365 1367 var grmembers = oResultData.grmembers;
1366 1368 var grnameMatchIndex = grname.toLowerCase().indexOf(query);
1367 1369 var grprefix = "{0}: ".format(_TM['Group']);
1368 1370 var grsuffix = " (" + grmembers + " )";
1369 1371 var grsuffix = " ({0} {1})".format(grmembers, _TM['members']);
1370 1372
1371 1373 if (grnameMatchIndex > -1) {
1372 1374 return _gravatar(grprefix + highlightMatch(grname, query, grnameMatchIndex) + grsuffix,null,true);
1373 1375 }
1374 1376 return _gravatar(grprefix + oResultData.grname + grsuffix, null,true);
1375 1377 // Users
1376 1378 } else if (oResultData.nname != undefined) {
1377 1379 var fname = oResultData.fname || "";
1378 1380 var lname = oResultData.lname || "";
1379 1381 var nname = oResultData.nname;
1380 1382
1381 1383 // Guard against null value
1382 1384 var fnameMatchIndex = fname.toLowerCase().indexOf(query),
1383 1385 lnameMatchIndex = lname.toLowerCase().indexOf(query),
1384 1386 nnameMatchIndex = nname.toLowerCase().indexOf(query),
1385 1387 displayfname, displaylname, displaynname;
1386 1388
1387 1389 if (fnameMatchIndex > -1) {
1388 1390 displayfname = highlightMatch(fname, query, fnameMatchIndex);
1389 1391 } else {
1390 1392 displayfname = fname;
1391 1393 }
1392 1394
1393 1395 if (lnameMatchIndex > -1) {
1394 1396 displaylname = highlightMatch(lname, query, lnameMatchIndex);
1395 1397 } else {
1396 1398 displaylname = lname;
1397 1399 }
1398 1400
1399 1401 if (nnameMatchIndex > -1) {
1400 1402 displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")";
1401 1403 } else {
1402 1404 displaynname = nname ? "(" + nname + ")" : "";
1403 1405 }
1404 1406
1405 1407 return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk);
1406 1408 } else {
1407 1409 return '';
1408 1410 }
1409 1411 };
1410 1412 membersAC.formatResult = custom_formatter;
1411 1413 ownerAC.formatResult = custom_formatter;
1412 1414
1413 1415 var myHandler = function (sType, aArgs) {
1414 1416 var nextId = divid.split('perm_new_member_name_')[1];
1415 1417 var myAC = aArgs[0]; // reference back to the AC instance
1416 1418 var elLI = aArgs[1]; // reference to the selected LI element
1417 1419 var oData = aArgs[2]; // object literal of selected item's result data
1418 1420 //fill the autocomplete with value
1419 1421 if (oData.nname != undefined) {
1420 1422 //users
1421 1423 myAC.getInputEl().value = oData.nname;
1422 1424 YUD.get('perm_new_member_type_'+nextId).value = 'user';
1423 1425 } else {
1424 1426 //groups
1425 1427 myAC.getInputEl().value = oData.grname;
1426 1428 YUD.get('perm_new_member_type_'+nextId).value = 'users_group';
1427 1429 }
1428 1430 };
1429 1431
1430 1432 membersAC.itemSelectEvent.subscribe(myHandler);
1431 1433 if(ownerAC.itemSelectEvent){
1432 1434 ownerAC.itemSelectEvent.subscribe(myHandler);
1433 1435 }
1434 1436
1435 1437 return {
1436 1438 memberDS: memberDS,
1437 1439 ownerDS: ownerDS,
1438 1440 membersAC: membersAC,
1439 1441 ownerAC: ownerAC,
1440 1442 };
1441 1443 }
1442 1444
1443 1445
1444 1446 var MentionsAutoComplete = function (divid, cont, users_list, groups_list) {
1445 1447 var myUsers = users_list;
1446 1448 var myGroups = groups_list;
1447 1449
1448 1450 // Define a custom search function for the DataSource of users
1449 1451 var matchUsers = function (sQuery) {
1450 1452 var org_sQuery = sQuery;
1451 1453 if(this.mentionQuery == null){
1452 1454 return []
1453 1455 }
1454 1456 sQuery = this.mentionQuery;
1455 1457 // Case insensitive matching
1456 1458 var query = sQuery.toLowerCase();
1457 1459 var i = 0;
1458 1460 var l = myUsers.length;
1459 1461 var matches = [];
1460 1462
1461 1463 // Match against each name of each contact
1462 1464 for (; i < l; i++) {
1463 1465 contact = myUsers[i];
1464 1466 if (((contact.fname+"").toLowerCase().indexOf(query) > -1) ||
1465 1467 ((contact.lname+"").toLowerCase().indexOf(query) > -1) ||
1466 1468 ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
1467 1469 matches[matches.length] = contact;
1468 1470 }
1469 1471 }
1470 1472 return matches
1471 1473 };
1472 1474
1473 1475 //match all
1474 1476 var matchAll = function (sQuery) {
1475 1477 u = matchUsers(sQuery);
1476 1478 return u
1477 1479 };
1478 1480
1479 1481 // DataScheme for owner
1480 1482 var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers);
1481 1483
1482 1484 ownerDS.responseSchema = {
1483 1485 fields: ["id", "fname", "lname", "nname", "gravatar_lnk"]
1484 1486 };
1485 1487
1486 1488 // Instantiate AutoComplete for mentions
1487 1489 var ownerAC = new YAHOO.widget.AutoComplete(divid, cont, ownerDS);
1488 1490 ownerAC.useShadow = false;
1489 1491 ownerAC.resultTypeList = false;
1490 1492 ownerAC.suppressInputUpdate = true;
1491 1493 ownerAC.animVert = false;
1492 1494 ownerAC.animHoriz = false;
1493 1495 ownerAC.animSpeed = 0.1;
1494 1496
1495 1497 // Helper highlight function for the formatter
1496 1498 var highlightMatch = function (full, snippet, matchindex) {
1497 1499 return full.substring(0, matchindex)
1498 1500 + "<span class='match'>"
1499 1501 + full.substr(matchindex, snippet.length)
1500 1502 + "</span>" + full.substring(matchindex + snippet.length);
1501 1503 };
1502 1504
1503 1505 // Custom formatter to highlight the matching letters
1504 1506 ownerAC.formatResult = function (oResultData, sQuery, sResultMatch) {
1505 1507 var org_sQuery = sQuery;
1506 1508 if(this.dataSource.mentionQuery != null){
1507 1509 sQuery = this.dataSource.mentionQuery;
1508 1510 }
1509 1511
1510 1512 var query = sQuery.toLowerCase();
1511 1513 var _gravatar = function(res, em, group){
1512 1514 if (group !== undefined){
1513 1515 em = '/images/icons/group.png'
1514 1516 }
1515 1517 tmpl = '<div class="ac-container-wrap"><img class="perm-gravatar-ac" src="{0}"/>{1}</div>'
1516 1518 return tmpl.format(em,res)
1517 1519 }
1518 1520 if (oResultData.nname != undefined) {
1519 1521 var fname = oResultData.fname || "";
1520 1522 var lname = oResultData.lname || "";
1521 1523 var nname = oResultData.nname;
1522 1524
1523 1525 // Guard against null value
1524 1526 var fnameMatchIndex = fname.toLowerCase().indexOf(query),
1525 1527 lnameMatchIndex = lname.toLowerCase().indexOf(query),
1526 1528 nnameMatchIndex = nname.toLowerCase().indexOf(query),
1527 1529 displayfname, displaylname, displaynname;
1528 1530
1529 1531 if (fnameMatchIndex > -1) {
1530 1532 displayfname = highlightMatch(fname, query, fnameMatchIndex);
1531 1533 } else {
1532 1534 displayfname = fname;
1533 1535 }
1534 1536
1535 1537 if (lnameMatchIndex > -1) {
1536 1538 displaylname = highlightMatch(lname, query, lnameMatchIndex);
1537 1539 } else {
1538 1540 displaylname = lname;
1539 1541 }
1540 1542
1541 1543 if (nnameMatchIndex > -1) {
1542 1544 displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")";
1543 1545 } else {
1544 1546 displaynname = nname ? "(" + nname + ")" : "";
1545 1547 }
1546 1548
1547 1549 return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk);
1548 1550 } else {
1549 1551 return '';
1550 1552 }
1551 1553 };
1552 1554
1553 1555 if(ownerAC.itemSelectEvent){
1554 1556 ownerAC.itemSelectEvent.subscribe(function (sType, aArgs) {
1555 1557
1556 1558 var myAC = aArgs[0]; // reference back to the AC instance
1557 1559 var elLI = aArgs[1]; // reference to the selected LI element
1558 1560 var oData = aArgs[2]; // object literal of selected item's result data
1559 1561 //fill the autocomplete with value
1560 1562 if (oData.nname != undefined) {
1561 1563 //users
1562 1564 //Replace the mention name with replaced
1563 1565 var re = new RegExp();
1564 1566 var org = myAC.getInputEl().value;
1565 1567 var chunks = myAC.dataSource.chunks
1566 1568 // replace middle chunk(the search term) with actuall match
1567 1569 chunks[1] = chunks[1].replace('@'+myAC.dataSource.mentionQuery,
1568 1570 '@'+oData.nname+' ');
1569 1571 myAC.getInputEl().value = chunks.join('')
1570 1572 YUD.get(myAC.getInputEl()).focus(); // Y U NO WORK !?
1571 1573 } else {
1572 1574 //groups
1573 1575 myAC.getInputEl().value = oData.grname;
1574 1576 YUD.get('perm_new_member_type').value = 'users_group';
1575 1577 }
1576 1578 });
1577 1579 }
1578 1580
1579 1581 // in this keybuffer we will gather current value of search !
1580 1582 // since we need to get this just when someone does `@` then we do the
1581 1583 // search
1582 1584 ownerAC.dataSource.chunks = [];
1583 1585 ownerAC.dataSource.mentionQuery = null;
1584 1586
1585 1587 ownerAC.get_mention = function(msg, max_pos) {
1586 1588 var org = msg;
1587 1589 var re = new RegExp('(?:^@|\s@)([a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+)$')
1588 1590 var chunks = [];
1589 1591
1590 1592
1591 1593 // cut first chunk until curret pos
1592 1594 var to_max = msg.substr(0, max_pos);
1593 1595 var at_pos = Math.max(0,to_max.lastIndexOf('@')-1);
1594 1596 var msg2 = to_max.substr(at_pos);
1595 1597
1596 1598 chunks.push(org.substr(0,at_pos))// prefix chunk
1597 1599 chunks.push(msg2) // search chunk
1598 1600 chunks.push(org.substr(max_pos)) // postfix chunk
1599 1601
1600 1602 // clean up msg2 for filtering and regex match
1601 1603 var msg2 = msg2.lstrip(' ').lstrip('\n');
1602 1604
1603 1605 if(re.test(msg2)){
1604 1606 var unam = re.exec(msg2)[1];
1605 1607 return [unam, chunks];
1606 1608 }
1607 1609 return [null, null];
1608 1610 };
1609 1611
1610 1612 if (ownerAC.textboxKeyUpEvent){
1611 1613 ownerAC.textboxKeyUpEvent.subscribe(function(type, args){
1612 1614
1613 1615 var ac_obj = args[0];
1614 1616 var currentMessage = args[1];
1615 1617 var currentCaretPosition = args[0]._elTextbox.selectionStart;
1616 1618
1617 1619 var unam = ownerAC.get_mention(currentMessage, currentCaretPosition);
1618 1620 var curr_search = null;
1619 1621 if(unam[0]){
1620 1622 curr_search = unam[0];
1621 1623 }
1622 1624
1623 1625 ownerAC.dataSource.chunks = unam[1];
1624 1626 ownerAC.dataSource.mentionQuery = curr_search;
1625 1627
1626 1628 })
1627 1629 }
1628 1630 return {
1629 1631 ownerDS: ownerDS,
1630 1632 ownerAC: ownerAC,
1631 1633 };
1632 1634 }
1633 1635
1634 1636 var addReviewMember = function(id,fname,lname,nname,gravatar_link){
1635 1637 var members = YUD.get('review_members');
1636 1638 var tmpl = '<li id="reviewer_{2}">'+
1637 1639 '<div class="reviewers_member">'+
1638 1640 '<div class="gravatar"><img alt="gravatar" src="{0}"/> </div>'+
1639 1641 '<div style="float:left">{1}</div>'+
1640 1642 '<input type="hidden" value="{2}" name="review_members" />'+
1641 1643 '<span class="delete_icon action_button" onclick="removeReviewMember({2})"></span>'+
1642 1644 '</div>'+
1643 1645 '</li>' ;
1644 1646 var displayname = "{0} {1} ({2})".format(fname,lname,nname);
1645 1647 var element = tmpl.format(gravatar_link,displayname,id);
1646 1648 // check if we don't have this ID already in
1647 1649 var ids = [];
1648 1650 var _els = YUQ('#review_members li');
1649 1651 for (el in _els){
1650 1652 ids.push(_els[el].id)
1651 1653 }
1652 1654 if(ids.indexOf('reviewer_'+id) == -1){
1653 1655 //only add if it's not there
1654 1656 members.innerHTML += element;
1655 1657 }
1656 1658
1657 1659 }
1658 1660
1659 1661 var removeReviewMember = function(reviewer_id, repo_name, pull_request_id){
1660 1662 var el = YUD.get('reviewer_{0}'.format(reviewer_id));
1661 1663 if (el.parentNode !== undefined){
1662 1664 el.parentNode.removeChild(el);
1663 1665 }
1664 1666 }
1665 1667
1666 1668 var updateReviewers = function(reviewers_ids, repo_name, pull_request_id){
1667 1669 if (reviewers_ids === undefined){
1668 1670 var reviewers_ids = [];
1669 1671 var ids = YUQ('#review_members input');
1670 1672 for(var i=0; i<ids.length;i++){
1671 1673 var id = ids[i].value
1672 1674 reviewers_ids.push(id);
1673 1675 }
1674 1676 }
1675 1677 var url = pyroutes.url('pullrequest_update', {"repo_name":repo_name,
1676 1678 "pull_request_id": pull_request_id});
1677 1679 var postData = {'_method':'put',
1678 1680 'reviewers_ids': reviewers_ids};
1679 1681 var success = function(o){
1680 1682 window.location.reload();
1681 1683 }
1682 1684 ajaxPOST(url,postData,success);
1683 1685 }
1684 1686
1685 1687 var PullRequestAutoComplete = function (divid, cont, users_list, groups_list) {
1686 1688 var myUsers = users_list;
1687 1689 var myGroups = groups_list;
1688 1690
1689 1691 // Define a custom search function for the DataSource of users
1690 1692 var matchUsers = function (sQuery) {
1691 1693 // Case insensitive matching
1692 1694 var query = sQuery.toLowerCase();
1693 1695 var i = 0;
1694 1696 var l = myUsers.length;
1695 1697 var matches = [];
1696 1698
1697 1699 // Match against each name of each contact
1698 1700 for (; i < l; i++) {
1699 1701 contact = myUsers[i];
1700 1702 if (((contact.fname+"").toLowerCase().indexOf(query) > -1) ||
1701 1703 ((contact.lname+"").toLowerCase().indexOf(query) > -1) ||
1702 1704 ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
1703 1705 matches[matches.length] = contact;
1704 1706 }
1705 1707 }
1706 1708 return matches;
1707 1709 };
1708 1710
1709 1711 // Define a custom search function for the DataSource of userGroups
1710 1712 var matchGroups = function (sQuery) {
1711 1713 // Case insensitive matching
1712 1714 var query = sQuery.toLowerCase();
1713 1715 var i = 0;
1714 1716 var l = myGroups.length;
1715 1717 var matches = [];
1716 1718
1717 1719 // Match against each name of each contact
1718 1720 for (; i < l; i++) {
1719 1721 matched_group = myGroups[i];
1720 1722 if (matched_group.grname.toLowerCase().indexOf(query) > -1) {
1721 1723 matches[matches.length] = matched_group;
1722 1724 }
1723 1725 }
1724 1726 return matches;
1725 1727 };
1726 1728
1727 1729 //match all
1728 1730 var matchAll = function (sQuery) {
1729 1731 u = matchUsers(sQuery);
1730 1732 return u
1731 1733 };
1732 1734
1733 1735 // DataScheme for owner
1734 1736 var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers);
1735 1737
1736 1738 ownerDS.responseSchema = {
1737 1739 fields: ["id", "fname", "lname", "nname", "gravatar_lnk"]
1738 1740 };
1739 1741
1740 1742 // Instantiate AutoComplete for mentions
1741 1743 var reviewerAC = new YAHOO.widget.AutoComplete(divid, cont, ownerDS);
1742 1744 reviewerAC.useShadow = false;
1743 1745 reviewerAC.resultTypeList = false;
1744 1746 reviewerAC.suppressInputUpdate = true;
1745 1747 reviewerAC.animVert = false;
1746 1748 reviewerAC.animHoriz = false;
1747 1749 reviewerAC.animSpeed = 0.1;
1748 1750
1749 1751 // Helper highlight function for the formatter
1750 1752 var highlightMatch = function (full, snippet, matchindex) {
1751 1753 return full.substring(0, matchindex)
1752 1754 + "<span class='match'>"
1753 1755 + full.substr(matchindex, snippet.length)
1754 1756 + "</span>" + full.substring(matchindex + snippet.length);
1755 1757 };
1756 1758
1757 1759 // Custom formatter to highlight the matching letters
1758 1760 reviewerAC.formatResult = function (oResultData, sQuery, sResultMatch) {
1759 1761 var org_sQuery = sQuery;
1760 1762 if(this.dataSource.mentionQuery != null){
1761 1763 sQuery = this.dataSource.mentionQuery;
1762 1764 }
1763 1765
1764 1766 var query = sQuery.toLowerCase();
1765 1767 var _gravatar = function(res, em, group){
1766 1768 if (group !== undefined){
1767 1769 em = '/images/icons/group.png'
1768 1770 }
1769 1771 tmpl = '<div class="ac-container-wrap"><img class="perm-gravatar-ac" src="{0}"/>{1}</div>'
1770 1772 return tmpl.format(em,res)
1771 1773 }
1772 1774 if (oResultData.nname != undefined) {
1773 1775 var fname = oResultData.fname || "";
1774 1776 var lname = oResultData.lname || "";
1775 1777 var nname = oResultData.nname;
1776 1778
1777 1779 // Guard against null value
1778 1780 var fnameMatchIndex = fname.toLowerCase().indexOf(query),
1779 1781 lnameMatchIndex = lname.toLowerCase().indexOf(query),
1780 1782 nnameMatchIndex = nname.toLowerCase().indexOf(query),
1781 1783 displayfname, displaylname, displaynname;
1782 1784
1783 1785 if (fnameMatchIndex > -1) {
1784 1786 displayfname = highlightMatch(fname, query, fnameMatchIndex);
1785 1787 } else {
1786 1788 displayfname = fname;
1787 1789 }
1788 1790
1789 1791 if (lnameMatchIndex > -1) {
1790 1792 displaylname = highlightMatch(lname, query, lnameMatchIndex);
1791 1793 } else {
1792 1794 displaylname = lname;
1793 1795 }
1794 1796
1795 1797 if (nnameMatchIndex > -1) {
1796 1798 displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")";
1797 1799 } else {
1798 1800 displaynname = nname ? "(" + nname + ")" : "";
1799 1801 }
1800 1802
1801 1803 return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk);
1802 1804 } else {
1803 1805 return '';
1804 1806 }
1805 1807 };
1806 1808
1807 1809 //members cache to catch duplicates
1808 1810 reviewerAC.dataSource.cache = [];
1809 1811 // hack into select event
1810 1812 if(reviewerAC.itemSelectEvent){
1811 1813 reviewerAC.itemSelectEvent.subscribe(function (sType, aArgs) {
1812 1814
1813 1815 var myAC = aArgs[0]; // reference back to the AC instance
1814 1816 var elLI = aArgs[1]; // reference to the selected LI element
1815 1817 var oData = aArgs[2]; // object literal of selected item's result data
1816 1818
1817 1819 //fill the autocomplete with value
1818 1820
1819 1821 if (oData.nname != undefined) {
1820 1822 addReviewMember(oData.id, oData.fname, oData.lname, oData.nname,
1821 1823 oData.gravatar_lnk);
1822 1824 myAC.dataSource.cache.push(oData.id);
1823 1825 YUD.get('user').value = ''
1824 1826 }
1825 1827 });
1826 1828 }
1827 1829 return {
1828 1830 ownerDS: ownerDS,
1829 1831 reviewerAC: reviewerAC,
1830 1832 };
1831 1833 }
1832 1834
1833 1835 /**
1834 1836 * QUICK REPO MENU
1835 1837 */
1836 1838 var quick_repo_menu = function(){
1837 1839 YUE.on(YUQ('.quick_repo_menu'),'mouseenter',function(e){
1838 1840 var menu = e.currentTarget.firstElementChild.firstElementChild;
1839 1841 if(YUD.hasClass(menu,'hidden')){
1840 1842 YUD.replaceClass(e.currentTarget,'hidden', 'active');
1841 1843 YUD.replaceClass(menu, 'hidden', 'active');
1842 1844 }
1843 1845 })
1844 1846 YUE.on(YUQ('.quick_repo_menu'),'mouseleave',function(e){
1845 1847 var menu = e.currentTarget.firstElementChild.firstElementChild;
1846 1848 if(YUD.hasClass(menu,'active')){
1847 1849 YUD.replaceClass(e.currentTarget, 'active', 'hidden');
1848 1850 YUD.replaceClass(menu, 'active', 'hidden');
1849 1851 }
1850 1852 })
1851 1853 };
1852 1854
1853 1855
1854 1856 /**
1855 1857 * TABLE SORTING
1856 1858 */
1857 1859
1858 1860 // returns a node from given html;
1859 1861 var fromHTML = function(html){
1860 1862 var _html = document.createElement('element');
1861 1863 _html.innerHTML = html;
1862 1864 return _html;
1863 1865 }
1864 1866 var get_rev = function(node){
1865 1867 var n = node.firstElementChild.firstElementChild;
1866 1868
1867 1869 if (n===null){
1868 1870 return -1
1869 1871 }
1870 1872 else{
1871 1873 out = n.firstElementChild.innerHTML.split(':')[0].replace('r','');
1872 1874 return parseInt(out);
1873 1875 }
1874 1876 }
1875 1877
1876 1878 var get_name = function(node){
1877 1879 var name = node.firstElementChild.children[2].innerHTML;
1878 1880 return name
1879 1881 }
1880 1882 var get_group_name = function(node){
1881 1883 var name = node.firstElementChild.children[1].innerHTML;
1882 1884 return name
1883 1885 }
1884 1886 var get_date = function(node){
1885 1887 var date_ = YUD.getAttribute(node.firstElementChild,'date');
1886 1888 return date_
1887 1889 }
1888 1890
1889 1891 var get_age = function(node){
1890 1892 return node
1891 1893 }
1892 1894
1893 1895 var get_link = function(node){
1894 1896 return node.firstElementChild.text;
1895 1897 }
1896 1898
1897 1899 var revisionSort = function(a, b, desc, field) {
1898 1900
1899 1901 var a_ = fromHTML(a.getData(field));
1900 1902 var b_ = fromHTML(b.getData(field));
1901 1903
1902 1904 // extract revisions from string nodes
1903 1905 a_ = get_rev(a_)
1904 1906 b_ = get_rev(b_)
1905 1907
1906 1908 var comp = YAHOO.util.Sort.compare;
1907 1909 var compState = comp(a_, b_, desc);
1908 1910 return compState;
1909 1911 };
1910 1912 var ageSort = function(a, b, desc, field) {
1911 1913 var a_ = fromHTML(a.getData(field));
1912 1914 var b_ = fromHTML(b.getData(field));
1913 1915
1914 1916 // extract name from table
1915 1917 a_ = get_date(a_)
1916 1918 b_ = get_date(b_)
1917 1919
1918 1920 var comp = YAHOO.util.Sort.compare;
1919 1921 var compState = comp(a_, b_, desc);
1920 1922 return compState;
1921 1923 };
1922 1924
1923 1925 var lastLoginSort = function(a, b, desc, field) {
1924 1926 var a_ = a.getData('last_login_raw') || 0;
1925 1927 var b_ = b.getData('last_login_raw') || 0;
1926 1928
1927 1929 var comp = YAHOO.util.Sort.compare;
1928 1930 var compState = comp(a_, b_, desc);
1929 1931 return compState;
1930 1932 };
1931 1933
1932 1934 var nameSort = function(a, b, desc, field) {
1933 1935 var a_ = fromHTML(a.getData(field));
1934 1936 var b_ = fromHTML(b.getData(field));
1935 1937
1936 1938 // extract name from table
1937 1939 a_ = get_name(a_)
1938 1940 b_ = get_name(b_)
1939 1941
1940 1942 var comp = YAHOO.util.Sort.compare;
1941 1943 var compState = comp(a_, b_, desc);
1942 1944 return compState;
1943 1945 };
1944 1946
1945 1947 var permNameSort = function(a, b, desc, field) {
1946 1948 var a_ = fromHTML(a.getData(field));
1947 1949 var b_ = fromHTML(b.getData(field));
1948 1950 // extract name from table
1949 1951
1950 1952 a_ = a_.children[0].innerHTML;
1951 1953 b_ = b_.children[0].innerHTML;
1952 1954
1953 1955 var comp = YAHOO.util.Sort.compare;
1954 1956 var compState = comp(a_, b_, desc);
1955 1957 return compState;
1956 1958 };
1957 1959
1958 1960 var groupNameSort = function(a, b, desc, field) {
1959 1961 var a_ = fromHTML(a.getData(field));
1960 1962 var b_ = fromHTML(b.getData(field));
1961 1963
1962 1964 // extract name from table
1963 1965 a_ = get_group_name(a_)
1964 1966 b_ = get_group_name(b_)
1965 1967
1966 1968 var comp = YAHOO.util.Sort.compare;
1967 1969 var compState = comp(a_, b_, desc);
1968 1970 return compState;
1969 1971 };
1970 1972 var dateSort = function(a, b, desc, field) {
1971 1973 var a_ = fromHTML(a.getData(field));
1972 1974 var b_ = fromHTML(b.getData(field));
1973 1975
1974 1976 // extract name from table
1975 1977 a_ = get_date(a_)
1976 1978 b_ = get_date(b_)
1977 1979
1978 1980 var comp = YAHOO.util.Sort.compare;
1979 1981 var compState = comp(a_, b_, desc);
1980 1982 return compState;
1981 1983 };
1982 1984
1983 1985 var linkSort = function(a, b, desc, field) {
1984 1986 var a_ = fromHTML(a.getData(field));
1985 1987 var b_ = fromHTML(a.getData(field));
1986 1988
1987 1989 // extract url text from string nodes
1988 1990 a_ = get_link(a_)
1989 1991 b_ = get_link(b_)
1990 1992
1991 1993 var comp = YAHOO.util.Sort.compare;
1992 1994 var compState = comp(a_, b_, desc);
1993 1995 return compState;
1994 1996 }
1995 1997
1996 1998 var addPermAction = function(_html, users_list, groups_list){
1997 1999 var elmts = YUD.getElementsByClassName('last_new_member');
1998 2000 var last_node = elmts[elmts.length-1];
1999 2001 if (last_node){
2000 2002 var next_id = (YUD.getElementsByClassName('new_members')).length;
2001 2003 _html = _html.format(next_id);
2002 2004 last_node.innerHTML = _html;
2003 2005 YUD.setStyle(last_node, 'display', '');
2004 2006 YUD.removeClass(last_node, 'last_new_member');
2005 2007 MembersAutoComplete("perm_new_member_name_"+next_id,
2006 2008 "perm_container_"+next_id, users_list, groups_list);
2007 2009 //create new last NODE
2008 2010 var el = document.createElement('tr');
2009 2011 el.id = 'add_perm_input';
2010 2012 YUD.addClass(el,'last_new_member');
2011 2013 YUD.addClass(el,'new_members');
2012 2014 YUD.insertAfter(el, last_node);
2013 2015 }
2014 2016 }
2015 2017
2016 2018 /* Multi selectors */
2017 2019
2018 2020 var MultiSelectWidget = function(selected_id, available_id, form_id){
2019 2021
2020 2022
2021 2023 //definition of containers ID's
2022 2024 var selected_container = selected_id;
2023 2025 var available_container = available_id;
2024 2026
2025 2027 //temp container for selected storage.
2026 2028 var cache = new Array();
2027 2029 var av_cache = new Array();
2028 2030 var c = YUD.get(selected_container);
2029 2031 var ac = YUD.get(available_container);
2030 2032
2031 2033 //get only selected options for further fullfilment
2032 2034 for(var i = 0;node =c.options[i];i++){
2033 2035 if(node.selected){
2034 2036 //push selected to my temp storage left overs :)
2035 2037 cache.push(node);
2036 2038 }
2037 2039 }
2038 2040
2039 2041 //get all available options to cache
2040 2042 for(var i = 0;node =ac.options[i];i++){
2041 2043 //push selected to my temp storage left overs :)
2042 2044 av_cache.push(node);
2043 2045 }
2044 2046
2045 2047 //fill available only with those not in choosen
2046 2048 ac.options.length=0;
2047 2049 tmp_cache = new Array();
2048 2050
2049 2051 for(var i = 0;node = av_cache[i];i++){
2050 2052 var add = true;
2051 2053 for(var i2 = 0;node_2 = cache[i2];i2++){
2052 2054 if(node.value == node_2.value){
2053 2055 add=false;
2054 2056 break;
2055 2057 }
2056 2058 }
2057 2059 if(add){
2058 2060 tmp_cache.push(new Option(node.text, node.value, false, false));
2059 2061 }
2060 2062 }
2061 2063
2062 2064 for(var i = 0;node = tmp_cache[i];i++){
2063 2065 ac.options[i] = node;
2064 2066 }
2065 2067
2066 2068 function prompts_action_callback(e){
2067 2069
2068 2070 var choosen = YUD.get(selected_container);
2069 2071 var available = YUD.get(available_container);
2070 2072
2071 2073 //get checked and unchecked options from field
2072 2074 function get_checked(from_field){
2073 2075 //temp container for storage.
2074 2076 var sel_cache = new Array();
2075 2077 var oth_cache = new Array();
2076 2078
2077 2079 for(var i = 0;node = from_field.options[i];i++){
2078 2080 if(node.selected){
2079 2081 //push selected fields :)
2080 2082 sel_cache.push(node);
2081 2083 }
2082 2084 else{
2083 2085 oth_cache.push(node)
2084 2086 }
2085 2087 }
2086 2088
2087 2089 return [sel_cache,oth_cache]
2088 2090 }
2089 2091
2090 2092 //fill the field with given options
2091 2093 function fill_with(field,options){
2092 2094 //clear firtst
2093 2095 field.options.length=0;
2094 2096 for(var i = 0;node = options[i];i++){
2095 2097 field.options[i]=new Option(node.text, node.value,
2096 2098 false, false);
2097 2099 }
2098 2100
2099 2101 }
2100 2102 //adds to current field
2101 2103 function add_to(field,options){
2102 2104 for(var i = 0;node = options[i];i++){
2103 2105 field.appendChild(new Option(node.text, node.value,
2104 2106 false, false));
2105 2107 }
2106 2108 }
2107 2109
2108 2110 // add action
2109 2111 if (this.id=='add_element'){
2110 2112 var c = get_checked(available);
2111 2113 add_to(choosen,c[0]);
2112 2114 fill_with(available,c[1]);
2113 2115 }
2114 2116 // remove action
2115 2117 if (this.id=='remove_element'){
2116 2118 var c = get_checked(choosen);
2117 2119 add_to(available,c[0]);
2118 2120 fill_with(choosen,c[1]);
2119 2121 }
2120 2122 // add all elements
2121 2123 if(this.id=='add_all_elements'){
2122 2124 for(var i=0; node = available.options[i];i++){
2123 2125 choosen.appendChild(new Option(node.text,
2124 2126 node.value, false, false));
2125 2127 }
2126 2128 available.options.length = 0;
2127 2129 }
2128 2130 //remove all elements
2129 2131 if(this.id=='remove_all_elements'){
2130 2132 for(var i=0; node = choosen.options[i];i++){
2131 2133 available.appendChild(new Option(node.text,
2132 2134 node.value, false, false));
2133 2135 }
2134 2136 choosen.options.length = 0;
2135 2137 }
2136 2138
2137 2139 }
2138 2140
2139 2141 YUE.addListener(['add_element','remove_element',
2140 2142 'add_all_elements','remove_all_elements'],'click',
2141 2143 prompts_action_callback)
2142 2144 if (form_id !== undefined) {
2143 2145 YUE.addListener(form_id,'submit',function(){
2144 2146 var choosen = YUD.get(selected_container);
2145 2147 for (var i = 0; i < choosen.options.length; i++) {
2146 2148 choosen.options[i].selected = 'selected';
2147 2149 }
2148 2150 });
2149 2151 }
2150 2152 }
2151 2153
2152 2154
2153 2155 // global hooks after DOM is loaded
2154 2156
2155 2157 YUE.onDOMReady(function(){
2156 2158 YUE.on(YUQ('.diff-collapse-button'), 'click', function(e){
2157 2159 var button = e.currentTarget;
2158 2160 var t = YUD.get(button).getAttribute('target');
2159 2161 console.log(t);
2160 2162 if(YUD.hasClass(t, 'hidden')){
2161 2163 YUD.removeClass(t, 'hidden');
2162 2164 YUD.get(button).innerHTML = "&uarr; {0} &uarr;".format(_TM['Collapse diff']);
2163 2165 }
2164 2166 else if(!YUD.hasClass(t, 'hidden')){
2165 2167 YUD.addClass(t, 'hidden');
2166 2168 YUD.get(button).innerHTML = "&darr; {0} &darr;".format(_TM['Expand diff']);
2167 2169 }
2168 2170 });
2169 2171
2170 2172
2171 2173
2172 2174 });
2173 2175
General Comments 0
You need to be logged in to leave comments. Login now