Odoo Help

Welcome!

This community 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.

0

How to load .js, in the web/database/manager form?

By
Carlos Almeida
on 11/3/15, 2:26 AM 487 views

How to load .js, in the web/database/manager form?

It seems this doesn't work on login form or before login

I even started odoo with --load web,mymodule adding .js in assets and they are not loaded.

2

Parikshit

--Parikshit--
939
| 6 3 8
Ahmedabad, India
--Parikshit--

Working as an OpenERP/Odoo developer both experience in web and addons. you can contact me at:

E-mail : parikshitvaghasiya@gmail.com

Blog : parikshitvaghasiya.blogspot.in

Stackoverflow : http://stackoverflow.com/users/5089106/parikshit-vaghasiya

Parikshit
On 11/3/15, 9:12 AM

Hello,

For This you have to copy paste database_manager.html file in your module and create one controller method for file like :

    @http.route('/web/database/manager', type='http', auth="none")
def manager(self, **kw):
request.session.logout()
loader = jinja2.PackageLoader('openerp.addons.module_name', "views")
env = jinja2.Environment(loader=loader, autoescape=True)
return env.get_template("database_manager.html").render({
'modules': simplejson.dumps(module_boot()),
})
Now you can add your .js in header of database_manager.html where other .js file added.

Hope this will help you !

0
Carlos Almeida
On 11/3/15, 8:46 PM

Thanks for you answer i manage to load the scripts.

But I got openerp is not defined error :(

My scripts are defined as:

openerp.addons.mymodule = function (instance) {
instance.web.myfunc = instance.web.DatabaseManager.extend( {

something...

});};


What could be the problem?

SOLVED: It was the order in the html file :)

=========================

Sorry text on comment is unreadable.

I was able to reach this point, the NEW.js is loaded, if I set a break point in "var break_point;" it stops there, I don't get any error, but it just don't execute the rest of the code...

openerp.MYMODULE = function (instance) {
/*just for test in a break point*/
var break_point;

/* redefine from chrome.js:412 */
instance.web.DatabaseManagerNEW = instance.web.DatabaseManager.extend( {
do_render: function() {
this._super(parent);
/* add new submit handler*/
self.$el.find("form[name=NEW_db_form]").validate({ submitHandler: self.do_NEW });
},
do_NEW: function(form) {
var self = this;
var $form = $(form),
fields = $form.serializeArray();
self.rpc("/web/database/NEW", {'fields': fields}).done(function(result) {
if (result.error) {
self.display_error(result);
return;
}
self.start();
});
},
});

/* redefine view_form.js:72 */
instance.web.FormViewNEW = instance.web.FormView.extend({
load_form: function(data) {
this._super(parent);
/* redefine button */
if (!this.sidebar && this.options.$sidebar) {
this.sidebar.add_items('other', _.compact([
self.is_action_enabled('create') && { label: _t('NEW'), callback: self.on_button_NEW }
]));
}
},
on_button_NEW: function() {
var self = this;
return this.has_been_loaded.then(function() {
return self.dataset.call('copy', [self.datarecord.id, {}, self.dataset.context]).then(function(new_id) {
self.record_created(new_id);
self.to_edit_mode();
});
});
},
});
};

This code inserted in those files works, but not in my NEW.js file.

It was the script order in html :P Now I don't have errors but it doesn't run :(

Carlos Almeida
on 11/3/15, 9:28 PM

I think I'm fighting with js... openerp.MYMODULE = function (instance) { instance.web.DatabaseManagerNEW = instance.web.DatabaseManager.extend( { do_render_replicate: function() { this._super(parent); self.$el.find("form[name=NEW_db_form]").validate({ submitHandler: self.do_NEW }); }, do_NEW: function(form) { var self = this; var $form = $(form), fields = $form.serializeArray(); self.rpc("/web/database/NEW", {'fields': fields}).done(function(result) { if (result.error) { self.display_error(result); return; } self.start(); }); }, }); instance.web.FormViewNEW = instance.web.FormView.extend({ load_form_NEW: function(data) { this._super(parent); if (!this.sidebar && this.options.$sidebar) { this.sidebar.add_items('other', _.compact([ self.is_action_enabled('create') && { label: _t('NEW'), callback: self.on_button_NEW } ])); } }, on_button_NEW: function() { var self = this; return this.has_been_loaded.then(function() { return self.dataset.call('copy', [self.datarecord.id, {}, self.dataset.context]).then(function(new_id) { self.record_created(new_id); self.to_edit_mode(); }); }); }, }); }; Can you point me the right direction?

Carlos Almeida
on 11/3/15, 11:12 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/3/15, 2:26 AM
Seen: 487 times
Last updated: 11/3/15, 11:42 PM