blob: 39c69dfa0a48a73e0456a30212ed6dd68fe46e99 [file] [log] [blame]
Rushabh Mehta3daa49a2014-10-21 16:16:30 +05301{% block title %} {{ title }} {% endblock %}
2
3{% block header %}<h2><i class="icon-ticket icon-fixed-width"></i> {{ title }}</h2>{% endblock %}
4
5{% block content %}
6{% set status_label = {
7 "Open": "label-success",
8 "To Reply": "label-danger",
9 "Closed": "label-default"
10} %}
11
12<div class="ticket-content">
13 <ul class="breadcrumb">
14 <li><a href="index">Home</a></li>
15 <li><a href="tickets">My Tickets</a></li>
16 <li class="active"><i class="icon-ticket icon-fixed-width"></i> {{ doc.name or "" }}</li>
17 </ul>
18 {% if not doc -%}
19 <script>ask_to_login();</script>
20 {% else %}
21 <hr>
22 {%- if doc.status -%}
23 {% if doc.status == "Waiting for Customer" -%}
24 {% set status = "To Reply" %}
25 {% else %}
26 {% set status = doc.status %}
27 {%- endif -%}
28 <div class="row">
29 <div class="col-md-2" style="margin-bottom: 7px;">
30 <span class="label {{ status_label.get(status) or 'label-default' }}">{{ status }}</span>
31 </div>
32 <div class="col-md-8">
33 <div class="row col-md-12">{{ doc.subject }}</div>
34 </div>
35 <div class="col-md-2">
36 <span class="text-muted pull-right">{{ frappe.utils.formatdate(doc.creation) }}</span>
37 </div>
38 </div>
39 <div class="row">
40 <h4 class="col-xs-6">Messages</h4>
41 <div class="col-xs-6">
42 <button class="btn btn-sm btn-primary pull-right" id="ticket-reply">
43 <i class="icon-envelope icon-fixed-width"></i> Reply</button>
44 <button class="btn btn-sm btn-success pull-right hide" id="ticket-reply-send">
45 <i class="icon-arrow-right icon-fixed-width"></i> Send</button>
46 </div>
47 </div>
48 <p id="ticket-alert" class="alert alert-danger"
49 style="display: none;">&nbsp;</p>
50 <div>
51 <table class="table table-bordered table-striped" id="ticket-thread">
52 <tbody>
53 {%- for comm in
54 (doc.get({"doctype":"Communication"})|sort(reverse=True, attribute="creation")) %}
55 <tr>
56 <td>
57 <h5 style="text-transform: none">
58 {{ comm.sender }} on {{ frappe.utils.formatdate(comm.creation) }}</h5>
59 <hr>
60 <p>{{ frappe.utils.is_html(comm.content) and comm.content or
61 comm.content.replace("\n", "<br>")}}</p>
62 </td>
63 </tr>
64 {% endfor -%}
65 </tbody>
66 </table>
67 </div>
68 {%- endif -%}
69 {% endif -%}
70</div>
71
72<script>
73$(document).ready(function() {
74 $("#ticket-reply").on("click", function() {
75 if(!$("#ticket-reply-editor").length) {
76 $('<tr id="ticket-reply-editor"><td>\
77 <h5 style="text-transform: none">Reply</h5>\
78 <hr>\
79 <textarea rows=10 class="form-control" style="resize: vertical;"></textarea>\
80 </td></tr>').prependTo($("#ticket-thread").find("tbody"));
81 $("#ticket-reply").addClass("hide");
82 $("#ticket-reply-send").removeClass("hide");
83 }
84 });
85
86 $("#ticket-reply-send").on("click", function() {
87 var reply = $("#ticket-reply-editor").find("textarea").val().trim();
88 if(!reply) {
89 msgprint("Please write something in reply!");
90 } else {
91 frappe.call({
92 type: "POST",
93 method: "shopping_cart.templates.pages.ticket.add_reply",
94 btn: this,
95 args: { ticket: "{{ doc.name }}", message: reply },
96 callback: function(r) {
97 if(r.exc) {
98 msgprint(r._server_messages
99 ? JSON.parse(r._server_messages).join("<br>")
100 : "Something went wrong!");
101 } else {
102 window.location.reload();
103 }
104 }
105 })
106 }
107 });
108});
109
110var msgprint = function(txt) {
111 if(txt) $("#ticket-alert").html(txt).toggle(true);
112}
113</script>
114
115<!-- no-sidebar -->
116{% endblock %}