]>
Commit | Line | Data |
---|---|---|
84fb5b46 MKG |
1 | %# BEGIN BPS TAGGED BLOCK {{{ |
2 | %# | |
3 | %# COPYRIGHT: | |
4 | %# | |
5 | %# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC | |
6 | %# <sales@bestpractical.com> | |
7 | %# | |
8 | %# (Except where explicitly superseded by other copyright notices) | |
9 | %# | |
10 | %# | |
11 | %# LICENSE: | |
12 | %# | |
13 | %# This work is made available to you under the terms of Version 2 of | |
14 | %# the GNU General Public License. A copy of that license should have | |
15 | %# been provided with this software, but in any event can be snarfed | |
16 | %# from www.gnu.org. | |
17 | %# | |
18 | %# This work is distributed in the hope that it will be useful, but | |
19 | %# WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | %# General Public License for more details. | |
22 | %# | |
23 | %# You should have received a copy of the GNU General Public License | |
24 | %# along with this program; if not, write to the Free Software | |
25 | %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
26 | %# 02110-1301 or visit their web page on the internet at | |
27 | %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. | |
28 | %# | |
29 | %# | |
30 | %# CONTRIBUTION SUBMISSION POLICY: | |
31 | %# | |
32 | %# (The following paragraph is not intended to limit the rights granted | |
33 | %# to you to modify and distribute this software under the terms of | |
34 | %# the GNU General Public License and is only of importance to you if | |
35 | %# you choose to contribute your changes and enhancements to the | |
36 | %# community by submitting them to Best Practical Solutions, LLC.) | |
37 | %# | |
38 | %# By intentionally submitting any modifications, corrections or | |
39 | %# derivatives to this work, or any other work intended for use with | |
40 | %# Request Tracker, to Best Practical Solutions, LLC, you confirm that | |
41 | %# you are the copyright holder for those contributions and you grant | |
42 | %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, | |
43 | %# royalty-free, perpetual, license to use, copy, create derivative | |
44 | %# works based on those contributions, and sublicense and distribute | |
45 | %# those contributions and any derivatives thereof. | |
46 | %# | |
47 | %# END BPS TAGGED BLOCK }}} | |
48 | /* Visibility */ | |
49 | ||
50 | function show(id) { delClass( id, 'hidden' ) } | |
51 | function hide(id) { addClass( id, 'hidden' ) } | |
52 | ||
53 | function hideshow(id) { return toggleVisibility( id ) } | |
54 | function toggleVisibility(id) { | |
55 | var e = jQuery('#' + id); | |
56 | ||
57 | if ( e.hasClass('hidden') ) { | |
58 | e.removeClass('hidden'); | |
59 | } | |
60 | else { | |
61 | e.addClass('hidden'); | |
62 | } | |
63 | ||
64 | return false; | |
65 | } | |
66 | ||
67 | function setVisibility(id, visibility) { | |
68 | if ( visibility ) show(id); | |
69 | else hide(id); | |
70 | } | |
71 | ||
72 | function switchVisibility(id1, id2) { | |
73 | // Show both and then hide the one we want | |
74 | show(id1); | |
75 | show(id2); | |
76 | hide(id2); | |
77 | return false; | |
78 | } | |
79 | ||
80 | /* Classes */ | |
81 | function jQueryWrap( id ) { | |
82 | return typeof id == 'object' ? jQuery(id) : jQuery('#'+id); | |
83 | } | |
84 | ||
85 | function addClass(id, value) { | |
86 | jQueryWrap(id).addClass(value); | |
87 | } | |
88 | ||
89 | function delClass(id, value) { | |
90 | jQueryWrap(id).removeClass(value); | |
91 | } | |
92 | ||
93 | /* Rollups */ | |
94 | ||
95 | function rollup(id) { | |
96 | var e = jQueryWrap(id); | |
97 | var e2 = e.parent(); | |
98 | ||
99 | if (e.hasClass('hidden')) { | |
100 | set_rollup_state(e,e2,'shown'); | |
101 | createCookie(id,1,365); | |
102 | } | |
103 | else { | |
104 | set_rollup_state(e,e2,'hidden'); | |
105 | createCookie(id,0,365); | |
106 | } | |
107 | return false; | |
108 | } | |
109 | ||
110 | function set_rollup_state(e,e2,state) { | |
111 | if (e && e2) { | |
112 | if (state == 'shown') { | |
113 | show(e); | |
114 | delClass( e2, 'rolled-up' ); | |
115 | } | |
116 | else if (state == 'hidden') { | |
117 | hide(e); | |
118 | addClass( e2, 'rolled-up' ); | |
119 | } | |
120 | } | |
121 | } | |
122 | ||
123 | /* other utils */ | |
124 | ||
125 | function focusElementById(id) { | |
126 | var e = jQuery('#'+id); | |
127 | if (e) e.focus(); | |
128 | } | |
129 | ||
130 | function setCheckbox(form, name, val) { | |
131 | var myfield = form.getElementsByTagName('input'); | |
132 | for ( var i = 0; i < myfield.length; i++ ) { | |
133 | if ( myfield[i].type != 'checkbox' ) continue; | |
134 | if ( name ) { | |
135 | if ( name instanceof RegExp ) { | |
136 | if ( ! myfield[i].name.match( name ) ) continue; | |
137 | } | |
138 | else { | |
139 | if ( myfield[i].name != name ) continue; | |
140 | } | |
141 | ||
142 | } | |
143 | ||
144 | myfield[i].checked = val; | |
145 | } | |
146 | } | |
147 | ||
148 | /* apply callback to nodes or elements */ | |
149 | ||
150 | function walkChildNodes(parent, callback) | |
151 | { | |
152 | if( !parent || !parent.childNodes ) return; | |
153 | var list = parent.childNodes; | |
154 | for( var i = 0; i < list.length; i++ ) { | |
155 | callback( list[i] ); | |
156 | } | |
157 | } | |
158 | ||
159 | function walkChildElements(parent, callback) | |
160 | { | |
161 | walkChildNodes( parent, function(node) { | |
162 | if( node.nodeType != 1 ) return; | |
163 | return callback( node ); | |
164 | } ); | |
165 | } | |
166 | ||
167 | /* shredder things */ | |
168 | ||
169 | function showShredderPluginTab( plugin ) | |
170 | { | |
171 | var plugin_tab_id = 'shredder-plugin-'+ plugin +'-tab'; | |
172 | var root = jQuery('#shredder-plugin-tabs'); | |
173 | ||
174 | root.children(':not(.hidden)').addClass('hidden'); | |
175 | root.children('#' + plugin_tab_id).removeClass('hidden'); | |
176 | ||
177 | if( plugin ) { | |
178 | show('shredder-submit-button'); | |
179 | } else { | |
180 | hide('shredder-submit-button'); | |
181 | } | |
182 | } | |
183 | ||
184 | function checkAllObjects() | |
185 | { | |
186 | var check = jQuery('#shredder-select-all-objects-checkbox').attr('checked'); | |
187 | var elements = jQuery('#shredder-search-form :checkbox[name=WipeoutObject]'); | |
188 | ||
189 | if( check ) { | |
190 | elements.attr('checked', true); | |
191 | } else { | |
192 | elements.attr('checked', false); | |
193 | } | |
194 | } | |
195 | ||
196 | function checkboxToInput(target,checkbox,val){ | |
197 | var tar = jQuery('#' + escapeCssSelector(target)); | |
198 | var box = jQuery('#' + escapeCssSelector(checkbox)); | |
199 | if(box.attr('checked')){ | |
200 | if (tar.val()==''){ | |
201 | tar.val(val); | |
202 | } | |
203 | else{ | |
204 | tar.val( val+', '+ tar.val() ); | |
205 | } | |
206 | } | |
207 | else{ | |
208 | tar.val(tar.val().replace(val+', ','')); | |
209 | tar.val(tar.val().replace(val,'')); | |
210 | } | |
211 | jQuery('#UpdateIgnoreAddressCheckboxes').val(true); | |
212 | } | |
213 | ||
214 | // ahah for back compatibility as plugins may still use it | |
215 | function ahah( url, id ) { | |
216 | jQuery('#'+id).load(url); | |
217 | } | |
218 | ||
219 | // only for back compatibility, please JQuery() instead | |
220 | function doOnLoad( js ) { | |
221 | jQuery(js); | |
222 | } | |
223 | ||
224 | jQuery(function() { | |
86404187 | 225 | var opts = { |
84fb5b46 MKG |
226 | dateFormat: 'yy-mm-dd', |
227 | constrainInput: false, | |
86404187 MKG |
228 | showButtonPanel: true, |
229 | changeMonth: true, | |
230 | changeYear: true, | |
231 | showOtherMonths: true, | |
232 | selectOtherMonths: true | |
233 | }; | |
234 | jQuery(".ui-datepicker:not(.withtime)").datepicker(opts); | |
235 | jQuery(".ui-datepicker.withtime").datetimepicker( jQuery.extend({}, opts, { | |
236 | stepHour: 1, | |
237 | // We fake this by snapping below for the minute slider | |
238 | //stepMinute: 5, | |
239 | hourGrid: 6, | |
240 | minuteGrid: 15, | |
241 | showSecond: false, | |
242 | timeFormat: 'hh:mm:ss' | |
243 | }) ).each(function(index, el) { | |
244 | var tp = jQuery.datepicker._get( jQuery.datepicker._getInst(el), 'timepicker'); | |
245 | if (!tp) return; | |
246 | ||
247 | // Hook after _injectTimePicker so we can modify the minute_slider | |
248 | // right after it's first created | |
249 | tp._base_injectTimePicker = tp._injectTimePicker; | |
250 | tp._injectTimePicker = function() { | |
251 | this._base_injectTimePicker.apply(this, arguments); | |
252 | ||
253 | // Now that we have minute_slider, modify it to be stepped for mouse movements | |
254 | var slider = jQuery.data(this.minute_slider[0], "slider"); | |
255 | slider._base_normValueFromMouse = slider._normValueFromMouse; | |
256 | slider._normValueFromMouse = function() { | |
257 | var value = this._base_normValueFromMouse.apply(this, arguments); | |
258 | var old_step = this.options.step; | |
259 | this.options.step = 5; | |
260 | var aligned = this._trimAlignValue( value ); | |
261 | this.options.step = old_step; | |
262 | return aligned; | |
263 | }; | |
264 | }; | |
265 | }); | |
84fb5b46 MKG |
266 | }); |
267 | ||
268 | function textToHTML(value) { | |
269 | return value.replace(/&/g, "&") | |
270 | .replace(/</g, "<") | |
271 | .replace(/>/g, ">") | |
272 | .replace(/-- \n/g,"-- \n") | |
273 | .replace(/\n/g, "\n<br />"); | |
274 | }; | |
275 | ||
276 | function ReplaceAllTextareas(encoded) { | |
277 | var sAgent = navigator.userAgent.toLowerCase(); | |
278 | if (!CKEDITOR.env.isCompatible || | |
279 | sAgent.indexOf('iphone') != -1 || | |
280 | sAgent.indexOf('ipad') != -1 || | |
281 | sAgent.indexOf('android') != -1 ) | |
282 | return false; | |
283 | ||
284 | // replace all content and signature message boxes | |
285 | var allTextAreas = document.getElementsByTagName("textarea"); | |
286 | ||
287 | for (var i=0; i < allTextAreas.length; i++) { | |
288 | var textArea = allTextAreas[i]; | |
289 | if (jQuery(textArea).hasClass("messagebox")) { | |
290 | // Turn the original plain text content into HTML | |
291 | if (encoded == 0) { | |
292 | textArea.value = textToHTML(textArea.value); | |
293 | } | |
294 | // For this javascript | |
295 | var CKeditorEncoded = document.createElement('input'); | |
296 | CKeditorEncoded.setAttribute('type', 'hidden'); | |
297 | CKeditorEncoded.setAttribute('name', 'CKeditorEncoded'); | |
298 | CKeditorEncoded.setAttribute('value', '1'); | |
299 | textArea.parentNode.appendChild(CKeditorEncoded); | |
300 | ||
301 | // For fckeditor | |
302 | var typeField = document.createElement('input'); | |
303 | typeField.setAttribute('type', 'hidden'); | |
304 | typeField.setAttribute('name', textArea.name + 'Type'); | |
305 | typeField.setAttribute('value', 'text/html'); | |
306 | textArea.parentNode.appendChild(typeField); | |
307 | ||
308 | ||
309 | CKEDITOR.replace(textArea.name,{width:'100%',height:<% RT->Config->Get('MessageBoxRichTextHeight') |n,j%>}); | |
310 | CKEDITOR.basePath = <%RT->Config->Get('WebPath')|n,j%>+"/NoAuth/RichText/"; | |
311 | ||
312 | jQuery("#" + textArea.name + "___Frame").addClass("richtext-editor"); | |
313 | } | |
314 | } | |
315 | }; | |
316 | ||
317 | function toggle_addprincipal_validity(input, good, title) { | |
318 | if (good) { | |
319 | jQuery(input).nextAll(".warning").hide(); | |
320 | jQuery("#acl-AddPrincipal input[type=checkbox]").removeAttr("disabled"); | |
321 | } else { | |
322 | jQuery(input).nextAll(".warning").css("display", "block"); | |
323 | jQuery("#acl-AddPrincipal input[type=checkbox]").attr("disabled", "disabled"); | |
324 | } | |
325 | ||
326 | if (title == null) | |
327 | title = jQuery(input).val(); | |
328 | ||
329 | update_addprincipal_title( title ); | |
330 | } | |
331 | ||
332 | function update_addprincipal_title(title) { | |
333 | var h3 = jQuery("#acl-AddPrincipal h3"); | |
334 | h3.html( h3.text().replace(/: .*$/,'') + ": " + title ); | |
335 | } | |
336 | ||
337 | // when a value is selected from the autocompleter | |
338 | function addprincipal_onselect(ev, ui) { | |
339 | // pass the item's value along as the title since the input's value | |
340 | // isn't actually updated yet | |
341 | toggle_addprincipal_validity(this, true, ui.item.value); | |
342 | } | |
343 | ||
344 | // when the input is actually changed, through typing or autocomplete | |
345 | function addprincipal_onchange(ev, ui) { | |
346 | // if we have a ui.item, then they selected from autocomplete and it's good | |
347 | if (!ui.item) { | |
348 | var input = jQuery(this); | |
349 | // Check using the same autocomplete source if the value typed would | |
350 | // have been autocompleted and is therefore valid | |
351 | jQuery.ajax({ | |
352 | url: input.autocomplete("option", "source"), | |
353 | data: { | |
354 | op: "=", | |
355 | term: input.val() | |
356 | }, | |
357 | dataType: "json", | |
358 | success: function(data) { | |
359 | if (data) | |
360 | toggle_addprincipal_validity(input, data.length ? true : false ); | |
361 | else | |
362 | toggle_addprincipal_validity(input, true); | |
363 | } | |
364 | }); | |
365 | } else { | |
366 | toggle_addprincipal_validity(this, true); | |
367 | } | |
368 | } | |
369 | ||
370 | ||
371 | function escapeCssSelector(str) { | |
372 | return str.replace(/([^A-Za-z0-9_-])/g,'\\$1'); | |
373 | } |