openerp.web.dialog = function(element) {
var result = element.dialog.apply(element, _.rest(_.toArray(arguments)));
- result.dialog("widget").addClass("openerp");
+ result.dialog("widget").addClass("openerp2");
return result;
}
return result;
},
/**
- * Waits until the new database is done creating, then unblocks the UI and
- * logs the user in as admin
- *
- * @param {Number} db_creation_id identifier for the db-creation operation, used to fetch the current installation progress
- * @param {Object} info info fields for this database creation
- * @param {String} info.db name of the database being created
- * @param {String} info.password super-admin password for the database
- */
- wait_for_newdb: function (db_creation_id, info) {
- var self = this;
- self.rpc('/web/database/progress', {
- id: db_creation_id,
- password: info.password
- }, function (result) {
- var progress = result[0];
- // I'd display a progress bar, but turns out the progress status
- // the server report kind-of blows goats: it's at 0 for ~75% of
- // the installation, then jumps to 75%, then jumps down to either
- // 0 or ~40%, then back up to 75%, then terminates. Let's keep that
- // mess hidden behind a not-very-useful but not overly weird
- // message instead.
- if (progress < 1) {
- setTimeout(function () {
- self.wait_for_newdb(db_creation_id, info);
- }, 500);
- return;
- }
-
- var admin = result[1][0];
- setTimeout(function () {
- self.getParent().do_login(
- info.db, admin.login, admin.password);
- self.destroy();
- self.unblockUI();
- });
- });
- },
- /**
* Blocks UI and replaces $.unblockUI by a noop to prevent third parties
* from unblocking the UI
*/
self.$option_id.find("form[name=create_db_form]").validate({
submitHandler: function (form) {
var fields = $(form).serializeArray();
- self.blockUI();
self.rpc("/web/database/create", {'fields': fields}, function(result) {
- if (result.error) {
- self.unblockUI();
- self.display_error(result);
- return;
- }
if (self.db_list) {
self.db_list.push(self.to_object(fields)['db_name']);
self.db_list.sort();
self.getParent().set_db_list(self.db_list);
}
+
var form_obj = self.to_object(fields);
- self.wait_for_newdb(result, {
- password: form_obj['super_admin_pwd'],
- db: form_obj['db_name']
- });
+ self.getParent().do_login(
+ form_obj['db_name'],
+ 'admin',
+ form_obj['create_admin_pwd']);
+ self.destroy();
});
}
});
submitHandler: function (form) {
var $form = $(form),
fields = $form.serializeArray(),
- $db_list = $form.find('select[name=drop_db]'),
+ $db_list = $form.find('[name=drop_db]'),
db = $db_list.val();
- if (!confirm("Do you really want to delete the database: " + db + " ?")) {
+ if (!db || !confirm("Do you really want to delete the database: " + db + " ?")) {
return;
}
self.rpc("/web/database/drop", {'fields': fields}, function(result) {
* @param parent
*/
template: 'Menu',
+ init: function() {
+ this._super.apply(this, arguments);
+ this.has_been_loaded = $.Deferred();
+ this.maximum_visible_links = 'auto'; // # of menu to show. 0 = do not crop, 'auto' = algo
+ },
+ start: function() {
+ this._super.apply(this, arguments);
+ this.$secondary_menus = this.getParent().$element.find('.oe_secondary_menus_container');
+ this.$secondary_menus.on('click', 'a[data-menu]', this.on_menu_click);
+ $('html').bind('click', this.do_hide_more);
+ },
do_reload: function() {
var self = this;
return this.rpc("/web/menu/load", {}, this.on_loaded).then(function () {
});
},
on_loaded: function(data) {
+ var self = this;
this.data = data;
- this.render_element();
- if (!this.$secondary_menus && this.getParent()) {
- // TODO: create Widget openerp.web.SubMenu
- this.$secondary_menus = this.getParent().$element.find('.oe_secondary_menus_container');
- this.$element.add(this.$secondary_menus).on('click', 'a[data-menu]', this.on_menu_click);
- }
+ this.renderElement();
+ this.limit_entries();
+ this.$element.on('click', 'a[data-menu]', this.on_menu_click);
+ this.$element.on('click', 'a.oe_menu_more_link', function() {
+ self.$element.find('.oe_menu_more').toggle();
+ return false;
+ });
this.$secondary_menus.html(QWeb.render("Menu.secondary", { widget : this }));
// Hide second level submenus
this.$secondary_menus.find('.oe_menu_toggler').siblings('.oe_secondary_submenu').hide();
+ this.has_been_loaded.resolve();
+ },
+ limit_entries: function() {
+ var maximum_visible_links = this.maximum_visible_links;
+ if (maximum_visible_links === 'auto') {
+ maximum_visible_links = this.auto_limit_entries();
+ }
+ if (maximum_visible_links < this.data.data.children.length) {
+ var $more = $(QWeb.render('Menu.more')),
+ $index = this.$element.find('li').eq(maximum_visible_links - 1);
+ $index.after($more);
+ $more.find('.oe_menu_more').append($index.next().nextAll());
+ }
+ },
+ auto_limit_entries: function() {
+ // TODO: auto detect overflow and bind window on resize
+ var width = $(window).width();
+ return Math.floor(width / 125);
+ },
+ do_hide_more: function() {
+ this.$element.find('.oe_menu_more').hide();
},
/**
* Opens a given menu by id, as if a user had browsed to that menu by hand
* except does not trigger any event on the way
*
- * @param {Number} menu_id database id of the terminal menu to select
+ * @param {Number} id database id of the terminal menu to select
*/
open_menu: function (id) {
var $clicked_menu, $sub_menu, $main_menu;
}
}
},
+ open_action: function (id) {
+ var menu_id, $menu = this.$element.add(this.$secondary_menus).find('a[data-action-id=' + id + ']');
+ if (menu_id = $menu.data('menu')) {
+ this.open_menu(menu_id);
+ }
+ },
on_menu_click: function(ev, id) {
+ this.do_hide_more();
id = id || 0;
var $clicked_menu, manual = false;
id = $clicked_menu.data('menu');
}
+ this.trigger('menuClicked', id, $clicked_menu);
+
if (id) {
this.open_menu(id);
this.current_menu = id;
this.session.active_id = id;
- this.rpc('/web/menu/action', {'menu_id': id}, this.on_menu_action_loaded);
+ var action_id = $clicked_menu.data('action-id');
+ if (action_id) {
+ this.on_action(action_id);
+ }
}
if (ev) {
ev.stopPropagation();
}
$sub_menu.show();
},
- on_menu_action_loaded: function(data) {
- var self = this;
- if (data.action.length) {
- var action = data.action[0][2];
- action.from_menu = true;
- self.on_action(action);
- } else {
- self.on_action({type: 'null_action'});
- }
- },
on_action: function(action) {
}
});
-openerp.web.DropDownMenu = openerp.web.Widget.extend(/** @lends openerp.web.DropDownMenu# */{
- template: "DropDownMenu",
+openerp.web.UserMenu = openerp.web.Widget.extend(/** @lends openerp.web.UserMenu# */{
+ template: "UserMenu",
/**
- * @constructs openerp.web.DropDownMenu
+ * @constructs openerp.web.UserMenu
* @extends openerp.web.Widget
*
* @param parent
return;
var func = new openerp.web.Model("res.users").get_func("read");
return func(self.session.uid, ["name", "company_id"]).pipe(function(res) {
- // TODO: Only show company if multicompany in use
- self.$element.find('.oe_topbar_name').text(res.name + '/' + res.company_id[1]);
+ // TODO: Show company if multicompany is in use
+ var topbar_name = _.str.sprintf("%s (%s)", res.name, openerp.connection.db, res.company_id[1]);
+ self.$element.find('.oe_topbar_name').text(topbar_name);
+ var avatar_src = _.str.sprintf('%s/web/binary/image?session_id=%s&model=res.users&field=avatar&id=%s', self.session.prefix, self.session.session_id, self.session.uid);
+ $avatar.attr('src', avatar_src);
return self.shortcut_load();
});
};
$(sc.binding).bind({
'add': function (e, attrs) {
shortcuts_ds.create(attrs, function (out) {
- var shortcut = QWeb.render('DropDownMenu.shortcut', {
+ var shortcut = QWeb.render('UserMenu.shortcut', {
shortcuts : [{
name : attrs.name,
id : out.result,
sc.splice(0, sc.length);
sc.push.apply(sc, shortcuts);
- $(QWeb.render('DropDownMenu.shortcut', {'shortcuts': shortcuts}))
+ $(QWeb.render('UserMenu.shortcut', {'shortcuts': shortcuts}))
.appendTo(self.$element.find('.oe_dropdown_options'));
});
},
}
]
}).open();
- action_manager.appendTo(this.dialog);
+ action_manager.appendTo(this.dialog.$element);
action_manager.render(this.dialog);
},
on_menu_about: function() {
},
start: function() {
var self = this;
- this.$element.addClass("openerp openerp2");
+ this.$element.addClass("openerp2");
if (jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) {
this.$element.addClass("kitten-mode-activated");
this.$element.delegate('img.oe-record-edit-link-img', 'hover', function(e) {
self.$element.toggleClass('clark-gable');
});
}
- this.session.bind().then(function() {
+ this.session.bind_session().then(function() {
if (!self.session.session_is_valid()) {
self.show_login();
}
this.session.on_session_valid.add(function() {
self.show_application();
- self.dropdown_menu.do_update();
+ self.user_menu.do_update();
self.menu.do_reload();
if(self.action_manager)
self.action_manager.destroy();
document.title = version_label;
}
});
+ this.$element.on('mouseenter', '.oe_systray > div:not([data-tipsy=true])', function() {
+ $(this).attr('data-tipsy', 'true').tipsy().trigger('mouseenter');
+ });
},
show_login: function() {
var self = this;
self.menu = new openerp.web.Menu(self);
self.menu.replace(this.$element.find('.oe_menu_placeholder'));
self.menu.on_action.add(this.proxy('on_menu_action'));
- self.dropdown_menu = new openerp.web.DropDownMenu(self);
- self.dropdown_menu.replace(this.$element.find('.oe_dropdown_menu_placeholder'));
- self.dropdown_menu.on_menu_logout.add(this.proxy('on_logout'));
- self.dropdown_menu.on_action.add(this.proxy('on_menu_action'));
+ self.user_menu = new openerp.web.UserMenu(self);
+ self.user_menu.replace(this.$element.find('.oe_user_menu_placeholder'));
+ self.user_menu.on_menu_logout.add(this.proxy('on_logout'));
+ self.user_menu.on_action.add(this.proxy('on_menu_action'));
},
show_common: function() {
var self = this;
self.menu.on_menu_click(null, action.menu_id);
});
}
+ },
+ set_content_full_screen: function(fullscreen) {
+ if (fullscreen)
+ $(".oe_webclient", this.$element).addClass("oe_content_full_screen");
+ else
+ $(".oe_webclient", this.$element).removeClass("oe_content_full_screen");
}
});
start: function() {
var self = this;
- this.am.appendTo(this.$element.addClass('openerp'));
+ this.am.appendTo(this.$element.addClass('openerp openerp2'));
return this.rpc("/web/action/load", { action_id: this.action_id }, function(result) {
var action = result.result;
action.flags = _.extend({
var sc = document.getElementsByTagName('script');
currentScript = sc[sc.length-1];
}
- openerp.connection.bind(origin).then(function () {
+ openerp.connection.bind_session(origin).then(function () {
openerp.connection.session_authenticate(dbname, login, key, true).then(function () {
var client = new openerp.web.EmbeddedClient(action, options);
client.insertAfter(currentScript);