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