Index: branches/RC/core/units/admin/admin_tag_processor.php =================================================================== diff -u -N -r11661 -r11665 --- branches/RC/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 11661) +++ branches/RC/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 11665) @@ -1083,6 +1083,28 @@ return $ret; } + + /** + * Checks, that new window should be opened in "incs/close_popup" template instead of refreshing parent window + * + * @param Array $params + * @return bool + */ + function OpenNewWindow($params) + { + if (!$this->UsePopups($params)) { + return false; + } + + $diff = array_key_exists('diff', $params) ? $params['diff'] : 0; + $wid = $this->Application->GetVar('m_wid'); + + $stack_name = rtrim('opener_stack_' . $wid, '_'); + $opener_stack = $this->Application->RecallVar($stack_name); + $opener_stack = $opener_stack ? unserialize($opener_stack) : Array (); + + return count($opener_stack) >= 2 - $diff; + } } ?> \ No newline at end of file Index: branches/RC/core/kernel/event_manager.php =================================================================== diff -u -N -r11538 -r11665 --- branches/RC/core/kernel/event_manager.php (.../event_manager.php) (revision 11538) +++ branches/RC/core/kernel/event_manager.php (.../event_manager.php) (revision 11665) @@ -469,12 +469,33 @@ $last_template = '../'.$last_template; } else { - $last_template = $this->Application->RecallVar(rtrim('last_template_popup_'.$parent_wid, '_')); + if ($this->Application->GetVar('merge_opener_stack')) { + // get last template from parent (that was closed) window opener stack + $parent_opener_stack_name = rtrim('opener_stack_' . $parent_wid, '_'); + $parent_opener_stack = unserialize( $this->Application->RecallVar($parent_opener_stack_name) ); + $last_template = array_pop($parent_opener_stack); + + if ($parent_opener_stack) { + $this->Application->StoreVar($parent_opener_stack_name, serialize($parent_opener_stack)); + } + else { + $this->Application->RemoveVar($parent_opener_stack_name); + } + } + else { + $last_template = $this->Application->RecallVar(rtrim('last_template_popup_'.$parent_wid, '_')); + } } $opener_stack = Array ( $last_template ); $this->Application->SetVar('m_opener', 's'); $wid = $popup_wid; + + /*// store window relations + $window_relations = $this->Application->RecallVar('window_relations'); + $window_relations = $window_relations ? unserialize($window_relations) : Array (); + $window_relations[$popup_wid] = $parent_wid; + $this->Application->StoreVar('window_relations', serialize($window_relations));*/ break; default: // "s/0," stay on same deep level @@ -489,21 +510,31 @@ /** * Used from relationship event handler * - * @param string $t + * @param string $template * @param Array $params * @param string $pass */ - function openerStackPush($t, $params, $pass = 'all', $wid=null) + function openerStackPush($template, $params, $pass = 'all', $wid = null) { - if (!isset($wid)) $wid = $this->Application->GetVar('m_wid'); - $stack_name = rtrim('opener_stack_'.$wid, '_'); + if (!isset($wid)) { + $wid = $this->Application->GetVar('m_wid'); + } + /*// get parent window wid, when this was popup + $window_relations = $this->Application->RecallVar('window_relations'); + $window_relations = $window_relations ? unserialize($window_relations) : Array (); + $wid = array_key_exists($wid, $window_relations) ? $window_relations[$wid] : false;*/ + + // get opener stack + $stack_name = rtrim('opener_stack_' . $wid, '_'); $opener_stack = $this->Application->RecallVar($stack_name); - $opener_stack = $opener_stack ? unserialize($opener_stack) : Array(); + $opener_stack = $opener_stack ? unserialize($opener_stack) : Array (); - $redirect_params = array_merge_recursive2(Array('m_opener' => 'u', '__URLENCODE__' => 1), $params); - $new_level = $this->Application->BuildEnv($t, $redirect_params, $pass, true); - array_push($opener_stack, 'index.php|'.ltrim($new_level, ENV_VAR_NAME.'=') ); + // change opener stack + $default_params = Array ('m_opener' => 'u', '__URLENCODE__' => 1); + $redirect_params = array_merge_recursive2($default_params, $params); + $new_level = $this->Application->BuildEnv($template, $redirect_params, $pass, true); + array_push($opener_stack, 'index.php|' . ltrim($new_level, ENV_VAR_NAME . '=') ); $this->Application->StoreVar($stack_name, serialize($opener_stack)); } Index: branches/RC/core/units/relationship/relationship_event_handler.php =================================================================== diff -u -N -r8929 -r11665 --- branches/RC/core/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 8929) +++ branches/RC/core/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 11665) @@ -85,8 +85,6 @@ $redirect_params = Array($event->Prefix.'_event' => 'OnNew', 'target_id' => $target_id, 'm_opener' => 's', 'target_type' => $target_type); $this->Application->EventManager->openerStackPush($template, $redirect_params, 'all,'.$event->Prefix); - -// $event->SetRedirectParam('popup_stay', 1); // if popup mode, then set this } } else { Index: branches/RC/core/admin_templates/incs/close_popup.tpl =================================================================== diff -u -N -r11538 -r11665 --- branches/RC/core/admin_templates/incs/close_popup.tpl (.../close_popup.tpl) (revision 11538) +++ branches/RC/core/admin_templates/incs/close_popup.tpl (.../close_popup.tpl) (revision 11665) @@ -41,17 +41,29 @@ } function onAfterWindowClose($opener) { - - var $skip_refresh = true; + + var $ru = $redirect_url; + + // setTimeout allows to call method indirectly. Without it whole idea won't work 2nd time (try adding 2 relations one after another) + $opener.setTimeout( + function() { + $opener.openSelector('adm', $ru.replace('%5C', '\\') + '&merge_opener_stack=1'); + }, + 200 + ); - var $skip_refresh = isset($opener.$skip_refresh) && $opener.$skip_refresh ? true : false; - + + var $skip_refresh = true; + + var $skip_refresh = isset($opener.$skip_refresh) && $opener.$skip_refresh ? true : false; + - $opener.focus(); + $opener.focus(); - if (!$skip_refresh) { - $opener.location.href = $redirect_url.replace('%5C', '\\'); - } + if (!$skip_refresh) { + $opener.location.href = $redirect_url.replace('%5C', '\\'); + } + } // copied from "js/script.js" because it's not included here due performance reasons Index: branches/RC/core/kernel/application.php =================================================================== diff -u -N -r11661 -r11665 --- branches/RC/core/kernel/application.php (.../application.php) (revision 11661) +++ branches/RC/core/kernel/application.php (.../application.php) (revision 11665) @@ -1389,6 +1389,14 @@ else { $this->StoreVar($stack_name, serialize($opener_stack)); } + + /*// store window relations + $window_relations = $this->Application->RecallVar('window_relations'); + $window_relations = $window_relations ? unserialize($window_relations) : Array (); + if (array_key_exists($wid, $window_relations)) { + unset($window_relations[$wid]); + $this->Application->StoreVar('window_relations', serialize($window_relations)); + }*/ } return $ret; }