diff --git a/frappe/core/doctype/communication/email.py b/frappe/core/doctype/communication/email.py
index 7e0d12dda3..e5ba18b6a8 100755
--- a/frappe/core/doctype/communication/email.py
+++ b/frappe/core/doctype/communication/email.py
@@ -65,7 +65,13 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received =
# if no reference given, then send it against the communication
comm.db_set(dict(reference_doctype='Communication', reference_name=comm.name))
+ if isinstance(attachments, basestring):
+ attachments = json.loads(attachments)
+
# if not committed, delayed task doesn't find the communication
+ if attachments:
+ add_attachments(comm.name, attachments)
+
frappe.db.commit()
if cint(send_email):
@@ -320,6 +326,20 @@ def get_cc(doc, recipients=None, fetched_from_email_account=False):
return cc
+
+def add_attachments(name, attachments):
+ '''Add attachments to the given Communiction'''
+ from frappe.utils.file_manager import save_url
+
+ # loop through attachments
+ for a in attachments:
+ attach = frappe.db.get_value("File", {"name":a},
+ ["file_name", "file_url", "is_private"], as_dict=1)
+
+ # save attachments to new doc
+ save_url(attach.file_url, attach.file_name, "Communication", name,
+ "Home/Attachments", attach.is_private)
+
def filter_email_list(doc, email_list, exclude, is_cc=False):
# temp variables
filtered = []
diff --git a/frappe/public/js/frappe/form/footer/attachments.js b/frappe/public/js/frappe/form/footer/attachments.js
index 3f957f245e..13645e7083 100644
--- a/frappe/public/js/frappe/form/footer/attachments.js
+++ b/frappe/public/js/frappe/form/footer/attachments.js
@@ -63,7 +63,7 @@ frappe.ui.form.Attachments = Class.extend({
var me = this;
var $attach = $(repl('
\
- ×\
+ ×\
%(lock_icon)s\
\
@@ -228,13 +228,14 @@ frappe.ui.get_upload_dialog = function(opts){
'method': 'frappe.client.get_value',
'args': {
'doctype': 'File',
- 'fieldname': ['file_url','file_name'],
+ 'fieldname': ['file_url','file_name','is_private'],
'filters': {
'name': dialog.get_value("file")
}
},
callback: function(r){
dialog.$wrapper.find('[name="file_url"]').val(r.message.file_url);
+ dialog.$wrapper.find('.private-file input').prop('checked', r.message.is_private);
opts.args.filename = r.message.file_name
}
});
diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js
index 6f60fb848e..520a13fa2c 100644
--- a/frappe/public/js/frappe/views/communication.js
+++ b/frappe/public/js/frappe/views/communication.js
@@ -31,10 +31,10 @@ frappe.views.CommunicationComposer = Class.extend({
});
// reset attachment list
- me.setup_attach();
+ me.render_attach();
// check latest added
- checked_items.push(attachment.file_name);
+ checked_items.push(attachment.name);
$.each(checked_items, function(i, filename) {
wrapper.find('[data-file-name="'+ filename +'"]').prop("checked", true);
@@ -258,15 +258,56 @@ frappe.views.CommunicationComposer = Class.extend({
},
setup_attach: function() {
- if (!cur_frm) return;
-
var fields = this.dialog.fields_dict;
var attach = $(fields.select_attachments.wrapper);
- var files = cur_frm.get_files();
+ var me = this
+ me.attachments = []
+
+ var args = {
+ args: {
+ from_form: 1,folder:"Home/Attachments"
+ },
+ callback: function(attachment, r) { me.attachments.push(attachment); },
+ max_width: null,
+ max_height: null
+ };
+
+ if(me.frm) {
+ args = {
+ args: (me.frm.attachments.get_args
+ ? me.frm.attachments.get_args()
+ : { from_form: 1,folder:"Home/Attachments" }),
+ callback: function (attachment, r) {
+ me.frm.attachments.attachment_uploaded(attachment, r)
+ },
+ max_width: me.frm.cscript ? me.frm.cscript.attachment_max_width : null,
+ max_height: me.frm.cscript ? me.frm.cscript.attachment_max_height : null
+ }
+
+ }
+
+ $(""
+ +__("Select Attachments")+"
\
+ \
+ "
+ +__("Add Attachment")+"
").appendTo(attach.empty())
+ attach.find(".add-more-attachments a").on('click',this,function() {
+ me.upload = frappe.ui.get_upload_dialog(args);
+ })
+ me.render_attach()
+
+ },
+ render_attach:function(){
+ var fields = this.dialog.fields_dict;
+ var attach = $(fields.select_attachments.wrapper).find(".attach-list").empty();
+
+ if (cur_frm){
+ var files = cur_frm.get_files();
+ }else {
+ var files = this.attachments
+ }
if(files.length) {
- $(""
- +__("Add Attachments")+"
").appendTo(attach.empty());
$.each(files, function(i, f) {
if (!f.file_name) return;
f.file_url = frappe.urllib.get_full_url(f.file_url);
diff --git a/frappe/utils/file_manager.py b/frappe/utils/file_manager.py
index 23e2990806..7727a96f53 100644
--- a/frappe/utils/file_manager.py
+++ b/frappe/utils/file_manager.py
@@ -35,7 +35,7 @@ def upload():
if frappe.form_dict.filedata:
filedata = save_uploaded(dt, dn, folder, is_private)
elif file_url:
- filedata = save_url(file_url, filename, dt, dn, folder)
+ filedata = save_url(file_url, filename, dt, dn, folder, is_private)
comment = {}
if dt and dn:
@@ -60,7 +60,7 @@ def save_uploaded(dt, dn, folder, is_private):
else:
raise Exception
-def save_url(file_url, filename, dt, dn, folder):
+def save_url(file_url, filename, dt, dn, folder, is_private):
# if not (file_url.startswith("http://") or file_url.startswith("https://")):
# frappe.msgprint("URL must start with 'http://' or 'https://'")
# return None, None
@@ -70,10 +70,11 @@ def save_url(file_url, filename, dt, dn, folder):
f = frappe.get_doc({
"doctype": "File",
"file_url": file_url,
- "fieldname": filename,
+ "file_name": filename,
"attached_to_doctype": dt,
"attached_to_name": dn,
- "folder": folder
+ "folder": folder,
+ "is_private": is_private
})
f.flags.ignore_permissions = True
try: