Poprawienie serializacji
authorzuber <marek@stepniowski.com>
Wed, 30 Dec 2009 14:28:43 +0000 (15:28 +0100)
committerzuber <marek@stepniowski.com>
Wed, 30 Dec 2009 14:28:43 +0000 (15:28 +0100)
platforma/static/js/main.js
platforma/static/xsl/html2wl_client.xsl
platforma/static/xsl/wl2html_client.xsl
platforma/templates/wiki/document_details.html

index ff0d626..c1af60a 100644 (file)
@@ -1,7 +1,58 @@
+var MARGIN = {
+    dramat_wierszowany_l: 4,
+    dramat_wierszowany_lp: 4,
+    dramat_wspolczesny: 4,
+    wywiad: 4,
+    opowiadanie: 4,
+    powiesc: 4,
+    liryka_l: 4,
+    liryka_lp: 4,
+    naglowek_czesc: 4,
+    naglowek_akt: 4,
+    naglowek_rozdzial: 4,
+    naglowek_osoba: 4,
+    lista_osob: 4,
+    
+    akap: 3,
+    akap_cd: 3,
+    akap_dialog: 3,
+    strofa: 3,
+    motto: 3, 
+    miejsce_czas: 3,
+        
+    autor_utworu: 2,
+    nazwa_utworu: 2,
+    dzielo_nadrzedne: 2,
+    didaskalia: 2,
+    motto_podpis: 2,
+    naglowek_listy: 2,
+    
+    kwestia: 1,
+    lista_osoba: 1
+}
+
+MARGIN['rdf:RDF'] = 3;
+MARGIN['rdf:Description'] = 2;
+
+function elementType(element) {
+    if ($.inArray(element.tagName, ['akap', 'akap_cd', 'akap_dialog', 'strofa', 'didaskalia', 'wers', 'wers_cd', 'wers_akap', 'wers_wciety', 'autor_utworu', 'nazwa_utworu', 'dzielo_nadrzedne', 'podpis'])) {
+        return 'inline';
+    } else {
+        return 'block';
+    }
+}
 // Serializuje XML, wstawiając odpowiednie ilości białych znaków między elementami
