X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/c988cd5d12cb6203ca8216e05bcbc202e14a04f8..ae9eecda5561b99cd51b1f3709e3cdc803ba47eb:/platforma/static/js/models.js?ds=inline
diff --git a/platforma/static/js/models.js b/platforma/static/js/models.js
index d2869ede..dae64d8a 100755
--- a/platforma/static/js/models.js
+++ b/platforma/static/js/models.js
@@ -98,39 +98,94 @@ Editor.HTMLModel = Editor.Model.extend({
return false;
},
- asWLML: function(element)
- {
- var result = this.wlmlXSL.transformToFragment(element, document);
+ asWLML: function(element, inner)
+ {
+ console.log("Source", element);
+ var doc = this.parser.parseFromString(this.serializer.serializeToString(element), 'text/xml');
+
+ var result = this.wlmlXSL.transformToDocument(doc);
if(!result) {
- console.log(this.wlmlXSL.transformToDocument(element));
+ console.log("Failed", this.wlmlXSL, doc);
throw "Failed to transform fragment";
}
- console.log("Transform result:", result);
- return this.serializer.serializeToString(result);
+ console.log("Transformed", doc, " to: ", result.documentElement);
+ if(inner) {
+ var children = result.documentElement.childNodes;
+ var buf = '';
+
+ for(var i=0; i < children.length; i++)
+ buf += this.serializer.serializeToString(children.item(i));
+
+ return buf;
+ }
+
+ return this.serializer.serializeToString(result.documentElement);
+ },
+
+ innerAsWLML: function(elem)
+ {
+ return this.asWLML(elem, true);
+ },
+
+ updateInnerWithWLML: function($element, innerML)
+ {
+ var e = $element.clone().html('')[0];
+ var s = this.asWLML(e);
+ // hurray for dirty hacks :P
+ s = s.replace(/>%<\//, '>'+innerML+'');
+ return this.updateWithWLML($element, s);
},
updateWithWLML: function($element, text)
{
// filter the string
text = text.replace(/\/\s+/g, '
');
- var chunk = this.parser.parseFromString("
Źle sformatowana zawartoÅÄ:" + e.toString() + "
"; + } - // check if chunk is parsable - if(errors.length > 0) - throw {text: errors.text(), html: errors.html()}; + var parseError = chunk.getElementsByTagName('parsererror'); + console.log("Errors:", parseError); - var result = this.htmlXSL.transformToFragment(chunk, document); + if(parseError.length > 0) + { + console.log("Parse errors.") + return this.serializer.serializeToString(parseError.item(0)); + } - console.log("RESULT", this.serializer.serializeToString(result)); + console.log("Transforming to HTML"); + var result = this.htmlXSL.transformToFragment(chunk, $element[0].ownerDocument).firstChild; - if(!result) - throw "WLML->HTML transformation failed."; - - $element.replaceWith(result); + if(!result) { + return "BÅÄ d aplikacji - nie udaÅo siÄ wygenerowaÄ nowego widoku HTML."; + } + + var errors = result.getElementsByTagName('error'); + if(errors.length > 0) + { + var errorMessage = 'WystÄ piÅy bÅÄdy: