[IMP] make edition indexing work based on the current dataset
bzr revid: xmo@openerp.com-20110606114204-sjnil5xuhef0l2la
This commit is contained in:
parent
c452d85a7a
commit
0c673bb248
|
@ -61,13 +61,13 @@ openerp.base.list.editable = function (openerp) {
|
||||||
|
|
||||||
var old_list_row_clicked = openerp.base.ListView.List.prototype.row_clicked;
|
var old_list_row_clicked = openerp.base.ListView.List.prototype.row_clicked;
|
||||||
_.extend(openerp.base.ListView.List.prototype, {
|
_.extend(openerp.base.ListView.List.prototype, {
|
||||||
row_clicked: function (event, index) {
|
row_clicked: function (event) {
|
||||||
if (!this.options.editable) {
|
if (!this.options.editable) {
|
||||||
return old_list_row_clicked.call(this, event, index);
|
return old_list_row_clicked.call(this, event);
|
||||||
}
|
}
|
||||||
this.render_row_as_form(index, event.currentTarget);
|
this.render_row_as_form(event.currentTarget);
|
||||||
},
|
},
|
||||||
render_row_as_form: function (row_num, row) {
|
render_row_as_form: function (row) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var $new_row = $('<tr>', {
|
var $new_row = $('<tr>', {
|
||||||
id: _.uniqueId('oe-editable-row-'),
|
id: _.uniqueId('oe-editable-row-'),
|
||||||
|
@ -77,20 +77,20 @@ openerp.base.list.editable = function (openerp) {
|
||||||
.keyup(function (e) {
|
.keyup(function (e) {
|
||||||
switch (e.which) {
|
switch (e.which) {
|
||||||
case KEY_RETURN:
|
case KEY_RETURN:
|
||||||
self.save_row(row_num, true);
|
self.save_row(true);
|
||||||
break;
|
break;
|
||||||
case KEY_ESCAPE:
|
case KEY_ESCAPE:
|
||||||
self.cancel_edition(row_num);
|
self.cancel_edition();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.delegate('button.oe-edit-row-save', 'click', function () {
|
.delegate('button.oe-edit-row-save', 'click', function () {
|
||||||
self.save_row(row_num);
|
self.save_row();
|
||||||
})
|
})
|
||||||
.delegate('button.oe-edit-row-cancel', 'click', function () {
|
.delegate('button.oe-edit-row-cancel', 'click', function () {
|
||||||
self.cancel_edition(row_num);
|
self.cancel_edition();
|
||||||
});
|
});
|
||||||
if (row) {
|
if (row) {
|
||||||
$new_row.replaceAll(row);
|
$new_row.replaceAll(row);
|
||||||
|
@ -125,37 +125,38 @@ openerp.base.list.editable = function (openerp) {
|
||||||
* Saves the current row, and triggers the edition of its following
|
* Saves the current row, and triggers the edition of its following
|
||||||
* sibling if asked.
|
* sibling if asked.
|
||||||
*
|
*
|
||||||
* @param {Number} row_num the row to save
|
|
||||||
* @param {Boolean} [edit_next=false] should the next row become editable
|
* @param {Boolean} [edit_next=false] should the next row become editable
|
||||||
*/
|
*/
|
||||||
save_row: function (row_num, edit_next) {
|
save_row: function (edit_next) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.edition_form.do_save(function () {
|
this.edition_form.do_save(function () {
|
||||||
self.reload_record(row_num, true).then(function () {
|
self.reload_record(self.dataset.index, true).then(function () {
|
||||||
self.edition_form.stop();
|
self.edition_form.stop();
|
||||||
delete self.edition_form;
|
delete self.edition_form;
|
||||||
if (edit_next && self.rows.length > row_num + 1) {
|
if (edit_next) {
|
||||||
self.dataset.index++;
|
self.dataset.next();
|
||||||
self.row_clicked({
|
self.row_clicked({
|
||||||
currentTarget: self.$current.children().eq(row_num + 1)
|
currentTarget: self.$current.children().eq(
|
||||||
}, row_num + 1);
|
self.dataset.index)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Cancels the edition of the row at index ``row_num``.
|
* Cancels the edition of the row for the current dataset index
|
||||||
*
|
|
||||||
* @param {Number} row_num index of the row being edited
|
|
||||||
*/
|
*/
|
||||||
cancel_edition: function (row_num) {
|
cancel_edition: function () {
|
||||||
this.reload_record(row_num);
|
if (this.dataset.index !== null) {
|
||||||
|
this.reload_record(this.dataset.index);
|
||||||
|
}
|
||||||
this.edition_form.stop();
|
this.edition_form.stop();
|
||||||
|
this.edition_form.$element.remove();
|
||||||
delete this.edition_form;
|
delete this.edition_form;
|
||||||
},
|
},
|
||||||
new_record: function () {
|
new_record: function () {
|
||||||
this.dataset.index = null;
|
this.dataset.index = null;
|
||||||
this.render_row_as_form(-1, null);
|
this.render_row_as_form();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
openerp.base.list = {form: {}};
|
openerp.base.list = {form: {}};
|
||||||
|
|
|
@ -83,8 +83,8 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
||||||
'action': function (e, action_name, id, callback) {
|
'action': function (e, action_name, id, callback) {
|
||||||
self.do_action(action_name, id, callback);
|
self.do_action(action_name, id, callback);
|
||||||
},
|
},
|
||||||
'row_link': function (e, index, id, dataset) {
|
'row_link': function (e, id, dataset) {
|
||||||
self.do_activate_record(index, id, dataset);
|
self.do_activate_record(dataset.index, id, dataset);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -565,16 +565,14 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
|
||||||
})
|
})
|
||||||
.delegate('tr', 'click', function (e) {
|
.delegate('tr', 'click', function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
var index = self.row_position(e.currentTarget);
|
self.dataset.index = self.row_position(e.currentTarget);
|
||||||
self.dataset.index = index;
|
self.row_clicked(e);
|
||||||
self.row_clicked(e, index);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
row_clicked: function (event, index) {
|
row_clicked: function () {
|
||||||
$(this).trigger(
|
$(this).trigger(
|
||||||
'row_link',
|
'row_link',
|
||||||
[index,
|
[this.rows[this.dataset.index].data.id.value,
|
||||||
this.rows[index].data.id.value,
|
|
||||||
this.dataset]);
|
this.dataset]);
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
|
|
Loading…
Reference in New Issue