Skip to content

Commit

Permalink
Commonify function
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashah115 committed Oct 1, 2018
1 parent a93a2a5 commit a28b528
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
21 changes: 21 additions & 0 deletions frappe/contacts/address_and_contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2018, Frappe Technologies and contributors
// For license information, please see license.txt

frappe.ui.form.on(cur_frm.doctype, {
get_last_doc: function() {
const reverse_routes = frappe.route_history.reverse();
const last_route = reverse_routes.find(route => {
return route[0] === 'Form' && route[1] !== cur_frm.doctype
})
let doctype = last_route && last_route[1];
let docname = last_route && last_route[2];

if (last_route && last_route.length > 3)
docname = last_route.slice(2).join("/");

return {
doctype,
docname
}
}
});
18 changes: 2 additions & 16 deletions frappe/contacts/doctype/address/address.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2016, Frappe Technologies and contributors
// For license information, please see license.txt

{% include 'frappe/contacts/address_and_contact.js' %};

frappe.ui.form.on("Address", {
refresh: function(frm) {
if(frm.doc.__islocal) {
Expand Down Expand Up @@ -44,21 +46,5 @@ frappe.ui.form.on("Address", {
}
}
]);
},
get_last_doc() {
const reverse_routes = frappe.route_history.reverse();
const last_route = reverse_routes.find(route => {
return route[0] === 'Form' && route[1] !== 'Address'
})
let doctype = last_route && last_route[1];
let docname = last_route && last_route[2];

if (last_route && last_route.length > 3)
docname = last_route.slice(2).join("/");

return {
doctype,
docname
}
}
});
18 changes: 2 additions & 16 deletions frappe/contacts/doctype/contact/contact.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2016, Frappe Technologies and contributors
// For license information, please see license.txt

{% include 'frappe/contacts/address_and_contact.js' %};

cur_frm.email_field = "email_id";
frappe.ui.form.on("Contact", {
refresh: function(frm) {
Expand Down Expand Up @@ -59,22 +61,6 @@ frappe.ui.form.on("Contact", {
}
}
]);
},
get_last_doc() {
const reverse_routes = frappe.route_history.reverse();
const last_route = reverse_routes.find(route => {
return route[0] === 'Form' && route[1] !== 'Contact'
})
let doctype = last_route && last_route[1];
let docname = last_route && last_route[2];

if (last_route && last_route.length > 3)
docname = last_route.slice(2).join("/");

return {
doctype,
docname
}
}
});

Expand Down

0 comments on commit a28b528

Please sign in to comment.