[IMP]added the legend widget for priority and kanban state

bzr revid: mba@tinyerp.com-20140107131121-unl7honraf5d9tna
This commit is contained in:
Mahendra Barad (OpenERP) 2014-01-07 18:41:21 +05:30
commit 2e732f0aaf
5 changed files with 191 additions and 3 deletions

View File

@ -1,4 +1,4 @@
@charset "utf-8";
@charset "UTF-8";
@font-face {
font-family: "mnmliconsRegular";
src: url("/web/static/src/font/mnmliconsv21-webfont.eot") format("eot");
@ -2290,7 +2290,7 @@
}
.openerp .oe_form .oe_form_label_help[for] span, .openerp .oe_form .oe_form_label[for] span {
font-size: 80%;
color: darkGreen;
color: darkgreen;
vertical-align: top;
position: relative;
top: -4px;
@ -3434,7 +3434,6 @@ div.ui-widget-overlay {
overflow: hidden !important;
}
}
.nav li > a {
padding: 3px 4px 2px 18px;
color: #4c4c4c;
@ -3569,6 +3568,40 @@ h5 {
color: #eeeeee;
}
.dropdown-menu.with-arrow {
background: white;
background: white !important;
}
.dropdown-menu.with-arrow:before {
position: absolute;
top: -12px;
left: 0px;
display: inline-block;
border-right: 12px solid transparent;
border-bottom: 12px solid #cccccc;
border-left: 12px solid transparent;
border-bottom-color: rgba(0, 0, 0, 0.2);
content: "";
}
.dropdown-menu.with-arrow:after {
position: absolute;
top: -11px;
left: 1px;
display: inline-block;
border-right: 11px solid transparent;
border-bottom: 11px solid white;
border-left: 11px solid transparent;
content: "";
}
.dropdown-menu.with-arrow li a {
color: black;
}
.dropdown-menu.with-arrow li a, .dropdown-menu.with-arrow li a:hover, .dropdown-menu.with-arrow li a:focus {
text-decoration: none;
}
.ui-icon {
width: 18px;
height: 18px;

View File

@ -2843,6 +2843,32 @@ h5
li
a,a:hover,a:focus
color: #eeeeee
.dropdown-menu.with-arrow
background: #FFF
background: #FFF !important
.dropdown-menu.with-arrow:before
position: absolute
top: -12px
left: 0px
display: inline-block
border-right: 12px solid transparent
border-bottom: 12px solid #ccc
border-left: 12px solid transparent
border-bottom-color: rgba(0, 0, 0, 0.2)
content: ''
.dropdown-menu.with-arrow:after
position: absolute
top: -11px
left: 1px
display: inline-block
border-right: 11px solid transparent
border-bottom: 11px solid #ffffff
border-left: 11px solid transparent
content: ''
.dropdown-menu.with-arrow li a
color: #000
.dropdown-menu.with-arrow li a, .dropdown-menu.with-arrow li a:hover, .dropdown-menu.with-arrow li a:focus
text-decoration: none;
// End hack }}}
// Hack for ui icon {{{

View File

@ -2331,6 +2331,83 @@ instance.web.form.FieldChar = instance.web.form.AbstractField.extend(instance.we
}
});
instance.web.Legend = instance.web.Widget.extend({
init: function (parent, dataset, options) {
this._super(parent);
this.parent = parent;
this.dataset = dataset;
this.options = options;
},
prepare_data: function() {
var self =this;
var def = $.Deferred();
if (this.parent.name == 'kanban_state'){
var datas = [{ 'name': 'normal', 'legend_name': ' Normal', 'legend': '<img src="/web/static/src/img/icons/gtk-normal.png"/>' },
{ 'name': 'blocked', 'legend_name': ' Blocked', 'legend': '<img src="/web/static/src/img/icons/gtk-no.png"/>' },
{ 'name': 'done', 'legend_name': ' Done', 'legend': '<img src="/web/static/src/img/icons/gtk-yes.png"/>' }]
return def.resolve(datas);
}
if (this.parent.name == 'priority'){
var data = [];
var selection = this.parent.field.selection || [];
for (var index in selection) {
value = {
'name': selection[index][0],
'legend_name': selection[index][1]
}
if (selection[index][0] == '0'){
value['legend']= '<img src="/web/static/src/img/icons/star-off.png"/>';
value['legend_name'] = 'Set the Priority';
}else{
value['legend']= '<img src="/web/static/src/img/icons/star-on.png"/>';
}
data.push(value)
}
return def.resolve(data);
}
},
render_value: function(record_id, data) {
var self = this;
var content;
self.record_id = record_id;
this.prepare_data().then(function (res){
data['res'] = res;
content = QWeb.render("Legend."+ self.parent.name, data);
});
if (data.view_mode === 'form')
this.parent.$el.html(content);
else
this.parent.$el = $(content);
if (!this.parent.get("effective_readonly")){
this.parent.$el.find('.oe_legend').click(self.do_action.bind(self));
}
},
do_action: function(e){
var self = this;
var li = $(e.target).closest( "li" );
if (li.length){
var value = li.data('value');
return self.dataset.call_button(self.options.action, [self.record_id, value, self.dataset.get_context()]).done(self.parent.reload_record.bind(self.parent));
}
}
});
instance.web.form.Legend = instance.web.form.FieldChar.extend({
init: function (field_manager, node) {
this._super(field_manager, node);
this.legend = new instance.web.Legend(this, this.view.dataset, py.eval(node.attrs.options));
},
reload_record: function(){
this.view.reload();
},
render_value: function() {
var self = this;
self.legend.render_value(this.view.datarecord.id, {
'widget': self,
'view_mode':'form'
});
},
});
instance.web.form.FieldID = instance.web.form.FieldChar.extend({
process_modifiers: function () {
this._super();
@ -5853,6 +5930,7 @@ instance.web.form.widgets = new instance.web.Registry({
'monetary': 'instance.web.form.FieldMonetary',
'many2many_checkboxes': 'instance.web.form.FieldMany2ManyCheckBoxes',
'x2many_counter': 'instance.web.form.X2ManyCounter',
'legend':'instance.web.form.Legend'
});
/**

View File

@ -1031,6 +1031,37 @@
</t>
</span>
</t>
<t t-name="Legend.kanban_state">
<span class="btn-group">
<t t-foreach="res" t-as="rec">
<a class="dropdown-toggle oe_legend" data-toggle="dropdown" href="#" t-if="widget.get('value') === rec.name" t-att-title="rec.legend_name" >
<t t-raw="rec.legend" />
</a>
</t>
<ul class="dropdown-menu with-arrow">
<t t-foreach="res" t-as="rec">
<t t-if="widget.get('value') !== rec.name">
<li class="oe_legend" t-att-data-value="rec.name" ><a href="#"><t t-raw="rec.legend" /><t t-raw="rec.legend_name" /></a></li>
</t>
</t>
</ul>
</span>
</t>
<t t-name="Legend.priority">
<ul style="list-style: none; padding-left: 2px;">
<t t-foreach="res" t-as="test" >
<t t-if="widget.get('value') gte test.name and !test_first">
<li t-att-data-value="test.name - 1" class="oe_left oe_legend"><a href="#" t-att-title="test.legend_name"><t t-raw="test.legend"/></a></li>
</t>
</t>
<t t-foreach="res" t-as="test" >
<t t-if="widget.get('value') lt test.name">
<li t-att-data-value="test.name" class="oe_left oe_legend"><a href="#" t-att-title="res[0].legend_name"><t t-raw="res[0].legend"/></a></li>
</t>
</t>
</ul>
</t>
<t t-name="FieldEmail">
<span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style">
<a t-if="widget.get('effective_readonly')" href="#" class="oe_form_uri" target="_blank"/>

View File

@ -1258,7 +1258,27 @@ instance.web_kanban.AbstractField = instance.web.Widget.extend(instance.web_kanb
},
});
instance.web_kanban.Legend = instance.web_kanban.AbstractField.extend({
init: function(parent, field, $node) {
this._super.apply(this, arguments);
this.name = $node.attr('name')
this.parent = parent;
this.legend = new instance.web.Legend(this, parent.view.dataset, this.options);
},
reload_record: function(){
this.parent.do_reload();
},
renderElement: function() {
var self = this;
self.legend.render_value(self.parent.id, {
'widget': self,
});
},
});
instance.web_kanban.fields_registry = new instance.web.Registry({});
instance.web_kanban.fields_registry.add('legend','instance.web_kanban.Legend');
};
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: