[FIX] web: form view: priority and kanban widgets cleaning, now more like classic form widgets (edit mode: use set_value, view mode: perform a write)

This commit is contained in:
Thibault Delavallée 2014-08-08 16:59:48 +02:00
parent 0aef6fac10
commit 765beaa0c9
5 changed files with 49 additions and 51 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");
@ -549,14 +549,6 @@
padding-top: 8px;
margin-right: 4px !important;
}
.openerp .btn-group.kanban_state .dropdown-menu {
min-width: 100%;
padding-right: 10px !important;
}
.openerp .btn-group.kanban_state .dropdown-menu li a, .openerp .btn-group.kanban_state .dropdown-menu li a:hover, .openerp .btn-group.kanban_state .dropdown-menu li a:focus {
padding-left: 5px;
padding-right: 0px;
}
.openerp .btn-group.kanban_state a {
color: #333333;
}

View File

@ -498,12 +498,6 @@ $sheet-padding: 16px
.btn-group.kanban_state
padding-top: 8px
margin-right: 4px !important
.dropdown-menu
min-width: 100%
padding-right: 10px !important
.dropdown-menu li a, .dropdown-menu li a:hover, .dropdown-menu li a:focus
padding-left: 5px
padding-right: 0px
a
color: #333333
// }}}

View File

@ -2335,26 +2335,31 @@ instance.web.form.KanbanSelection = instance.web.form.FieldChar.extend({
},
render_value: function() {
var self = this;
this.record_id = self.view.datarecord.id;
this.states = self.prepare_dropdown_selection();;
this.record_id = this.view.datarecord.id;
this.states = this.prepare_dropdown_selection();;
this.$el.html(QWeb.render("KanbanSelection", {'widget': self}));
this.$el.find('.oe_legend').click(self.do_action.bind(self));
this.$el.find('li').on('click', this.set_kanban_selection.bind(this));
},
do_action: function(e) {
/* setting the value: in view mode, perform an asynchronous call and reload
the form view; in edit mode, use set_value to save the new value that will
be written when saving the record. */
set_kanban_selection: function (ev) {
var self = this;
var li = $(e.target).closest( "li" );
var li = $(ev.target).closest('li');
if (li.length) {
var value = {};
value[self.name] = String(li.data('value'));
self.record_id = self.view.datarecord.id;
if (self.record_id) {
return self.view.dataset._model.call('write', [[self.record_id], value, self.view.dataset.get_context()]).done(self.reload_record.bind(self));
} else {
return self.view.on_button_save().done(function(result) {
if (result) {
self.view.dataset._model.call('write', [[result], value, self.view.dataset.get_context()]).done(self.reload_record.bind(self));
}
});
var value = String(li.data('value'));
if (this.view.get('actual_mode') == 'view') {
var write_values = {}
write_values[self.name] = value;
return this.view.dataset._model.call(
'write', [
[self.record_id],
write_values,
self.view.dataset.get_context()
]).done(self.reload_record.bind(self));
}
else {
return this.set_value(value);
}
}
},
@ -2386,27 +2391,34 @@ instance.web.form.Priority = instance.web.form.FieldChar.extend({
},
render_value: function() {
var self = this;
this.record_id = self.view.datarecord.id;
this.priorities = self.prepare_priority();
this.record_id = this.view.datarecord.id;
this.priorities = this.prepare_priority();
this.$el.html(QWeb.render("Priority", {'widget': this}));
this.$el.find('.oe_legend').click(self.do_action.bind(self));
this.$el.find('li').on('click', this.set_priority.bind(this));
},
do_action: function(e) {
/* setting the value: in view mode, perform an asynchronous call and reload
the form view; in edit mode, use set_value to save the new value that will
be written when saving the record. */
set_priority: function (ev) {
var self = this;
var li = $(e.target).closest( "li" );
var li = $(ev.target).closest('li');
if (li.length) {
var value = {};
value[self.name] = String(li.data('value'));
if (self.record_id) {
return self.view.dataset._model.call('write', [[self.record_id], value, self.view.dataset.get_context()]).done(self.reload_record.bind(self));
} else {
return self.view.on_button_save().done(function(result) {
if (result) {
self.view.dataset._model.call('write', [[result], value, self.view.dataset.get_context()]).done(self.reload_record.bind(self));
}
});
var value = String(li.data('value'));
if (this.view.get('actual_mode') == 'view') {
var write_values = {}
write_values[self.name] = value;
return this.view.dataset._model.call(
'write', [
[self.record_id],
write_values,
self.view.dataset.get_context()
]).done(self.reload_record.bind(self));
}
else {
return this.set_value(value);
}
}
},
reload_record: function() {
this.view.reload();

View File

@ -962,7 +962,7 @@
<div class="btn-group kanban_state">
<t t-foreach="widget.states" t-as="rec">
<a t-if="widget.get('value') === rec.name">
<a class="oe_legend dropdown-toggle" data-toggle="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">
<span t-att-class="rec.state_class" t-if="widget.get('value') === rec.name" t-att-title="rec.tooltip"/>
<span class="sr-only">Toggle Dropdown</span>
</a>
@ -971,7 +971,7 @@
<ul class="dropdown-menu state" role="menu">
<t t-foreach="widget.states" t-as="rec">
<t t-if="widget.get('value') !== rec.name">
<li class="oe_legend" t-att-data-value="rec.name" ><a href="#">
<li t-att-data-value="rec.name" ><a href="#">
<span t-att-class="rec.state_class" t-att-title="rec.tooltip"/>
<t t-raw="rec.state_name" /></a>
</li>
@ -983,7 +983,7 @@
<t t-name="Priority">
<ul style="list-style: none; padding-left: 2px; display: inline-block;">
<t t-foreach="widget.priorities" t-as="rec" >
<li t-att-data-value="rec.click_value" class="oe_legend" style="display: inline-block;">
<li t-att-data-value="rec.click_value" style="display: inline-block;">
<a href="#" t-att-title="rec.name">
<span t-att-class="widget.get('value') gte rec.value and 'oe_e oe_star_on' or 'oe_e oe_star_off'">7</span>
</a>

View File

@ -1295,7 +1295,7 @@ instance.web_kanban.Priority = instance.web_kanban.AbstractField.extend({
this.record_id = self.parent.id;
this.priorities = self.prepare_priority();
this.$el = $(QWeb.render("Priority", {'widget': this}));
this.$el.find('.oe_legend').click(self.do_action.bind(self));
this.$el.find('li').click(self.do_action.bind(self));
},
do_action: function(e) {
var self = this;
@ -1337,7 +1337,7 @@ instance.web_kanban.KanbanSelection = instance.web_kanban.AbstractField.extend({
this.record_id = self.parent.id;
this.states = self.prepare_dropdown_selection();;
this.$el = $(QWeb.render("KanbanSelection", {'widget': self}));
this.$el.find('.oe_legend').click(self.do_action.bind(self));
this.$el.find('li').click(self.do_action.bind(self));
},
do_action: function(e) {
var self = this;