Index: branches/RC/core/admin_templates/js/catalog.js =================================================================== diff -u -r11163 -r11368 --- branches/RC/core/admin_templates/js/catalog.js (.../catalog.js) (revision 11163) +++ branches/RC/core/admin_templates/js/catalog.js (.../catalog.js) (revision 11368) @@ -5,19 +5,29 @@ this.Separator = '#separator#'; this.ParentCategoryID = 0; this.OnResponceMethod = null; - this.TabShift = isset($tab_shift) ? $tab_shift : 1; // start from 2nd tab (index starting from 0) this.TabRegistry = new Array(); - this.ActivePrefix = getCookie(this.CookiePrefix + 'active_prefix'); + + if (window.location.hash && window.location.hash.match(/^#tab-(.*)/)) { + // get active tab from anchor + this.ActivePrefix = RegExp.$1; + } + else { + // get active tab from cookie + this.ActivePrefix = getCookie(this.CookiePrefix + 'active_prefix'); + } + this.PreviousPrefix = this.ActivePrefix; this.TabByCategory = false; // preselect tab by category (used in catalog only) $ViewMenus = new Array('c'); + + this.searchInfo = {}; // information about search (for each tab) } Catalog.prototype.Init = function () { var $prefix = this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix'); - if ($prefix !== this.ActivePrefix && this.TabRegistry.length > this.TabShift) { + if ($prefix !== this.ActivePrefix && this.TabRegistry.length > 0) { // ActivePrefix not set or has non-existing prefix value - this.ActivePrefix = this.TabRegistry[this.TabShift]['prefix']; + this.ActivePrefix = this.TabRegistry[0]['prefix']; } this.SetAlternativeTabs(); this.AfterInit(); @@ -29,10 +39,10 @@ Catalog.prototype.SetAlternativeTabs = function () { // set alternative grids between all items (catalog is set when tab is loaded via AJAX first time) - var $i = this.TabShift; + var $i = 0; while ($i < this.TabRegistry.length) { // run through all prefixes - var $j = this.TabShift; + var $j = 0; while ($j < this.TabRegistry.length) { if (this.TabRegistry[$i]['prefix'] == this.TabRegistry[$j]['prefix']) { $j++; @@ -65,19 +75,15 @@ Request.makeRequest($kf.action, this.BusyRequest[$prefix], $result_div, this.successCallback, this.errorCallback, $result_div, this); $form_name = 'kernel_form'; // restore back to main form with current category id of catalog -}; +} Catalog.prototype.successCallback = function($request, $params, $object) { + if (Request.processRedirect($request)) { + return ; + } var $text = $request.responseText; - var $match_redirect = new RegExp('^#redirect#(.*)').exec($text); - if ($match_redirect != null) { - // redirect to external template requested - window.location.href = $match_redirect[1]; - return false; - } - $params = $params.split(','); var $js_end = $text.indexOf($object.Separator); @@ -106,8 +112,28 @@ if (typeof($Debugger) != 'undefined') { $Debugger.Clear(); } + +// var $tab_id = $params[0].replace(/_div$/, ''); +// var $prefix = $object.queryTabRegistry('tab_id', $tab_id, 'prefix'); } +Catalog.prototype.resizeGrid = function ($prefix) { + if ($prefix != this.ActivePrefix) { + // no need to resize, because grid is already visible + return true; + } + + var $grid = GridScrollers[$prefix]; + if ($grid) { + $grid.RefreshPos(); + $grid.Resize( $grid.GetAutoSize('auto') ); + + return true; + } + + return false; +} + Catalog.prototype.trim = function ($string) { return $string.replace(/\s*((\S+\s*)*)/, "$1").replace(/((\s*\S+)*)\s*/, "$1"); } @@ -152,29 +178,39 @@ set_hidden_field('m_cat_id', $cat_id); } + // 1. make all tabs unselected this.resetTabs(false); - // query sub categories of $cat_id - var $url = this.URLMask.replace('#TEMPLATE_NAME#', 'categories/xml/categories_list').replace('#CATEGORY_ID#', $cat_id); + // 2. update grid for current tab + this.switchTab(this.TabByCategory ? $module_prefix : null); // refresh current item tab + // 3. update counters for all tabs var $prefix = this.TabRegistry[0]['prefix']; - var $tab_id = this.TabRegistry[0]['tab_id']; + + var $url = this.URLMask.replace('#TEMPLATE_NAME#', 'catalog/catalog_counters').replace('#CATEGORY_ID#', $cat_id); this.BusyRequest[$prefix] = false; - Request.makeRequest($url, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this); - this.switchTab(this.TabByCategory ? $module_prefix : null); // refresh current item tab + Request.makeRequest($url, this.BusyRequest[$prefix], '', this.updateCounters, this.errorCallback, '', this); } +Catalog.prototype.updateCounters = function($request, $params, $object) { + if (Request.processRedirect($request)) { + return ; + } + + eval($request.responseText); +} + // set all item tabs counters to "?" before quering catagories Catalog.prototype.resetTabs = function($reset_content) { - var $i = this.TabShift; + var $i = 0; while ($i < this.TabRegistry.length) { this.setItemCount(this.TabRegistry[$i]['prefix'], '?'); $i++; } if ($reset_content) { // set category for all tabs to -1 (forces reload next time) - $i = this.TabShift; + $i = 0; while ($i < this.TabRegistry.length) { document.getElementById(this.TabRegistry[$i]['tab_id'] + '_div').setAttribute('category_id', -1); $i++; @@ -211,8 +247,12 @@ var $div_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id') + '_div'; // destination tab document.getElementById($div_id).style.display = 'block'; this.ShowDependentButtons(this.ActivePrefix); + + this.displaySearch($prefix); this.setViewMenu(this.ActivePrefix); + setCookie(this.CookiePrefix + 'active_prefix', this.ActivePrefix); + window.location.hash = '#tab-' + this.ActivePrefix; this.refreshTab($prefix, $div_id, $force); } @@ -229,9 +269,10 @@ this.BusyRequest[$prefix] = false; Request.makeRequest($url, this.BusyRequest[$prefix], $div_id, this.successCallback, this.errorCallback, $div_id, this); } - /*else { - alert('refresh disabled = {tab: '+this.ActivePrefix+'; cat_id: '+$cat_id+'; form_name: '+$form_name+'}'); - }*/ + else { +// alert('refresh disabled = {tab: '+this.ActivePrefix+'; cat_id: '+$cat_id+'; form_name: '+$form_name+'}'); + this.resizeGrid($prefix); + } } // adds information about tab to tab_registry @@ -300,6 +341,25 @@ setInnerHTML($prefix + '_item_count', $count); } +Catalog.prototype.saveSearch = function ($prefix, $keyword, $grid_name) { + this.searchInfo[$prefix] = { + 'keyword': $keyword, + 'grid': $grid_name + } + + this.displaySearch($prefix); +} +Catalog.prototype.displaySearch = function ($prefix) { + var $search_input = document.getElementById('search_keyword') + + $search_input.setAttribute('PrefixSpecial', $prefix); + + if (this.searchInfo[$prefix]) { + $search_input.value = this.searchInfo[$prefix].keyword; + $search_input.setAttribute('Grid', this.searchInfo[$prefix].grid); + } +} + Catalog.prototype.setCurrentCategory = function($prefix, $category_id) { var $tab_id = this.queryTabRegistry('prefix', $prefix, 'tab_id'); // alert('setting current category for prefix: ['+$prefix+']; tab_id ['+$tab_id+'] = ['+$category_id+']'); @@ -308,23 +368,11 @@ Catalog.prototype.getCurrentPrefix = function() { - if (isset(Grids[this.ActivePrefix]) && (Grids[this.ActivePrefix].SelectedCount > 0)) { - // item tab grid exists and some items are selected - return this.ActivePrefix; - } - else { - // return prefix of first registred tab -> categories - return this.TabRegistry[0]['prefix']; - } + return this.ActivePrefix; } Catalog.prototype.setViewMenu = function($item_prefix) { - if (this.TabShift == 1) { - $ViewMenus = isset($item_prefix) ? new Array('c', $item_prefix) : new Array('c'); - } - else { - $ViewMenus = isset($item_prefix) ? new Array($item_prefix) : new Array(); - } + $ViewMenus = isset($item_prefix) ? new Array($item_prefix) : new Array(); } Catalog.prototype.reflectPasteButton = function($status) {