Example #1
0
    _render_value: function(v) {
        var value = this.value;
        var max_value = this.max_value;
        if(!isNaN(v)) {
            if(this.edit_max_value) {
                max_value = v;
            } else {
                value = v;
            }
        }
        value = value || 0;
        max_value = max_value || 0;

        var widthComplete;
        if(value <= max_value) {
            widthComplete = value/max_value * 100;
        } else {
            widthComplete = max_value/value * 100;
        }

        this.$('.o_progress').toggleClass('o_progress_overflow', value > max_value);
        this.$('.o_progressbar_complete').css('width', widthComplete + '%');

        if(this.readonly) {
            if(max_value !== 100) {
                this.$('.o_progressbar_value').html(utils.human_number(value) + " / " + utils.human_number(max_value));
            } else {
                this.$('.o_progressbar_value').html(utils.human_number(value) + "%");
            }
        } else if(isNaN(v)) {
            this.$('.o_progressbar_value').val(this.edit_max_value ? max_value : value);
        }
    }
 build_button: function(channel, options, session, rule){
     var button = new ChatButton(null, channel, options, session);
     button.appendTo($("body"));
     var auto_popup_cookie = utils.get_cookie('im_livechat_auto_popup') ? JSON.parse(utils.get_cookie('im_livechat_auto_popup')) : true;
     if (rule.action === 'auto_popup' && auto_popup_cookie){
         setTimeout(function() {
             button.click();
         }, rule.auto_popup_timer*1000);
     }
 }
Example #3
0
    do_tip: function() {
        var self = this;

        if(!$(this.highlight_selector).length > 0 || !$(this.highlight_selector).is(":visible")) {
            return false;
        }

        for (var i = 0; i < this.triggers.length; i++) {
            if(!$(this.triggers[i]).length > 0) {
                return false;
            }
        }

        this.$element = $(this.highlight_selector).first();
        if (utils.float_is_zero(this.$element.height(), 1) || utils.float_is_zero(this.$element.width(), 1)) {
            var $images = this.$element.find('img');
            if ($images.length > 0) {
                $images.first().load(function() {
                    var t = new Tip(self.tip);
                    t.do_tip();
                    bus.trigger('image_loaded');
                });
            }
            return false;
        }

        if (!this.$element.next().hasClass('oe_breathing')) {
            this.$breathing = $("<div>", { class: 'oe_breathing' });
            this.$element.after(this.$breathing);
        } else {
            this.$breathing = this.$element.next();
        }
        this._set_breathing_position();

        this.$breathing.on('click', function(e) {
            e.stopImmediatePropagation();
            self.$breathing.addClass('oe_explode');
            self.trigger_tip();
        });

        // resize
        bus.on('resize', this, function() {
            self._set_breathing_position();
        });

        bus.on('image_loaded', this, function() {
            self._set_breathing_position();
        });

        bus.on('please_reposition_tip', this, function() {
            self._set_breathing_position();
        });

        return true;
    },
Example #4
0
    QUnit.test('unaccent', function (assert) {
        assert.expect(3);

        var singleCharacters = utils.unaccent("ⱮɀꝾƶⱵȥ");
        var doubledCharacters = utils.unaccent("DZDŽꝎꜩꝡƕ");
        var caseSensetiveCharacters = utils.unaccent("ⱮɀꝾƶⱵȥ", true);

        assert.strictEqual("mzgzhz", singleCharacters);
        assert.strictEqual("dzdzootzvyhv", doubledCharacters);
        assert.strictEqual("MzGzHz", caseSensetiveCharacters);
    });
Example #5
0
 return function (state) {
     if(state.lengthComputable) {
         deferred.notify({
             h_loaded: utils.human_size(state.loaded),
             h_total : utils.human_size(state.total),
             loaded  : state.loaded,
             total   : state.total,
             pcent   : Math.round((state.loaded/state.total)*100)
         });
     }
 };
