blob: 6942d3bff036a0d590deaf81f75b9ea70bdec731 [file] [log] [blame]
Rushabh Mehtadf200f32013-12-25 15:19:22 +05301{% extends "templates/includes/transactions.html" %}
Anand Doshi330dae92013-09-10 13:46:15 +05302
3{% block javascript -%}
4{{ super() }}
5
6<script>
7 var status_label = {
8 "Open": "label-success",
9 "Waiting for Customer": "label-danger",
10 "Closed": "label-default"
11 }
12
13 var render = function(doc) {
14 doc.status = doc.status.trim();
15 doc.label_class = status_label[doc.status] || "label-default";
16 if(doc.status==="Waiting for Customer") doc.status = "To Reply";
17
18 $(repl('<a href="{{ page }}?name=%(name)s" class="list-group-item">\
19 <div class="row">\
20 <div class="col-md-2" style="margin-bottom: 7px;"><span class="label %(label_class)s">\
21 %(status)s</span></div>\
22 <div class="col-md-8">\
23 <div class="row col-md-12">%(name)s</div>\
24 <div class="row col-md-12 text-muted">%(subject)s</div>\
25 </div>\
26 <div class="col-md-2 pull-right">\
27 <span class="text-muted">%(creation)s</span>\
28 </div>\
29 </div>\
30 </a>', doc)).appendTo($list);
31 };
Anand Doshifb109ad2013-09-11 18:58:20 +053032
33 $(document).ready(function() {
34 if(!window.$new_ticket) {
35 window.$new_ticket = $('<div>\
36 <button class="btn btn-primary" style="margin-bottom: 15px;" id="new-ticket">\
37 <i class="icon-tag icon-fixed-width"></i> New Ticket\
38 </button>\
39 <button class="btn btn-success hide" style="margin-bottom: 15px;" id="new-ticket-send">\
40 <i class="icon-arrow-right icon-fixed-width"></i> Send\
41 </button>\
42 </div>').insertBefore(".transaction-list");
43 }
44
45 window.$new_ticket.find("#new-ticket").on("click", function() {
46 $(this).addClass("hide");
47 $(window.$new_ticket).find("#new-ticket-send").removeClass("hide");
48 $('<div class="well" id="ticket-editor">\
49 <div class="form-group"><input class="form-control" type="data"\
50 placeholder="Subject" data-fieldname="subject"></div>\
51 <div class="form-group"><textarea rows=10 class="form-control" \
52 style="resize: vertical;" placeholder="Message" \
53 data-fieldname="message"></textarea></div>\
54 </div>')
55 .insertAfter(window.$new_ticket);
56 });
57
58 window.$new_ticket.find("#new-ticket-send").on("click", function() {
59 var subject = $("#ticket-editor").find('[data-fieldname="subject"]').val().trim();
60 var message = $("#ticket-editor").find('[data-fieldname="message"]').val().trim();
61 if(!(subject && message)) {
62 msgprint("Please write something in subject and message!");
63 } else {
64 wn.call({
65 type: "POST",
66 method: "support.doctype.support_ticket.templates.pages.tickets.make_new_ticket",
67 btn: this,
68 args: { subject: subject, message: message },
69 callback: function(r) {
70 if(r.exc) {
71 msgprint(r._server_messages
72 ? JSON.parse(r._server_messages).join("<br>")
73 : "Something went wrong!");
74 } else {
75 window.location.href = "ticket?name=" + encodeURIComponent(r.message);
76 }
77 }
78 })
79 }
80 });
81 });
82
83 var msgprint = function(txt) {
84 if(txt) $("#msgprint-alert").html(txt).toggle(true);
85 }
Anand Doshi330dae92013-09-10 13:46:15 +053086</script>
87{%- endblock %}