From 594998281db97c722685e9e8ed5759d4e5b2ded0 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 27 Aug 2010 12:41:39 +0200 Subject: [PATCH] Fixes #778: better handle ajax problems in html view --- redakcja/static/css/html.css | 5 ++ .../static/js/wiki/view_editor_wysiwyg.js | 19 ++-- redakcja/static/js/wiki/xslt.js | 88 +++++++++---------- 3 files changed, 60 insertions(+), 52 deletions(-) diff --git a/redakcja/static/css/html.css b/redakcja/static/css/html.css index c0936cf2..971e4b85 100644 --- a/redakcja/static/css/html.css +++ b/redakcja/static/css/html.css @@ -354,6 +354,11 @@ div[x-node] > .uwaga { user-select: none; margin-right: -12em; text-align: left; + color: #999; +} + +.htmlview .canon { + color: black; } .htmlview .noncanon { diff --git a/redakcja/static/js/wiki/view_editor_wysiwyg.js b/redakcja/static/js/wiki/view_editor_wysiwyg.js index a661a1cd..2f4e43d4 100644 --- a/redakcja/static/js/wiki/view_editor_wysiwyg.js +++ b/redakcja/static/js/wiki/view_editor_wysiwyg.js @@ -313,12 +313,14 @@ if ($origin.is('.motyw')) { - $('textarea', $overlay).autocomplete('/themes', { - autoFill: true, - multiple: true, - selectFirst: true, - highlight: false - }); + withThemes(function(canonThemes){ + $('textarea', $overlay).autocomplete(canonThemes, { + autoFill: true, + multiple: true, + selectFirst: true, + highlight: false + }); + }) } if ($origin.is('.motyw')){ @@ -487,8 +489,9 @@ error: function(text){ /* only basic error message */ var errorArray = text.split("\n"); - var errorLocation = errorArray[2].split(":")[0]; - text = errorLocation; + if (errorArray.length >= 3) { + text = errorArray[2].split(":")[0]; + } $('#html-view').html('

Wystąpił błąd: '+ text + '

'); _finalize(failure); } diff --git a/redakcja/static/js/wiki/xslt.js b/redakcja/static/js/wiki/xslt.js index a5093b04..86c6d362 100644 --- a/redakcja/static/js/wiki/xslt.js +++ b/redakcja/static/js/wiki/xslt.js @@ -19,6 +19,7 @@ function withStylesheets(code_block, onError) $.ajax({ url: STATIC_URL + 'xsl/wl2html_client.xsl', dataType: 'xml', + timeout: 10000, success: function(data) { xml2htmlStylesheet = createXSLT(data); $.unblockUI(); @@ -33,30 +34,26 @@ function withStylesheets(code_block, onError) } } -var canonThemes = null; // Wykonuje block z załadowanymi kanonicznymi motywami function withThemes(code_block, onError) { - if (!canonThemes) { - $.blockUI({message: 'Ładowanie motywów...'}); + if (typeof withThemes.canon == 'undefined') { $.ajax({ url: '/themes', dataType: 'text', success: function(data) { - canonThemes = {}; - themes = data.split('\n'); - for (i in themes) { - canonThemes[themes[i]] = 1; - } - $.unblockUI(); - code_block(); + withThemes.canon = data.split('\n'); + code_block(withThemes.canon); }, - error: onError + error: function() { + withThemes.canon = null; + code_block(withThemes.canon); + } }) } else { - code_block(); + code_block(withThemes.canon); } } @@ -64,40 +61,43 @@ function withThemes(code_block, onError) function xml2html(options) { withStylesheets(function() { - withThemes(function() { - var xml = options.xml.replace(/\/\s+/g, '
'); - var parser = new DOMParser(); - var serializer = new XMLSerializer(); - var doc = parser.parseFromString(xml, 'text/xml'); - var error = $('parsererror', doc); - - if (error.length == 0) { - doc = xml2htmlStylesheet.transformToFragment(doc, document); - console.log(doc.firstChild); - - if(doc.firstChild === null) { - options.error("Błąd w przetwarzaniu XML."); - return; - } - - error = $('parsererror', doc); + var xml = options.xml.replace(/\/\s+/g, '
'); + var parser = new DOMParser(); + var serializer = new XMLSerializer(); + var doc = parser.parseFromString(xml, 'text/xml'); + var error = $('parsererror', doc); + + if (error.length == 0) { + doc = xml2htmlStylesheet.transformToFragment(doc, document); + console.log(doc.firstChild); + + if(doc.firstChild === null) { + options.error("Błąd w przetwarzaniu XML."); + return; } - if (error.length > 0 && options.error) { - options.error(error.text()); - } else { - $('.theme-text-list', doc.firstChild).each(function(){ - var themes = $(this).html().split(','); - for (i in themes) { - themes[i] = $.trim(themes[i]); - if (!(themes[i] in canonThemes)) - themes[i] = '' + themes[i] + "" - } - $(this).html(themes.join(', ')); - }); - options.success(doc.firstChild); - } - }, function() { options.error && options.error('Nie udało się załadować motywów'); }); + error = $('parsererror', doc); + } + + if (error.length > 0 && options.error) { + options.error(error.text()); + } else { + options.success(doc.firstChild); + + withThemes(function(canonThemes) { + if (canonThemes != null) { + $('.theme-text-list').addClass('canon').each(function(){ + var themes = $(this).html().split(','); + for (i in themes) { + themes[i] = $.trim(themes[i]); + if (canonThemes.indexOf(themes[i]) == -1) + themes[i] = '' + themes[i] + "" + } + $(this).html(themes.join(', ')); + }); + } + }); + } }, function() { options.error && options.error('Nie udało się załadować XSLT'); }); } -- 2.20.1