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