openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #05005
[Merge] lp:~openerp-dev/openobject-client-web/sidebar-feature-niv into lp:~openerp-dev/openobject-client-web/trunk-proto61
Nicolas Vanhoren (OpenERP) has proposed merging lp:~openerp-dev/openobject-client-web/sidebar-feature-niv into lp:~openerp-dev/openobject-client-web/trunk-proto61.
Requested reviews:
Antony Lesuisse (al-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client-web/sidebar-feature-niv/+merge/56180
Sidebar.
--
https://code.launchpad.net/~openerp-dev/openobject-client-web/sidebar-feature-niv/+merge/56180
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-client-web/trunk-proto61.
=== modified file 'addons/base/controllers/main.py'
--- addons/base/controllers/main.py 2011-04-01 10:45:00 +0000
+++ addons/base/controllers/main.py 2011-04-04 14:36:38 +0000
@@ -171,6 +171,54 @@
'domain': domain,
'group_by': group_by_sequence
}
+
+def load_actions_from_ir_values(req, key, key2, models, meta, context):
+ Values = req.session.model('ir.values')
+ actions = Values.get(key, key2, models, meta, context)
+
+ for _, _, action in actions:
+ # values come from the server, we can just eval them
+ if isinstance(action['context'], basestring):
+ action['context'] = eval(
+ action['context'],
+ req.session.evaluation_context()) or {}
+
+ if isinstance(action['domain'], basestring):
+ action['domain'] = eval(
+ action['domain'],
+ req.session.evaluation_context(
+ action['context'])) or []
+ fix_view_modes(action)
+ return actions
+
+def fix_view_modes(action):
+ """ For historical reasons, OpenERP has weird dealings in relation to
+ view_mode and the view_type attribute (on window actions):
+
+ * one of the view modes is ``tree``, which stands for both list views
+ and tree views
+ * the choice is made by checking ``view_type``, which is either
+ ``form`` for a list view or ``tree`` for an actual tree view
+
+ This methods simply folds the view_type into view_mode by adding a
+ new view mode ``list`` which is the result of the ``tree`` view_mode
+ in conjunction with the ``form`` view_type.
+
+ TODO: this should go into the doc, some kind of "peculiarities" section
+
+ :param dict action: an action descriptor
+ :returns: nothing, the action is modified in place
+ """
+ if action.pop('view_type') != 'form':
+ return
+
+ action['view_mode'] = ','.join(
+ mode if mode != 'tree' else 'list'
+ for mode in action['view_mode'].split(','))
+ action['views'] = [
+ [id, mode if mode != 'tree' else 'list']
+ for id, mode in action['views']
+ ]
class Menu(openerpweb.Controller):
_cp_path = "/base/menu"
@@ -215,55 +263,11 @@
@openerpweb.jsonrequest
def action(self, req, menu_id):
- Values = req.session.model('ir.values')
- actions = Values.get('action', 'tree_but_open', [('ir.ui.menu', menu_id)], False, {})
-
- for _, _, action in actions:
- # values come from the server, we can just eval them
- if isinstance(action['context'], basestring):
- action['context'] = eval(
- action['context'],
- req.session.evaluation_context()) or {}
-
- if isinstance(action['domain'], basestring):
- action['domain'] = eval(
- action['domain'],
- req.session.evaluation_context(
- action['context'])) or []
-
- self.fix_view_modes(action)
+ actions = load_actions_from_ir_values(req,'action', 'tree_but_open',
+ [('ir.ui.menu', menu_id)], False, {})
return {"action": actions}
- def fix_view_modes(self, action):
- """ For historical reasons, OpenERP has weird dealings in relation to
- view_mode and the view_type attribute (on window actions):
-
- * one of the view modes is ``tree``, which stands for both list views
- and tree views
- * the choice is made by checking ``view_type``, which is either
- ``form`` for a list view or ``tree`` for an actual tree view
-
- This methods simply folds the view_type into view_mode by adding a
- new view mode ``list`` which is the result of the ``tree`` view_mode
- in conjunction with the ``form`` view_type.
-
- TODO: this should go into the doc, some kind of "peculiarities" section
-
- :param dict action: an action descriptor
- :returns: nothing, the action is modified in place
- """
- if action.pop('view_type') != 'form':
- return
-
- action['view_mode'] = ','.join(
- mode if mode != 'tree' else 'list'
- for mode in action['view_mode'].split(','))
- action['views'] = [
- [id, mode if mode != 'tree' else 'list']
- for id, mode in action['views']
- ]
-
class DataSet(openerpweb.Controller):
_cp_path = "/base/dataset"
@@ -469,6 +473,15 @@
def load(self, req, model, view_id):
fields_view = self.fields_view_get(req.session, model, view_id, 'search')
return {'fields_view': fields_view}
+
+class SideBar(View):
+ _cp_path = "/base/sidebar"
+
+ @openerpweb.jsonrequest
+ def get_actions(self, request, model, object_id=0):
+ result = load_actions_from_ir_values(request, "action", "client_action_multi",
+ [[model, object_id]], False, {})
+ return result
class Action(openerpweb.Controller):
=== modified file 'addons/base/static/src/css/base.css'
--- addons/base/static/src/css/base.css 2011-04-04 11:25:35 +0000
+++ addons/base/static/src/css/base.css 2011-04-04 14:36:38 +0000
@@ -443,3 +443,26 @@
.openerp .ui-widget {
font-size: 1em;
}
+
+/* Sidebar */
+.openerp .view-manager-main-sidebar {
+ vertical-align: top;
+}
+
+.openerp .view-manager-main-sidebar .sidebar-main-div {
+ border: solid 1px #1F1F1F;
+ border-bottom-width: 0;
+}
+
+.openerp .view-manager-main-sidebar ul {
+ list-style-type: none;
+ margin: 0;
+ padding: 0;
+ width: 120px;
+ border-bottom: solid 1px #1F1F1F;
+}
+
+.openerp .view-manager-main-sidebar li {
+ padding: 3px;
+}
+
=== modified file 'addons/base/static/src/js/form.js'
--- addons/base/static/src/js/form.js 2011-04-04 11:25:35 +0000
+++ addons/base/static/src/js/form.js 2011-04-04 14:36:38 +0000
@@ -16,8 +16,9 @@
* @param {openerp.base.DataSet} dataset the dataset this view will work with
* @param {String} view_id the identifier of the OpenERP view object
*/
- init: function(session, element_id, dataset, view_id) {
+ init: function(view_manager, session, element_id, dataset, view_id) {
this._super(session, element_id);
+ this.view_manager = view_manager;
this.dataset = dataset;
this.model = dataset.model;
this.view_id = view_id;
=== modified file 'addons/base/static/src/js/list.js'
--- addons/base/static/src/js/list.js 2011-04-01 11:50:05 +0000
+++ addons/base/static/src/js/list.js 2011-04-04 14:36:38 +0000
@@ -3,8 +3,9 @@
openerp.base.views.add('list', 'openerp.base.ListView');
openerp.base.ListView = openerp.base.Controller.extend({
- init: function(session, element_id, dataset, view_id) {
+ init: function(view_manager, session, element_id, dataset, view_id) {
this._super(session, element_id);
+ this.view_manager = view_manager;
this.dataset = dataset;
this.model = dataset.model;
this.view_id = view_id;
@@ -66,6 +67,14 @@
self.$table.setGridWidth(self.$element.width());
self.$element.children().show();
}).trigger('resize');
+
+ // sidebar stuff
+ this.rpc("/base/sidebar/get_actions",
+ {"model": this.model}, function(result) {
+ self.view_manager.sidebar.sections.push({elements:
+ _.map(result, function(x) {return {text:x[2].name, action:x}; })});
+ self.view_manager.sidebar.refresh();
+ });
},
do_fill_table: function(records) {
this.log("do_fill_table");
=== modified file 'addons/base/static/src/js/search.js'
--- addons/base/static/src/js/search.js 2011-04-04 11:25:35 +0000
+++ addons/base/static/src/js/search.js 2011-04-04 14:36:38 +0000
@@ -1,8 +1,9 @@
openerp.base.search = function(openerp) {
openerp.base.SearchView = openerp.base.Controller.extend({
- init: function(session, element_id, dataset, view_id, defaults) {
+ init: function(view_manager, session, element_id, dataset, view_id, defaults) {
this._super(session, element_id);
+ this.view_manager = view_manager;
this.dataset = dataset;
this.model = dataset.model;
this.view_id = view_id;
@@ -388,8 +389,10 @@
var _this = this;
openerp.base.search.add_expand_listener(this.$element);
this.add_group();
- this.$element.find('.searchview_extended_add_group').click(function () {
+ this.$element.find('.searchview_extended_add_group').click(function (e) {
_this.add_group();
+ e.stopPropagation();
+ e.preventDefault();
});
},
get_context: function() {
@@ -421,12 +424,16 @@
this._super();
var _this = this;
this.add_prop();
- this.$element.find('.searchview_extended_add_proposition').click(function () {
+ this.$element.find('.searchview_extended_add_proposition').click(function (e) {
_this.add_prop();
+ e.stopPropagation();
+ e.preventDefault();
});
var delete_btn = this.$element.find('.searchview_extended_delete_group');
delete_btn.click(function (e) {
_this.stop();
+ e.stopPropagation();
+ e.preventDefault();
});
},
get_domain: function() {
@@ -474,9 +481,11 @@
start: function () {
this._super();
var self = this;
- this.$element.click(function () {
+ this.$element.click(function (e) {
$(this).toggleClass('enabled');
self.view.do_toggle_filter(self);
+ e.stopPropagation();
+ e.preventDefault();
});
},
/**
@@ -772,8 +781,10 @@
_this.changed();
});
var delete_btn = this.$element.find('.searchview_extended_delete_prop');
- delete_btn.click(function () {
+ delete_btn.click(function (e) {
_this.stop();
+ e.stopPropagation();
+ e.preventDefault();
});
},
changed: function() {
=== modified file 'addons/base/static/src/js/views.js'
--- addons/base/static/src/js/views.js 2011-04-04 11:38:03 +0000
+++ addons/base/static/src/js/views.js 2011-04-04 14:36:38 +0000
@@ -41,8 +41,16 @@
this.active_view = null;
// this.views = { "list": { "view_id":1234, "controller": instance} }
this.views = {};
+ this.sidebar = new openerp.base.Sidebar(null);
},
start: function() {
+ this.$element.find('.view-manager-main-sidebar').html(this.sidebar.render());
+ this.sidebar.start();
+ },
+ stop: function() {
+ // should be replaced by automatic destruction implemented in BaseWidget
+ this.sidebar.stop();
+ this._super();
},
/**
* Asks the view manager to switch visualization mode.
@@ -57,7 +65,7 @@
if (!view.controller) {
// Lazy loading of views
var controller = new (openerp.base.views.get_object(view_type))(
- this.session, this.element_id + "_view_" + view_type, this.dataset, view.view_id);
+ this, this.session, this.element_id + "_view_" + view_type, this.dataset, view.view_id);
view_promise = controller.start();
this.views[view_type].controller = controller;
}
@@ -110,7 +118,7 @@
}
var searchview = this.searchview = new openerp.base.SearchView(
- this.session, this.element_id + "_search",
+ this, this.session, this.element_id + "_search",
this.dataset, action.search_view_id[0] || false,
this.search_defaults());
searchview.on_search.add(function() {
@@ -255,7 +263,33 @@
}
});
+openerp.base.Sidebar = openerp.base.BaseWidget.extend({
+ template: "ViewManager.sidebar",
+ init: function(parent) {
+ this._super(parent);
+ this.sections = [];
+ },
+ refresh: function() {
+ this.$element.html(QWeb.render("ViewManager.sidebar.internal", this));
+ var self = this;
+ this.$element.find("a").click(function(e) {
+ $this = jQuery(this);
+ var i = $this.attr("data-i");
+ var j = $this.attr("data-i");
+ var action = self.sections[i].elements[j];
+ // TODO: do something with the action
+ e.stopPropagation();
+ e.preventDefault();
+ });
+ },
+ start: function() {
+ this._super();
+ this.refresh();
+ }
+});
+
openerp.base.views.add('calendar', 'openerp.base.CalendarView');
+
openerp.base.CalendarView = openerp.base.Controller.extend({
start: function () {
this._super();
=== modified file 'addons/base/static/src/xml/base.xml'
--- addons/base/static/src/xml/base.xml 2011-04-04 11:25:35 +0000
+++ addons/base/static/src/xml/base.xml 2011-04-04 14:36:38 +0000
@@ -125,18 +125,26 @@
</div>
</t>
<t t-name="ViewManager">
- <!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" -->
- <div class="views-switchers">
+ <table class="view-manager-main-table">
+ <tr>
+ <td class="view-manager-main-content">
+ <!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" -->
+ <div class="views-switchers">
+ <t t-foreach="views" t-as="view">
+ <button type="button" t-att-data-view-type="view[1]">
+ <t t-esc="view[1]"/>
+ </button>
+ </t>
+ </div>
+ <div t-attf-id="#{prefix}_search"/>
<t t-foreach="views" t-as="view">
- <button type="button" t-att-data-view-type="view[1]">
- <t t-esc="view[1]"/>
- </button>
+ <div t-attf-id="#{prefix}_view_#{view[1]}"/>
</t>
- </div>
- <div t-attf-id="#{prefix}_search"/>
- <t t-foreach="views" t-as="view">
- <div t-attf-id="#{prefix}_view_#{view[1]}"/>
- </t>
+ </td>
+ <td class="view-manager-main-sidebar">
+ </td>
+ </tr>
+ </table>
</t>
<t t-name="ListView">
<!--
@@ -422,4 +430,22 @@
<t t-name="SearchView.extended_search.proposition.char">
<input t-att-id="element_id"/>
</t>
+<t t-name="ViewManager.sidebar">
+ <div t-att-id="element_id" class="sidebar-main-div">
+
+ </div>
+</t>
+<t t-name="ViewManager.sidebar.internal">
+ <t t-set="i" t-value="0"/>
+ <t t-foreach="sections" t-as="section">
+ <ul>
+ <t t-set="j" t-value="0"/>
+ <t t-foreach="section.elements" t-as="element">
+ <li><a t-att-data-i="i" t-att-data-j="j" href="#"><t t-esc="element.text"/></a></li>
+ <t t-set="j+1" t-value="0"/>
+ </t>
+ </ul>
+ <t t-set="i" t-value="i+1"/>
+ </t>
+</t>
</templates>
=== modified file 'addons/base/test/test_menu.py'
--- addons/base/test/test_menu.py 2011-03-31 15:25:31 +0000
+++ addons/base/test/test_menu.py 2011-04-04 14:36:38 +0000
@@ -111,7 +111,7 @@
}
changed = action.copy()
del action['view_type']
- self.menu.fix_view_modes(changed)
+ base.controllers.main.fix_view_modes(changed)
self.assertEqual(changed, action)
@@ -123,7 +123,7 @@
"view_id": False,
"view_mode": "tree,form,calendar"
}
- self.menu.fix_view_modes(action)
+ base.controllers.main.fix_view_modes(action)
self.assertEqual(action, {
"views": [[False, "list"], [False, "form"],
@@ -141,7 +141,7 @@
"view_id": False,
"view_mode": "tree,form,calendar"
}
- self.menu.fix_view_modes(action)
+ base.controllers.main.fix_view_modes(action)
self.assertEqual(action, {
"views": [[False, "list"], [False, "form"],
Follow ups