Example #6
0
 this.manager._session_defs[mail_channel.id].then(function(){
     // start the polling
     bus.bus.add_channel(mail_channel.uuid);
     bus.bus.start_polling();
     // add the automatic welcome message
     if(welcome_message){
         self.send_welcome_message();
     }
     // create the cookies
     utils.set_cookie('im_livechat_auto_popup', JSON.stringify(false), 60*60);
     utils.set_cookie('im_livechat_session', JSON.stringify(mail_channel), 60*60);
 })
Example #7
0
    __init__: function () {
        var args = py.PY_parseArgs(arguments, [
            ['days', zero], ['seconds', zero], ['microseconds', zero],
            ['milliseconds', zero], ['minutes', zero], ['hours', zero],
            ['weeks', zero]
        ]);

        var d = 0, s = 0, m = 0;
        var days = args.days.toJSON() + args.weeks.toJSON() * 7;
        var seconds = args.seconds.toJSON()
                    + args.minutes.toJSON() * 60
                    + args.hours.toJSON() * 3600;
        var microseconds = args.microseconds.toJSON()
                         + args.milliseconds.toJSON() * 1000;

        // Get rid of all fractions, and normalize s and us.
        // Take a deep breath <wink>.
        var daysecondsfrac = utils.modf(days, function (dayfrac, days) {
            d = days;
            if (dayfrac) {
                return utils.modf(dayfrac * 24 * 3600, function (dsf, dsw) {
                    s = dsw;
                    return dsf;
                });
            }
            return 0;
        });

        var secondsfrac = utils.modf(seconds, function (sf, s) {
            seconds = s;
            return sf + daysecondsfrac;
        });
        utils.divmod(seconds, 24*3600, function (days, seconds) {
            d += days;
            s += seconds;
        });
        // seconds isn't referenced again before redefinition

        microseconds += secondsfrac * 1e6;
        utils.divmod(microseconds, 1000000, function (seconds, microseconds) {
            utils.divmod(seconds, 24*3600, function (days, seconds) {
                d += days;
                s += seconds;
                m += Math.round(microseconds);
            });
        });

        // Carrying still possible here?

        this.days = d;
        this.seconds = s;
        this.microseconds = m;
    },
 click_close: function(event) {
     if(!this.feedback && (this.get('messages').length > 1)){
         this.feedback = new Feedback(this);
         this.$(".oe_im_chatview_content").empty();
         this.$(".oe_im_chatview_input").prop('disabled', true);
         this.feedback.appendTo( this.$(".oe_im_chatview_content"));
         // bind event to close conversation
         this.feedback.on("feedback_sent", this, this.click_close);
     }else{
         this._super.apply(this, arguments);
         utils.set_cookie(COOKIE_NAME, "", -1);
         utils.set_cookie('im_livechat_auto_popup', JSON.stringify(false), 60*60);
     }
 },
Example #9
0
    facet_for: function (value) {
        var self = this;
        if (value instanceof Array) {
            if (value.length === 2 && _.isString(value[1])) {
                return $.when(facet_from(this, value));
            }
            utils.assert(value.length <= 1,
                   _t("M2O search fields do not currently handle multiple default values"));
            // there are many cases of {search_default_$m2ofield: [id]}, need
            // to handle this as if it were a single value.
            value = value[0];
        }
        var context = pyeval.eval('contexts', [this.searchview.dataset.get_context()]);

        return this._rpc({
                model: this.attrs.relation,
                method: 'name_get',
                args: [value],
                context: context,
            })
            .then(function (names) {
                if (_(names).isEmpty()) { return null; }
                return facet_from(self, names[0]);
            });
    },
Example #10
0
 _processFieldsView: function (viewInfo) {
     var viewFields = this._processFields(viewInfo.type, viewInfo.arch, viewInfo.fields);
     viewInfo.fieldsInfo = {};
     viewInfo.fieldsInfo[viewInfo.type] = viewFields;
     utils.deepFreeze(viewInfo.fields);
     return viewInfo;
 },
