Merge branch 'master' of git@stigma:platforma
authorLukasz Rekucki <lreqc@localhost.(none)>
Wed, 19 Aug 2009 14:21:51 +0000 (16:21 +0200)
committerLukasz Rekucki <lreqc@localhost.(none)>
Wed, 19 Aug 2009 14:21:51 +0000 (16:21 +0200)
13 files changed:
apps/explorer/models.py
apps/explorer/views.py
apps/toolbar/__init__.py [new file with mode: 0644]
apps/toolbar/admin.py [new file with mode: 0644]
apps/toolbar/models.py [new file with mode: 0644]
apps/toolbar/templates/toolbar/toolbar.html [new file with mode: 0644]
apps/toolbar/templatetags/__init__.py [new file with mode: 0644]
apps/toolbar/templatetags/toolbar_tags.py [new file with mode: 0644]
project/settings.py
project/static/css/master.css
project/templates/base.html
project/templates/explorer/file_xml.html
project/urls.py

index 3b5848b..5fa93ad 100644 (file)
@@ -4,11 +4,11 @@ from django.conf import settings
 
 
 def get_image_folders():
-    return [fn for fn in os.listdir(settings.IMAGE_DIR) if not fn.startswith('.')]
+    return [fn for fn in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR)) if not fn.startswith('.')]
 
 
 def get_images_from_folder(folder):
-    return ['/media/images/' + folder + '/' + fn for fn 
-            in os.listdir(os.path.join(settings.IMAGE_DIR, folder))
+    return [settings.MEDIA_URL + settings.IMAGE_DIR + '/' + folder + '/' + fn for fn 
+            in os.listdir(os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, folder))
             if not fn.startswith('.')]
 
index acbcd19..ac83c4e 100644 (file)
@@ -1,5 +1,6 @@
 from librarian import html
-import hg, urllib2, json
+import hg, urllib2
+from django.utils import simplejson as json
 
 from django.views.generic.simple import direct_to_template
 from django.conf import settings
diff --git a/apps/toolbar/__init__.py b/apps/toolbar/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/apps/toolbar/admin.py b/apps/toolbar/admin.py
new file mode 100644 (file)
index 0000000..2c8cd28
--- /dev/null
@@ -0,0 +1,25 @@
+from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
+
+from toolbar import models
+
+
+class ButtonGroupAdmin(admin.ModelAdmin):
+    list_display = ('name', 'slug', 'position',)
+    search_fields = ('name', 'slug',)
+    prepopulated_fields = {'slug': ('name',)}
+    list_editable = ('position',)
+
+admin.site.register(models.ButtonGroup, ButtonGroupAdmin)
+
+
+class ButtonAdmin(admin.ModelAdmin):
+    list_display = ('label', 'slug', 'tag', 'key', 'position',)
+    list_filter = ('group',)
+    search_fields = ('label', 'slug', 'tag', 'key',)
+    prepopulated_fields = {'slug': ('label',)}
+    filter_horizontal = ('group',)
+    list_editable = ('position',)
+
+admin.site.register(models.Button, ButtonAdmin)
+
diff --git a/apps/toolbar/models.py b/apps/toolbar/models.py
new file mode 100644 (file)
index 0000000..8e2387d
--- /dev/null
@@ -0,0 +1,33 @@
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+
+class ButtonGroup(models.Model):
+    name = models.CharField(max_length=32)
+    slug = models.SlugField()
+    position = models.IntegerField(default=0)
+    
+    class Meta:
+        ordering = ('position', 'name',)
+        verbose_name, verbose_name_plural = _('button group'), _('button groups')
+    
+    def __unicode__(self):
+        return self.name
+
+
+class Button(models.Model):
+    label = models.CharField(max_length=32)
+    slug = models.SlugField()
+    tag = models.CharField(max_length=128)
+    key = models.IntegerField(blank=True, null=True)
+    position = models.IntegerField(default=0)
+    
+    group = models.ManyToManyField(ButtonGroup)
+    
+    class Meta:
+        ordering = ('position', 'label',)
+        verbose_name, verbose_name_plural = _('button'), _('buttons')
+    
+    def __unicode__(self):
+        return self.label
+
diff --git a/apps/toolbar/templates/toolbar/toolbar.html b/apps/toolbar/templates/toolbar/toolbar.html
new file mode 100644 (file)
index 0000000..2e61288
--- /dev/null
@@ -0,0 +1,18 @@
+<div id="toolbar">
+    <ol id="toolbar-tabs">
+        {% for group in groups %}
+        <li p:button-list="{{ group.slug }}">{{ group.name }}</li>
+        {% endfor %}
+    </ol>
+    <div style="clear: both; height: 0; width: 0">&nbsp;</div>
+    <div id="toolbar-buttons">
+        {% for group in groups %}
+        <ol id="{{ group.slug }}" style="display:none">
+            {% for button in group.button_set.all %}
+            <li p:tag="{{ button.slug }}" {% if button.key %}p:key="{{ button.key }}"{% endif %}>{{ button.label }}</li>
+            {% endfor %}
+        </ol>
+        {% endfor %}
+        <div style="clear: both; height: 0; width: 0">&nbsp;</div>
+    </div>
+</div>
\ No newline at end of file
diff --git a/apps/toolbar/templatetags/__init__.py b/apps/toolbar/templatetags/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/apps/toolbar/templatetags/toolbar_tags.py b/apps/toolbar/templatetags/toolbar_tags.py
new file mode 100644 (file)
index 0000000..69b5b38
--- /dev/null
@@ -0,0 +1,13 @@
+from django import template
+
+from toolbar import models
+
+
+register = template.Library()
+
+
+@register.inclusion_tag('toolbar/toolbar.html')
+def toolbar():
+    groups = models.ButtonGroup.objects.all()
+    return {'groups': groups}
+
index aad5a88..c5b0c2d 100644 (file)
@@ -101,11 +101,12 @@ INSTALLED_APPS = (
     'django.contrib.admin',
     'django.contrib.admindocs',
     
-    'explorer'
+    'explorer',
+    'toolbar',
 )
 
 REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books'
