[ADD] basic handling of addition button, not hooked in yet
bzr revid: xmo@openerp.com-20110412130229-78sg833pdcbi1gx3
This commit is contained in:
parent
6c9886700e
commit
b840e25c1d
|
@ -8,7 +8,9 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
// list rows can be deleted
|
// list rows can be deleted
|
||||||
'deletable': true,
|
'deletable': true,
|
||||||
// whether the column headers should be displayed
|
// whether the column headers should be displayed
|
||||||
'header': true
|
'header': true,
|
||||||
|
// display addition button, with that label
|
||||||
|
'addable': "New"
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @constructs
|
* @constructs
|
||||||
|
@ -21,6 +23,7 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
* @param {Boolean} [options.selectable=true] determines whether view rows are selectable (e.g. via a checkbox)
|
* @param {Boolean} [options.selectable=true] determines whether view rows are selectable (e.g. via a checkbox)
|
||||||
* @param {Boolean} [options.header=true] should the list's header be displayed
|
* @param {Boolean} [options.header=true] should the list's header be displayed
|
||||||
* @param {Boolean} [options.deletable=true] are the list rows deletable
|
* @param {Boolean} [options.deletable=true] are the list rows deletable
|
||||||
|
* @param {null|String} [options.addable="New"] should the new-record button be displayed, and what should its label be. Use ``null`` to hide the button.
|
||||||
*/
|
*/
|
||||||
init: function(view_manager, session, element_id, dataset, view_id, options) {
|
init: function(view_manager, session, element_id, dataset, view_id, options) {
|
||||||
this._super(session, element_id);
|
this._super(session, element_id);
|
||||||
|
@ -73,6 +76,7 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
this.$element.html(QWeb.render("ListView", this));
|
this.$element.html(QWeb.render("ListView", this));
|
||||||
|
|
||||||
// Head hook
|
// Head hook
|
||||||
|
this.$element.find('#oe-list-add').click(this.do_add_record);
|
||||||
this.$element.find('#oe-list-delete')
|
this.$element.find('#oe-list-delete')
|
||||||
.hide()
|
.hide()
|
||||||
.click(this.do_delete_selected);
|
.click(this.do_delete_selected);
|
||||||
|
@ -159,6 +163,23 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
$old_body.remove();
|
$old_body.remove();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Asks the view manager to switch to a different view, using the provided
|
||||||
|
* record index (within the current dataset).
|
||||||
|
*
|
||||||
|
* If the index is null, ``switch_to_record`` asks for the creation of a
|
||||||
|
* new record.
|
||||||
|
*
|
||||||
|
* @param {Number|null} index the record index (in the current dataset) to switch to
|
||||||
|
* @param {String} [view="form"] the view to switch to
|
||||||
|
*/
|
||||||
|
switch_to_record:function (index, view) {
|
||||||
|
view = view || 'form';
|
||||||
|
this.dataset.index = index;
|
||||||
|
_.delay(_.bind(function () {
|
||||||
|
this.view_manager.on_mode_switch(view);
|
||||||
|
}, this));
|
||||||
|
},
|
||||||
on_select_row: function (event) {
|
on_select_row: function (event) {
|
||||||
var $target = $(event.currentTarget);
|
var $target = $(event.currentTarget);
|
||||||
if (!$target.parent().is('tbody')) {
|
if (!$target.parent().is('tbody')) {
|
||||||
|
@ -171,12 +192,8 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
if (index == undefined || index === -1) {
|
if (index == undefined || index === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.dataset.index = index;
|
this.switch_to_record(index);
|
||||||
_.delay(_.bind(function () {
|
},
|
||||||
this.view_manager.on_mode_switch('form');
|
|
||||||
}, this));
|
|
||||||
|
|
||||||
},
|
|
||||||
do_show: function () {
|
do_show: function () {
|
||||||
// TODO: re-trigger search
|
// TODO: re-trigger search
|
||||||
this.$element.show();
|
this.$element.show();
|
||||||
|
@ -221,6 +238,16 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
this.dataset.unlink(
|
this.dataset.unlink(
|
||||||
[this.rows[$(e.currentTarget).closest('tr').prevAll().length].data.id.value]);
|
[this.rows[$(e.currentTarget).closest('tr').prevAll().length].data.id.value]);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Handles signal for the addition of a new record (can be a creation,
|
||||||
|
* can be the addition from a remote source, ...)
|
||||||
|
*
|
||||||
|
* The default implementation is to switch to a new record on the form view
|
||||||
|
*/
|
||||||
|
do_add_record: function () {
|
||||||
|
this.notification['default']('Add', "New record");
|
||||||
|
// this.switch_to_record(null);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Handles deletion of all selected lines
|
* Handles deletion of all selected lines
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -153,15 +153,22 @@
|
||||||
</table>
|
</table>
|
||||||
</t>
|
</t>
|
||||||
<table t-name="ListView">
|
<table t-name="ListView">
|
||||||
|
<t t-set="columns_count" t-value="visible_columns.length + (options.selectable ? 1 : 0) + (options.deletable ? 1 : 0)"/>
|
||||||
|
<t t-set="actions_span" t-value="Math.floor((options.deletable or options.addable) ? columns_count/2 : 0)"/>
|
||||||
<thead class="ui-widget-header">
|
<thead class="ui-widget-header">
|
||||||
<tr t-if="options.selectable and options.deletable">
|
<tr t-if="options.selectable">
|
||||||
<th t-att-colspan="Math.floor((visible_columns.length + 2) / 2)"
|
<th t-if="actions_span" t-att-colspan="actions_span"
|
||||||
class="oe-actions">
|
class="oe-actions">
|
||||||
<button type="button" id="oe-list-delete">
|
<button type="button" id="oe-list-add"
|
||||||
|
t-if="options.addable">
|
||||||
|
<t t-esc="options.addable"/>
|
||||||
|
</button>
|
||||||
|
<button type="button" id="oe-list-delete"
|
||||||
|
t-if="options.deletable">
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
<th t-att-colspan="Math.ceil((visible_columns.length + 2) / 2)"
|
<th t-att-colspan="columns_count - actions_span"
|
||||||
class="oe-list-pager">
|
class="oe-list-pager">
|
||||||
<button type="button" data-pager-action="first">First</button>
|
<button type="button" data-pager-action="first">First</button>
|
||||||
<button type="button" data-pager-action="previous"
|
<button type="button" data-pager-action="previous"
|
||||||
|
|
Loading…
Reference in New Issue