Odoo Help

2

How to use widget="url" in tree view

By
Narayanamurthy
on 9/4/14, 8:56 AM 5,152 views

I Have website field in tree view, need to create link onclick of the wesite field...

 widget="url" is working fine in form view, but not in tree view

2
Praveen Kumar
On 9/4/14, 9:09 AM

Hi narayan

First download and install the Web/URL widget module and use widget="url"

 

1
Vinay
On 9/4/14, 10:12 AM

If the email address format doesn't contains "http://", it doesnt work

0
Dr Obx
On 4/14/15, 6:30 PM

This is maybe not perfect example but if it doesn't work you can fix it or built something what will work :)

As an example based on existing widget I've built for myself a new widget to create a link to skype so you can run skype straight from Odoo (Customer page or Human resorces :) ) just clicking on link to contact with your customers, also i made vendor support and local support page links based on this widget so it is possible and quiet easy - I'm not a programmer too ;)

So in my case I added at the end of /addons/web/static/js/view_form.js line somwhere around 6400 after "instance.web.form.widgets = new instance.web.Registry({"

this line to create a new instance in registry

" 'skype' : 'instance.web.form.FieldSkype', "

and sowhere around line 2600 before:

"instance.web.form.FieldUrl = instance.web.form.FieldChar.extend({"

this block of code:

"instance.web.form.FieldSkype = instance.web.form.FieldChar.extend({

template: 'FieldUrl',

initialize_content: function() {

this._super();

var $button = this.$el.find('button');

$button.click(this.on_button_clicked);

this.setupFocus($button);

},

render_value: function() {

if (!this.get("effective_readonly")) {

this._super();

} else {

var tmp = this.get('value');

var s = /(\w+):(.+)|^\.{0,2}\//.exec(tmp);

if (!s) {

tmp = "http://" + this.get('value');

}

var suf = document.getElementById('id');

if (suf = 'skype'){ var suf_x = 'skype:'; tmp = suf_x + this.get('value') + '?call';}

var text = this.get('value') ? this.node.attrs.text || tmp : '';

this.$el.find('a').attr('href', tmp).text(this.get('value'));

}

},

on_button_clicked: function() {

if (!this.get('value')) {

this.do_warn(_t("Resource Error"), _t("This resource is empty"));

} else {

var url = $.trim(this.get('value'));

if(/^www\./i.test(url))

url = 'skype:'+url+'?call';

window.close(url);

}

}

});"

and in XML file:

<field name="your_field_name" id="skype" widget="skype"/> - it will create a input box where you have to put skype nick.

(of course "your_field_name" needs to be defined in your_module.py)

'skype': fields.char('Skype'), - old API

skype = fields.Char('Skype') - new API

This solution works perfect for me. Same way you can create other useful widget extensions ;)

For example i created a simple connection to ebayshop, product name is automatically pulled from field "name" and added to the link making a search key on ebayshop (http://stores.ebay.co.uk/CharlesComputers/_i.html?_nkw="here is added a product name"). This solution is not the most elegant but it works :)

Example of Instance for ebayshop:

"instance.web.form.FieldEbay = instance.web.form.FieldChar.extend({

template: 'FieldUrl',

initialize_content: function() {

this._super();

var $button = this.$el.find('button');

$button.click(this.on_button_clicked);

this.setupFocus($button); },

render_value: function() {

if (!this.get("effective_readonly")) {

this._super();  } else {  var tmp = this.get('value');

var s = /(\w+):(.+)|^\.{0,2}\//.exec(tmp);

if (!s) {  tmp = "http://" + this.get('value'); }

var suf = document.getElementById('id');

if (suf = 'ebay'){ var suf_x = 'http://stores.ebay.co.uk/Your_Ebay_shop_name/_i.html?_nkw='; tmp = suf_x + this.get('value');}

var text = this.get('value') ? this.node.attrs.text || tmp : '';

this.$el.find('a').attr('href', tmp).text(this.get('value')); } },

on_button_clicked: function() { if (!this.get('value')) {

this.do_warn(_t("Resource Error"), _t("This resource is empty"));

} else {  var url = $.trim(this.get('value'));

if(/^www\./i.test(url))

url = 'http://'+url;

window.open(url);

} } });"

Check this code you may find how it works and try change it for your purpose.

Remember this is just an example.

Same Way you can create url widget for list.

In view_list.js insert this code somwhere around line 2400:

instance.web.list.Url = instance.web.list.Column.extend({

PROTOCOL_REGEX: /^(?!\w+:?\/\/)/,

  _format: function(row_data, options) {

var value = row_data[this.id].value;

if (value) {

return _.template("<a href='<%-href%>' target='_blank'><%-text%></a>", {

href: value.trim().replace(this.PROTOCOL_REGEX, '//'),

text: value  });

}

return this._super(row_data, options);

} });

This definitely work, tested it.

0
Anthony Gardiner
On 4/14/15, 4:34 PM

I'm not really a programmer yet I have installed both this module and the WEB module with no success to show the clickable link in the tree view.

Does anyone know where there are examples of the code?

Should I be setting up the custom field or script in a certain way?

How to use widget="url" in tree view
My script is <field name="x_showworkurl2" widget="url"/>

Check example above, you may find it useful

Dr Obx
on 4/14/15, 6:45 PM

Widget directly may not work so maybe you should try with button.

Dr Obx
on 4/14/15, 6:51 PM

It works, Install "Web/URL widget" Module, it is different from "web" module

Narayanamurthy
on 4/15/15, 1:01 AM
0
Carlos Lopez
On 11/12/14, 9:07 PM

Hi,

Check this PR https://github.com/odoo/odoo/pull/3592

 

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/4/14, 8:56 AM
Seen: 5152 times
Last updated: 4/15/15, 5:40 AM