[IMP] imrpved code to remove error of undefined record
[odoo/odoo.git] / addons / crm / static / src / js / crm_case_section.js
1 openerp.crm = function(openerp) {
2 var _t = openerp.web._t;
3     openerp.web_kanban.KanbanRecord.include({
4         on_card_clicked: function() {
5             if (this.view.dataset.model === 'crm.case.section') {
6                 this.$('.oe_kanban_crm_salesteams_list a').first().click();
7             } else {
8                 this._super.apply(this, arguments);
9             }
10         },
11     });
12     openerp.crm.SparklineBarWidget = openerp.web_kanban.AbstractField.extend({
13         className: "oe_sparkline_bar",
14         start: function() {
15             var self = this;
16             var title = this.$node.html();
17             setTimeout(function () {
18                 var value = _.pluck(self.field.value, 'value');
19                 var tooltips = _.pluck(self.field.value, 'tooltip');
20                 var currency_symbol = "";
21                 if (self.getParent()){
22                     currency_symbol = self.getParent().record.currency_symbol.raw_value;
23                 };
24                 self.$el.sparkline(value, {
25                     type: 'bar',
26                     barWidth: 5,
27                     tooltipFormat: _.str.sprintf("{{offset:offset}}: {{value}} %s",self.$el.closest("div[class='oe_salesteams_leads']").attr('class') ? _t('Lead(s)') : currency_symbol),
28                     tooltipValueLookups: {
29                         'offset': tooltips
30                     },
31                 });
32                 self.$el.tipsy({'delayIn': 3000, 'html': true, 'title': function(){return title}, 'gravity': 'n'});
33             }, 0);
34         },
35     });
36     openerp.web_kanban.fields_registry.add("sparkline_bar", "openerp.crm.SparklineBarWidget");
37
38 };