Extending DataImportTool class from javascript

Hi there,

any hint on how access a page like backups, data-import-tool from javascript and hide button?

thx

2 Likes

Anyone knows how to get on_page_load event for pages? like onload for doctypes?

check pos.js

https://github.com/frappe/erpnext/blob/develop/erpnext/accounts/page/pos/pos.js#L26

@Sangram thx for the hint, i’ve tried on data import tool but it seems not allowing to extend.

What you tried?

probably i’m doing something wrong …

frappe.data_import_tool = frappe.data_import_tool.extends({
	init: function (wrapper) {
		this.onload();
	},

	onload: function () {
		var me = this;
		console.log(me);
	}
});

if you are creating a new js file for customization. Then you have to include your .js file in data_import_tool.js

it rise an error while importing:

{% include "frappe/core/page/data_import_tool/data_import_tool.js" %}

Uncaught SyntaxError: Unexpected token %

Cant get to work :frowning: …do u have any other hint?

can someone help on how to extend DataImportTool page?! i’m really getting frustrated …

@JoEz
After some tries got one solution :smile:
Refer Simple JavaScript Inheritance to know more

Write following script in your custom js file

frappe.CustomDataImportTool = frappe.DataImportTool.extend({
	init: function(parent) {
		console.log("custom init")
		this._super(parent)
		this.onload()
	},
	onload: function(parent) {
		console.log(" custom onload")
	}
})

You have to call this Class from data_import_tool.js

Changes in data_import_tool.js

{% include path to your custom js' %}

frappe.pages['data-import-tool'].on_page_load = function(wrapper) {
	frappe.data_import_tool = new frappe.CustomDataImportTool(wrapper);
}

There is an another way to do it If you have custom app. Simply add your own data_import_tool.js include it in app_include_js via hooks.py

Thx, i’ll have a test on second option …i’ll let you know

HI @Sangram, i’m getting an error:

TypeError: undefined is not an object (evaluating 'frappe.DataImportTool.extend')

Seems DataImportTool is not found

seems like you did something wrong. It is working perfectly for me.
Have you made changes in data_import_tool.js as I suggested?
Please check it again.

Edit:

include custom js exactly above the

frappe.pages['data-import-tool'].on_page_load = function(wrapper) {

I think the problem is not on importing in data_import_tool.js, seems more a problem extending DataImportTool class.

And importing file in js will rise another exception:

SyntaxError: Unexpected token '%'

always getting :

SyntaxError: Unexpected token '%'

Where did you import it?
Import it just before below line as it is executing sequentialy
frappe.pages['data-import-tool'].on_page_load = function(wrapper) {

see

{% include js file %}

frappe.pages['data-import-tool'].on_page_load = function(wrapper) {
	frappe.data_import_tool = new frappe.CustomDataImportTool(wrapper);
}

it doesn’t in what line i import, it keep giving me SyntaxError: Unexpected token '%' error. Not sure why, but seems {% include 'path/to/js/file' %} is not correct even if it should be …

FrappeTeam …any hint on this? Seems page DataImportTool is not affected by custom js code and can’t be extended …can u suggest some way to fix it?

All day on this …but no results …what version are u using?