Misc fixes (#6379)

* fix(Quill): Set value using simple innerHTML assignment

- earlier it used to focus the editor

* fix(Event Emitter): Make EventEmitterMixin

* fix(EmailComposer): Delete draft mail when email is sent

* fix: Override comment area value in Email Composer

* fix(Quill): Enable attaching GIF to editor

* fix: Missing semicolon
This commit is contained in:
Faris Ansari 2018-11-01 18:33:16 +05:30 committed by Rushabh Mehta
parent ae558c6d52
commit 86e5201384
5 changed files with 29 additions and 18 deletions

View file

@ -1,26 +1,26 @@
frappe.provide('frappe.utils');
/**
* Simple EventEmitter which uses jQuery's event system
* Simple EventEmitterMixin which uses jQuery's event system
*/
class EventEmitter {
const EventEmitterMixin = {
init() {
this.jq = jQuery(this);
}
},
trigger(evt, data) {
!this.jq && this.init();
this.jq.trigger(evt, data);
}
},
once(evt, handler) {
!this.jq && this.init();
this.jq.one(evt, (e, data) => handler(data));
}
},
on(evt, handler) {
!this.jq && this.init();
this.jq.bind(evt, (e, data) => handler(data));
}
},
off(evt, handler) {
!this.jq && this.init();
@ -29,8 +29,8 @@ class EventEmitter {
}
frappe.utils.make_event_emitter = function(object) {
Object.assign(object, EventEmitter.prototype);
Object.assign(object, EventEmitterMixin);
return object;
};
export default EventEmitter;
export default EventEmitterMixin;

View file

@ -16,6 +16,10 @@ Table.create = (value) => {
}
Quill.register(Table, true);
// image uploader
const Uploader = Quill.import('modules/uploader');
Uploader.DEFAULTS.mimetypes.push('image/gif');
// inline style
const BackgroundStyle = Quill.import('attributors/style/background');
const ColorStyle = Quill.import('attributors/style/color');
@ -150,8 +154,7 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({
return;
}
this.quill.setText('');
this.quill.clipboard.dangerouslyPasteHTML(0, value);
this.quill.root.innerHTML = value;
},
get_input_value() {

View file

@ -92,8 +92,9 @@ frappe.ui.form.Timeline = class Timeline {
subject: __("Re: {0}", [me.frm.doc.subject]),
});
} else {
const comment_value = frappe.markdown(me.comment_area.get_value());
$.extend(args, {
txt: frappe.markdown(me.comment_area.get_value())
txt: strip_html(comment_value) ? comment_value : ''
});
}
new frappe.views.CommunicationComposer(args)

View file

@ -3,7 +3,7 @@
frappe.provide('frappe.utils');
frappe.utils = {
Object.assign(frappe.utils, {
get_random: function(len) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@ -648,7 +648,7 @@ frappe.utils = {
}
return route;
}
};
});
// Array de duplicate
if (!Array.prototype.uniqBy) {

View file

@ -17,6 +17,7 @@ frappe.views.CommunicationComposer = Class.extend({
fields: this.get_fields(),
primary_action_label: __("Send"),
primary_action: function() {
me.delete_saved_draft();
me.send_action();
}
});
@ -82,8 +83,7 @@ frappe.views.CommunicationComposer = Class.extend({
label:__("Message"),
fieldtype:"Text Editor", reqd: 1,
fieldname:"content",
onchange: frappe.utils.debounce(this.save_as_draft.bind(this), 300),
default: localStorage.getItem(this.frm.doctype + this.frm.docname) || ''
onchange: frappe.utils.debounce(this.save_as_draft.bind(this), 300)
},
{fieldtype: "Section Break"},
@ -135,9 +135,7 @@ frappe.views.CommunicationComposer = Class.extend({
}
this.dialog.fields_dict.subject.set_value(this.subject || '');
if(!localStorage.getItem(this.frm.doctype + this.frm.docname)) {
this.setup_earlier_reply();
}
this.setup_earlier_reply();
},
setup_subject_and_recipients: function() {
@ -509,6 +507,12 @@ frappe.views.CommunicationComposer = Class.extend({
}
},
delete_saved_draft() {
if (this.dialog) {
localStorage.removeItem(this.frm.doctype + this.frm.docname);
}
},
send_email: function(btn, form_values, selected_attachments, print_html, print_format) {
var me = this;
me.dialog.hide();
@ -629,6 +633,9 @@ frappe.views.CommunicationComposer = Class.extend({
if(this.txt) {
this.message = this.txt + (this.message ? ("<br><br>" + this.message) : "");
} else {
// saved draft in localStorage
this.message = localStorage.getItem(this.frm.doctype + this.frm.docname) || '';
}
if(this.real_name) {