From 465f9d370fb3b96b4cc30e139d24e4479a9f7ab0 Mon Sep 17 00:00:00 2001 From: zuber Date: Fri, 15 Jan 2010 01:05:55 +0100 Subject: [PATCH] Konwersja HTML do XML przed zapisaniem XML na serwer. --- platforma/static/js/main.js | 81 ++++++++++++++++++++--------------- platforma/templates/base.html | 3 +- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/platforma/static/js/main.js b/platforma/static/js/main.js index de848350..a19dc14e 100644 --- a/platforma/static/js/main.js +++ b/platforma/static/js/main.js @@ -253,7 +253,7 @@ function transform(editor) { }; -function reverseTransform(editor) { +function reverseTransform(editor, cont) { var serializer = new XMLSerializer(); if ($('#html-view .error').length > 0) { return; @@ -265,6 +265,9 @@ function reverseTransform(editor) { success: function(text) { editor.setCode(text); $.unblockUI(); + if (cont) { + cont(); + } }, error: function(text) { $('#source-editor').html('

Wystąpił błąd:

' + text + '
'); $.unblockUI(); @@ -410,41 +413,49 @@ $(function() { $('#save-ok').click(function() { $.blockUI({message: 'Zapisywanie...'}); - var metaComment = '' - - 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 = '' + + 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); + }, + }) + } - $.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); - }, - }) + if ('#simple-view-tab.active') { + reverseTransform(editor, doSave); + } else { + doSave(); + } }); $('#save-cancel').click(function() { diff --git a/platforma/templates/base.html b/platforma/templates/base.html index 4819b7c4..750cf7b3 100755 --- a/platforma/templates/base.html +++ b/platforma/templates/base.html @@ -4,7 +4,8 @@ {% block title %}Platforma Redakcyjna{% block subtitle %}{% endblock subtitle %}{% endblock title%} - + + {# #} {% block extrahead %} {% endblock %} -- 2.20.1