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