Example #11
0
    init: function () {
        this._super.apply(this, arguments);

        this.product_data = {};
        this.comparelist_product_ids = JSON.parse(utils.get_cookie('comparelist_product_ids') || '[]');
        this.product_compare_limit = 4;
    },
Example #12
0
 _makeHeader: function (value, domain, root, i, j, parent_header) {
     var total = _t("Total");
     var title = value.length ? value[value.length - 1] : total;
     var path, parent;
     if (parent_header) {
         path = parent_header.path.concat(title);
         parent = parent_header;
     } else {
         path = [total].concat(value.slice(i,j-1));
         parent = value.length ? this._findPathInTree(root, path) : null;
     }
     var header = {
         id: utils.generateID(),
         expanded: false,
         domain: domain || [],
         children: [],
         path: value.length ? parent.path.concat(title) : [title]
     };
     this.data.headers[header.id] = header;
     header.root = root || header;
     if (parent) {
         parent.children.push(header);
         parent.expanded = true;
     }
     return header;
 },
Example #13
0
    open_chat: function () {
        var self = this;
        var cookie = utils.get_cookie('im_livechat_session');
        var def;
        clearTimeout(this.auto_popup_timeout);
        if (cookie) {
            def = $.when(JSON.parse(cookie));
        } else {
            this.messages = []; // re-initialize messages cache
            def = session.rpc('/im_livechat/get_session', {
                channel_id : this.options.channel_id,
                anonymous_name : this.options.default_username,
            }, {shadow: true});
        }
        def.then(function (channel) {
            if (!channel || !channel.operator_pid) {
                alert(_t("None of our collaborators seems to be available, please try again later."));
            } else {
                self.channel = channel;
                self.open_chat_window(channel);
                self.send_welcome_message();
                self.render_messages();

                bus.add_channel(channel.uuid);
                bus.start_polling();

                utils.set_cookie('im_livechat_session', JSON.stringify(channel), 60*60);
                utils.set_cookie('im_livechat_auto_popup', JSON.stringify(false), 60*60);
            }
        });
    },
Example #14
0
 utils.divmod(this.seconds, 60, function (m, s) {
     utils.divmod(m, 60, function (h, m) {
         hh = h;
         mm = m;
         ss = s;
     });
 });
Example #15
0
File: mrp.js Project: 10537/odoo
    _render: function () {
        var self = this;
        var $pdfViewer = this.$('.o_form_pdf_controls').children().add(this.$('.o_pdfview_iframe'));
        var $selectUpload = this.$('.o_select_file_button').first();
        var $iFrame = this.$('.o_pdfview_iframe');

        $iFrame.on('load', function () {
            self.PDFViewerApplication = this.contentWindow.window.PDFViewerApplication;
            self._disableButtons(this);
        });
        if (this.mode === "readonly" && this.value) {
            $iFrame.attr('src', this._getURI());
        } else {
            if (this.value) {
                var binSize = utils.is_bin_size(this.value);
                $pdfViewer.removeClass('o_hidden');
                $selectUpload.addClass('o_hidden');
                if (binSize) {
                    $iFrame.attr('src', this._getURI());
                }
            } else {
                $pdfViewer.addClass('o_hidden');
                $selectUpload.removeClass('o_hidden');
            }
        }
    },