-IMAGE_DIR = '/Users/zuber/Projekty/platforma/files/images'
+IMAGE_DIR = 'images'
 
 try:
     from localsettings import *
index f699cd6..03bcd21 100644 (file)
@@ -1,6 +1,6 @@
 body {
     margin: 0;
-    font: 100%/1.5 Georgia, Verdana, sans-serif;
+    font: 14px Helvetica, Verdana, sans-serif;
     overflow: hidden;
 }
 
@@ -127,3 +127,61 @@ p {
 .image-box {
     border-top: 1px solid #DDD;
 }
+
+#toolbar, #toolbar ol {
+    display: block;
+    margin: 0;
+    padding: 0;
+    background-color: #CCC;
+    border-bottom: 1px solid #AAA;
+}
+
+#toolbar {
+    overflow: hidden;
+    width: 400%;
+}
+
+#toolbar-tabs li {
+    font-size: 14px;
+    display: block;
+    float: left;
+    margin: 4px 4px 0 0;
+    padding: 2px 10px 0 10px;
+    border-left: 1px solid #EEE;
+    border-right: 1px solid #AAA;
+    margin-bottom: -1px;
+    border: 1px solid #AAA;
+    border-radius-topleft: 8px;
+    border-radius-topright: 8px;
+    -moz-border-radius-topleft: 8px;
+    -moz-border-radius-topright: 8px;
+    -webkit-border-top-left-radius: 8px;
+    -webkit-border-top-right-radius: 8px;
+}
+
+#toolbar-tabs li:hover, #toolbar-tabs li.active {
+    cursor: default;
+    background-color: #EEE;
+    border-bottom: 1px solid #EEE;
+}
+
+#toolbar-buttons {
+    background-color: #EEE;
+}
+
+#toolbar-buttons li {
+    display: block;
+    font-size: 12px;
+    padding: 1px 8px;
+    margin: 4px;
+    border-radius: 10px;
+    -moz-border-radius: 10px;
+    -webkit-border-radius: 8px;
+    float: left;
+}
+
+#toolbar-buttons li:hover {
+    background-color: #777;
+    color: #FFF;
+    cursor: default;
+}
index 7ddfc18..6e9c389 100644 (file)
@@ -1,6 +1,6 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://platforma.wolnelektury.pl/">
     <head>
         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
         <title>{% block title %}Platforma Redakcyjna{% endblock %}</title>
