odoo.define(['web.core', 'web.form_widgets', 'web.Model', 'web.utils', 'web.WebClient'], function (require) { "use strict"; var core = require('web.core'); var form_widgets = require('web.form_widgets'); var Model = require('web.Model'); var utils = require('web.utils'); var WebClient = require('web.WebClient'); var bus = core.bus; var Class = core.Class; var Tip = Class.extend({ init: function() { var self = this; self.tips = []; self.tip_mutex = new utils.Mutex(); self.$overlay = null; self.$element = null; var Tips = new Model('web.tip'); Tips.query(['title', 'description', 'action_id', 'model', 'type', 'mode', 'trigger_selector', 'highlight_selector', 'end_selector', 'end_event', 'placement', 'is_consumed']) .all().then(function(tips) { self.tips = tips; }) ; core.bus.on('action', this, function(action) { self.on_action(action); }); bus.on('view_shown', this, function(view) { if (_.keys(view.fields_view).length === 0) { view.on('view_loaded', this, function(fields_view) { self.on_view(view); }); } else { self.on_view(view); } view.on('switch_mode', this, function() { }); }); bus.on('view_switch_mode', this, function(viewManager, mode) { self.on_switch(viewManager, mode); }); bus.on('form_view_shown', this, function(formView) { self.on_form_view(formView); }); bus.on('form_view_saved', this, function(formView) { self.on_form_view(formView); }); }, // stub on_action: function(action) { var self = this; var action_id = action.id; var model = action.res_model; }, on_view: function(view) { var self = this; var fields_view = view.fields_view; var action_id = view.ViewManager.action ? view.ViewManager.action.id : null; var model = fields_view.model; // kanban if(fields_view.type === 'kanban') { var dataset_def = $.Deferred(); var groups_def = $.Deferred(); view.on("kanban_dataset_processed", self, function() { var length = view.dataset.ids.length; dataset_def.resolve(length); }); view.on('kanban_groups_processed', self, function() { groups_def.resolve(); }); dataset_def.done(function(length) { self.eval_tip(action_id, model, fields_view.type); }); groups_def.done(function() { self.eval_tip(action_id, model, fields_view.type); }); } else if (fields_view.type === 'tree') { view.on('view_list_rendered', self, function() { self.eval_tip(action_id, model, fields_view.type); }); } else if (view.hasOwnProperty('editor')) { view.on('view_list_rendered', self, function() { self.reposition(); }); } }, on_form_view: function(formView) { var self = this; var model = formView.model; var type = formView.datarecord.type ? formView.datarecord.type : null; var mode = 'form'; formView.on('view_content_has_changed', self, _.once(function() { self.eval_tip(null, model, mode, type); })); if ($('.oe_chatter').length > 0) { core.bus.on('chatter_messages_fetched', this, _.once(function () { self.eval_tip(null, model, mode, type); })); } else { self.eval_tip(null, model, mode, type); } }, // stub on_switch: function (viewManager, mode) { var self = this; var action = viewManager.action; var action_id = action.id; var model = action.res_model; }, eval_tip: function(action_id, model, mode, type) { var self = this; var filter = {}; var valid_tips = []; var tips = []; if (action_id) { valid_tips = _.filter(self.tips, function (tip) { return tip.action_id[0] === action_id; }); } filter.model = model; filter.mode = mode; tips = _.where(self.tips, filter); if (type) { tips = _.filter(tips, function(tip) { if (!tip.type) { return true; } return tip.type === type; }); } valid_tips = _.uniq(valid_tips.concat(tips)); _.each(valid_tips, function(tip) { if (!tip.is_consumed) { self.add_tip(tip); } }); }, add_tip: function(tip) { var self = this; self.tip_mutex.exec(function() { if (!tip.is_consumed) { return $.when(self.do_tip(tip)); } }); }, do_tip: function (tip) { var self = this; var def = $.Deferred(); var Tips = new Model('web.tip'); var highlight_selector = tip.highlight_selector; var triggers = tip.trigger_selector ? tip.trigger_selector.split(',') : []; var trigger_tip = true; if(!$(highlight_selector).length > 0 || !$(highlight_selector).is(":visible")) { return def.reject(); } for (var i = 0; i < triggers.length; i++) { if(!$(triggers[i]).length > 0) { trigger_tip = false; } } if (trigger_tip) { self.$element = $(highlight_selector).first(); if (self.$element.height() === 0 || self.$element.width() === 0) { var $images = self.$element.find('img'); if ($images.length > 0) { $images.first().load(function() { self.add_tip(tip); }); } return def.reject(); } self.scroll_to_tip(); self.$helper = $("