document = Document(self.get_storage(), name=self.cleaned_data['name'], text=self.cleaned_data['text'])
storage.put(document, self.cleaned_data['author'], self.cleaned_data['comment'],
self.cleaned_data['revision'])
+ return storage.get(self.cleaned_data['name'])
from django.views.generic.simple import direct_to_template
-from django.http import HttpResponse, HttpResponseRedirect
+from django.http import HttpResponse
+from django.utils import simplejson as json
from wiki.models import storage, Document, DocumentNotFound
from wiki.forms import DocumentForm
document = storage.get(name)
except DocumentNotFound:
document = Document(storage, name=name, text='')
-
+
+
if request.method == 'POST':
form = DocumentForm(request.POST, instance=document)
if form.is_valid():
- form.save()
- return HttpResponse('OK')
+ document = form.save()
+ return HttpResponse(json.dumps({'text': document.text, 'revision': document.revision()}))
else:
- print form.errors
+ return HttpResponse(json.dumps({'errors': form.errors}))
else:
form = DocumentForm(instance=document)
$('#save-button').click(function(event) {
event.preventDefault();
$.blockUI({message: $('#save-dialog')});
-
- // console.log(editor.getCode(), $('form input[name=text]').get(0));
- // $('form textarea[name=text]').val(editor.getCode());
- // $('form').ajaxSubmit(function() {
- // alert('Udało się!');
- // });
});
$('#save-ok').click(function() {
$.ajax({
url: document.location.href,
type: "POST",
- dataType: "html",
+ dataType: "json",
data: data,
- success: function() {
+ success: function(data) {
+ if (data.text) {
+ editor.setCode(data.text);
+ $('#document-revision').html(data.revision);
+ } else {
+ console.log(data.errors);
+ alert(data.errors);
+ }
$.unblockUI();
},
error: function(xhr, textStatus, errorThrown) {
},
})
});
+
+ $('#save-cancel').click(function() {
+ $.unblockUI();
+ });
$('#simple-view-tab').click(function() {
if ($(this).hasClass('active')) {
</div>
</div>
<div id="save-dialog" style="display: none">
- <p>Zapisywanie</p>
<label for="komentarz">Komentarz</label><input type="text" name="komentarz" value="" id="komentarz" />
- <button id="save-ok">Ok</button>
+ <button id="save-ok">Zapisz</button>
+ <button id="save-cancel">Anuluj</button>
</div>
{% endblock %}
\ No newline at end of file