Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
6 Antwoorden
11370 Weergaven

Hello there,

Apparently it is a serious problem and nobody know how to do it  so I need help, I'm new in Odoo, it's still a mistery for me how to build something in this system.

How can I create and how should it look like a function which will create a link. For example I have a field "ebay_number" which contain 12 digits long number of product and I would like to create a link to the item based on constant element like "www.ebay.com/itm/ + <item number>"  but on screen I want only see this number. Hope you understand guys what I'm talking about.

Can anyone help me with it please?

Too complicated ?

Can anyone show me how to do it ?

Avatar
Annuleer

Take a look here : https://www.odoo.com/documentation/8.0/howtos/web.html#the-form-view-fields...

Auteur

Thank you Jeremy, it might be useful but like i said, I'm new in Odoo so even if i know something about JS HTML and other stuff I don't really know how to combine it together. In PHP is piece of cake but modyfying existing js code is completely different thing.

Auteur

By the way, do you know where should i search for js files containing widgets ?

Auteur

GREAT thanx, you saved a lot of my precious time Jeremy :)

Auteur

//============================================================= instance.web.form.FieldLink = instance.web.form.FieldChar.extend({ template: 'FieldLink', 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://www.ebay.co.uk/itm/" + this.get('value'); } var text = this.get('value') ? this.node.attrs.text || tmp : ''; this.$el.find('a').attr('href', tmp).text(text); } }, 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://www.ebay.co.uk/itm/'+ this.get('value'); window.open(url); } } }); What do you think ? Will it work ?

Auteur

Finally i did it. But i made one step further to keep old widget untouched I created a separate widget for this purpose. Now i have a special widget for Ebay :) and finally i know how i can make some more depending on what I will need. And this is the best option.

Auteur

Now i got it even better because whole address is hidden and only product name is displayed as a link :):)

Auteur

I just created a new widget and the code you suggested in my widget looks like: this.$el.find('a').attr('href', tmp).text(this.get('value')); and works perfectly fine ;) Thanx

Auteur

By the way Jeremy, string you asked me to change doesn't exist in Odoo8.0 or I can't find (blindness ?) I've found only this.$el.find('a').attr('href', tmp).text(text); is this the string you've had in mind ? What i've done: var suf = document.getElementById('id'); if (suf = 'ebay'){ var suf_x = 'http://

'; 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')); At the end getting only a name on screen but link is generated correctly so that's what i wanted.
Beste antwoord

in view_form.js you have all basic widget... If you need module which add a widget, you can grep 'instance.web.form.widgets = '...

But your widget is really basic, you can copy past the widget Field2 from documentation...

replace the

this.$el.text(this.get("value")); 

by 

this.$el.html("<a href='<your_url>/'>"+ this.get("value") + "</a>");

and it will works !

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
jul. 15
4854
0
aug. 15
2871
3
feb. 24
14781
3
dec. 24
20119
1
mrt. 15
9901