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