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