index c23ad41..1f074fc 100644 (file)
@@ -1,4 +1,5 @@
 {% extends "base.html" %}
+{% load toolbar_tags %}
 
 {% block extrahead %}
     <script src="/static/js/jquery.fieldselection.js" type="text/javascript" charset="utf-8"></script>
@@ -8,7 +9,7 @@
     <script type="text/javascript" charset="utf-8">        
         $(function() {
             $('#id_folders').change(function() {
-                $('#images').load('/images/' + $('#id_folders').val() + '/', function() {
+                $('#images').load('{% url folder_image_ajax %}' + $('#id_folders').val() + '/', function() {
                     $('#images').data('lastScroll', -1000);
                 });
             });
                         $(this).html('Nie synchronizuj przewijania');
                         $('#images').enableAutoscroll();
                     })
-
-                    keys = {}
                     
-                    function addEditorButton(editor, label, keyCode, fn) {
+                    // Toolbar
+                    $('#toolbar-tabs li').click(function() {
+                        var id = $(this).attr('p:button-list');
+                        $('#toolbar-tabs li').removeClass('active');
+                        $(this).addClass('active');
+                        if (!$('#' + id).is(':visible')) {
+                            $('#toolbar-buttons ol').not('#' + id).hide();
+                            $('#' + id).show();
+                        }
+                    })
+
+                    var keys = {};
+                    $('#toolbar-buttons li').each(function() {
+                        var tag = $(this).attr('p:tag');
                         var handler = function() {
                             var text = editor.selection();
-                            editor.replaceSelection(fn(text));
+                            editor.replaceSelection('<' + tag + '>' + text + '</' + tag + '>');
+                            if (text.length == 0) {
+                                var pos = editor.cursorPosition();
+                                editor.selectLines(pos.line, pos.character + tag.length + 2);
+                            }
                         }
-                        
-                        keys[keyCode] = handler;
-                        
-                        $('<button type="button">' + label + '</button>').click(function(event) {
-                            event.preventDefault();
-                            handler();
-                        }).appendTo('#buttons');
-                    }
-                    
-                    addEditorButton(editor, 'utwór', 65, function(text) { return '<utwor>' + text + '</utwor>'; });
-                    addEditorButton(editor, 'akap', 83, function(text) { return '<akap>' + text + '</akap>'; });
+                        if ($(this).attr('p:key')) {
+                            keys[$(this).attr('p:key')] = handler;
+                        }
+                        $(this).click(handler)
+                    });
                     
                     editor.grabKeys(function(event) { 
-                        // console.log('handle', event, event.keyCode)
+                        console.log('handle', event, event.keyCode)
                         if (keys[event.keyCode]) {
                             keys[event.keyCode]();
                         }
@@ -77,7 +87,7 @@
                     resizePanels();
                 }
             });
-
+            
             $('#images-wrap').lazyload('.image-box', {threshold: 640 * 10, scrollTreshold: 640 * 5});
         });
 
 {% block breadcrumbs %}<a href="{% url file_list %}">Platforma Redakcyjna</a> ❯ plik {{ hash }}{% endblock breadcrumbs %}
 
 {% block maincontent %}
-    <div id="tabs">
-        <a href="{% url file_xml hash %}" class="active">Źródło</a>
-        <a href="{% url file_html hash %}">HTML</a>
-        <div style="float: left" id="buttons"></div>
-        <div style="clear: both; height: 0; width: 0">&nbsp;</div>
-    </div>
+    {% toolbar %}
     
     <form action="." method="post" accept-charset="utf-8">
         <div id="panels">
index 3b75849..19f0520 100644 (file)
@@ -12,6 +12,7 @@ urlpatterns = patterns('',
     url(r'^file/(?P<path>[^/]+)/$', 'explorer.views.file_xml', name='file_xml'),
     url(r'^html/(?P<path>[^/]+)/$', 'explorer.views.file_html', name='file_html'),
     url(r'^images/(?P<folder>[^/]+)/$', 'explorer.views.folder_images', name='folder_image'),
+    url(r'^images/$', 'explorer.views.folder_images', {'folder': '.'}, name='folder_image_ajax'),
     
     # Admin panel
     url(r'^admin/doc/', include('django.contrib.admindocs.urls')),