mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-16 03:29:16 +00:00
[website] [minor] moving to framework
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.utils import cstr, cint, decode_dict
|
||||
from webnotes.utils import cstr, cint, decode_dict, today
|
||||
from webnotes.utils.email_lib import sendmail
|
||||
from webnotes.utils.email_lib.receive import POP3Mailbox
|
||||
from core.doctype.communication.communication import make
|
||||
@@ -22,32 +22,13 @@ class SupportMailbox(POP3Mailbox):
|
||||
if mail.from_email == self.email_settings.fields.get('support_email'):
|
||||
return
|
||||
thread_id = mail.get_thread_id()
|
||||
ticket = None
|
||||
new_ticket = False
|
||||
|
||||
if thread_id and webnotes.conn.exists("Support Ticket", thread_id):
|
||||
ticket = webnotes.bean("Support Ticket", thread_id)
|
||||
ticket.doc.status = 'Open'
|
||||
ticket.doc.save()
|
||||
|
||||
else:
|
||||
ticket = webnotes.bean([decode_dict({
|
||||
"doctype":"Support Ticket",
|
||||
"description": mail.content,
|
||||
"subject": mail.subject,
|
||||
"raised_by": mail.from_email,
|
||||
"content_type": mail.content_type,
|
||||
"status": "Open",
|
||||
})])
|
||||
|
||||
ticket.insert()
|
||||
if not (thread_id and webnotes.conn.exists("Support Ticket", thread_id)):
|
||||
new_ticket = True
|
||||
|
||||
mail.save_attachments_in_doc(ticket.doc)
|
||||
|
||||
make(content=mail.content, sender=mail.from_email, subject = ticket.doc.subject,
|
||||
doctype="Support Ticket", name=ticket.doc.name,
|
||||
date=mail.date)
|
||||
|
||||
ticket = add_support_communication(mail.subject, mail.content, mail.from_email,
|
||||
docname=thread_id if new_ticket else None, mail=mail)
|
||||
|
||||
if new_ticket and cint(self.email_settings.send_autoreply) and \
|
||||
"mailer-daemon" not in mail.from_email.lower():
|
||||
@@ -78,4 +59,31 @@ Original Query:
|
||||
|
||||
def get_support_mails():
|
||||
if cint(webnotes.conn.get_value('Email Settings', None, 'sync_support_mails')):
|
||||
SupportMailbox()
|
||||
SupportMailbox()
|
||||
|
||||
def add_support_communication(subject, content, sender, docname=None, mail=None):
|
||||
if docname:
|
||||
ticket = webnotes.bean("Support Ticket", docname)
|
||||
ticket.doc.status = 'Open'
|
||||
ticket.ignore_permissions = True
|
||||
ticket.doc.save()
|
||||
else:
|
||||
ticket = webnotes.bean([decode_dict({
|
||||
"doctype":"Support Ticket",
|
||||
"description": content,
|
||||
"subject": subject,
|
||||
"raised_by": sender,
|
||||
"content_type": mail.content_type if mail else None,
|
||||
"status": "Open",
|
||||
})])
|
||||
ticket.ignore_permissions = True
|
||||
ticket.insert()
|
||||
|
||||
make(content=content, sender=sender, subject = subject,
|
||||
doctype="Support Ticket", name=ticket.doc.name,
|
||||
date=mail.date if mail else today())
|
||||
|
||||
if mail:
|
||||
mail.save_attachments_in_doc(ticket.doc)
|
||||
|
||||
return ticket
|
||||
@@ -38,17 +38,27 @@
|
||||
<span class="text-muted">{{ utils.formatdate(doc.creation) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<h4>Messages</h4>
|
||||
<div class="row">
|
||||
<h4 class="col-xs-6">Messages</h4>
|
||||
<div class="col-xs-6">
|
||||
<button class="btn btn-sm btn-primary pull-right" id="ticket-reply">
|
||||
<i class="icon-envelope icon-fixed-width"></i> Reply</button>
|
||||
<button class="btn btn-sm btn-success pull-right hide" id="ticket-reply-send">
|
||||
<i class="icon-arrow-right icon-fixed-width"></i> Send</button>
|
||||
</div>
|
||||
</div>
|
||||
<p id="ticket-alert" class="alert alert-danger"
|
||||
style="display: none;"> </p>
|
||||
{%- if doclist.get({"doctype":"Communication"}) -%}
|
||||
<div>
|
||||
<table class="table table-bordered table-striped">
|
||||
<table class="table table-bordered table-striped" id="ticket-thread">
|
||||
<tbody>
|
||||
{%- for comm in doclist.get({"doctype":"Communication"}) %}
|
||||
{%- for comm in
|
||||
(doclist.get({"doctype":"Communication"})|sort(reverse=True, attribute="creation")) %}
|
||||
<tr>
|
||||
<td>
|
||||
<h5 style="text-transform: none">
|
||||
{{ comm.sender }} on {{ utils.formatdate(doc.modified) }}</h5>
|
||||
{{ comm.sender }} on {{ utils.formatdate(comm.creation) }}</h5>
|
||||
<hr>
|
||||
<p>{{ webnotes.utils.is_html(comm.content) and comm.content or
|
||||
comm.content.replace("\n", "<br>")}}</p>
|
||||
@@ -64,4 +74,49 @@
|
||||
{%- endif -%}
|
||||
{% endif -%}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block javascript %}
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#ticket-reply").on("click", function() {
|
||||
if(!$("#ticket-reply-editor").length) {
|
||||
$('<tr id="ticket-reply-editor"><td>\
|
||||
<h5 style="text-transform: none">Reply</h5>\
|
||||
<hr>\
|
||||
<textarea rows=10 class="form-control" style="resize: vertical;"></textarea>\
|
||||
</td></tr>').prependTo($("#ticket-thread").find("tbody"));
|
||||
$("#ticket-reply").addClass("hide");
|
||||
$("#ticket-reply-send").removeClass("hide");
|
||||
}
|
||||
});
|
||||
|
||||
$("#ticket-reply-send").on("click", function() {
|
||||
var reply = $("#ticket-reply-editor").find("textarea").val().trim();
|
||||
if(!reply) {
|
||||
msgprint("Please write something in reply!");
|
||||
} else {
|
||||
wn.call({
|
||||
type: "POST",
|
||||
method: "support.doctype.support_ticket.templates.pages.ticket.add_reply",
|
||||
btn: this,
|
||||
args: { ticket: "{{ doc.name }}", message: reply },
|
||||
callback: function(r) {
|
||||
if(r.exc) {
|
||||
msgprint(r._server_messages
|
||||
? JSON.parse(r._server_messages).join("<br>")
|
||||
: "Something went wrong!");
|
||||
} else {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var msgprint = function(txt) {
|
||||
if(txt) $("#ticket-alert").html(txt).toggle(true);
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes import _
|
||||
from webnotes.utils import today
|
||||
|
||||
no_cache = True
|
||||
|
||||
@@ -19,3 +21,17 @@ def get_context():
|
||||
"webnotes": webnotes,
|
||||
"utils": webnotes.utils
|
||||
}
|
||||
|
||||
@webnotes.whitelist()
|
||||
def add_reply(ticket, message):
|
||||
if not message:
|
||||
raise webnotes.throw(_("Please write something"))
|
||||
|
||||
bean = webnotes.bean("Support Ticket", ticket)
|
||||
if bean.doc.raised_by != webnotes.session.user:
|
||||
raise webnotes.throw(_("You are not allowed to reply to this ticket."), webnotes.PermissionError)
|
||||
|
||||
from core.doctype.communication.communication import make
|
||||
make(content=message, sender=bean.doc.raised_by, subject = bean.doc.subject,
|
||||
doctype="Support Ticket", name=bean.doc.name,
|
||||
date=today())
|
||||
@@ -29,5 +29,59 @@
|
||||
</div>\
|
||||
</a>', doc)).appendTo($list);
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
if(!window.$new_ticket) {
|
||||
window.$new_ticket = $('<div>\
|
||||
<button class="btn btn-primary" style="margin-bottom: 15px;" id="new-ticket">\
|
||||
<i class="icon-tag icon-fixed-width"></i> New Ticket\
|
||||
</button>\
|
||||
<button class="btn btn-success hide" style="margin-bottom: 15px;" id="new-ticket-send">\
|
||||
<i class="icon-arrow-right icon-fixed-width"></i> Send\
|
||||
</button>\
|
||||
</div>').insertBefore(".transaction-list");
|
||||
}
|
||||
|
||||
window.$new_ticket.find("#new-ticket").on("click", function() {
|
||||
$(this).addClass("hide");
|
||||
$(window.$new_ticket).find("#new-ticket-send").removeClass("hide");
|
||||
$('<div class="well" id="ticket-editor">\
|
||||
<div class="form-group"><input class="form-control" type="data"\
|
||||
placeholder="Subject" data-fieldname="subject"></div>\
|
||||
<div class="form-group"><textarea rows=10 class="form-control" \
|
||||
style="resize: vertical;" placeholder="Message" \
|
||||
data-fieldname="message"></textarea></div>\
|
||||
</div>')
|
||||
.insertAfter(window.$new_ticket);
|
||||
});
|
||||
|
||||
window.$new_ticket.find("#new-ticket-send").on("click", function() {
|
||||
var subject = $("#ticket-editor").find('[data-fieldname="subject"]').val().trim();
|
||||
var message = $("#ticket-editor").find('[data-fieldname="message"]').val().trim();
|
||||
if(!(subject && message)) {
|
||||
msgprint("Please write something in subject and message!");
|
||||
} else {
|
||||
wn.call({
|
||||
type: "POST",
|
||||
method: "support.doctype.support_ticket.templates.pages.tickets.make_new_ticket",
|
||||
btn: this,
|
||||
args: { subject: subject, message: message },
|
||||
callback: function(r) {
|
||||
if(r.exc) {
|
||||
msgprint(r._server_messages
|
||||
? JSON.parse(r._server_messages).join("<br>")
|
||||
: "Something went wrong!");
|
||||
} else {
|
||||
window.location.href = "ticket?name=" + encodeURIComponent(r.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var msgprint = function(txt) {
|
||||
if(txt) $("#msgprint-alert").html(txt).toggle(true);
|
||||
}
|
||||
</script>
|
||||
{%- endblock %}
|
||||
@@ -25,4 +25,14 @@ def get_tickets(start=0):
|
||||
for t in tickets:
|
||||
t.creation = formatdate(t.creation)
|
||||
|
||||
return tickets
|
||||
return tickets
|
||||
|
||||
@webnotes.whitelist()
|
||||
def make_new_ticket(subject, message):
|
||||
if not (subject and message):
|
||||
raise webnotes.throw(_("Please write something in subject and message!"))
|
||||
|
||||
from support.doctype.support_ticket.get_support_mails import add_support_communication
|
||||
ticket = add_support_communication(subject, message, webnotes.session.user)
|
||||
|
||||
return ticket.doc.name
|
||||
@@ -1,66 +0,0 @@
|
||||
{% extends base_template %}
|
||||
|
||||
{% set title=doc.name %}
|
||||
|
||||
{% set status_label = {
|
||||
"Open": "label-success",
|
||||
"To Reply": "label-danger",
|
||||
"Closed": "label-default"
|
||||
} %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-md-12">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="index">Home</a></li>
|
||||
<li><a href="tickets">My Tickets</a></li>
|
||||
<li class="active"><i class="icon-ticket icon-fixed-width"></i> {{ doc.name }}</li>
|
||||
</ul>
|
||||
<h3><i class="icon-ticket icon-fixed-width"></i> {{ doc.name }}</h3>
|
||||
{% if doc.name == "Not Allowed" -%}
|
||||
<script>ask_to_login();</script>
|
||||
{% else %}
|
||||
<hr>
|
||||
{%- if doc.status -%}
|
||||
{% if doc.status == "Waiting for Customer" -%}
|
||||
{% set status = "To Reply" %}
|
||||
{% else %}
|
||||
{% set status = doc.status %}
|
||||
{%- endif -%}
|
||||
<div class="row">
|
||||
<div class="col-md-2" style="margin-bottom: 7px;">
|
||||
<span class="label {{ status_label.get(status) or 'label-default' }}">{{ status }}</span>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="row col-md-12">{{ doc.subject }}</div>
|
||||
</div>
|
||||
<div class="col-md-2 pull-right">
|
||||
<span class="text-muted">{{ utils.formatdate(doc.creation) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<h4>Messages</h4>
|
||||
{%- if doclist.get({"doctype":"Communication"}) -%}
|
||||
<div>
|
||||
<table class="table table-bordered table-striped">
|
||||
<tbody>
|
||||
{%- for comm in doclist.get({"doctype":"Communication"}) %}
|
||||
<tr>
|
||||
<td>
|
||||
<h5 style="text-transform: none">
|
||||
{{ comm.sender }} on {{ utils.formatdate(doc.modified) }}</h5>
|
||||
<hr>
|
||||
<p>{{ webnotes.utils.is_html(comm.content) and comm.content or
|
||||
comm.content.replace("\n", "<br>")}}</p>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor -%}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{%- else -%}
|
||||
<div class="alert">No messages</div>
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
{% endif -%}
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user