[IMP] website_project_issue: add search input in searchbar.

Allow to search issues with criteria: content, message, customer
This commit is contained in:
Jeremy Kersten
2017-02-24 08:51:26 +01:00
parent 561d68bafd
commit c5d2d78aa7
3 changed files with 38 additions and 10 deletions
@@ -15,4 +15,11 @@
.portal-wrap table.table tr {
word-wrap: break-word;
}
}
.search_panel_fixed_width {
overflow: hidden;
max-width: 125px;
text-overflow: ellipsis;
white-space: nowrap;
}
@@ -47,7 +47,7 @@
-->
<template id="portal_searchbar" name="Portal Search Bar">
<t t-if='searchbar_inputs'>
<div class='pull-right o_portal_search_panel'>
<div class='hidden-xs pull-right o_portal_search_panel'>
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
@@ -59,17 +59,17 @@
</li>
</ul>
</div>
<input type="text" class="form-control" t-att-value='search' name="search"/>
<input type="text" class="form-control search_panel_fixed_width" t-att-value='search' name="search"/>
<span class="input-group-btn">
<button class="btn btn-default search-submit" type="button"><span class="fa fa-search"></span></button>
</span>
</div>
</div>
</t>
<div t-if="searchbar_sortings" class="dropdown pull-right mr8">
<button id="portal_searchbar_sortby" class="btn btn-default" type="button" data-toggle="dropdown">
<div t-if="searchbar_sortings" class="dropdown pull-right mr4">
<button id="portal_searchbar_sortby" class="search_panel_fixed_width btn btn-default" type="button" data-toggle="dropdown">
<span class="fa fa-sort fa-lg" />
<span t-esc="searchbar_sortings[sortby].get('label', 'Newest')"/>
<span class='hidden-xs hidden-sm hidden-md' t-esc="searchbar_sortings[sortby].get('label', 'Newest')"/>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="portal_searchbar_sortby">
@@ -80,10 +80,10 @@
</li>
</ul>
</div>
<div t-if="searchbar_filters" class="dropdown pull-right mr8">
<button id="portal_searchbar_filters" class="btn btn-default" type="button" data-toggle="dropdown">
<div t-if="searchbar_filters" class="dropdown pull-right mr4">
<button id="portal_searchbar_filters" class="search_panel_fixed_width btn btn-default" type="button" data-toggle="dropdown">
<span class="fa fa-filter fa-lg" />
<span t-esc="searchbar_filters[filterby].get('label', 'All')"/>
<span class='hidden-xs hidden-sm hidden-md' t-esc="searchbar_filters[filterby].get('label', 'All')"/>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="portal_searchbar_filters">
@@ -6,6 +6,7 @@ from collections import OrderedDict
from odoo import http, _
from odoo.addons.website_portal.controllers.main import website_account, get_records_pager
from odoo.http import request
from odoo.osv.expression import OR
class WebsiteAccount(website_account):
@@ -22,7 +23,7 @@ class WebsiteAccount(website_account):
return response
@http.route(['/my/issues', '/my/issues/page/<int:page>'], type='http', auth="user", website=True)
def my_issues(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw):
def my_issues(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, search=None, search_in='content', **kw):
values = self._prepare_portal_layout_values()
# portal users can't see the privacy_visibility, fetch the domain for them in sudo
portal_projects = request.env['project.project'].sudo().search([('privacy_visibility', '=', 'portal')])
@@ -37,6 +38,12 @@ class WebsiteAccount(website_account):
searchbar_filters = {
'all': {'label': _('All'), 'domain': []},
}
searchbar_inputs = {
'content': {'input': 'content', 'label': _('Search <span class="nolabel"> (in Content)</span>')},
'message': {'input': 'message', 'label': _('Search in Messages')},
'customer': {'input': 'customer', 'label': _('Search in Customer')},
'all': {'input': 'all', 'label': _('Search in All')},
}
# extends filterby criteria with project (criteria name is the project id)
projects = request.env['project.project'].search([('privacy_visibility', '=', 'portal')])
for proj in projects:
@@ -58,6 +65,17 @@ class WebsiteAccount(website_account):
if date_begin and date_end:
domain += [('create_date', '>', date_begin), ('create_date', '<=', date_end)]
# search
if search and search_in:
search_domain = []
if search_in in ('content', 'all'):
search_domain = OR([search_domain, ['|', ('name', 'ilike', search), ('description', 'ilike', search)]])
if search_in in ('customer', 'all'):
search_domain = OR([search_domain, [('partner_id', 'ilike', search)]])
if search_in in ('message', 'all'):
search_domain = OR([search_domain, [('message_ids.body', 'ilike', search)]])
domain += search_domain
# issue count
issue_count = request.env['project.issue'].search_count(domain)
# pager
@@ -82,9 +100,12 @@ class WebsiteAccount(website_account):
'default_url': '/my/issues',
'pager': pager,
'searchbar_sortings': searchbar_sortings,
'searchbar_inputs': searchbar_inputs,
'sortby': sortby,
'searchbar_filters': OrderedDict(sorted(searchbar_filters.items())),
'filterby': filterby,
'search_in': search_in,
'search': search,
})
return request.render("website_project_issue.my_issues", values)