fix: Show content in right timeline

- Previously, it used to show content of other form's
timeline in another form's timeline
This commit is contained in:
Suraj Shetty 2021-01-25 17:01:36 +05:30
parent d1175c1e88
commit 4f32726cd7
3 changed files with 18 additions and 10 deletions

View file

@ -27,7 +27,8 @@ class Comment(Document):
def on_update(self):
update_comment_in_doc(self)
self.notify_change('update')
if self.is_new():
self.notify_change('update')
def on_trash(self):
self.remove_comment_from_cache()

View file

@ -7,7 +7,6 @@ class FormTimeline extends BaseTimeline {
make() {
super.make();
this.setup_document_email_link();
this.setup_timeline_actions();
this.render_timeline_items();
this.setup_activity_toggle();
@ -16,6 +15,7 @@ class FormTimeline extends BaseTimeline {
refresh() {
super.refresh();
this.frm.trigger('timeline_refresh');
this.setup_document_email_link();
}
setup_timeline_actions() {
@ -70,9 +70,11 @@ class FormTimeline extends BaseTimeline {
setup_document_email_link() {
let doc_info = this.doc_info || this.frm.get_docinfo();
this.document_email_link_wrapper && this.document_email_link_wrapper.remove();
if (doc_info.document_email) {
const link = `<a class="document-email-link">${doc_info.document_email}</a>`;
const message = __("Send an email to {0} to link it here", [link.bold()]);
const message = __("Add to this activity by mailing to {0}", [link.bold()]);
this.document_email_link_wrapper = $(`
<div class="document-email-link-container">
@ -80,7 +82,7 @@ class FormTimeline extends BaseTimeline {
<span class="ellipsis">${message}</span>
</div>
`);
this.timeline_wrapper.prepend(this.document_email_link_wrapper);
this.timeline_wrapper.append(this.document_email_link_wrapper);
this.document_email_link_wrapper
.find('.document-email-link')

View file

@ -102,7 +102,6 @@ frappe.ui.form.Form = class FrappeForm {
}
this.setup_file_drop();
this.setup_doctype_actions();
this.setup_docinfo_change_listener();
this.setup_notify_on_rename();
this.setup_done = true;
@ -369,6 +368,7 @@ frappe.ui.form.Form = class FrappeForm {
});
frappe.ui.form.close_grid_form();
this.docname = docname;
this.setup_docinfo_change_listener();
}
check_reload() {
@ -1650,10 +1650,15 @@ frappe.ui.form.Form = class FrappeForm {
}
setup_docinfo_change_listener() {
frappe.realtime.on(`update_docinfo_for_${this.doctype}_${this.docname}`, ({doc, key, action='update'}) => {
let doc_list = (frappe.model.docinfo[this.doctype][this.docname][key] || []);
let doctype = this.doctype;
let docname = this.docname;
let listener_name = `update_docinfo_for_${doctype}_${docname}`;
// to avoid duplicates
frappe.realtime.off(listener_name);
frappe.realtime.on(listener_name, ({doc, key, action='update'}) => {
let doc_list = (frappe.model.docinfo[doctype][docname][key] || []);
if (action === 'add') {
frappe.model.docinfo[this.doctype][this.docname][key].push(doc);
frappe.model.docinfo[doctype][docname][key].push(doc);
}
let docindex = doc_list.findIndex(old_doc => {
@ -1662,10 +1667,10 @@ frappe.ui.form.Form = class FrappeForm {
if (docindex > -1) {
if (action === 'update') {
frappe.model.docinfo[this.doctype][this.docname][key].splice(docindex, 1, doc);
frappe.model.docinfo[doctype][docname][key].splice(docindex, 1, doc);
}
if (action === 'delete') {
frappe.model.docinfo[this.doctype][this.docname][key].splice(docindex, 1);
frappe.model.docinfo[doctype][docname][key].splice(docindex, 1);
}
}
// no need to update timeline of owner of comment