[ADD] Added the module for letting the end user search basd on alphabets

pull/4/head
unknown 2014-02-24 13:15:02 +01:00 committed by Holger Brunn
commit d76e471353
6 changed files with 245 additions and 0 deletions

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2011-2014 Serpent Consulting Services (<http://www.serpentcs.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################################
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2011-2014 Serpent Consulting Services (<http://www.serpentcs.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################################
{
'name': 'Web Alphabetical Search',
'author' : 'Serpent Consulting Services Pvt. Ltd.',
'category' : 'Web',
'website': 'http://www.serpentcs.com',
'description': """
OpenERP Web Search Extended.
============================
This module used for search record base on alphabetical character be default it will search on name field.
User also is able to change search field name instead of name field.
""",
'version': '1.0',
'depends': ['web'],
'js': [
'static/src/js/web_search.js'
],
'css': [
'static/src/css/web_search.css'
],
'qweb' : [
'static/src/xml/web_search.xml',
],
'auto_install': False
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,44 @@
.openerp .search_filter {
background: #F0F0F0;
width: 100%;
border: 1px solid #999;
background: -moz-linear-gradient(top, #F0F0F0 0%, #C0C0C0 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F0F0F0), color-stop(100%,#C0C0C0));
}
.openerp .oe_filter_label {
background: #F0F0F0;
width: 3.35%;
border: 1px solid #999;
background: -moz-linear-gradient(top, #F0F0F0 0%, #C0C0C0 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F0F0F0), color-stop(100%,#C0C0C0));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#F0F0F0', endColorstr='#C0C0C0',GradientType=0 );
}
.openerp .oe_filter_label:hover {
background: #F0F0F0;
background: -moz-linear-gradient(top, #F0F0F0 0%, #A1A7CE 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F0F0F0), color-stop(100%,#A1A7CE));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#F0F0F0', endColorstr='#A1A7CE',GradientType=0 );
}
.openerp .oe_filter_label:active {
background: #aaa;
background: -moz-linear-gradient(top, #999999 0%, #EEEEEE 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#999999), color-stop(100%,#EEEEEE));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#999999', endColorstr='#EEEEEE',GradientType=0 );
}
.openerp .oe_filter_label.enabled {
background: #aaa;
filter: none;
-moz-box-shadow: none;
-webkit-box-shadow: none;
-o-box-shadow: none;
box-shadow: none;
}
.openerp .oe_filter_label {
font-weight: bold;
text-transform: uppercase;
text-shadow: #EEE 0 1px 0;
color: #4C4C4C;
white-space: nowrap;
margin: 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,80 @@
openerp.web_search_alphabetic = function (instance) {
var QWeb = instance.web.qweb;
instance.web.SearchView.include({
start: function() {
var result = this._super();
var self = this;
self.search_on = "name";
self.fields_selection = [];
this.dataset.call('fields_get', [false, {}]).done(function (fields) {
$.each(fields, function (value) {
if(fields[value].type == "char"){
fields[value].id = value;
self.fields_selection.push(fields[value]);
}
})
if(self.fields_selection.length){
$('.field_selection_column').append((QWeb.render('field-selection', {widget: self})));
$("#field_name_selection").change(function(){
self.search_on = $(this).val() || false;
})
}
});
$('.oe_filter_label').click(function (e) {
$(this).toggleClass('enabled');
self.do_search();
});
return result;
},
search_filter: function(){
var filter_domain = [];
var self = this;
_.each($('.oe_filter_label'), function(value) {
if ($(value).hasClass('enabled') && $(value).attr('id') && self.search_on) {
filter_domain.push("[('" + self.search_on + "', '=ilike', '" + $(value).attr('id').split('_')[1] + "%')]")
}
});
if (filter_domain.length) {
var filter_or_domain = [];
for (i = 0; i < filter_domain.length-1; i++) {
filter_or_domain.push("['|']");
}
return filter_or_domain.concat(filter_domain || []);
}
return false;
},
build_search_data: function () {
var result = this._super();
filter_domain = this.search_filter();
if (filter_domain)
result['domains'] = filter_domain.concat(result.domains || []);
return result;
},
});
instance.web.ViewManager.include({
switch_mode: function(view_type, no_store, view_options) {
var view = this.views[view_type];
var result = this._super(view_type, no_store, view_options);
if (this.searchview && this.active_view != "form") {
if ((view.controller.searchable === false || this.searchview.options.hidden) || this.active_view == "form"){
$('.search_filter').live().hide();
}else
$('.search_filter').show();
}
else{
$('.search_filter').live().hide();
}
return result;
},
});
instance.web.FormView.include({
load_defaults: function () {
if($('.search_filter'))
$('.search_filter').hide();
return this._super();
},
});
};
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:

View File

@ -0,0 +1,49 @@
<template>
<t t-name="field-selection">
<t t-if="widget.fields_selection">
<select id="field_name_selection">
<t t-foreach="widget.fields_selection" t-as="record">
<option t-att-value="record.id"><t t-esc="record.string"/></option>
</t>
</select>
</t>
</t>
<t t-extend="ViewManagerAction">
<t t-jquery=".oe_view_manager .oe_view_manager_header" t-operation="append">
<table class="search_filter">
<tr>
<th class="field_selection_column"/>
<th>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_a" title="A">A</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_b" title="B">B</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_c" title="C">C</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_d" title="D">D</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_e" title="E">E</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_f" title="F">F</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_g" title="G">G</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_h" title="H">H</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_i" title="I">I</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_j" title="J">J</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_k" title="K">K</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_l" title="L">L</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_m" title="M">M</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_n" title="N">N</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_o" title="O">O</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_p" title="P">P</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_q" title="Q">Q</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_r" title="R">R</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_s" title="S">S</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_t" title="T">T</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_u" title="U">U</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_v" title="V">V</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_w" title="W">W</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_x" title="X">X</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_y" title="Y">Y</button>
<button type="button" autofocus="autofocus" class="oe_filter_label" id="filter_z" title="Z">z</button>
</th>
</tr>
</table>
</t>
</t>
</template>