-function serialize(element) {
+function serialize(element, mode) {
+    if (!mode) {
+        mode = 'block';
+    }
+    
     if (element.nodeType == 3) { // tekst
-        return [$.trim(element.nodeValue)];
+        if (mode == 'block') {
+            return [$.trim(element.nodeValue)];
+        } else {
+            return [element.nodeValue];
+        }
     } else if (element.nodeType != 1) { // pomijamy węzły nie będące elementami XML ani tekstem
         return [];
     }
@@ -9,6 +60,14 @@ function serialize(element) {
     var result = [];
     var hasContent = false;
     
+    if (MARGIN[element.tagName]) {
+        for (var i=0; i < MARGIN[element.tagName]; i++) {
+            result.push('\n');
+        };
+    } else if (element.tagName.indexOf('dc:') != -1) {
+        result.push('\n');
+    }
+    
     result.push('<');
     result.push(element.tagName);
     
@@ -40,7 +99,8 @@ function serialize(element) {
         result.push('>');
 
         for (var i=0; i < element.childNodes.length; i++) {
-            result = result.concat(serialize(element.childNodes[i]));
+            result = result.concat(serialize(element.childNodes[i], 
+                mode == 'inline' ? 'inline' : elementType(element.childNodes[i])));
         }
 
         result.push('</');
@@ -48,16 +108,6 @@ function serialize(element) {
         result.push('>');
     }
     
-    if (element.tagName == 'akap' || element.tagName == 'akap_dialog' || element.tagName == 'akap_cd' || element.tagName == 'strofa') {
-        result.push('\n\n\n');
-    } else if (element.tagName == 'naglowek_rozdzial') {
-        result.push('\n\n');
-    } else if (element.tagName == 'rdf:RDF') {
-        result.push('\n\n\n\n\n');
-    } else if (element.tagName.indexOf('dc:') != -1) {
-        result.push('\n');
-    }
-    
     return result;
 };
 
@@ -274,17 +324,60 @@ function html(element) {
         var range = document.createRange();
         var s = $(".motyw[theme-class='"+themeId+"']")[0];
         var e = $(".end[theme-class='"+themeId+"']")[0];
-        // console.log('Selecting range:', themeId, range, s, e);
 
         if(s && e) {
             range.setStartAfter(s);
             range.setEndBefore(e);
             selection.addRange(range);
-            // highlight('yellow');
-            // selection.removeAllRanges();
         }
     };
     
+    // function openForEdit($origin)
+    // {       
+    //     // if(this.currentOpen && this.currentOpen != $origin) {
+    //     //     this.closeWithSave(this.currentOpen);
+    //     // }
+    //     
+    //     var $box = null
+    // 
+    //     // annotations overlay their sub box - not their own box //
+    //     if($origin.is(".annotation-inline-box"))
+    //         $box = $("*[x-annotation-box]", $origin);
+    //     else
+    //         $box = $origin;
+    //     
+    //     var x = $box[0].offsetLeft;
+    //     var y = $box[0].offsetTop;
+    //     var w = $box.outerWidth();
+    //     var h = $box.innerHeight();
+    // 
+    //     console.log("Edit origin:", $origin, " box:", $box);
+    //     console.log("offsetParent:", $box[0].offsetParent);
+    //     console.log("Dimensions: ", x, y, w , h);
+    // 
+    //     // start edition on this node
+    //     var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
+    // 
+    //     h = Math.max(h - 20, 2*parseInt($box.css('line-height')));
+    //     
+    //     console.log(h);
+    //     
+    //     $overlay.css({
+    //         position: 'absolute',
+    //         height: h,
+    //         left: x,
+    //         top: y,
+    //         right: 0
+    //     });
+    //     
+    //     $($box[0].offsetParent).append($overlay);
+    //     console.log($overlay);
+    // }
+    // 
+    // $('.edit-button').live('click', function() {
+    //     openForEdit($(this).parent());
+    // });
+    // 
     var button = $('<button class="edit-button">Edytuj</button>');
     $(element).bind('mousemove', function(event) {
         var editable = $(event.target).closest('*[x-editable]');
index 7660293..4a5ab96 100755 (executable)
@@ -7,7 +7,7 @@
     xmlns:dc="http://purl.org/dc/elements/1.1/"\r
 >\r
 \r
-    <xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes" />\r
+    <xsl:output method="xml" encoding="utf-8" indent="no" omit-xml-declaration="yes" />\r
     <!--\r
         Ten dokument definiuję przekształcenie odwrotne do wl2html\r
     -->\r
index 8cd780e..fa3665b 100755 (executable)
                 <xsl:value-of select="substring-after(@id, 'm')" />
             </xsl:attribute>
             <xsl:call-template name="context-menu" />
-            <span class="theme-text-list"><xsl:value-of select="." /></span>
+            <span class="theme-text-list"><xsl:value-of select=".|node()" /></span>
         </span>
     </xsl:template>
 
index e5c9d0c..6d4823b 100644 (file)
@@ -54,9 +54,9 @@
                 </div>
             </div>
         </div>
-        <div id="save-dialog" style="display: none">
-            <label for="komentarz">Komentarz</label><input type="text" name="komentarz" value="" id="komentarz" />
-            <button id="save-ok">Zapisz</button>
-            <button id="save-cancel">Anuluj</button>
+        <div id="save-dialog" style="display: none; text-align: left">
+            <label for="komentarz" style="display: block">Opis zmian:</label>
+            <textarea name="komentarz" id="komentarz" style="display: block; width: 100%"></textarea>
+            <button id="save-ok">Zapisz</button> <button id="save-cancel">Anuluj</button>
         </div>
 {% endblock %}
\ No newline at end of file