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