- var metaComment = '<!--';
- $('#document-meta div').each(function() {
- metaComment += '\n\t' + $(this).attr('class') + ': ' + $(this).html();
- });
- metaComment += '\n-->'
-
- var data = {
- name: $('#document-name').html(),
- text: metaComment + editor.getCode(),
- revision: $('#document-revision').html(),
- author: 'annonymous',
- comment: $('#komentarz').val()
- };
-
- console.log(data);
+ function doSave (argument) {
+ var metaComment = '<!--';
+ $('#document-meta div').each(function() {
+ metaComment += '\n\t' + $(this).attr('class') + ': ' + $(this).html();
+ });
+ metaComment += '\n-->'
+
+ var data = {
+ name: $('#document-name').html(),
+ text: metaComment + editor.getCode(),
+ revision: $('#document-revision').html(),
+ author: 'annonymous',
+ comment: $('#komentarz').val()
+ };
+
+ console.log(data);
+
+ $.ajax({
+ url: document.location.href,
+ type: "POST",
+ dataType: "json",
+ data: data,
+ 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) {
+ alert('error: ' + textStatus + ' ' + errorThrown);
+ },
+ })
+ }