var SID = ''; // whether to ask confirmation before action or not: 0 - no, 1 - yes //var dont_ask = 1; // available actions var actions = [ 4, 256, 32, 128, 1024, 512, 64 ]; // Current states of checkboxes in action-columns. var state_4 = false; var state_256 = false; var state_32 = false; var state_128 = false; var state_1024 = false; var state_512 = false; var state_64 = false; /* * Clears values of given form fields. */ function clearFields( form, field_name1 ) { if ( ! form || arguments.length < 2 ) return; for ( var i = 1; i < arguments.length; i++ ) { var field = eval( 'form.' + arguments[i] ); if ( field ) field.value = ''; } } /* * Does some action by replacing URL of current document location. * If 'cfrm'-parameter is 1, then confirm-dialog is executed before real action. */ function doAction( url, cfrm ) { if ( ! cfrm || confirm( 'Are you sure?' )) { url = url + (( url.indexOf ('?') > -1 ) ? '&' : '?') + SID; document.location.replace( url ); } } /* * Gets values of checked checkboxes in listings according to given action and frame. * If frame isn't given, then checkboxes are assumet to be in current frame. */ function getChecked( act, frame ) { if ( ! IS_MOZ && ! IS_IE ) return; var out = ''; var objs = ( frame ? frame.document.getElementsByTagName( 'input' ) : document.getElementsByTagName( 'input' )); if ( ! objs ) return; for ( i = 0; i < objs.length; i++ ) { if ( objs[i].name == 'id[' + act + '][]' && objs[i].checked == true ) { out = out + ( out != '' ? ',' : '' ) + objs[i].value; } } return out; } /* * Goes back from view to listing. */ function goBack( where ) { if ( document.form.back_url ) { document.location.replace( document.form.back_url.value ); } else { document.form.act.value = 1; document.form.submit(); } } /* * Updates lock of object, which is opened in change-form. */ function lockObject() { if ( typeof LOCK_URL == 'undefined' ) return; addScript( LOCK_URL ); } /* * Refreshes content of form. */ function refreshForm() { if ( document.form.act.value == 16 ) { document.form.done.value = 1; } document.form.submit(); } /* * Selects/unselects action-column of checkboxes in listings according to given action. */ function selectAll( act ) { if ( ! IS_MOZ && ! IS_IE ) return; var state = eval( 'state_' + act ); var objs = document.getElementsByTagName( 'input' ); if ( ! objs ) return; // check/uncheck all checkboxes of column for ( var i = 0; i < objs.length; i++ ) { if ( objs[i].name == 'id[' + act + '][]' ) { objs[i].checked = ( state == true ? false : true ); toggleSelected( objs[i] ); } } // set global states of action-columns for ( var i = 0; i < actions.length; i++ ) { // toggle state of given action if ( act == actions[i] ) eval( 'state_' + actions[i] + ' = ( state == true ? false : true );' ); // unselect states of other actions else eval( 'state_' + actions[i] + ' = false;' ); } toggleAdmButtons(); } /* * Sets value of field according to given field name. * * Accepts more than one field and value, i.e. setValue( 'field1', 0, 'field2', 12, 'field3', 'abc' ) */ function setValue( field1, value1 ) { var f = document.form; if ( ! f ) return; for ( var a = 0; a < arguments.length; a += 2 ) { var field = arguments[a]; var value = arguments[a+1]; for ( var i = 0; i < f.elements.length; i++ ) { if ( f.elements[i].name == field ) { f.elements[i].value = value; } } } } /* * Submits form for generating some action. * If 'cfrm'-parameter is 1, then confirm-dialog is executed before real action. */ function submitForm( act, cfrm, popup_name, popup_w, popup_h ) { var f = document.form; f.target = '_self'; if ( ! cfrm || confirm( 'Are you sure?' )) { // current action won't change, i.e. saving form data if ( ! act ) { if ( f.act && f.act.value == 16 ) { f.done.value = 2; } else if ( f.act && f.act.value == "inc" ) { f.done.value=parseInt(f.done.value)+1; } else { f.done.value = 1; } // change current action: set permissions or go from view to change } else if ( act == 1024 || ( f.act.value == 2 && act == 16 )) { if ( popup_name ) { var win = openPopup( '', popup_name, popup_w, popup_h ); if ( win ) { var save_target = f.target; var save_act = f.act.value; var save_done = f.done.value; f.popup.value = act; f.target = popup_name; } } f.act.value = act; f.done.value = 0; // change current action: others } else { if ( act == 16384 ) { var save_act = f.act.value; } f.act.value = act; if ( act == 2 ) { f.done.value = 0; } } f.submit(); if ( save_target ) f.target = save_target; if ( save_act ) f.act.value = save_act; if ( save_done ) f.done.value = save_done; if ( f.popup ) f.popup.value = 0; } } /* * Submits form if ENTER-key is pressed in some textfield. Use this function in 'onKeyUp'-property of textfields. */ function submitFormOnEnter( event ) { var ok = 0; if ( IS_MOZ && event && event.which == 13 ) { ok = 1; } else if ( IS_IE && window.event.keyCode == 13 ) { ok = 1; } if ( ok ) { submitForm.arguments = submitFormOnEnter.arguments; submitForm(); } } /* * Shows/hides AdmButtons of action-columns. * Appropriate AdmButton will be shown if at least one checkbox of action-column is checked. */ function toggleAdmButtons() { if (( ! IS_MOZ && ! IS_IE )) return; var objs = document.getElementsByTagName( 'input' ); if ( ! objs ) return; for ( var i = 0; i < actions.length; i++ ) { var admbutton = document.getElementById( 'admbutton_' + actions[i] ); if ( ! admbutton ) continue; var display = 'none'; for ( var j = 0; j < objs.length; j++ ) { var name = objs[j].name; // at least one checked checkbox is found if ( name == 'id[' + actions[i] + '][]' && objs[j].checked ) { display = 'block'; break; } } admbutton.style.display = display; } } /* * Selects/unselects cells of table row, which contain given checkbox. */ function toggleSelected( checkbox ) { if (( ! IS_MOZ && ! IS_IE ) || ! checkbox || ! checkbox.parentNode || ! checkbox.parentNode.parentNode ) return; // given table row var row = checkbox.parentNode.parentNode; // go through cells of row for ( var i = 0; i < row.cells.length; i++ ) { var className = row.cells[i].className; // remove cell highlighting className = className.replace( / highlight/, "" ); // select/unselect cell row.cells[i].className = ( checkbox.checked == true ? ( className.indexOf( 'selected' ) == -1 ? ( className + ' selected' ) : className ) : className.replace( / selected/, "" ) ); // uncheck other checkboxes in same row if ( row.cells[i].childNodes.length ) { var firstChild = row.cells[i].firstChild; if ( firstChild.tagName == 'INPUT' && ( firstChild.name != checkbox.name )) { firstChild.checked = false; } } } toggleAdmButtons(); } /* * Reoves lock of object, which is opened in change-form of popup window. */ function unlockObject() { if ( typeof UNLOCK_URL == 'undefined' ) return; addScript( UNLOCK_URL ); } if ( typeof openPopup == "undefined") { /* * Opens popup window in center of the screen. */ function openPopup( url, name, width, height, prop ) { var left = Math.floor( screen.availWidth / 2 ) - Math.floor( width / 2 ); var top = Math.floor( screen.availHeight / 2 ) - Math.floor( height / 2 ); if ( ! prop ) prop = 'location=no,resizable=yes,menubar=no,status=yes,scrollbars=yes' if ( SID ) { url = url + (( url.indexOf ('?') > -1 ) ? '&' : '?') + SID; } var win = window.open( url, name, 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',' + prop ); if ( win ) win.focus(); return win; } }