Ponowne dodanie przycisków do edytora XML.
authorzuber <marek@stepniowski.com>
Thu, 3 Dec 2009 13:34:36 +0000 (14:34 +0100)
committerzuber <marek@stepniowski.com>
Thu, 3 Dec 2009 13:34:36 +0000 (14:34 +0100)
apps/toolbar/templates/toolbar/toolbar.html
apps/toolbar/templatetags/toolbar_tags.py
apps/wiki/views.py
platforma/static/js/button_scripts.js
platforma/templates/wiki/document_details.html

index c4fcdcb..a69dc3b 100644 (file)
@@ -1,32 +1,20 @@
 {% load toolbar_tags %}
 <div class="toolbar" xmlns:ui="http://nowoczesnapolska.org.pl/platforma/ui">
 {% load toolbar_tags %}
 <div class="toolbar" xmlns:ui="http://nowoczesnapolska.org.pl/platforma/ui">
-    
-    {# This div will be connected to the right place #}
-    <span class="panel-toolbar-extra">
-    {% for button in toolbar_extra_group.button_set.all %}
-    {% toolbar_button button %}
-    {% endfor %} 
-    </span>
-
-    <div class="toolbar-tabs-container toolbar-buttons-container">
-    <p>
+    <select name="button_group" id="toolbar-button-group-select" size="1">
         {% for group in toolbar_groups %}
         {% for group in toolbar_groups %}
-        <button ui:group="{{ group.slug }}" {% if forloop.first %}class="active"{% endif %}>
-            {{ group.name }}
-        </button>
+        <option value="{{ group.slug }}" {% if forloop.first %}selected="selected"{% endif %}>{{ group.name }}</option>
         {% endfor %}
         {% endfor %}
-    </p>
-    </div>
-
+    </select>
+    
     <div class="toolbar-button-groups-container">
         {% for group in toolbar_groups %}
     <div class="toolbar-button-groups-container">
         {% for group in toolbar_groups %}
-        <p ui:group="{{group.slug}}" class="toolbar-buttons-container" {% if not forloop.first %}style="display:none;"{% endif %}>
+        <div data-group="{{group.slug}}" class="toolbar-buttons-container">
             {# buttons for this group #}            
             {% for button in group.button_set.all %}
             {% toolbar_button button %}
             {% endfor %}
             {# buttons for this group #}            
             {% for button in group.button_set.all %}
             {% toolbar_button button %}
             {% endfor %}
-        </p>
+        </div>
         {% endfor %}
     </div>
         {% endfor %}
     </div>
-
+    <div class="toolbar-end"></div>
 </div>
 </div>
index 9957a93..14d3679 100644 (file)
@@ -1,11 +1,11 @@
 from django import template
 from django import template
-from toolbar import models
+from toolbar import models
 
 register = template.Library()
 
 @register.inclusion_tag('toolbar/toolbar.html')
 
 register = template.Library()
 
 @register.inclusion_tag('toolbar/toolbar.html')
-def toolbar(groups, extra):
-    return {'toolbar_groups': groups, 'toolbar_extra_group': extra}
+def toolbar():
+    return {'toolbar_groups': models.ButtonGroup.objects.all()}
 
 @register.inclusion_tag('toolbar/button.html')
 def toolbar_button(b):
 
 @register.inclusion_tag('toolbar/button.html')
 def toolbar_button(b):
index 339bde8..33d6610 100644 (file)
@@ -1,5 +1,5 @@
 from django.views.generic.simple import direct_to_template
 from django.views.generic.simple import direct_to_template
-from django.http import HttpResponseRedirect
+from django.http import HttpResponse, HttpResponseRedirect
 
 from wiki.models import storage, Document, DocumentNotFound
 from wiki.forms import DocumentForm
 
 from wiki.models import storage, Document, DocumentNotFound
 from wiki.forms import DocumentForm
@@ -21,7 +21,9 @@ def document_detail(request, name, template_name='wiki/document_details.html'):
         form = DocumentForm(request.POST, instance=document)
         if form.is_valid():
             form.save()
         form = DocumentForm(request.POST, instance=document)
         if form.is_valid():
             form.save()
-            return HttpResponseRedirect('/')
+            return HttpResponse('OK')
+        else:
+            print form.errors
     else:
         form = DocumentForm(instance=document)
     
     else:
         form = DocumentForm(instance=document)
     
index 4af9d72..4f93d9b 100755 (executable)
@@ -1,3 +1,32 @@
+(function() {
+  var slice = Array.prototype.slice;
+  
+  function update(array, args) {
+    var arrayLength = array.length, length = args.length;
+    while (length--) array[arrayLength + length] = args[length];
+    return array;
+  };
+  
+  function merge(array, args) {
+    array = slice.call(array, 0);
+    return update(array, args);
+  };
+  
+  Function.prototype.bind = function(context) {
+    if (arguments.length < 2 && typeof arguments[0] === 'undefined') {
+      return this;
+    } 
+    var __method = this;
+    var args = slice.call(arguments, 1);
+    return function() {
+      var a = merge(args, arguments);
+      return __method.apply(context, a);
+    }
+  }
+  
+})();
+
+
 function ScriptletCenter()
 {
     this.scriptlets = {};
 function ScriptletCenter()
 {
     this.scriptlets = {};
@@ -198,19 +227,19 @@ function ScriptletCenter()
 }
 
 ScriptletCenter.prototype.XMLEditorSelectedText = function(panel) {
 }
 
 ScriptletCenter.prototype.XMLEditorSelectedText = function(panel) {
-    return panel.contentView.editor.selection();
+    return panel.selection();
 };
 
 ScriptletCenter.prototype.XMLEditorReplaceSelectedText = function(panel, replacement)
 {
 };
 
 ScriptletCenter.prototype.XMLEditorReplaceSelectedText = function(panel, replacement)
 {
-    panel.contentView.editor.replaceSelection(replacement);
+    panel.replaceSelection(replacement);
     // Tell XML view that it's data has changed
     // Tell XML view that it's data has changed
-    panel.contentView.editorDataChanged();
+    // panel.contentView.editorDataChanged();
 };
 
 ScriptletCenter.prototype.XMLEditorMoveCursorForward = function(panel, n) {
 };
 
 ScriptletCenter.prototype.XMLEditorMoveCursorForward = function(panel, n) {
-    var pos = panel.contentView.editor.cursorPosition();
-    panel.contentView.editor.selectLines(pos.line, pos.character + n);
+    var pos = panel.cursorPosition();
+    panel.selectLines(pos.line, pos.character + n);
 };
 
 var scriptletCenter;
 };
 
 var scriptletCenter;
index e4c69ed..8a05589 100644 (file)
@@ -1,21 +1,27 @@
 {% extends "base.html" %}
 {% extends "base.html" %}
+{% load toolbar_tags %}
 
 {% block extrahead %}
     <script src="{{STATIC_URL}}js/lib/codemirror/codemirror.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.splitter.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.form.js" type="text/javascript" charset="utf-8"></script>
 
 {% block extrahead %}
     <script src="{{STATIC_URL}}js/lib/codemirror/codemirror.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.splitter.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.form.js" type="text/javascript" charset="utf-8"></script>
+    <script src="{{STATIC_URL}}js/button_scripts.js" type="text/javascript" charset="utf-8"></script>
     <script type="text/javascript" charset="utf-8">
     
         function serialize(element) {
     <script type="text/javascript" charset="utf-8">
     
         function serialize(element) {
-            if (element.nodeType == 3) {
+            if (element.nodeType == 3) { // tekst
                 return [$.trim(element.nodeValue)];
                 return [$.trim(element.nodeValue)];
+            } else if (element.nodeType != 1) { // pomijamy węzły nie będące elementami XML ani tekstem
+                return [];
             }
             
             var result = [];
             }
             
             var result = [];
+            var hasContent = false;
             
             result.push('<');
             result.push(element.tagName);
             
             
             result.push('<');
             result.push(element.tagName);
             
+            // Mozilla nie uważa deklaracji namespace za atrybuty
             var ns = element.tagName.indexOf(':');
             if (ns != -1 && $.browser.mozilla) {
                 result.push(' xmlns:');
             var ns = element.tagName.indexOf(':');
             if (ns != -1 && $.browser.mozilla) {
                 result.push(' xmlns:');
                     result.push('="');
                     result.push(attr.value);
                     result.push('"');
                     result.push('="');
                     result.push(attr.value);
                     result.push('"');
+                    hasContent = true;
                 }
             }
             
                 }
             }
             
-            result.push('>');
+            if (element.childNodes.length == 0) {
+                result.push(' />');
+            } else {
+                result.push('>');
     
     
-            for (var i=0; i < element.childNodes.length; i++) {
-                var child = element.childNodes[i];
-                result = result.concat(serialize(child));
-            }
-    
-            result.push('</');
-            result.push(element.tagName);
-            result.push('>');
+                for (var i=0; i < element.childNodes.length; i++) {
+                    result = result.concat(serialize(element.childNodes[i]));
+                }
     
     
-            if (element.tagName == 'akap') {
+                result.push('</');
+                result.push(element.tagName);
+                result.push('>');
+            }
+            
+            if (element.tagName == 'akap' || element.tagName == 'akap_dialog') {
                 result.push('\n\n\n');
             } else if (element.tagName == 'rdf:RDF') {
                 result.push('\n\n\n\n\n');
                 result.push('\n\n\n');
             } else if (element.tagName == 'rdf:RDF') {
                 result.push('\n\n\n\n\n');
                         doc = serializer.serializeToString($('#simple-editor div').get(0))
                         doc = parser.parseFromString(doc, 'text/xml');
                         console.log('xml',doc, doc.documentElement);
                         doc = serializer.serializeToString($('#simple-editor div').get(0))
                         doc = parser.parseFromString(doc, 'text/xml');
                         console.log('xml',doc, doc.documentElement);
+                        // TODO: Sprawdzenie błędów
                         doc = xsl.transformToDocument(doc);
                         console.log('after transform', doc, doc.documentElement);
                         doc = serialize(doc.documentElement).join('');
                         doc = xsl.transformToDocument(doc);
                         console.log('after transform', doc, doc.documentElement);
                         doc = serialize(doc.documentElement).join('');
             });
             
             $('#simple-view-tab').click(function() {
             });
             
             $('#simple-view-tab').click(function() {
+                if ($(this).hasClass('active')) {
+                    return;
+                }
                 $(this).addClass('active');
                 $('#source-view-tab').removeClass('active');
                 $('#source-editor').hide();
                 $(this).addClass('active');
                 $('#source-view-tab').removeClass('active');
                 $('#source-editor').hide();
             });
             
             $('#source-view-tab').click(function() {
             });
             
             $('#source-view-tab').click(function() {
+                if ($(this).hasClass('active')) {
+                    return;
+                }
                 $(this).addClass('active');
                 $('#simple-view-tab').removeClass('active');
                 $('#simple-editor').hide();
                 $('#source-editor').show();
                 reverseTransform();
             });
                 $(this).addClass('active');
                 $('#simple-view-tab').removeClass('active');
                 $('#simple-editor').hide();
                 $('#source-editor').show();
                 reverseTransform();
             });
+            
+            $('.toolbar button').click(function(event) {
+                event.preventDefault();
+                var params = eval("(" + $(this).attr('ui:action-params') + ")");
+                scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
+            });
+            
+            $('.toolbar select').change(function() {
+                var slug = $(this).val();
+                
+                $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
+            });
+            
+            $('.toolbar-buttons-container').hide();
+            $('.toolbar select').change();
         });
     </script>
     
         });
     </script>
     
         
         #sidebar {
             overflow: auto;
         
         #sidebar {
             overflow: auto;
