Changeset 594


Ignore:
Timestamp:
Jun 11, 2010, 8:48:40 AM (10 years ago)
Author:
gav
Message:

Remember inventoryItemPurchase search and sort, as per ticket #71

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/InventoryItemPurchaseDetailedController.groovy

    r468 r594  
    3939        params.max = Math.min( params.max ? params.max.toInteger() : 10,  1000 )
    4040        params.offset = params.offset?.toInteger() ?: 0
    41         params.sort = params.sort ?: "purchaseOrderNumber"
    42         params.order = params.order ?: "desc"
    4341
    4442        def inventoryItemPurchaseList = []
    4543        def inventoryItemPurchaseTotal
    46         def filterParams = [:]
    47 
    48         // Quick Search:
    49         if(!FilterUtils.isFilterApplied(params)) {
     44        def filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
     45        def isFilterApplied = FilterUtils.isFilterApplied(params)
     46
     47        // Restore search unless a new search is being requested.
     48        if(!params.quickSearch && !filterParams) {
     49            if(session.inventoryItemPurchaseQuickSearch)
     50                params.quickSearch = session.inventoryItemPurchaseQuickSearch
     51            else if(session.inventoryItemPurchaseSearchFilterParams) {
     52                session.inventoryItemPurchaseSearchFilterParams.each() { params[it.key] = it.value }
     53                params.filter = session.inventoryItemPurchaseSearchFilter
     54                isFilterApplied = FilterUtils.isFilterApplied(params)
     55            }
     56        }
     57
     58        // Remember sort if supplied, otherwise try to restore.
     59        if(params.sort && params.order) {
     60            // Reset to defaultSort if requested.
     61            if(params.sort == 'defaultSort') {
     62                params.sort = null
     63                params.order = null
     64                session.removeAttribute("inventoryItemPurchaseSearchSort")
     65                session.removeAttribute("inventoryItemPurchaseSearchOrder")
     66            }
     67            else {
     68                session.inventoryItemPurchaseSearchSort = params.sort
     69                session.inventoryItemPurchaseSearchOrder = params.order
     70            }
     71        }
     72        else if(session.inventoryItemPurchaseSearchSort && session.inventoryItemPurchaseSearchOrder) {
     73            params.sort = session.inventoryItemPurchaseSearchSort
     74            params.order = session.inventoryItemPurchaseSearchOrder
     75        }
     76        else {
     77            params.sort = "purchaseOrderNumber"
     78            params.order = "desc"
     79        }
     80
     81        if(isFilterApplied) {
     82            // filterPane:
     83            params.sort = params.sort ?: "id"
     84            params.order = params.order ?: "desc"
     85            //if(params.sort == "attentionFlag") // See ticket #64 in Trac.
     86                //params.sort = "id"
     87
     88            // Call filterService.
     89            inventoryItemPurchaseList = filterService.filter( params, InventoryItemPurchase )
     90            inventoryItemPurchaseTotal = filterService.count( params, InventoryItemPurchase )
     91            filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
     92            // Remember search.
     93            session.inventoryItemPurchaseSearchFilterParams = new LinkedHashMap(filterParams)
     94            session.inventoryItemPurchaseSearchFilter = new LinkedHashMap(params.filter)
     95            session.removeAttribute("inventoryItemPurchaseQuickSearch")
     96        }
     97        else {
     98            // Quick Search:
    5099
    51100            if(params.quickSearch == "searchAllOrders") {
     
    80129            inventoryItemPurchaseTotal = inventoryItemPurchaseList.size()
    81130            filterParams.quickSearch = params.quickSearch
    82         }
    83         else {
    84             // filterPane:
    85             inventoryItemPurchaseList = filterService.filter( params, InventoryItemPurchase )
    86             inventoryItemPurchaseTotal = filterService.count( params, InventoryItemPurchase )
    87             filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
     131            // Remember search.
     132            session.removeAttribute("inventoryItemPurchaseSearchFilterParams")
     133            session.removeAttribute("inventoryItemPurchaseSearchFilter")
     134            session.inventoryItemPurchaseQuickSearch = params.quickSearch
    88135        }
    89136
Note: See TracChangeset for help on using the changeset viewer.