User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:devel:corebos_menufilter [2016/12/05 13:27]
joebordes
en:devel:corebos_menufilter [2016/12/13 12:59] (current)
joebordes
Line 28: Line 28:
 <wrap hi>​[[en:​devel:​corebos_hooks#​corebosfilterlistviewquerygeneratorbefore|corebos.filter.listview.querygenerator.before]]</​wrap>​ <wrap hi>​[[en:​devel:​corebos_hooks#​corebosfilterlistviewquerygeneratorbefore|corebos.filter.listview.querygenerator.before]]</​wrap>​
  
-and our handler script will be **modules/​Accounts/​filterAustralia.php**+and our handler script will be **modules/​Accounts/​FilterAustralia.php**
  
 The code to register the event is The code to register the event is
Line 72: Line 72:
  case '​corebos.filter.listview.querygenerator.before':​  case '​corebos.filter.listview.querygenerator.before':​
  // $parameter is the QueryGenerator Object  // $parameter is the QueryGenerator Object
- if (isset($_REQUEST['​AccountsFilterAustralia']) and $_REQUEST['​AccountsFilterAustralia'​]=='​Australia'​) {+ if (isset($_REQUEST['​filterAustralia']) and $_REQUEST['​filterAustralia'​]=='​Australia'​) {
  $parameter->​addCondition('​bill_country','​Australia','​e','​and'​);​  $parameter->​addCondition('​bill_country','​Australia','​e','​and'​);​
  } else {  } else {
Line 130: Line 130:
 and we can navigate anywhere we want and even search inside the filtered record set with no problem. As soon as we go to the menu and access the other category the filter value changes and we see the other set of records. and we can navigate anywhere we want and even search inside the filtered record set with no problem. As soon as we go to the menu and access the other category the filter value changes and we see the other set of records.
  
-Now this is all fine and dandy until the user decides to open a new tab in the browser. It turns out that the session variables are application based, so the new tab inherits all the values (which is why you don't have to login again on the new tab). When the user goes to accounts he sees the records filtered depending on the menu entry selected, which is correct but if it is different then the menu option selected in the first tab the session variable is overwritten and now any action taken on the first tab will load the set it records selected on the second tab instead of respecting the set selected there. In other words the filter is browser based, not tab based and that just isn't right. We need some way to detect the tab we are on and put the filter variable in the session based on the tab: **coreBOS to the rescue!!**+Now this is all fine and dandy until the user decides to open a new tab in the browser. It turns out that the session variables are application based, so the new tab inherits all the values (which is why you don't have to login again on the new tab). When the user goes to accounts he sees the records filtered depending on the menu entry selected, which is correct but if it is different then the menu option selected in the first tab the session variable is overwritten and now any action taken on the first tab will load the set of records selected on the second tab instead of respecting the set selected there. In other words the filter is browser based, not tab based and that just isn't right. We need some way to detect the tab we are on and put the filter variable in the session based on the tab: **coreBOS to the rescue!!**
  
 coreBOS has a browser variable called **corebos_browsertabID** which identifies the tab it is in and it sends that information in to PHP on every call to the backend as a cookie. This variable can be used freely by any programmer both in JavaScript and PHP. coreBOS has a browser variable called **corebos_browsertabID** which identifies the tab it is in and it sends that information in to PHP on every call to the backend as a cookie. This variable can be used freely by any programmer both in JavaScript and PHP.
Line 136: Line 136:
 The application itself does not use this variable but in the case we are trying to solve in this article it is exactly what we need. We save the filter variable coming from the menu in a session variable marked with the browser tab identifier and we are done. The application itself does not use this variable but in the case we are trying to solve in this article it is exactly what we need. We save the filter variable coming from the menu in a session variable marked with the browser tab identifier and we are done.
  
-The final version of our modifications ​look like this:+The final version of our modifications ​looks like this:
  
-**modules/​Accounts/​filterAustralia.php**+**modules/​Accounts/​FilterAustralia.php**
 <code php> <code php>
 class AccountFilterAustraliaHandler extends VTEventHandler { class AccountFilterAustraliaHandler extends VTEventHandler {
Line 156: Line 156:
  case '​corebos.filter.listview.querygenerator.before':​  case '​corebos.filter.listview.querygenerator.before':​
  // $parameter is the QueryGenerator Object  // $parameter is the QueryGenerator Object
- global $log;​$log->​fatal($_COOKIE);​ 
  if (isset($_SESSION['​AccountsFilterAustralia'​.$_COOKIE['​corebos_browsertabID'​]]) and $_SESSION['​AccountsFilterAustralia'​.$_COOKIE['​corebos_browsertabID'​]]=='​Australia'​) {  if (isset($_SESSION['​AccountsFilterAustralia'​.$_COOKIE['​corebos_browsertabID'​]]) and $_SESSION['​AccountsFilterAustralia'​.$_COOKIE['​corebos_browsertabID'​]]=='​Australia'​) {
  $parameter->​addCondition('​bill_country','​Australia','​e','​and'​);​  $parameter->​addCondition('​bill_country','​Australia','​e','​and'​);​
Line 181: Line 180:
  
 **Enjoy the power of a system that helps you help your users!!** **Enjoy the power of a system that helps you help your users!!**
 +
 +<WRAP center round info 60%>
 +{{ :​en:​devel:​filteraustralia.zip |Download the code.}}
 +</​WRAP>​