From: zuber Date: Mon, 21 Dec 2009 12:42:00 +0000 (+0100) Subject: Dodanie obsługi błędów. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/c1cc36d07592b0f9c61a3c9ee89b28e6576c65d7?ds=sidebyside Dodanie obsługi błędów. --- diff --git a/platforma/static/js/main.js b/platforma/static/js/main.js index 75e3746f..ff0d626b 100644 --- a/platforma/static/js/main.js +++ b/platforma/static/js/main.js @@ -337,10 +337,21 @@ $(function() { doc = editor.getCode().replace(/\/\s+/g, '
'); doc = parser.parseFromString(doc, 'text/xml'); + var error = $('parsererror', doc); + console.log(error); + if (error.length == 0) { + doc = htmlXSL.transformToFragment(doc, document); + error = $('parsererror', doc); + } console.log('xml', doc); - doc = htmlXSL.transformToFragment(doc, document); - console.log('after transform', doc); - $('#html-view').html(doc.firstChild); + if (error.length > 0) { + console.log(error); + $('#html-view').html('

Wystąpił błąd:

' + error.text() + '
'); + } else { + console.log('after transform', doc); + $('#html-view').html(doc.firstChild); + } + $('#simple-editor').unblock(); }, error: function() {alert('Error loading XSL!')} @@ -360,15 +371,30 @@ $(function() { var serializer = new XMLSerializer(); var xsl = createXSLT(data); + if ($('#html-view .error').length > 0) { + $('#source-editor').unblock(); + return; + } doc = serializer.serializeToString($('#html-view div').get(0)) doc = parser.parseFromString(doc, 'text/xml'); console.log('xml',doc, doc.documentElement); // TODO: Sprawdzenie błędów - doc = xsl.transformToDocument(doc); + var error = $('parsererror', doc.documentElement); + console.log(error); + if (error.length == 0) { + doc = xsl.transformToDocument(doc, document); + error = $('parsererror', doc.documentElement); + } + + if (error.length > 0) { + console.log(error); + $('#source-editor').html('

Wystąpił błąd:

' + error.text()); + } else { + doc = serialize(doc.documentElement).join(''); + editor.setCode(doc); + } + console.log('after transform', doc, doc.documentElement); - doc = serialize(doc.documentElement).join(''); - // doc = serializer.serializeToString(doc.documentElement) - editor.setCode(doc); $('#source-editor').unblock(); }, error: function() {alert('Error loading XSL!')}