Anonymous avatar Anonymous committed d9d133c

initial commit

Comments (0)

Files changed (6)

+import test_customview
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+{
+    'name': 'Custom Web View',
+    'version': '1.0',
+    'category': 'Tools',
+    'description': """
+This module is supposed to demonstrate the implementation of an arbitrary custom view.
+
+It adds a new menu item under Settings/Customizations that shows a simple string sent to the server and passed back to the client.
+    """,
+    'author': 'Viktor Nagy',
+    'depends': ['board'],
+    'update_xml': ['custom_view.xml'],
+    'demo_xml': [],
+    'test': [],
+    'js': ['static/src/js/testview.js'],
+    'css': [],
+    'qweb': ["static/src/xml/*.xml"],
+    'installable': True,
+    'auto_install': False
+}
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data>
+	<record id="custom_view" model="res.widget">
+      <field name="title">Custom View</field>
+      <field name="content"><![CDATA[ 
+        /* This is a placeholder text 
+
+        It could be retrieved from the web client using a call like
+
+        <pre>
+          request.session.model('res.widget').read(
+            [int(widget_id)], ['content'], request.session.eval_context(request.context)
+        )[0]
+      </pre>
+
+        See the web_dashboard controller and js file for its usage.
+        */
+        ]]></field>
+    </record>
+
+    <record id="action_test_customview" model="ir.actions.client">
+      <field name="name">Custom View Widget</field>
+      <field name="tag">test.custom.view</field>
+      <field name="params" eval="{'widget_id': ref('test_customview.custom_view')}"/>
+    </record>
+    
+    <record id="menu_test_customview" model="ir.ui.menu">
+      <field name="name">Test View</field>
+      <field name="sequence" eval="1"/>
+      <field name="action" ref="action_test_customview"/>
+      <field name="parent_id" ref="base.menu_custom"/>
+    </record>
+</data>
+</openerp>

static/src/js/testview.js

+openerp.test_customview = function(openerp) {
+var QWeb = openerp.web.qweb;
+
+/** @namespace */
+openerp.test_customview = openerp.test_customview || {};
+
+/*
+ * Widgets
+ * This client action designed to be used as a dashboard widget display
+ * the html content of a res_widget given as argument
+ */
+openerp.web.client_actions.add( 'test.custom.view', 'openerp.test_customview.Widget');
+openerp.test_customview.Widget = openerp.web.View.extend(/** @lends openerp.test_customview.Widgets# */{
+    template: 'CustomWidget',
+    /**
+     * Initializes a "HomeWidget" client widget: handles the display of a given
+     * res.widget objects in an OpenERP view (mainly a dashboard).
+     *
+     * @constructs openerp.test_customview.Widget
+     * @extends openerp.web.View
+     *
+     * @param {Object} parent
+     * @param {Object} options
+     * @param {Number} options.widget_id
+     */
+    init: function (parent, options) {
+        this._super(parent);
+        this.widget_id = options.widget_id;
+    },
+    start: function () {
+        this._super();
+        var param = {"model": 'res.partner', "method": "say_hello", args: ['Hello']};
+        return this.rpc('/web/dataset/call', param).then(this.on_widget_loaded);
+    },
+    on_widget_loaded: function (widget) {
+        this.$element.html(QWeb.render('CustomWidget.content', {
+            response: widget.response
+        }));
+    }
+});
+
+};

static/src/xml/test_customview.xml

+<template>
+<div t-name="CustomWidget" class="oe-dashboard-home-widget"/>
+<t t-name="CustomWidget.content">
+    <h3><t t-esc="response"/></h3>
+</t>
+</template>

test_customview.py

+from osv import osv
+
+class res_partner(osv.osv):
+	_inherit = 'res.partner'
+	def say_hello(self, cr, uid, message):
+		return {'response': message}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.