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