Example #16
0
 _handleNotification: function  (notification){
     if (this._livechat && (notification[0] === this._livechat.getUUID())) {
         if (notification[1]._type === 'history_command') { // history request
             var cookie = utils.get_cookie(LIVECHAT_COOKIE_HISTORY);
             var history = cookie ? JSON.parse(cookie) : [];
             session.rpc('/im_livechat/history', {
                 pid: this._livechat.getOperatorPID()[0],
                 channel_uuid: this._livechat.getUUID(),
                 page_history: history,
             });
         } else if (notification[1].info === 'typing_status') {
             var isWebsiteUser = notification[1].is_website_user;
             if (isWebsiteUser) {
                 return; // do not handle typing status notification of myself
             }
             var partnerID = notification[1].partner_id;
             if (notification[1].is_typing) {
                 this._livechat.registerTyping({ partnerID: partnerID });
             } else {
                 this._livechat.unregisterTyping({ partnerID: partnerID });
             }
         } else { // normal message
             this._addMessage(notification[1]);
             this._renderMessages();
             if (this._chatWindow.isFolded() || !this._chatWindow.isAtBottom()) {
                 this._livechat.incrementUnreadCounter();
             }
         }
     }
 },
Example #17
0
                return self._openChatWindow().then(function () {
                    self._sendWelcomeMessage();
                    self._renderMessages();
                    self.call('bus_service', 'addChannel', self._livechat.getUUID());
                    self.call('bus_service', 'startPolling');

                    utils.set_cookie('im_livechat_session', JSON.stringify(self._livechat.toData()), 60*60);
                    utils.set_cookie('im_livechat_auto_popup', JSON.stringify(false), 60*60);
                    if (livechatData.operator_pid[0]) {
                        // livechatData.operator_pid contains a tuple (id, name)
                        // we are only interested in the id
                        var operatorPidId = livechatData.operator_pid[0];
                        var oneWeek = 7*24*60*60;
                        utils.set_cookie('im_livechat_previous_operator_pid', operatorPidId, oneWeek);
                    }
                });
Example #18
0
 utils.divmod(microseconds, 1000000, function (seconds, microseconds) {
     utils.divmod(seconds, 24*3600, function (days, seconds) {
         d += days;
         s += seconds;
         m += Math.round(microseconds);
     });
 });
Example #19
0
 _.each(map, function(val, key) {
     var tmp = self.__getterSetterInternalMap[key];
     if (tmp === val)
         return;
     // seriously, why are you doing this? it is obviously a stupid design.
     // the properties mixin should not be concerned with handling fields details.
     // this also has the side effect of introducing a dependency on utils.  Todo:
     // remove this, or move it elsewhere.  Also, learn OO programming.
     if (key === 'value' && self.field && self.field.type === 'float' && tmp && val){
         var digits = self.field.digits;
         if (digits !== 0){
             digits = digits ? digits[1] : 2;
             if (utils.float_is_zero(tmp - val, digits)) {
                 return;
             }
         }
     }
     changed = true;
     self.__getterSetterInternalMap[key] = val;
     if (! options.silent)
         self.trigger("change:" + key, self, {
             oldValue: tmp,
             newValue: val
         });
 });
Example #20
0
 utils.divmod(n, DI4Y, function (_n4, n) {
     n4 = _n4;
     utils.divmod(n, 365, function (_n1, n) {
         n1 = _n1;
         n0 = n;
     });
 });
Example #21
0
/**
 * Returns a string representing an integer.  If the value is false, then we
 * return an empty string.
 *
 * @param {integer|false} value
 * @param {Object} [field]
 *        a description of the field (note: this parameter is ignored)
 * @param {Object} [options] additional options
 * @param {boolean} [options.isPassword=false] if true, returns '********'
 * @param {function} [options.humanReadable] if returns true,
 *   formatFloat acts like utils.human_number
 * @returns {string}
 */
