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