Skip to Content
Menu
This question has been flagged
2 Replies
7048 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.

Avatar
Discard
Best Answer

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 !

Avatar
Discard
Author Best Answer

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.

Avatar
Discard
Author

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

Author

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?

Related Posts Replies Views Activity
1
Mar 24
7840
3
May 20
5879
1
Jan 16
4470
1
Aug 23
12546
1
Aug 23
11041