[MOVE] editability code for listviews in a separate files: customizations of Form View require load-time dependencies on form.js, but form.js already depends on ListView (in order to create m2m widgets and sub-widgets), so we need to execute that part after both openep.base.list and openerp.base.form have loaded
bzr revid: xmo@openerp.com-20110603093606-gw00iidxfakjmvt3
This commit is contained in:
parent
0d21e3b074
commit
3895bcb954
|
@ -28,6 +28,7 @@
|
||||||
<script type="text/javascript" src="/base/static/src/js/views.js"></script>
|
<script type="text/javascript" src="/base/static/src/js/views.js"></script>
|
||||||
<script type="text/javascript" src="/base/static/src/js/form.js"></script>
|
<script type="text/javascript" src="/base/static/src/js/form.js"></script>
|
||||||
<script type="text/javascript" src="/base/static/src/js/list.js"></script>
|
<script type="text/javascript" src="/base/static/src/js/list.js"></script>
|
||||||
|
<script type="text/javascript" src="/base/static/src/js/list-editable.js"></script>
|
||||||
<script type="text/javascript" src="/base/static/src/js/tree.js"></script>
|
<script type="text/javascript" src="/base/static/src/js/tree.js"></script>
|
||||||
<script type="text/javascript" src="/base/static/src/js/search.js"></script>
|
<script type="text/javascript" src="/base/static/src/js/search.js"></script>
|
||||||
<script type="text/javascript" src="/base/static/src/js/m2o.js"></script>
|
<script type="text/javascript" src="/base/static/src/js/m2o.js"></script>
|
||||||
|
|
|
@ -132,6 +132,7 @@ openerp.base = function(instance) {
|
||||||
openerp.base.tree(instance);
|
openerp.base.tree(instance);
|
||||||
openerp.base.m2o(instance);
|
openerp.base.m2o(instance);
|
||||||
openerp.base.form(instance);
|
openerp.base.form(instance);
|
||||||
|
openerp.base.list.editable(instance);
|
||||||
};
|
};
|
||||||
|
|
||||||
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
* @namespace handles editability case for lists, because it depends on form and forms already depends on lists it had to be split out
|
||||||
|
*/
|
||||||
|
openerp.base.list.editable = function (openerp) {
|
||||||
|
// editability status of list rows
|
||||||
|
openerp.base.ListView.prototype.defaults.editable = null;
|
||||||
|
|
||||||
|
var old_actual_search = openerp.base.ListView.prototype.do_actual_search;
|
||||||
|
_.extend(openerp.base.ListView.prototype, {
|
||||||
|
/**
|
||||||
|
* Sets editability status for the list, based on defaults, view
|
||||||
|
* architecture and the provided flag, if any.
|
||||||
|
*
|
||||||
|
* @param {Boolean} [force] forces the list to editability. Sets new row edition status to "bottom".
|
||||||
|
*/
|
||||||
|
set_editable: function (force) {
|
||||||
|
// If ``force``, set editability to bottom
|
||||||
|
// else if editability flag in view arch, use that
|
||||||
|
// otherwise rely on view default
|
||||||
|
this.options.editable = (
|
||||||
|
(force && "bottom")
|
||||||
|
|| this.fields_view.arch.attrs.editable
|
||||||
|
|| this.defaults.editable);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Replace do_actual_search to handle editability process
|
||||||
|
*/
|
||||||
|
do_actual_search: function (results) {
|
||||||
|
this.set_editable(results.context['set_editable']);
|
||||||
|
old_actual_search.call(this, results);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var old_list_row_clicked = openerp.base.ListView.List.prototype.row_clicked;
|
||||||
|
_.extend(openerp.base.ListView.List.prototype, {
|
||||||
|
row_clicked: function (event, index) {
|
||||||
|
if (!this.options.editable) {
|
||||||
|
return old_list_row_clicked.call(this, event, index);
|
||||||
|
}
|
||||||
|
this.render_row_as_form(index, event.currentTarget);
|
||||||
|
},
|
||||||
|
render_row_as_form: function (row_num, row) {
|
||||||
|
var $new_row = $('<tr>', {
|
||||||
|
id: _.uniqueId('oe-editable-row-'),
|
||||||
|
'class': $(row).attr('class'),
|
||||||
|
onclick: function (e) {e.stopPropagation();}
|
||||||
|
}).replaceAll(row);
|
||||||
|
var editable_row_form = new openerp.base.FormView(
|
||||||
|
null, this.group.view.session, $new_row.attr('id'),
|
||||||
|
this.dataset, false);
|
||||||
|
editable_row_form.template = 'ListView.row.form';
|
||||||
|
editable_row_form.on_loaded({fields_view: this.get_fields_view()});
|
||||||
|
editable_row_form.on_record_loaded.add({
|
||||||
|
position: 'last',
|
||||||
|
unique: true,
|
||||||
|
callback: function () {
|
||||||
|
editable_row_form.$element.find('td')
|
||||||
|
// remove tr, tbody, table
|
||||||
|
.unwrap().unwrap().unwrap()
|
||||||
|
.removeAttr('width');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
editable_row_form.do_show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
|
@ -14,9 +14,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
||||||
// sorted it can not be reordered anymore
|
// sorted it can not be reordered anymore
|
||||||
'sortable': true,
|
'sortable': true,
|
||||||
// whether the view rows can be reordered (via vertical drag & drop)
|
// whether the view rows can be reordered (via vertical drag & drop)
|
||||||
'reorderable': true,
|
'reorderable': true
|
||||||
// editability status of list rows
|
|
||||||
'editable': null
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Core class for list-type displays.
|
* Core class for list-type displays.
|
||||||
|
@ -41,7 +39,6 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
||||||
* @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.
|
* @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.
|
||||||
* @param {Boolean} [options.sortable=true] is it possible to sort the table by clicking on column headers
|
* @param {Boolean} [options.sortable=true] is it possible to sort the table by clicking on column headers
|
||||||
* @param {Boolean} [options.reorderable=true] is it possible to reorder list rows
|
* @param {Boolean} [options.reorderable=true] is it possible to reorder list rows
|
||||||
* @param {null|"bottom"|"top"} [options.editable=null] can rows be edited, and do new rows appear at the top or the bottom of the list
|
|
||||||
*
|
*
|
||||||
* @borrows openerp.base.ActionExecutor#execute_action as #execute_action
|
* @borrows openerp.base.ActionExecutor#execute_action as #execute_action
|
||||||
*/
|
*/
|
||||||
|
@ -273,21 +270,6 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
||||||
this.groups.apoptosis().render(
|
this.groups.apoptosis().render(
|
||||||
$.proxy(this, 'compute_aggregates')));
|
$.proxy(this, 'compute_aggregates')));
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Sets editability status for the list, based on defaults, view
|
|
||||||
* architecture and the provided flag, if any.
|
|
||||||
*
|
|
||||||
* @param {Boolean} [force] forces the list to editability. Sets new row edition status to "bottom".
|
|
||||||
*/
|
|
||||||
set_editable: function (force) {
|
|
||||||
// If ``force``, set editability to bottom
|
|
||||||
// else if editability flag in view arch, use that
|
|
||||||
// otherwise rely on view default
|
|
||||||
this.options.editable = (
|
|
||||||
(force && "bottom")
|
|
||||||
|| this.fields_view.arch.attrs.editable
|
|
||||||
|| this.defaults.editable);
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Event handler for a search, asks for the computation/folding of domains
|
* Event handler for a search, asks for the computation/folding of domains
|
||||||
* and contexts (and group-by), then reloads the view's content.
|
* and contexts (and group-by), then reloads the view's content.
|
||||||
|
@ -298,27 +280,32 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
||||||
* @returns {$.Deferred} fold request evaluation promise
|
* @returns {$.Deferred} fold request evaluation promise
|
||||||
*/
|
*/
|
||||||
do_search: function (domains, contexts, groupbys) {
|
do_search: function (domains, contexts, groupbys) {
|
||||||
var self = this;
|
|
||||||
return this.rpc('/base/session/eval_domain_and_context', {
|
return this.rpc('/base/session/eval_domain_and_context', {
|
||||||
domains: domains,
|
domains: domains,
|
||||||
contexts: contexts,
|
contexts: contexts,
|
||||||
group_by_seq: groupbys
|
group_by_seq: groupbys
|
||||||
}, function (results) {
|
}, $.proxy(this, 'do_actual_search'));
|
||||||
self.dataset.context = results.context;
|
},
|
||||||
self.dataset.domain = results.domain;
|
/**
|
||||||
self.groups.datagroup = new openerp.base.DataGroup(
|
* Handler for the result of eval_domain_and_context, actually perform the
|
||||||
self.session, self.model,
|
* searching
|
||||||
results.domain, results.context,
|
*
|
||||||
results.group_by);
|
* @param {Object} results results of evaluating domain and process for a search
|
||||||
|
*/
|
||||||
|
do_actual_search: function (results) {
|
||||||
|
this.dataset.context = results.context;
|
||||||
|
this.dataset.domain = results.domain;
|
||||||
|
this.groups.datagroup = new openerp.base.DataGroup(
|
||||||
|
this.session, this.model,
|
||||||
|
results.domain, results.context,
|
||||||
|
results.group_by);
|
||||||
|
|
||||||
if (_.isEmpty(results.group_by) && !results.context['group_by_no_leaf']) {
|
if (_.isEmpty(results.group_by) && !results.context['group_by_no_leaf']) {
|
||||||
results.group_by = null;
|
results.group_by = null;
|
||||||
}
|
}
|
||||||
self.set_editable(results.context['set_editable']);
|
|
||||||
|
|
||||||
self.reload_view(!!results.group_by).then(
|
this.reload_view(!!results.group_by).then(
|
||||||
$.proxy(self, 'reload_content'));
|
$.proxy(this, 'reload_content'));
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Handles the signal to delete a line from the DOM
|
* Handles the signal to delete a line from the DOM
|
||||||
|
@ -566,18 +553,16 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
var index = self.row_position(e.currentTarget);
|
var index = self.row_position(e.currentTarget);
|
||||||
self.dataset.index = index;
|
self.dataset.index = index;
|
||||||
if (self.options.editable) {
|
self.row_clicked(e, index);
|
||||||
self.render_row_as_form(
|
|
||||||
index, e.currentTarget);
|
|
||||||
} else {
|
|
||||||
$(self).trigger(
|
|
||||||
'row_link',
|
|
||||||
[index,
|
|
||||||
self.rows[index].data.id.value,
|
|
||||||
self.dataset]);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
row_clicked: function (event, index) {
|
||||||
|
$(this).trigger(
|
||||||
|
'row_link',
|
||||||
|
[index,
|
||||||
|
this.rows[index].data.id.value,
|
||||||
|
this.dataset]);
|
||||||
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
if (this.$current) {
|
if (this.$current) {
|
||||||
this.$current.remove();
|
this.$current.remove();
|
||||||
|
@ -597,29 +582,6 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
|
||||||
view.arch.attrs.col = 2 * view.arch.children.length;
|
view.arch.attrs.col = 2 * view.arch.children.length;
|
||||||
return view;
|
return view;
|
||||||
},
|
},
|
||||||
render_row_as_form: function (row_num, row) {
|
|
||||||
var $new_row = $('<tr>', {
|
|
||||||
id: _.uniqueId('oe-editable-row-'),
|
|
||||||
'class': $(row).attr('class'),
|
|
||||||
onclick: function (e) {e.stopPropagation();}
|
|
||||||
}).replaceAll(row);
|
|
||||||
var editable_row_form = new openerp.base.FormView(
|
|
||||||
null, this.group.view.session, $new_row.attr('id'),
|
|
||||||
this.dataset, false);
|
|
||||||
editable_row_form.template = 'ListView.row.form';
|
|
||||||
editable_row_form.on_loaded({fields_view: this.get_fields_view()});
|
|
||||||
editable_row_form.on_record_loaded.add({
|
|
||||||
position: 'last',
|
|
||||||
unique: true,
|
|
||||||
callback: function () {
|
|
||||||
editable_row_form.$element.find('td')
|
|
||||||
// remove tr, tbody, table
|
|
||||||
.unwrap().unwrap().unwrap()
|
|
||||||
.removeAttr('width');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
editable_row_form.do_show();
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Gets the ids of all currently selected records, if any
|
* Gets the ids of all currently selected records, if any
|
||||||
* @returns {Object} object with the keys ``ids`` and ``records``, holding respectively the ids of all selected records and the records themselves.
|
* @returns {Object} object with the keys ``ids`` and ``records``, holding respectively the ids of all selected records and the records themselves.
|
||||||
|
@ -679,7 +641,6 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// drag and drop
|
// drag and drop
|
||||||
// editable?
|
|
||||||
});
|
});
|
||||||
openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Groups# */{
|
openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Groups# */{
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue