1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 %# CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 %# END BPS TAGGED BLOCK }}}
49 Returns DOM node or array of nodes (if more then one argument passed).
50 If argument is node object allready then do nothing.
51 // Stolen from Prototype
54 var elements = new Array();
56 for (var i = 0; i < arguments.length; i++) {
57 var element = arguments[i];
58 if (typeof element == 'string')
59 element = document.getElementById(element);
61 if (arguments.length == 1)
64 elements.push(element);
72 function show(id) { delClass( id, 'hidden' ) }
73 function hide(id) { addClass( id, 'hidden' ) }
75 function hideshow(id) { return toggleVisibility( id ) }
76 function toggleVisibility(id) {
79 if ( e.className.match( /\bhidden\b/ ) )
87 function setVisibility(id, visibility) {
88 if ( visibility ) show(id);
92 function switchVisibility(id1, id2) {
93 // Show both and then hide the one we want
102 function addClass(id, value) {
104 if ( e.className.match( new RegExp('\b'+ value +'\b') ) )
106 e.className += e.className? ' '+value : value;
109 function delClass(id, value) {
111 e.className = e.className.replace( new RegExp('\\s?\\b'+ value +'\\b', 'g'), '' );
116 function rollup(id) {
118 var e2 = e.parentNode;
120 if (e.className.match(/\bhidden\b/)) {
121 set_rollup_state(e,e2,'shown');
122 createCookie(id,1,365);
125 set_rollup_state(e,e2,'hidden');
126 createCookie(id,0,365);
131 function set_rollup_state(e,e2,state) {
133 if (state == 'shown') {
135 delClass( e2, 'rolled-up' );
137 else if (state == 'hidden') {
139 addClass( e2, 'rolled-up' );
145 /* onload handlers */
146 /* New code should be using doOnLoad which makes use of prototype
147 instead. See HeaderJavascript. It works better than clobbering
148 window.onload. Left around in case other code is using them */
150 var onLoadStack = new Array();
151 var onLoadLastStack = new Array();
152 var onLoadExecuted = 0;
154 function onLoadHook(commandStr) {
155 if(typeof(commandStr) == "string") {
156 onLoadStack[ onLoadStack.length ] = commandStr;
162 // some things *really* need to be done after everything else
163 function onLoadLastHook(commandStr) {
164 if(typeof(commandStr) == "string"){
165 onLoadLastStack[onLoadLastStack.length] = commandStr;
171 function doOnLoadHooks() {
172 if(onLoadExecuted) return;
175 for ( i in onLoadStack ) {
176 eval( onLoadStack[i] );
178 for ( i in onLoadLastStack ) {
179 eval( onLoadLastStack[i] );
184 window.onload = doOnLoadHooks;
186 /* new onLoad code */
188 function doOnLoad(handler) {
189 Event.observe(window, 'load', handler);
192 /* calendar functions */
194 function openCalWindow(field) {
195 var objWindow = window.open('<%RT->Config->Get('WebPath')%>/Helpers/CalPopup.html?field='+field,
197 'height=235,width=285,scrollbars=1');
201 function createCalendarLink(input) {
204 var link = document.createElement('a');
205 link.setAttribute('href', '#');
206 $(link).observe('click', function(ev) { openCalWindow(input); ev.stop(); });
207 //link.setAttribute('onclick', "openCalWindow('"+input+"'); return false;");
209 var text = document.createTextNode('<% loc("Calendar") %>');
210 link.appendChild(text);
212 var space = document.createTextNode(' ');
214 e.parentNode.insertBefore(link, e.nextSibling);
215 e.parentNode.insertBefore(space, e.nextSibling);
224 function focusElementById(id) {
229 function updateParentField(field, value) {
231 window.opener.$(field).value = value;
236 function setCheckbox(form, name, val) {
237 var myfield = form.getElementsByTagName('input');
238 for ( var i = 0; i < myfield.length; i++ ) {
239 if ( name && myfield[i].name != name ) continue;
240 if ( myfield[i].type != 'checkbox' ) continue;
242 myfield[i].checked = val;
246 /* apply callback to nodes or elements */
248 function walkChildNodes(parent, callback)
250 if( !parent || !parent.childNodes ) return;
251 var list = parent.childNodes;
252 for( var i = 0; i < list.length; i++ ) {
257 function walkChildElements(parent, callback)
259 walkChildNodes( parent, function(node) {
260 if( node.nodeType != 1 ) return;
261 return callback( node );
265 /* shredder things */
267 function showShredderPluginTab( plugin )
269 var plugin_tab_id = 'shredder-plugin-'+ plugin +'-tab';
270 var root = $('shredder-plugin-tabs');
271 walkChildElements( root, function(node) {
272 if( node.id == plugin_tab_id ) {
279 show('shredder-submit-button');
281 hide('shredder-submit-button');
285 function checkAllObjects()
287 var check = $('shredder-select-all-objects-checkbox').checked;
288 var elements = $('shredder-search-form').elements;
289 for( var i = 0; i < elements.length; i++ ) {
290 if( elements[i].name != 'WipeoutObject' ) {
293 if( elements[i].type != 'checkbox' ) {
297 elements[i].checked = true;
299 elements[i].checked = false;
304 function checkboxToInput(target,checkbox,val){
306 var box = $(checkbox);
311 tar.value=val+', '+tar.value; }
313 tar.value=tar.value.replace(val+', ','');
314 tar.value=tar.value.replace(val,'');