~therp-nl/openerp-web/7.0-lp1013636-x2m_honour_required_attribute

« back to all changes in this revision

Viewing changes to addons/web/static/src/js/chrome.js

[MERGE] from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
351
351
        return result;
352
352
    },
353
353
    /**
354
 
     * Waits until the new database is done creating, then unblocks the UI and
355
 
     * logs the user in as admin
356
 
     *
357
 
     * @param {Number} db_creation_id identifier for the db-creation operation, used to fetch the current installation progress
358
 
     * @param {Object} info info fields for this database creation
359
 
     * @param {String} info.db name of the database being created
360
 
     * @param {String} info.password super-admin password for the database
361
 
     */
362
 
    wait_for_newdb: function (db_creation_id, info) {
363
 
        var self = this;
364
 
        self.rpc('/web/database/progress', {
365
 
            id: db_creation_id,
366
 
            password: info.password
367
 
        }, function (result) {
368
 
            var progress = result[0];
369
 
            // I'd display a progress bar, but turns out the progress status
370
 
            // the server report kind-of blows goats: it's at 0 for ~75% of
371
 
            // the installation, then jumps to 75%, then jumps down to either
372
 
            // 0 or ~40%, then back up to 75%, then terminates. Let's keep that
373
 
            // mess hidden behind a not-very-useful but not overly weird
374
 
            // message instead.
375
 
            if (progress < 1) {
376
 
                setTimeout(function () {
377
 
                    self.wait_for_newdb(db_creation_id, info);
378
 
                }, 500);
379
 
                return;
380
 
            }
381
 
 
382
 
            var admin = result[1][0];
383
 
            setTimeout(function () {
384
 
                self.getParent().do_login(
385
 
                        info.db, admin.login, admin.password);
386
 
                self.destroy();
387
 
                self.unblockUI();
388
 
            });
389
 
        });
390
 
    },
391
 
    /**
392
354
     * Blocks UI and replaces $.unblockUI by a noop to prevent third parties
393
355
     * from unblocking the UI
394
356
     */
427
389
        self.$option_id.find("form[name=create_db_form]").validate({
428
390
            submitHandler: function (form) {
429
391
                var fields = $(form).serializeArray();
430
 
                self.blockUI();
431
392
                self.rpc("/web/database/create", {'fields': fields}, function(result) {
432
 
                    if (result.error) {
433
 
                        self.unblockUI();
434
 
                        self.display_error(result);
435
 
                        return;
436
 
                    }
437
393
                    if (self.db_list) {
438
394
                        self.db_list.push(self.to_object(fields)['db_name']);
439
395
                        self.db_list.sort();
440
396
                        self.getParent().set_db_list(self.db_list);
441
397
                    }
 
398
 
442
399
                    var form_obj = self.to_object(fields);
443
 
                    self.wait_for_newdb(result, {
444
 
                        password: form_obj['super_admin_pwd'],
445
 
                        db: form_obj['db_name']
446
 
                    });
 
400
                    self.getParent().do_login(
 
401
                            form_obj['db_name'],
 
402
                            'admin',
 
403
                            form_obj['create_admin_pwd']);
 
404
                    self.destroy();
447
405
                });
448
406
            }
449
407
        });
677
635
    init: function() {
678
636
        this._super.apply(this, arguments);
679
637
        this.has_been_loaded = $.Deferred();
 
638
        this.maximum_visible_links = 'auto'; // # of menu to show. 0 = do not crop, 'auto' = algo
680
639
    },
681
640
    start: function() {
682
641
        this._super.apply(this, arguments);
683
642
        this.$secondary_menus = this.getParent().$element.find('.oe_secondary_menus_container');
684
643
        this.$secondary_menus.on('click', 'a[data-menu]', this.on_menu_click);
 
644
        $('html').bind('click', this.do_hide_more);
685
645
    },
686
646
    do_reload: function() {
687
647
        var self = this;
692
652
        });
693
653
    },
694
654
    on_loaded: function(data) {
 
655
        var self = this;
695
656
        this.data = data;
696
657
        this.renderElement();
 
658
        this.limit_entries();
697
659
        this.$element.on('click', 'a[data-menu]', this.on_menu_click);
 
660
        this.$element.on('click', 'a.oe_menu_more_link', function() {
 
661
            self.$element.find('.oe_menu_more').toggle();
 
662
            return false;
 
663
        });
698
664
        this.$secondary_menus.html(QWeb.render("Menu.secondary", { widget : this }));
699
665
        // Hide second level submenus
700
666
        this.$secondary_menus.find('.oe_menu_toggler').siblings('.oe_secondary_submenu').hide();
701
667
        this.has_been_loaded.resolve();
702
668
    },
 
669
    limit_entries: function() {
 
670
        var maximum_visible_links = this.maximum_visible_links;
 
671
        if (maximum_visible_links === 'auto') {
 
672
            maximum_visible_links = this.auto_limit_entries();
 
673
        }
 
674
        if (maximum_visible_links < this.data.data.children.length) {
 
675
            var $more = $(QWeb.render('Menu.more')),
 
676
                $index = this.$element.find('li').eq(maximum_visible_links - 1);
 
677
            $index.after($more);
 
678
            $more.find('.oe_menu_more').append($index.next().nextAll());
 
679
        }
 
680
    },
 
681
    auto_limit_entries: function() {
 
682
        // TODO: auto detect overflow and bind window on resize
 
683
        var width = $(window).width();
 
684
        return Math.floor(width / 125);
 
685
    },
 
686
    do_hide_more: function() {
 
687
        this.$element.find('.oe_menu_more').hide();
 
688
    },
703
689
    /**
704
690
     * Opens a given menu by id, as if a user had browsed to that menu by hand
705
691
     * except does not trigger any event on the way
744
730
        }
745
731
    },
746
732
    on_menu_click: function(ev, id) {
 
733
        this.do_hide_more();
747
734
        id = id || 0;
748
735
        var $clicked_menu, manual = false;
749
736
 
856
843
                return;
857
844
            var func = new openerp.web.Model("res.users").get_func("read");
858
845
            return func(self.session.uid, ["name", "company_id"]).pipe(function(res) {
859
 
                // TODO: Only show company if multicompany in use
860
 
                self.$element.find('.oe_topbar_name').text(res.name + '/' + res.company_id[1]);
 
846
                // TODO: Show company if multicompany is in use
 
847
                var topbar_name = _.str.sprintf("%s (%s)", res.name, openerp.connection.db, res.company_id[1]);
 
848
                self.$element.find('.oe_topbar_name').text(topbar_name);
861
849
                return self.shortcut_load();
862
850
            });
863
851
        };
950
938
                }
951
939
            ]
952
940
        }).open();
953
 
       action_manager.appendTo(this.dialog);
 
941
       action_manager.appendTo(this.dialog.$element);
954
942
       action_manager.render(this.dialog);
955
943
    },
956
944
    on_menu_about: function() {