Index: trunk/kernel/admin_templates/incs/script.js =================================================================== diff -u -r4199 -r4243 --- trunk/kernel/admin_templates/incs/script.js (.../script.js) (revision 4199) +++ trunk/kernel/admin_templates/incs/script.js (.../script.js) (revision 4243) @@ -1,5 +1,4 @@ -if( !( isset($init_made) && $init_made ) ) -{ +if ( !( isset($init_made) && $init_made ) ) { var Grids = new Array(); var Toolbars = new Array(); var $Menus = new Array(); @@ -11,8 +10,64 @@ var submitted = false; var $edit_mode = false; var $init_made = true; // in case of double inclusion of script.js :) + + // hook processing + var hBEFORE = 1; // this is const, but including this twice causes errors + var hAFTER = 2; // this is const, but including this twice causes errors + var $hooks = new Array(); } +function getArrayValue() +{ + var $value = arguments[0]; + var $current_key = 0; + $i = 1; + while ($i < arguments.length) { + $current_key = arguments[$i]; + if (isset($value[$current_key])) { + $value = $value[$current_key]; + } + else { + return false; + } + $i++; + } + return $value; +} + +function setArrayValue() +{ + // first argument - array, other arguments - keys (arrays too), last argument - value + var $array = arguments[0]; + var $current_key = 0; + $i = 1; + while ($i < arguments.length - 1) { + $current_key = arguments[$i]; + if (!isset($array[$current_key])) { + $array[$current_key] = new Array(); + } + $array = $array[$current_key]; + $i++; + } + $array[$array.length] = arguments[arguments.length - 1]; +} + +function processHooks($function_name, $hook_type) +{ + var $i = 0; + var $local_hooks = getArrayValue($hooks, $function_name, $hook_type); + + while($i < $local_hooks.length) { + $local_hooks[$i]($function_name); + $i++; + } +} + +function registerHook($function_name, $hook_type, $hook_body) +{ + setArrayValue($hooks, $function_name, $hook_type, $hook_body); +} + function resort_grid(prefix_special,field,form_action) { set_hidden_field(prefix_special+'_Sort1', field); @@ -255,7 +310,7 @@ if(!isset($width)) $width=750; if(!isset($height)) $height=400; if(!isset($event)) $event=''; - + processHooks('openSelector', hBEFORE); cur_opener = get_hidden_field('m_opener'); set_hidden_field('m_opener','p'); @@ -265,6 +320,7 @@ var old_action = document.kernel_form.action; document.kernel_form.action = $url; submit_event($prefix,$event,$t); + processHooks('openSelector', hAFTER); document.kernel_form.action = old_action; set_hidden_field('m_opener',cur_opener); } @@ -723,12 +779,53 @@ { var $src_html = $aSelect.options[$src_num].innerHTML; var $dst_html = $aSelect.options[$dst_num].innerHTML; - - var $src_option = new Option($aSelect.options[$src_num].innerHTML, $aSelect.options[$src_num].value); - $src_option.innerHTML = $src_html; - var $dst_option = new Option($aSelect.options[$dst_num].innerHTML, $aSelect.options[$dst_num].value); + var $src_value = $aSelect.options[$src_num].value; + var $dst_value = $aSelect.options[$dst_num].value; + + var $src_option = document.createElement('OPTION'); + var $dst_option = document.createElement('OPTION'); + + $aSelect.remove($src_num); + $aSelect.options.add($dst_option, $src_num); + $dst_option.innerText = $dst_html; + $dst_option.value = $dst_value; $dst_option.innerHTML = $dst_html; - - $aSelect.options[$src_num] = $dst_option; - $aSelect.options[$dst_num] = $src_option; - } \ No newline at end of file + + $aSelect.remove($dst_num); + $aSelect.options.add($src_option, $dst_num); + $src_option.innerText = $src_html; + $src_option.value = $src_value; + $src_option.innerHTML = $src_html; + } + + function getXMLHTTPObject() + { + var http_request = false; + if (window.XMLHttpRequest) { // Mozilla, Safari,... + http_request = new XMLHttpRequest(); + if (http_request.overrideMimeType) { + http_request.overrideMimeType('text/plain'); + // See note below about this line + } + } else if (window.ActiveXObject) { // IE + try { + http_request = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + http_request = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (e) {} + } + } + return http_request; + } + + function str_repeat($symbol, $count) + { + var $i = 0; + var $ret = ''; + while($i < $count) { + $ret += $symbol; + $i++; + } + return $ret; + }