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