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