summaryrefslogtreecommitdiff
path: root/addons/project/static/src
diff options
context:
space:
mode:
authorAntonin Bourguignon <abo@openerp.com>2012-07-12 13:33:26 +0200
committerAntonin Bourguignon <abo@openerp.com>2012-07-12 13:33:26 +0200
commit4af50da7dc0e75222ae3fd94ef7c2ac58d5a9c00 (patch)
tree50a2e0d44d413d5f4cc2e1dcac4ca5277b344158 /addons/project/static/src
parent7ccb648390b0b7ed5cf0276e0fe6b724acb87dff (diff)
[IMP] refactor the handling of many2many tags in issues and tasks kanban views
bzr revid: abo@openerp.com-20120712113326-a0p30oij7g67gmtj
Diffstat (limited to 'addons/project/static/src')
-rw-r--r--addons/project/static/src/js/project.js70
1 files changed, 53 insertions, 17 deletions
diff --git a/addons/project/static/src/js/project.js b/addons/project/static/src/js/project.js
index 510fcbb99e7..978d3012b26 100644
--- a/addons/project/static/src/js/project.js
+++ b/addons/project/static/src/js/project.js
@@ -1,25 +1,61 @@
openerp.project = function(openerp) {
openerp.web_kanban.KanbanView.include({
- on_groups_started: function() {
+ project_display_members_names: function() {
+ /*
+ * Set avatar title for members.
+ * In kanban views, many2many fields only return a list of ids.
+ * We can implement return value of m2m fields like [(1,"Adminstration"),...].
+ */
var self = this;
- self._super.apply(this, arguments);
- if (this.dataset.model === 'project.project') {
- /* Set avatar title for members.
- In many2many fields, returns only list of ids.
- we can implement return value of m2m fields like [(1,"Adminstration"),...].
- */
- var members_ids = [];
- this.$element.find('.oe_kanban_project_avatars img').each(function() {
- members_ids.push($(this).data('member_id'));
- });
- var dataset = new openerp.web.DataSetSearch(this, 'res.users', self.session.context, [['id', 'in', _.uniq(members_ids)]]);
- dataset.read_slice(['id', 'name']).then(function(result) {
- _.each(result, function(v, k) {
- self.$element.find('.oe_kanban_project_avatars img[data-member_id=' + v.id + ']').attr('title', v.name).tipsy({
- offset: 10
- });
+ var members_ids = [];
+
+ // Collect members ids
+ self.$element.find('.oe_kanban_project_avatars img').each(function() {
+ members_ids.push($(this).data('member_id'));
+ });
+
+ // Find their matching names
+ var dataset = new openerp.web.DataSetSearch(self, 'res.users', self.session.context, [['id', 'in', _.uniq(members_ids)]]);
+ dataset.read_slice(['id', 'name']).then(function(result) {
+ _.each(result, function(v, k) {
+ // Set the proper value in the DOM
+ self.$element.find('.oe_kanban_project_avatars img[data-member_id=' + v.id + ']').attr('title', v.name).tipsy({
+ offset: 10
});
});
+ });
+ },
+ project_display_categ_names: function() {
+ /*
+ * Set proper names to project categories.
+ * In kanban views, many2many fields only return a list of ids.
+ * Therefore, we have to fetch the matching data by ourselves.
+ */
+ var self = this;
+ var categ_ids = [];
+
+ // Collect categories ids
+ self.$element.find('.oe_form_field_many2manytags_box').each(function() {
+ categ_ids.push($(this).data('categ_id'));
+ });
+
+ // Find their matching names
+ var dataset = new openerp.web.DataSetSearch(self, 'project.category', self.session.context, [['id', 'in', _.uniq(categ_ids)]]);
+ dataset.read_slice(['id', 'name']).then(function(result) {
+ _.each(result, function(v, k) {
+ // Set the proper value in the DOM and display the element
+ self.$element.find('.oe_form_field_many2manytags_box[data-categ_id=' + v.id + ']').text(v.name).toggle();
+ });
+ });
+ },
+ on_groups_started: function() {
+ var self = this;
+ self._super.apply(self, arguments);
+
+ if (self.dataset.model === 'project.project') {
+ self.project_display_members_names();
+ } else if (self.dataset.model === 'project.task') {
+ self.project_display_categ_names();
}
}
});