import urllib
import os
import pprint
+import re
import sys
import traceback
import uuid
response = werkzeug.wrappers.Response(request_id, headers=headers)
return response
+ @jsonrequest
+ def static_proxy(self, req, path):
+ #req.config.socket_port
+
+
+ #if not re.match('^/[^/]+/static/.*', path):
+ # return werkzeug.exceptions.BadRequest()
+
+ env = req.httprequest.environ
+ port = env['SERVER_PORT']
+
+ o = urllib.urlopen('http://127.0.0.1:%s%s' % (port, path))
+ return o.read()
class Root(object):
"""Root WSGI application for the OpenERP Web Client.
init: function(server) {
this._super();
var hostname = _('%s//%s').sprintf(location.protocol, location.host);
- this.server = (server == undefined) ? hostname : server;
+ this.server = _.rtrim((server == undefined) ? hostname : server, '/');
this.rpc_mode = (this.server == hostname) ? "oe-json" : "oe-jsonp";
this.debug = ($.deparam($.param.querystring()).debug != undefined);
this.session_id = false;
start: function() {
this.session_restore();
},
+
+ get_absolute_url: function(path) {
+ var r_has_protocol = /^https?:\/\//,
+ r_absolute_internal = /^\/[^\/]/; // starts with / (but not //)
+
+
+ if (r_has_protocol.test(path)) {
+ if (!_(path).startsWith(this.server + '/')) {
+ $.error('can only contact openerp.server');
+ }
+ absolute_url = path;
+ } else if (r_absolute_internal.test(path)) {
+ absolute_url = this.server + path;
+ } else { // relative url
+ // XXX is it correct to mix document.location and this.server ??
+ var parts = document.location.pathname.split('/');
+ parts.pop();
+ parts.push(path);
+ absolute_url = this.server + parts.join('/');
+ }
+ return absolute_url
+ },
+
/**
* Executes an RPC call, registering the provided callbacks.
*
self.user_context.lang.replace("_", "-") + ".js"
];
+ self.rpc('/web/webclient/qweblist', {"mods": modules}, self.do_load_qweb);
self.rpc('/web/webclient/csslist', {"mods": modules}, self.do_load_css);
self.rpc('/web/webclient/jslist', {"mods": modules}, function(files) {
self.do_load_js(file_list.concat(files));
});
- self.rpc('/web/webclient/qweblist', {"mods": modules}, self.do_load_qweb);
openerp._modules_loaded = true;
});
});
var self = this;
_.each(files, function (file) {
$('head').append($('<link>', {
- 'href': file,
+ 'href': self.get_absolute_url(file),
'rel': 'stylesheet',
'type': 'text/css'
}));
var file = files.shift();
var tag = document.createElement('script');
tag.type = 'text/javascript';
- tag.src = file;
+ tag.src = self.get_absolute_url(file);
tag.onload = tag.onreadystatechange = function() {
if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done )
return;
do_load_qweb: function(files) {
var self = this;
_.each(files, function(file) {
- openerp.web.qweb.add_template(file);
+ self.rpc({
+ //url: self.get_absolute_url(file),
+ url: '/web/jsonp/static_proxy',
+ async: false,
+ //dataType: 'text',
+
+ },
+ {
+ path: file,
+ },
+ function(xml) {
+ //function(result) {
+ // console.log('do_load_qweb', result);
+ // var xml = result.result;
+ //}).then(function(xml) {
+ openerp.web.qweb.add_template(_(xml).trim());
+ });
});
},
on_modules_loaded: function() {
// common preconditions checks
$.ajaxPrefilter("oe-json oe-jsonp", function(options, originalOptions, jqXHR) {
- console.log('use', options.dataType);
if (!$.isPlainObject(options.openerp)) {
console.error(options.openerp);
$.error('"openerp" option is required.');
}
- if (_(options.openerp.server).endsWith('/')) {
- options.openerp.server = options.openerp.server.substr(0, options.openerp.server.length-1);
- }
-
if (!$.isPlainObject(options.data)) {
$.error('data must not be serialized');
}
}
+
var max_url_length = options.max_url_length || 1000,
absolute_url, full_url;
-
+ /*
var r_has_protocol = /^https?:\/\//,
r_absolute_internal = /^\/[^\/]/; // starts with / (but not //)
parts.push(options.url);
absolute_url = options.openerp.server + parts.join('/');
}
-
+ // */
+
+ var absolute_url = options.openerp.get_absolute_url(options.url);
/// now, made the same url changes that jQuery will do...
var rquery = /\?/,
// if nothing was replaced, add timestamp to the end
full_url = ret + ((ret === full_url) ? (rquery.test(full_url) ? "&" : "?") + "_=" + ts : "");
}
-
- console.log('absolute_url', absolute_url);
- console.log('full_url', full_url);
options.url = absolute_url;
$.ajaxTransport("oe-jsonp", function(options, originalOptions, jqXHR) {
- console.log('real oe-jsonp', options);
var $iframe = null;
var $form = $('<form>')
.attr('method', 'POST')
.appendTo($('body'))
;
- console.log($form);
-
function cleanUp() {
if ($iframe) {
$iframe.unbind("load").attr("src", "javascript:false;").remove();
// the first bind is fired up when the iframe is added to the DOM
$iframe.bind('load', function() {
- //console.log('bind1', this);
// the second bind is fired up when the result of the form submission is received
$iframe.unbind('load').bind('load', function() {
- //console.log('bind2', this);
-
// we cannot access the content of remote iframe.
// but we don't care, we try to get the result in any cases