[IMP] web_rpc example
bzr revid: al@openerp.com-20110818233811-yiee3czhbtc6p3ob
This commit is contained in:
parent
47e709eb73
commit
056a91f724
|
@ -323,7 +323,6 @@ openerp.base.CallbackEnabled = openerp.base.Class.extend({
|
|||
openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.base.Session# */{
|
||||
/**
|
||||
* @constructs
|
||||
* @param element_id to use for exception reporting
|
||||
* @param server
|
||||
* @param port
|
||||
*/
|
||||
|
@ -344,6 +343,7 @@ openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.b
|
|||
this.context = {};
|
||||
this.shortcuts = [];
|
||||
this.active_id = null;
|
||||
this.session = this;
|
||||
},
|
||||
start: function() {
|
||||
this.session_restore();
|
||||
|
|
|
@ -537,6 +537,7 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({
|
|||
*/
|
||||
read_slice: function (fields, options, callback) {
|
||||
var self = this;
|
||||
var options = options || {};
|
||||
var offset = options.offset || 0;
|
||||
return this.rpc('/base/dataset/search_read', {
|
||||
model: this.model,
|
||||
|
|
|
@ -78,15 +78,13 @@ openerp.base_default_home = function (openerp) {
|
|||
});
|
||||
},
|
||||
install_module: function (module_name) {
|
||||
var Modules = new openerp.base.DataSetSearch(
|
||||
this, 'ir.module.module', null,
|
||||
[['name', '=', module_name], ['state', '=', 'uninstalled']]),
|
||||
Upgrade = new openerp.base.DataSet(this, 'base.module.upgrade');
|
||||
var Modules = new openerp.base.DataSetSearch( this, 'ir.module.module', null, [['name', '=', module_name], ['state', '=', 'uninstalled']]);
|
||||
var Upgrade = new openerp.base.DataSet(this, 'base.module.upgrade');
|
||||
|
||||
$.blockUI({
|
||||
message: '<img src="/base_default_home/static/src/img/throbber.gif">'
|
||||
});
|
||||
Modules.read_slice(['id'], function (records) {
|
||||
Modules.read_slice(['id'], {}, function (records) {
|
||||
if (!(records.length === 1)) { return; }
|
||||
Modules.call('state_update',
|
||||
[_.pluck(records, 'id'), 'to install', ['uninstalled']],
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html style="height: 100%">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<title>OpenERP RPC example</title>
|
||||
<title>OpenERP web_rpc example</title>
|
||||
<link rel="stylesheet" href="/base/static/src/css/base-ie7.css" type="text/css"/>
|
||||
|
||||
<link rel="stylesheet" href="/base/static/src/css/base-ie7.css" type="text/css"/>
|
||||
|
@ -15,37 +15,40 @@
|
|||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$("#ex1but").bind("click",function(){
|
||||
eval($("#ex1").html());
|
||||
eval($("#ex1").text());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>OpenERP web_rpc module examples</h1>
|
||||
<h2>Example 1: Display all res_users in an html table <button id="ex1but">Run it !</button> </h2>
|
||||
<h1>OpenERP web_rpc examples</h1>
|
||||
<h2>Example 1: Display a list of defined ir.model <button id="ex1but">Run it !</button> </h2>
|
||||
<h3>Code: </h3>
|
||||
<pre>
|
||||
<script type="text/javascript" src="/base/webclient/js?mods=web_rpc"></script>
|
||||
<script type="text/javascript">
|
||||
<pre id="ex1" class="run">
|
||||
QWeb = new QWeb2.Engine();
|
||||
var o_db = openerp.init();
|
||||
var o_sess = new o_db.base.Session();
|
||||
o_sess.debug = 1;
|
||||
o_sess.session_login("web-trunk", "admin", "admin", function() {
|
||||
var o_ds = new o_db.base.DataSet(o_sess,"res.users",{});
|
||||
// search for res.users
|
||||
//o_ds.sear()
|
||||
// read res.users
|
||||
// display them
|
||||
$("#ex1res").html(o_sess.debug.toString());
|
||||
});
|
||||
var c = openerp.init(); // get a new webclient
|
||||
c._modules_loaded = true; // Hack to prevent loading of additional modules
|
||||
|
||||
var s = new c.base.Session(); // setup a Session
|
||||
s.session_login("web-trunk", "admin", "admin", function() {
|
||||
|
||||
var ds = new c.base.DataSetSearch(s, "ir.model"); // DataSetSearch used to search, read
|
||||
ds.read_slice(['name','model'], {}, function(users){
|
||||
for(var i in users) {
|
||||
$("#ex1res").append("<li>" + users[i].model + " (" + users[i].name + ") </li>")
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
</pre></script>
|
||||
</pre>
|
||||
<h3>div id="ex1res" to output results:</h3>
|
||||
<h3>Div for output:</h3>
|
||||
<div id="ex1res" style="border: 1px solid black;">
|
||||
|
||||
</div>
|
||||
<h2>Help me to complete this example page on <a href="http://bazaar.launchpad.net/~openerp/openerp-web/trunk/view/head:/addons/web_rpc/static/src/example.html">launchpad</a></h2>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
Loading…
Reference in New Issue