fat_free_crm
fat_free_crm copied to clipboard
Advanced search is lost when traversing into a result item
I'm in Opportunities and I carefully build an advanced find set of criteria, then want to view the details, I forget to click on the "edit" button on the row and instead click the link on the name which takes me to the opportunity. That's fine, but when I click the go back arrow I have then lost my criteria and found set and have to build it again.
Hi, Steve! I'm into Rails again! So how can we solve this? I am thinking something like a session params, will it work? Or you can give me your algo and I will implement this! After all I worked on the search before!
Hi Stanley, good to hear from you :) I think ideally, with advanced search, we should build the browser url as new criteria are added. If you try creating an advanced search, and then save it as a list, you'll see the list is just a url that you go to. The best way I can think of to tackle this would be to update the browser url as new search elements are added. There should be a javascript way to do this without reloading the page each time.
The formatting is a bit crazy, but here is a url for advanced search where "first_name contains Stanley"
http://demo.fatfreecrm.com/contacts?utf8=%E2%9C%93&q%5Bs%5D%5B0%5D%5Bname%5D=&q%5Bs%5D%5B0%5D%5Bdir%5D=asc&q%5Bg%5D%5B0%5D%5Bm%5D=and&q%5Bg%5D%5B0%5D%5Bc%5D%5B0%5D%5Ba%5D%5B0%5D%5Bname%5D=first_name&q%5Bg%5D%5B0%5D%5Bc%5D%5B0%5D%5Bp%5D=cont&q%5Bg%5D%5B0%5D%5Bc%5D%5B0%5D%5Bv%5D%5B0%5D%5Bvalue%5D=stanley&distinct=1&page=1
The demo login is "aaron" and "aaron" (username/password)
history.pushState(state, title, url);
https://developer.mozilla.org/en-US/docs/Web/API/History_API
I will try to implement it with the History API, but I have a hard time of decoding the search params and arrays!
For just updating the URL, it is just one line:
history.pushState("","",window.location.pathname + '?' + $('form.ransack_search').serialize())
But since the History API accepts a stateObj
, another way to do it is to jsonify $('form.ransack_search')
and store it inside the stateObj
, but then we need to repopulate the form with the data from stateObj
.