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