fnp
/
redakcja.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
befc244
)
Zapisywanie via AJAX.
author
zuber
<marek@stepniowski.com>
Mon, 21 Dec 2009 10:16:42 +0000
(11:16 +0100)
committer
zuber
<marek@stepniowski.com>
Mon, 21 Dec 2009 10:16:42 +0000
(11:16 +0100)
apps/wiki/forms.py
patch
|
blob
|
history
apps/wiki/views.py
patch
|
blob
|
history
platforma/static/js/main.js
patch
|
blob
|
history
platforma/templates/wiki/document_details.html
patch
|
blob
|
history
diff --git
a/apps/wiki/forms.py
b/apps/wiki/forms.py
index
e247487
..
836d8f0
100644
(file)
--- a/
apps/wiki/forms.py
+++ b/
apps/wiki/forms.py
@@
-24,4
+24,5
@@
class DocumentForm(forms.Form):
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'])
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'])
diff --git
a/apps/wiki/views.py
b/apps/wiki/views.py
index
33d6610
..
b242802
100644
(file)
--- a/
apps/wiki/views.py
+++ b/
apps/wiki/views.py
@@
-1,5
+1,6
@@
from django.views.generic.simple import direct_to_template
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
from wiki.models import storage, Document, DocumentNotFound
from wiki.forms import DocumentForm
@@
-16,14
+17,15
@@
def document_detail(request, name, template_name='wiki/document_details.html'):
document = storage.get(name)
except DocumentNotFound:
document = Document(storage, name=name, text='')
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():
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:
else:
- print form.errors
+ return HttpResponse(json.dumps({'errors': form.errors}))
else:
form = DocumentForm(instance=document)
else:
form = DocumentForm(instance=document)
diff --git
a/platforma/static/js/main.js
b/platforma/static/js/main.js
index
cec5e22
..
75e3746
100644
(file)
--- a/
platforma/static/js/main.js
+++ b/
platforma/static/js/main.js
@@
-379,12
+379,6
@@
$(function() {
$('#save-button').click(function(event) {
event.preventDefault();
$.blockUI({message: $('#save-dialog')});
$('#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() {
});
$('#save-ok').click(function() {
@@
-403,9
+397,16
@@
$(function() {
$.ajax({
url: document.location.href,
type: "POST",
$.ajax({
url: document.location.href,
type: "POST",
- dataType: "
html
",
+ dataType: "
json
",
data: data,
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) {
$.unblockUI();
},
error: function(xhr, textStatus, errorThrown) {
@@
-413,6
+414,10
@@
$(function() {
},
})
});
},
})
});
+
+ $('#save-cancel').click(function() {
+ $.unblockUI();
+ });
$('#simple-view-tab').click(function() {
if ($(this).hasClass('active')) {
$('#simple-view-tab').click(function() {
if ($(this).hasClass('active')) {
diff --git
a/platforma/templates/wiki/document_details.html
b/platforma/templates/wiki/document_details.html
index
2c8030e
..
e5c9d0c
100644
(file)
--- a/
platforma/templates/wiki/document_details.html
+++ b/
platforma/templates/wiki/document_details.html
@@
-55,8
+55,8
@@
</div>
</div>
<div id="save-dialog" style="display: none">
</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" />
<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
</div>
{% endblock %}
\ No newline at end of file