[IMP] add method session.url() to generate correct url
bzr revid: chs@openerp.com-20121114174150-9nhj50vftt4lrf0k
This commit is contained in:
parent
17c426870f
commit
eb5a5bf838
|
@ -903,7 +903,7 @@ instance.web.UserMenu = instance.web.Widget.extend({
|
||||||
if(res.company_id[0] > 1)
|
if(res.company_id[0] > 1)
|
||||||
topbar_name = _.str.sprintf("%s (%s)", topbar_name, res.company_id[1]);
|
topbar_name = _.str.sprintf("%s (%s)", topbar_name, res.company_id[1]);
|
||||||
self.$el.find('.oe_topbar_name').text(topbar_name);
|
self.$el.find('.oe_topbar_name').text(topbar_name);
|
||||||
var avatar_src = _.str.sprintf('%s/web/binary/image?session_id=%s&model=res.users&field=image_small&id=%s', self.session.prefix, self.session.session_id, self.session.uid);
|
var avatar_src = self.session.url('/web/binary/image', {model:'res.users', field: 'image_small', id: self.session.uid});
|
||||||
$avatar.attr('src', avatar_src);
|
$avatar.attr('src', avatar_src);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1320,7 +1320,7 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
url.url = this.get_url(url.url);
|
url.url = this.url(url.url, null);
|
||||||
var ajax = _.extend({
|
var ajax = _.extend({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
dataType: 'jsonp',
|
dataType: 'jsonp',
|
||||||
|
@ -1376,8 +1376,17 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
|
||||||
return deferred.done(set_sid);
|
return deferred.done(set_sid);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get_url: function (file) {
|
|
||||||
return this.prefix + file;
|
url: function(path, params) {
|
||||||
|
var qs = '';
|
||||||
|
if (!_.isNull(params)) {
|
||||||
|
params = _.extend(params || {}, {session_id: this.session_id});
|
||||||
|
if (this.httpsessionid) {
|
||||||
|
params.sid = this.httpsessionid;
|
||||||
|
}
|
||||||
|
qs = '?' + $.param(params);
|
||||||
|
}
|
||||||
|
return this.prefix + path + qs;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess
|
||||||
var self = this;
|
var self = this;
|
||||||
_.each(files, function (file) {
|
_.each(files, function (file) {
|
||||||
$('head').append($('<link>', {
|
$('head').append($('<link>', {
|
||||||
'href': self.get_url(file),
|
'href': self.url(file, null),
|
||||||
'rel': 'stylesheet',
|
'rel': 'stylesheet',
|
||||||
'type': 'text/css'
|
'type': 'text/css'
|
||||||
}));
|
}));
|
||||||
|
@ -210,11 +210,11 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess
|
||||||
load_js: function(files) {
|
load_js: function(files) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var d = $.Deferred();
|
var d = $.Deferred();
|
||||||
if(files.length != 0) {
|
if(files.length !== 0) {
|
||||||
var file = files.shift();
|
var file = files.shift();
|
||||||
var tag = document.createElement('script');
|
var tag = document.createElement('script');
|
||||||
tag.type = 'text/javascript';
|
tag.type = 'text/javascript';
|
||||||
tag.src = self.get_url(file);
|
tag.src = self.url(file, null);
|
||||||
tag.onload = tag.onreadystatechange = function() {
|
tag.onload = tag.onreadystatechange = function() {
|
||||||
if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done )
|
if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done )
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4956,8 +4956,12 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
|
||||||
var field = this.name;
|
var field = this.name;
|
||||||
if (this.options.preview_image)
|
if (this.options.preview_image)
|
||||||
field = this.options.preview_image;
|
field = this.options.preview_image;
|
||||||
url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
|
url = this.session.url('/web/binary/image', {
|
||||||
this.view.dataset.model +'&id=' + id + '&field=' + field + '&t=' + (new Date().getTime());
|
model: this.view.dataset.model,
|
||||||
|
id: id,
|
||||||
|
field: field,
|
||||||
|
t: (new Date().getTime()),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
url = this.placeholder;
|
url = this.placeholder;
|
||||||
}
|
}
|
||||||
|
@ -5017,7 +5021,7 @@ instance.web.form.FieldOne2ManyBinaryMultiFiles = instance.web.form.AbstractFiel
|
||||||
return _.map(this.get('value'), function (value) { return commands.link_to( value.id ); });
|
return _.map(this.get('value'), function (value) { return commands.link_to( value.id ); });
|
||||||
},
|
},
|
||||||
get_file_url: function (attachment) {
|
get_file_url: function (attachment) {
|
||||||
return instance.origin + '/web/binary/saveas?session_id=' + this.session.session_id + '&model=ir.attachment&field=datas&filename_field=datas_fname&id=' + attachment['id'];
|
return this.session.url('/web/binary/saveas', {model: 'ir.attachment', field: 'datas', filename_field: 'datas_fname', id: attachment['id']});
|
||||||
},
|
},
|
||||||
render_value: function () {
|
render_value: function () {
|
||||||
var render = $(instance.web.qweb.render('FieldBinaryFileUploader.files', {'widget': this}));
|
var render = $(instance.web.qweb.render('FieldBinaryFileUploader.files', {'widget': this}));
|
||||||
|
|
|
@ -2173,9 +2173,7 @@ instance.web.list.Binary = instance.web.list.Column.extend({
|
||||||
if (value && value.substr(0, 10).indexOf(' ') == -1) {
|
if (value && value.substr(0, 10).indexOf(' ') == -1) {
|
||||||
download_url = "data:application/octet-stream;base64," + value;
|
download_url = "data:application/octet-stream;base64," + value;
|
||||||
} else {
|
} else {
|
||||||
download_url = _.str.sprintf(
|
download_url = this.session.url('/web/binary/saveas', {model: options.model, field: this.id, id: options.id});
|
||||||
'/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d',
|
|
||||||
instance.session.session_id, options.model, this.id, options.id);
|
|
||||||
if (this.filename) {
|
if (this.filename) {
|
||||||
download_url += '&filename_field=' + this.filename;
|
download_url += '&filename_field=' + this.filename;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1102,11 +1102,11 @@ instance.web.Sidebar = instance.web.Widget.extend({
|
||||||
on_attachments_loaded: function(attachments) {
|
on_attachments_loaded: function(attachments) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var items = [];
|
var items = [];
|
||||||
var prefix = this.session.origin + '/web/binary/saveas?session_id=' + self.session.session_id + '&model=ir.attachment&field=datas&filename_field=name&id=';
|
var prefix = this.session.url('/web/binary/saveas', {model: 'ir.attachment', field: 'datas', filename_field: 'name'});
|
||||||
_.each(attachments,function(a) {
|
_.each(attachments,function(a) {
|
||||||
a.label = a.name;
|
a.label = a.name;
|
||||||
if(a.type === "binary") {
|
if(a.type === "binary") {
|
||||||
a.url = prefix + a.id + '&t=' + (new Date().getTime());
|
a.url = prefix + '&id=' + a.id + '&t=' + (new Date().getTime());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.items['files'] = attachments;
|
self.items['files'] = attachments;
|
||||||
|
|
|
@ -995,7 +995,7 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
|
||||||
id = escape(JSON.stringify(id));
|
id = escape(JSON.stringify(id));
|
||||||
if (options.preview_image)
|
if (options.preview_image)
|
||||||
field = options.preview_image;
|
field = options.preview_image;
|
||||||
url = instance.session.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id;
|
url = this.session.url('/web/binary/image', {model: model, field: field, id: id});
|
||||||
if (cache !== undefined) {
|
if (cache !== undefined) {
|
||||||
// Set the cache duration in seconds.
|
// Set the cache duration in seconds.
|
||||||
url += '&cache=' + parseInt(cache, 10);
|
url += '&cache=' + parseInt(cache, 10);
|
||||||
|
|
Loading…
Reference in New Issue