-            padding: 5px;
+/*            padding: 5px; */
         }
         
         #header {
         }
         
         #header {
         }
         
         #tabs li.active {
         }
         
         #tabs li.active {
-            background-color: #FFF;
+            background-color: #FEFCDF;
             background-image: none;
 /*            background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.25, #C1C1C1), to(#FFFFFF));            */
             background-image: none;
 /*            background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.25, #C1C1C1), to(#FFFFFF));            */
-            border-bottom: 1px solid #FFF;
+            border-bottom: 1px solid #FEFCDF;
         }
         }
+        
+        .toolbar {
+            border-bottom: 1px solid #777;
+            background-color: #FEFCDF;
+            margin: 0;
+            padding: 2px;
+        }
+        
+        .toolbar select {
+            float: left;
+            margin: 2px 5px 2px 0;
+            background: none;
+            border: 1px solid #999;
+            padding: 1px;
+        }
+        
+        .toolbar button {
+            display: block;
+            float: left;
+            margin: 4px 0 2px 0;
+            padding: 0 5px 2px 5px;
+            border: none;
+            background: none;
+        }
+        
+        .toolbar-end {
+            clear: both;
+        }
+        
+        .toolbar button:hover, .toolbar button:active {
+            background: #A2A2A2;
+            color: #FFF;
+            -webkit-border-radius: 10px;
+            -moz-border-radius: 10px;
+            border-radius: 10px;
+        }
+        
+        p { margin: 0;}
     </style>
 {% endblock %}
 
     </style>
 {% endblock %}
 
         <div id="splitter">
             <div id="editor">
                 <div id="source-editor">
         <div id="splitter">
             <div id="editor">
                 <div id="source-editor">
+                    {% toolbar %}
                     {{ form.text }}
                     <input type="hidden" name="name" value="{{ document.name }}" />
                     <input type="hidden" name="author" value="annonymous" />
                     {{ form.text }}
                     <input type="hidden" name="name" value="{{ document.name }}" />
                     <input type="hidden" name="author" value="annonymous" />