function formatInteger(value, field, options) {
    options = options || {};
    if (options.isPassword) {
        return _.str.repeat('*', String(value).length);
    }
    if (!value && value !== 0) {
        // previously, it returned 'false'. I don't know why.  But for the Pivot
        // view, I want to display the concept of 'no value' with an empty
        // string.
        return "";
    }
    if (options.humanReadable && options.humanReadable(value)) {
        return utils.human_number(value, options.decimals, options.minDigits, options.formatterCallback);
    }
    return utils.insert_thousand_seps(_.str.sprintf('%d', value));
}
Example #22
0
 make_header: function (data_pt, root, i, j, parent_header) {
     var total = _t("Total");
     var attrs = data_pt.attributes,
         value = attrs.value,
         title = value.length ? value[value.length - 1] : total;
     var path, parent;
     if (parent_header) {
         path = parent_header.path.concat(title);
         parent = parent_header;
     } else {
         path = [total].concat(value.slice(i,j-1));
         parent = value.length ? find_path_in_tree(root, path) : null;
     } 
     var header = {
         id: utils.generate_id(),
         expanded: false,
         domain: data_pt.model._domain,
         children: [],
         path: value.length ? parent.path.concat(title) : [title]
     };
     this.headers[header.id] = header;
     header.root = root || header;
     if (parent) {
         parent.children.push(header);
         parent.expanded = true;
     }
     return header;
 },
