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