Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Routing while adding address #6171

Merged
merged 4 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions frappe/contacts/doctype/address/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
frappe.ui.form.on("Address", {
refresh: function(frm) {
if(frm.doc.__islocal) {
var last_route = frappe.route_history.slice(-2, -1)[0];
let docname = last_route[2];
if (last_route.length > 3)
docname = last_route.slice(2).join("/");
const last_doc = frappe.contacts.get_last_doc(frm);
if(frappe.dynamic_link && frappe.dynamic_link.doc
&& frappe.dynamic_link.doc.name==docname) {
&& frappe.dynamic_link.doc.name == last_doc.docname) {
frm.set_value('links', '');
frm.add_child('links', {
link_doctype: frappe.dynamic_link.doctype,
link_name: frappe.dynamic_link.doc[frappe.dynamic_link.fieldname]
Expand All @@ -35,14 +33,14 @@ frappe.ui.form.on("Address", {
});
}
},
after_save: function() {
after_save: function(frm) {
frappe.run_serially([
() => frappe.timeout(1),
() => {
var last_route = frappe.route_history.slice(-2, -1)[0];
const last_doc = frappe.contacts.get_last_doc(frm);
if(frappe.dynamic_link && frappe.dynamic_link.doc
&& frappe.dynamic_link.doc.name == last_route[2]){
frappe.set_route(last_route[0], last_route[1], last_route[2]);
&& frappe.dynamic_link.doc.name == last_doc.docname){
frappe.set_route('Form', last_doc.doctype, last_doc.docname);
}
}
]);
Expand Down
18 changes: 7 additions & 11 deletions frappe/contacts/doctype/contact/contact.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// Copyright (c) 2016, Frappe Technologies and contributors
// For license information, please see license.txt


cur_frm.email_field = "email_id";
frappe.ui.form.on("Contact", {
refresh: function(frm) {
if(frm.doc.__islocal) {
var last_route = frappe.route_history.slice(-2, -1)[0];
let docname = last_route[2];
if (last_route && last_route.length > 3) {
docname = last_route.slice(2).join("/");
}
const last_doc = frappe.contacts.get_last_doc(frm);
if(frappe.dynamic_link && frappe.dynamic_link.doc
&& frappe.dynamic_link.doc.name==docname) {
&& frappe.dynamic_link.doc.name == last_doc.docname) {
frm.set_value('links', '');
frm.add_child('links', {
link_doctype: frappe.dynamic_link.doctype,
link_name: frappe.dynamic_link.doc[frappe.dynamic_link.fieldname]
Expand Down Expand Up @@ -52,14 +48,14 @@ frappe.ui.form.on("Contact", {
});
}
},
after_save: function() {
after_save: function(frm) {
frappe.run_serially([
() => frappe.timeout(1),
() => {
var last_route = frappe.route_history.slice(-2, -1)[0];
const last_doc = frappe.contacts.get_last_doc(frm);
if(frappe.dynamic_link && frappe.dynamic_link.doc
&& last_route.length > 2 && frappe.dynamic_link.doc.name == last_route[2]){
frappe.set_route(last_route[0], last_route[1], last_route[2]);
&& frappe.dynamic_link.doc.name == last_doc.docname){
frappe.set_route('Form', last_doc.doctype, last_doc.docname);
}
}
]);
Expand Down
16 changes: 16 additions & 0 deletions frappe/public/js/frappe/misc/address_and_contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,21 @@ $.extend(frappe.contacts, {
}
);
}
},
get_last_doc: function(frm) {
const reverse_routes = frappe.route_history.reverse();
const last_route = reverse_routes.find(route => {
return route[0] === 'Form' && route[1] !== 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
}
}
})