Example #23
0
        this.options.validate().then(function() {
            var value = $input.val().split("-");
            var min = utils.confine(parseInt(value[0], 10), 1, self.state.size);
            var max = utils.confine(parseInt(value[1], 10), 1, self.state.size);

            if (!isNaN(min)) {
                self.state.current_min = min;
                if (!isNaN(max)) {
                    self.state.limit = utils.confine(max-min+1, 1, self.state.size);
                } else {
                    // The state has been given as a single value -> set the limit to 1
                    self.state.limit = 1;
                }
                self.trigger('pager_changed', _.clone(self.state));
            }
        }).always(function() {
Example #24
0
 return $.when(this._mentionPrefetchedPartners).then(function (prefetchedPartners) {
     // filter prefetched partners with the given search string
     var suggestions = [];
     var limit = self.options.mentionFetchLimit;
     var searchRegexp = new RegExp(_.str.escapeRegExp(utils.unaccent(search)), 'i');
     _.each(prefetchedPartners, function (partners) {
         if (limit > 0) {
             var filteredPartners = _.filter(partners, function (partner) {
                 return partner.email && searchRegexp.test(partner.email) ||
                     partner.name && searchRegexp.test(utils.unaccent(partner.name));
             });
             if (filteredPartners.length) {
                 suggestions.push(filteredPartners.slice(0, limit));
                 limit -= filteredPartners.length;
             }
         }
     });
     if (!suggestions.length && !self.options.mentionPartnersRestricted) {
         // no result found among prefetched partners, fetch other suggestions
         suggestions = self._mentionFetchThrottled(
             'res.partner',
             'get_mention_suggestions',
             { limit: limit, search: search }
         );
     }
     return $.when(suggestions).then(function (suggestions) {
         //add im_status on suggestions
         _.each(suggestions, function (suggestionsSet) {
             _.each(suggestionsSet, function (suggestion) {
                 suggestion.im_status = self.call('mail_service', 'getImStatus', { partnerID: suggestion.id });
             });
         });
         return suggestions;
     });
 });
Example #25
0
    _onMouseMovePicker: function (ev) {
        if (!this.pickerFlag) {
            return;
        }

        var offset = this.$colorpickerArea.offset();
        var top = ev.pageY - offset.top;
        var left = ev.pageX - offset.left;
        var saturation = Math.round(100 * left / this.$colorpickerArea.width());
        var lightness = Math.round(100 * (this.$colorpickerArea.height() - top) / this.$colorpickerArea.height());
        saturation = utils.confine(saturation, 0, 100);
        lightness = utils.confine(lightness, 0, 100);

        this._updateHsl(this.colorComponents.hue, saturation, lightness);
        this._updateUI();
    },
Example #26
0
    start: function () {
        var def = this._super.apply(this, arguments);

        var params = _.pick(this.$el.data(), 'href', 'height', 'tabs', 'small_header', 'hide_cover', 'show_facepile');
        if (!params.href) {
            return def;
        }
        params.width = utils.confine(this.$el.width(), 180, 500);

        var src = $.param.querystring('https://www.facebook.com/plugins/page.php', params);
        this.$iframe = $('<iframe/>', {
            src: src,
            width: params.width,
            height: params.height,
            css: {
                border: 'none',
                overflow: 'hidden',
            },
            scrolling: 'no',
            frameborder: '0',
            allowTransparency: 'true',
        });
        this.$el.append(this.$iframe);

        return def;
    },
Example #27
0
    _processFields: function (viewType, arch, fields) {
        var self = this;
        var fieldsInfo = Object.create(null);
        utils.traverse(arch, function (node) {
            if (typeof node === 'string') {
                return false;
            }
            if (!_.isObject(node.attrs.modifiers)) {
                node.attrs.modifiers = node.attrs.modifiers ? JSON.parse(node.attrs.modifiers) : {};
            }
            if (!_.isObject(node.attrs.options) && node.tag === 'button') {
                node.attrs.options = node.attrs.options ? JSON.parse(node.attrs.options) : {};
            }
            if (node.tag === 'field') {
                fieldsInfo[node.attrs.name] = self._processField(viewType,
                    fields[node.attrs.name], node.attrs ? _.clone(node.attrs) : {});

                if (fieldsInfo[node.attrs.name].fieldDependencies) {
                    var deps = fieldsInfo[node.attrs.name].fieldDependencies;
                    for (var dependency_name in deps) {
                        if (!(dependency_name in fieldsInfo)) {
                            fieldsInfo[dependency_name] = {'name': dependency_name, 'type': deps[dependency_name].type, 'options':  deps[dependency_name].options || {}};
                        }
                    }
                }
                return false;
            }
            return node.tag !== 'arch';
        });
        return fieldsInfo;
    },
Example #28
0
        def.then(function (channel) {
            if (!channel || !channel.operator_pid) {
                alert(_t("None of our collaborators seems to be available, please try again later."));
            } else {
                self.channel = channel;
                self.open_chat_window(channel);
                self.send_welcome_message();
                self.render_messages();

                bus.add_channel(channel.uuid);
                bus.start_polling();

                utils.set_cookie('im_livechat_session', JSON.stringify(channel), 60*60);
                utils.set_cookie('im_livechat_auto_popup', JSON.stringify(false), 60*60);
            }
        }).always(function () {
Example #29
0
 start: function () {
     this.$el.text(this.options.button_text);
     var small_screen = config.device.size_class === config.device.SIZES.XS;
     if (this.history) {
         _.each(this.history.reverse(), this.add_message.bind(this));
         this.open_chat();
     } else if (!small_screen && this.rule.action === 'auto_popup') {
         var auto_popup_cookie = utils.get_cookie('im_livechat_auto_popup');
         if (!auto_popup_cookie || JSON.parse(auto_popup_cookie)) {
             this.auto_popup_timeout = setTimeout(this.open_chat.bind(this), this.rule.auto_popup_timer*1000);
         }
     }
     bus.on('notification', this, function (notifications) {
         var self = this;
         _.each(notifications, function (notification) {
             if (self.channel && (notification[0] === self.channel.uuid)) {
                 self.add_message(notification[1]);
                 self.render_messages();
                 if (self.chat_window.folded || !self.chat_window.thread.is_at_bottom()) {
                     self.chat_window.update_unread(self.chat_window.unread_msgs+1);
                 }
             }
         });
     });
     return this._super();
 },
Example #30
0
 this._cannedTimeout = setTimeout(function () {
     var cannedResponses = self.call('mail_service', 'getCannedResponses');
     var matches = fuzzy.filter(utils.unaccent(search), _.pluck(cannedResponses, 'source'));
     var indexes = _.pluck(matches.slice(0, self.options.mentionFetchLimit), 'index');
     def.resolve(_.map(indexes, function (index) {
         return cannedResponses[index];
     }));
 }, 500);