[IMP] commment
[odoo/odoo.git] / addons / mass_mailing / static / src / js / mass_mailing.js
1 openerp.mass_mailing = function (instance) {
2     var _t = instance.web._t;
3     openerp.mass_mailing = function(openerp) {
4         openerp.web_kanban.KanbanRecord.include({
5             on_card_clicked: function (event) {
6                 if (this.view.dataset.model === 'mail.mass_mailing.campaign') {
7                     this.$('.oe_mailings').click();
8                 } else {
9                     this._super.apply(this, arguments);
10                 }
11             },
12         });
13     };
14
15     instance.web.form.CharDomainButton = instance.web.form.AbstractField.extend({
16         template: 'CharDomainButton',
17         init: function(field_manager, node) {
18             this._super.apply(this, arguments);
19         },
20         start: function() {
21             var self=this;
22             this._super.apply(this, arguments);
23             $('button', this.$el).on('click', self.on_click);
24             this.set_button();
25         },
26         set_button: function() {
27             if (this.get('value')) {
28                 // TODO: rpc to copute X
29                 $('.oe_domain_count', this.$el).text('X records selected');
30                 $('button span', this.$el).text(' Change selection');
31             } else {
32                 $('.oe_domain_count', this.$el).text('0 record selected');
33                 $('button span', this.$el).text(' Select records');
34             };
35         },
36         on_click: function(ev) {
37             var self = this;
38             var model = this.options.model || this.field_manager.get_field_value(this.options.model_field);
39             this.pop = new instance.web.form.SelectCreatePopup(this);
40             this.pop.select_element(
41                 model, {title: 'Select records...'},
42                 [], this.build_context());
43             this.pop.on("elements_selected", self, function() {
44                 var self2 = this;
45                 var search_data = this.pop.searchview.build_search_data()
46                 instance.web.pyeval.eval_domains_and_contexts({
47                     domains: search_data.domains,
48                     contexts: search_data.contexts,
49                     group_by_seq: search_data.groupbys || []
50                 }).then(function (results) {
51                     // if selected IDS change domain
52                     var domain = self2.pop.dataset.domain.concat(results.domain || []);
53                     self.set_value(JSON.stringify(domain))
54                 });
55             });
56             event.preventDefault();
57         },
58         set_value: function(value_) {
59             var self = this;
60             this.set('value', value_ || false);
61             this.set_button();
62          },
63     });
64
65     instance.web.form.widgets = instance.web.form.widgets.extend(
66         {'char_domain': 'instance.web.form.CharDomainButton'}
67     );
68
69 };