Changeset 392


Ignore:
Timestamp:
Feb 19, 2010, 1:46:29 AM (14 years ago)
Author:
gav
Message:

Add options div to InventoryItem search view and some minor detailing to other views.

Location:
trunk/grails-app
Files:
5 edited

Legend:

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

    r382 r392  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
     2import org.codehaus.groovy.grails.commons.ConfigurationHolder
    23
    34@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager'])
     
    56
    67    def filterService
     8    def exportService
    79    def inventoryItemService
    810    def inventoryMovementService
     
    1416    def index = { redirect(action:search, params:params) }
    1517
     18    /**
     19    * Set session.inventoryItemSearchParamsMax
     20    */
     21    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
     22    def setSearchParamsMax = {
     23        def max = 1000
     24        if(params.newMax.isInteger()) {
     25            def i = params.newMax.toInteger()
     26            if(i > 0 && i <= max)
     27                session.inventoryItemSearchParamsMax = params.newMax
     28            if(i > max)
     29                session.inventoryItemSearchParamsMax = max
     30        }
     31        forward(action: 'search', params: params)
     32    }
     33
    1634    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
    1735    def search = {
     36
     37        if(session.inventoryItemSearchParamsMax)
     38            params.max = session.inventoryItemSearchParamsMax
     39
    1840        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
     41
     42        def inventoryItemInstanceList = []
     43        def inventoryItemInstanceTotal
     44        def filterParams = [:]
    1945
    2046        // Quick Search:
    2147        if(!params.filter) {
    22             return[ inventoryItemInstanceList: InventoryItem.list( params ), inventoryItemInstanceTotal: InventoryItem.count(), filterParams: params ]
    23         }
     48            inventoryItemInstanceList = InventoryItem.list( params )
     49            inventoryItemInstanceTotal = InventoryItem.count()
     50            filterParams = params
     51        }
     52        else {
    2453        // filterPane:
    25         return[ inventoryItemInstanceList: filterService.filter( params, InventoryItem ),
    26                 inventoryItemInstanceTotal: filterService.count( params, InventoryItem ),
    27                 filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params),
    28                 params:params ]
    29     }
     54            inventoryItemInstanceList = filterService.filter( params, InventoryItem )
     55            inventoryItemInstanceTotal = filterService.count( params, InventoryItem )
     56            filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
     57        }
     58
     59        // export plugin:
     60        if(params?.format && params.format != "html") {
     61
     62            def dateFmt = { date ->
     63                formatDate(format: "EEE, dd-MMM-yyyy", date: date)
     64            }
     65            String title = "Inventory List."
     66
     67            response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
     68            response.setHeader("Content-disposition", "attachment; filename=Inventory.${params.extension}")
     69            List fields = ["name",
     70                                "description",
     71                                "unitsInStock",
     72                                "unitOfMeasure",
     73                                "inventoryLocation",
     74                                "inventoryLocation.inventoryStore"]
     75            Map labels = ["name": "Name",
     76                                "description": "Description",
     77                                "unitsInStock":"In Stock",
     78                                "unitOfMeasure": "UOM",
     79                                "inventoryLocation": "Location",
     80                                "inventoryLocation.inventoryStore": "Store"]
     81
     82            Map formatters = [:]
     83            Map parameters = [title: title, separator: ","]
     84
     85            exportService.export(params.format,
     86                                                response.outputStream,
     87                                                inventoryItemInstanceList.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) },
     88                                                fields,
     89                                                labels,
     90                                                formatters,
     91                                                parameters)
     92        }
     93
     94        // Add some basic params to filterParams.
     95        filterParams.max = params.max
     96        filterParams.offset = params.offset?.toInteger() ?: 0
     97        filterParams.sort = params.sort ?: "id"
     98        filterParams.order = params.order ?: "desc"
     99
     100        return[ inventoryItemInstanceList: inventoryItemInstanceList,
     101                inventoryItemInstanceTotal: inventoryItemInstanceTotal,
     102                filterParams: filterParams ]
     103    } // end search()
    30104
    31105    /**
  • trunk/grails-app/views/inventoryItemDetailed/create.gsp

    r382 r392  
    5151                                    <g:select optionKey="id"
    5252                                                        from="${ InventoryLocation.list().sort { p1, p2 -> p1.toString().compareToIgnoreCase(p2.toString()) } }"
    53                                                         name="inventoryLocation.id" value="${inventoryItemInstance?.inventoryLocation?.id}" >
     53                                                        name="inventoryLocation.id" value="${inventoryItemInstance?.inventoryLocation?.id}"
     54                                                        optionValue="${{it.name+ ' in ' + it.inventoryStore}}">
    5455                                    </g:select>
    5556
  • trunk/grails-app/views/inventoryItemDetailed/edit.gsp

    r382 r392  
    8383                                                        from="${ InventoryLocation.list().sort { p1, p2 -> p1.toString().compareToIgnoreCase(p2.toString()) } }"
    8484                                                        name="inventoryLocation.id"
    85                                                         value="${inventoryItemInstance?.inventoryLocation?.id}" >
     85                                                        value="${inventoryItemInstance?.inventoryLocation?.id}"
     86                                                        optionValue="${{it.name+ ' in ' + it.inventoryStore}}">
    8687                                    </g:select>
    8788                                </td>
  • trunk/grails-app/views/inventoryItemDetailed/search.gsp

    r221 r392  
    99        <g:render template="/shared/pictureHead" />
    1010        <filterpane:includes />
     11        <export:resource />
    1112    </head>
    1213    <body>
     
    2627
    2728            <div class="paginateButtons">
     29                Results: ${inventoryItemInstanceList.size()} / ${inventoryItemInstanceTotal}
    2830                <span class="searchButtons">
    2931                    <filterpane:filterButton text="Search" appliedText="Change Search" />
    3032                </span>
    31                 Results:${inventoryItemInstanceTotal}
    3233            </div>
     34
     35            <jsUtil:toggleControl toggleId="options"
     36                                                    imageId="optionsImg"
     37                                                    closedImgUrl="${resource(dir:'images/skin',file:'bullet_arrow_right.png')}"
     38                                                    openImgUrl="${resource(dir:'images/skin',file:'bullet_arrow_down.png')}"
     39                                                    text="${g.message(code: 'default.options.text')}"
     40                                                    />
     41
     42            <div id="options" style="display:none;">
     43                <g:form method="post" >
     44                    <g:hiddenField name="params" value="${filterParams}" />
     45                    <div class="dialog">
     46                        <table>
     47                            <tbody>
     48
     49                                <tr class="prop">
     50                                    <td valign="top" class="name">
     51                                        <label for="max">Results per page:</label>
     52                                    </td>
     53                                    <td valign="top" class="value">
     54                                        <input type="text" maxlength="4" id="description" name="newMax" value="${params.max}"/>
     55
     56                                        <span class="buttons">
     57                                            <g:actionSubmit action="setSearchParamsMax" class="go" value="Update" />
     58                                        </span>
     59                                    </td>
     60                                </tr>
     61
     62                            </tbody>
     63                        </table>
     64                    </div>
     65                </g:form>
     66                <export:formats  params="${filterParams}" formats="['csv', 'excel', 'pdf', 'rtf']"/>
     67            </div>
     68
     69            <br />
     70
     71            <g:if test="${inventoryItemInstanceList.size() > 10}">
     72                <g:if test="${inventoryItemInstanceTotal > inventoryItemInstanceList.size()}">
     73                    <div class="paginateButtons">
     74                        <g:paginate total="${inventoryItemInstanceTotal}" params="${filterParams}" />
     75                    </div>
     76                </g:if>
     77            </g:if>
    3378
    3479            <div class="list">
  • trunk/grails-app/views/inventoryItemDetailed/show.gsp

    r382 r392  
    133133                                                ${inventoryItemInstance.inventoryLocation?.encodeAsHTML()}
    134134                                            </g:link>
     135                                                in ${inventoryItemInstance.inventoryLocation?.inventoryStore.encodeAsHTML()}
    135136                                        </td>
    136137                                    </tr>
Note: See TracChangeset for help on using the changeset viewer.