aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-10-18 23:21:07 +0300
committerFilipp Lepalaan <filipp@mac.com>2015-10-18 23:21:07 +0300
commitc498e23d48548e8048d656677a6b7ee2a9c3fe36 (patch)
treea78e08c21a7ead38b8f95ec9ff0e21946715e0f4
parentcef2dc31b06c7070c5a4e7e3e608402230e1e4b2 (diff)
downloadServo-c498e23d48548e8048d656677a6b7ee2a9c3fe36.tar.gz
Servo-c498e23d48548e8048d656677a6b7ee2a9c3fe36.tar.bz2
Servo-c498e23d48548e8048d656677a6b7ee2a9c3fe36.zip
Fix issue with editing notes and multiple tabs
-rw-r--r--servo/forms/notes.py6
-rw-r--r--servo/urls/note.py13
-rw-r--r--servo/views/note.py11
-rwxr-xr-xstatic/js/servo.js6
4 files changed, 25 insertions, 11 deletions
diff --git a/servo/forms/notes.py b/servo/forms/notes.py
index fb96ff6..d6ed693 100644
--- a/servo/forms/notes.py
+++ b/servo/forms/notes.py
@@ -3,6 +3,7 @@
import json
from django import forms
from gsxws import escalations
+from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
@@ -32,11 +33,16 @@ class NoteForm(BaseModelForm):
choices=note.get_sender_choices(),
widget=forms.Select(attrs={'class': 'span12'})
)
+
self.fields['body'].widget = AutocompleteTextarea(
rows=20,
choices=Template.templates()
)
+ if note.order:
+ url = reverse('notes-render_template', args=[note.order.pk])
+ self.fields['body'].widget.attrs['data-url'] = url
+
class NoteSearchForm(forms.Form):
body = forms.CharField(required=False, label=_('Body contains'))
diff --git a/servo/urls/note.py b/servo/urls/note.py
index 87f3035..4057f40 100644
--- a/servo/urls/note.py
+++ b/servo/urls/note.py
@@ -11,10 +11,15 @@ urlpatterns = patterns(
url(r'^templates/$', 'templates'),
url(r'^new/$', 'edit', name="notes-create"),
url(r'^templates/(\d+)/$', 'templates', name='notes-template'),
- url(r'^render_template/$', 'render_template', name='notes-render_template'),
- url(r'^to/customer/(?P<customer>\d+)/new/$', 'edit', name="notes-create_to_customer"),
- url(r'^(?P<pk>\d+)/toggle/tag/(?P<tag_id>\d+)/$', 'toggle_tag', name="notes-toggle_tag"),
- url(r'^(?P<pk>\d+)/toggle/(?P<flag>[a-z]+)/$', 'toggle_flag', name="notes-toggle_flag"),
+ url(r'^render/$', 'render_template', name='notes-render_template'),
+ url(r'^render/(?P<order_id>\d+)/$', 'render_template',
+ name='notes-render_template'),
+ url(r'^to/customer/(?P<customer>\d+)/new/$', 'edit',
+ name="notes-create_to_customer"),
+ url(r'^(?P<pk>\d+)/toggle/tag/(?P<tag_id>\d+)/$', 'toggle_tag',
+ name="notes-toggle_tag"),
+ url(r'^(?P<pk>\d+)/toggle/(?P<flag>[a-z]+)/$', 'toggle_flag',
+ name="notes-toggle_flag"),
url(r'^(?P<parent>\d+)/reply/$', 'edit', name="notes-reply"),
url(r'^(?P<pk>\d+)/edit/$', 'edit', name="notes-edit"),
url(r'^(?P<pk>\d+)/messages/$', 'list_messages', name="notes-messages"),
diff --git a/servo/views/note.py b/servo/views/note.py
index 9eb2a4a..19dba8a 100644
--- a/servo/views/note.py
+++ b/servo/views/note.py
@@ -256,19 +256,18 @@ def delete_note(request, pk):
@csrf_exempt
-def render_template(request):
+def render_template(request, order_id=None):
"""
Renders the template with this title with the current
Service Order as the context
"""
- content = ''
title = request.POST.get('title')
tpl = get_object_or_404(Template, title=title)
+ content = tpl.content
- if request.session.get('current_order_id'):
- tpl = template.Template(tpl.content)
- order = Order.objects.get(pk=request.session['current_order_id'])
- content = tpl.render(template.Context({'order': order}))
+ if order_id:
+ order = get_object_or_404(Order, pk=order_id)
+ content = tpl.render(order)
return HttpResponse(content)
diff --git a/static/js/servo.js b/static/js/servo.js
index ed6be4d..7038b9f 100755
--- a/static/js/servo.js
+++ b/static/js/servo.js
@@ -289,7 +289,11 @@ $(document).ready(function() {
},
updater: function(item){
var that = $(this);
- $.post('/notes/render_template/', {title: item}, function(r){
+ var url = '/notes/render/';
+ if (that[0].$element.data('url')) {
+ url = that[0].$element.data('url');
+ }
+ $.post(url, {title: item}, function(r){
that[0].$element.val(r);
});
}