Getting the admin interface working

This commit is contained in:
Corey Oordt 2009-08-27 16:22:09 -04:00
parent 603352c84f
commit 01c6cf38c5
9 changed files with 3 additions and 582 deletions

View file

@ -3,7 +3,7 @@ from django.contrib import admin
from django import forms
from django.template.defaultfilters import slugify
from mptt.forms import TreeNodeChoiceField
from editor import TreeEditorMixin
from editor.tree_editor import TreeEditor
class NullTreeNodeChoiceField(forms.ModelChoiceField):
"""A ModelChoiceField for tree nodes."""
@ -57,7 +57,7 @@ class CategoryAdminForm(forms.ModelForm):
return self.cleaned_data
class CategoryAdmin(TreeEditorMixin, admin.ModelAdmin):
class CategoryAdmin(TreeEditor, admin.ModelAdmin):
form=CategoryAdminForm
list_display = ('__unicode__',)
search_fields = (('name',))

View file

@ -24,7 +24,7 @@ class Category(models.Model):
class Meta:
verbose_name_plural = 'categories'
unique_together = ('parent', 'name')
ordering = ('name',)
ordering = ('tree_id','lft')
def __unicode__(self):
ancestors = self.get_ancestors()

View file

@ -1,8 +0,0 @@
{% load i18n %}
DELETE_MESSAGES = ["{% trans "Really delete item?" %}", "{% trans "Confirm to delete item" %}",
"{% trans "Item deleted successfully." %}", "{% trans "Cannot delete item" %}",
"{% trans "Cannot delete item, because it is parent of at least one other item." %}"];
TREE_SAVED_MESSAGE = "{% trans "Tree saved successfully." %}";
CHANGE_TEMPLATE_MESSAGES = ["{% trans "Change template" %}",
"{% trans "Really change template? <br/>All content will be moved to main region." %}"];

View file

@ -1 +0,0 @@
<div class="fe_box" id="{{ identifier }}">{{ content|safe }}</div>

View file

@ -1,57 +0,0 @@
{% extends "admin/change_form.html" %}
{% load i18n admin_modify adminmedia %}
{% block extrahead %}{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />
<script type="text/javascript" src="../../jsi18n/"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}jquery.livequery.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}jquery.alerts.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}helper.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}listener.js"></script>
<script type="text/javascript">
var contentblock_init_handlers = [];
</script>
{% for inc in object.item_editor_includes.head %}{% include inc %}{% endfor %}
<script type="text/javascript">
{% include "admin/editor/_messages.html" %}
function init_contentblocks() {
for(var k in contentblock_init_handlers)
contentblock_init_handlers[k]();
}
$(function(){
init_contentblocks();
});
</script>
{% endblock %}
{% block content %}
<div class="content_main" id="frontend_editor">
<form method="post" action=".">
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
<table>
{{ form }}
</table>
<div class="submit-row" >
<input type="submit" value="{% trans "Save" %}" class="default" name="_save" />
</div>
</div>
</form>
</div>
{% endblock %}

View file

@ -1,12 +0,0 @@
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery.color.js"></script>
<div id="{{ identifier }}-new">
{{ content|safe }}
</div>
<script type="text/javascript">
opener.fe_update_content('{{ identifier }}', $('#{{ identifier }}-new').html());
window.close();
</script>

View file

@ -1,252 +0,0 @@
{% extends "admin/change_form.html" %}
{% load i18n admin_modify adminmedia %}
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}
{% block extrahead %}{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />
<script type="text/javascript" src="../../jsi18n/"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery.livequery.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}jquery.alerts.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}helper.js"></script>
<script type="text/javascript" src="{{ FEINCMS_ADMIN_MEDIA }}listener.js"></script>
<script type="text/javascript">
var contentblock_init_handlers = [];
</script>
{% for inc in object.feincms_item_editor_includes.head %}{% include inc %}{% endfor %}
<script type="text/javascript">
{% include "admin/feincms/_messages.html" %}
function init_contentblocks() {
for(var k in contentblock_init_handlers)
contentblock_init_handlers[k]();
}
IMG_ARROW_DOWN_PATH = "{{ FEINCMS_ADMIN_MEDIA }}img/arrow_down.gif";
IMG_ARROW_RIGHT_PATH = "{{ FEINCMS_ADMIN_MEDIA }}img/arrow_right.gif";
IMG_CIRCLE_PATH = "{{ FEINCMS_ADMIN_MEDIA }}img/circle.gif";
IMG_DELETELINK_PATH = "{{ FEINCMS_ADMIN_MEDIA }}img/icon_deletelink.gif";
IMG_MOVE_PATH = "{{ FEINCMS_ADMIN_MEDIA }}img/icon_move.gif";
REGIONS = [];
REGION_MAP = [];
{% for region in object.template.regions %}
REGIONS.push('{{ region.key }}');
REGION_MAP.push('{{ region.key }}');
{% endfor %}
ACTIVE_REGION = 0;
CONTENT_NAMES = {
{% for name, value in content_types %}'{{ value }}': '{{ name }}'{% if not forloop.last %},{% endif %}
{% endfor %}};
$(document).ready(function(){
// move contents into their corresponding regions and do some simple formatting
$("div[id$=_set]").children().each(function(){
var elem = $(this);
if (!(elem.hasClass("header"))) {
elem.find("input[name$=-region]").addClass("region-choice-field");
elem.find("input[name$=-DELETE]").addClass("delete-field").parents("div.form-row").hide();
elem.find("input[name$=-ordering]").addClass("order-field");
var region_id = elem.find(".region-choice-field").val();
region_id = REGION_MAP.indexOf(region_id);
var content_type = elem.attr("id").substr(0, elem.attr("id").indexOf("_"));
region_append(region_id,elem, CONTENT_NAMES[content_type]);
set_item_field_value(elem,"region-choice-field",region_id)
}
});
// register regions as sortable for drag N drop
$(".order-machine").sortable({
handle: '.handle',
helper: 'clone',
placeholder: 'highlight',
stop: function(event, ui) {
richify_poor($(ui.item));
}
});
attach_dragdrop_handlers();
if(window.location.hash) {
$('#'+window.location.hash.substr(5)+'_tab').trigger('click');
}
// bring order to chaos
zucht_und_ordnung(true);
{% block extra-init-js %}{# /* do not use this block, use feincms_item_editor_includes instead */ #}{% endblock %}
$('#inlines').hide();
});
$(window).load(function(){init_contentblocks()});
</script>
<link rel="stylesheet" type="text/css" href="{{ FEINCMS_ADMIN_MEDIA }}css/layout.css" />
<link rel="stylesheet" type="text/css" href="{{ FEINCMS_ADMIN_MEDIA }}css/jquery.alerts.css" media="screen" />
{% endblock %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
<a href="../../">{{ opts.app_label|capfirst|escape }}</a> &rsaquo;
<a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
{{ object.title|truncatewords:"18" }}
</div>
{% endblock %}
{% block content %}
<div id="content-main">
{% block object-tools %}
<ul class="object-tools">
{% if object.get_absolute_url %}
<li><a target="_blank" href="{{ object.get_absolute_url }}" class="viewsitelink">{% trans "View on site" %}</a></li>
{% endif %}
</ul>
{% endblock %}
<form name="main_form" enctype="multipart/form-data" action="." method="post" id="{{ opts.module_name }}_form">
<div>
<div class="submit-row" >
<input type="submit" value="{% trans "Save" %}" class="default" name="_save" />
<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>
<input type="submit" value="Sichern und neu hinzufügen" name="_addanother" />
<input type="submit" value="{% trans "Save and continue editing" %}" name="_continue" />
</div>
<fieldset class="module aligned">
{% for field in top_fieldset %}
<div class="form-row{% if field.errors %} errors{% endif %}">
{% ifequal field.name "language" %}
{# Maybe this should be moved somewhere else, since this is specific for translated objects... #}
{% with object.available_translations as translations %}
{% if translations %}
<div style="float:right;padding:5px 0 0 0">
{% trans "available translations" %}:
{% for translation in translations %}
<a href="../{{ translation.id }}/">{{ translation.language|upper }}</a>{% if not forloop.last %},{% endif %}
{% endfor %}
</div>
{% endif %}
{% endwith %}
{% endifequal %}
{{ field.label_tag }}{{ field }}
{% if field.field.help_text %}<p class="help">{{ field.field.help_text|safe }}</p>{% endif %}
</div>
{% endfor %}
{% if object_form.template_key %} {# Maybe this should be moved somewhere else, since this is page-module-specific #}
<div class="form-row{% if field.errors %} errors{% endif %}">
{{ object_form.template_key.label_tag }}
<span>{{ object_form.template_key }}{{ object_form.template_key.errors }}</span>
<input type="button" class="change-template" value="{% trans 'Change Template' %}" />
</div>
{% endif %}
</fieldset>
<div id="main_wrapper">
<div class="navi_tab tab_active" id="settings_tab">{% trans "Properties" %}</div>
{% for region in object.template.regions %}
<div class="navi_tab" id="{{ region.key }}_tab">{{ region.title }}</div>
{% endfor %}
<div id="main">
<fieldset class="module aligned" id="settings_body">
{% for field in settings_fieldset %}
<div class="form-row{% if field.errors %} errors{% endif %}">
{{ field.label_tag }}{{ field }}
{% if field.field.help_text %}<p class="help">{{ field.field.help_text|safe }}</p>{% endif %}
</div>
{% endfor %}
</fieldset>
{% for region in object.template.regions %}
<div id="{{ region.key }}_body" class="panel">
<div class="empty-machine-msg">
{% trans "Region empty" %}
</div>
<div class="empty-machine-msg" style="margin-left:20px; margin-top:20px;">
{% if region.inherited %}
{% trans "Content from the parent site is automatically inherited. To override this behaviour, add some content." %}
{% endif %}
</div>
<div class="order-machine"></div>
<div class="machine-control">
<div class="control-unit">
<span>{% trans "Add new item" %}:</span> <br/>
<select name="order-machine-add-select">
{% for n,v in content_types %} <option value="{{ v }}">{{ n }}</option> {% endfor %}
</select>
<input type="button" class="order-machine-add-button button" value="OK" />
</div>
<div class="control-unit">
<span>{% trans "Move selected item to" %}:</span> <br/>
<select name="order-machine-move-select">
{% for r in object.template.regions %} {% ifnotequal region r %} <option value="{{ r.key }}">{{ r.title }}</option> {% endifnotequal %} {% endfor %}
</select>
<input type="button" class="order-machine-move-button button" value="{% trans "OK" %}" />
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="submit-row" >
<input type="submit" value="{% trans "Save" %}" class="default" name="_save" />
<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>
<input type="submit" value="Sichern und neu hinzufügen" name="_addanother" />
<input type="submit" value="{% trans "Save and continue editing" %}" name="_continue" />
</div>
<div id="inlines">
{% for formset in inline_formsets %}
<div id="{{ formset.rel_name }}">
<div class="header">
{{ formset.management_form }}
</div>
{% for form in formset.forms %}
<div id="{{ formset.rel_name }}_item_{{ forloop.counter0 }}">
{% for field in form %}
{% if field.is_hidden %}
{{ field }}
{% else %}
<div class="form-row{% if field.errors %} errors{% endif %}">
{{ field.label_tag }}{{ field }}
{% if field.field.help_text %}<p class="help">{{ field.field.help_text|safe }}</p>{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
</form>
</div>
{% endblock %}

View file

@ -1,81 +0,0 @@
{% load i18n %}
<div id="fe_tools">
<a id="fe_tools_edit" href="#">{% trans "edit" %}</a>
<!--
<a id="fe_tools_new" href="#">{% trans "new" %}</a>
<a id="fe_tools_up" href="#">{% trans "up" %}</a>
<a id="fe_tools_down" href="#">{% trans "down" %}</a>
<a id="fe_tools_remove" href="#">{% trans "remove" %}</a>
-->
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var admin_base = '/admin/page/page/';
fe_init_animations();
var fe_tools = $('#fe_tools');
fe_tools.children('a').click(function(){
var fe_box = $(this).parents('div.fe_box');
if(this.id=='fe_tools_edit') {
res = fe_box.attr('id').match(/([^\-]+)-(\d+)-(\d+)/);
window.open(admin_base+res[2]+'/'+res[1]+'/'+res[3]+'/',
'fe_editor',
'height=500,width=800,resizable=yes,scrollbars=yes');
}
return false;
});
});
function fe_init_animations() {
var fe_tools = $('#fe_tools');
$('.fe_box').hover(function(){
$(this).append(fe_tools).css('background', '#e8e8ff').animate({'opacity': 1}, 100);
fe_tools.show();
}, function(){
$(this).animate({'opacity': 0.6}, 100).css('background', 'none');
fe_tools.hide();
});
}
function fe_update_content(identifier, content) {
var region = $('#'+identifier);
region.animate({'opacity': 0}).html(content);
region.animate({'opacity': 1.5}).animate({'opacity': 0.6});
fe_init_animations();
}
</script>
<style type="text/css">
.fe_box {
position: relative;
opacity: 0.6;
}
#fe_tools {
background: #fff;
border: 1px solid #000;
padding: 13px 5 13px 15px;
display: none;
position: absolute;
left: 10px;
bottom: -25px;
font-size: 70%;
opacity: 0.8;
}
#fe_tools a {
background: #000;
color: #fff;
text-decoration: none;
margin: 0 10px 0 0;
padding: 4px 5px;
display: block;
float: left;
}
</style>

View file

@ -1,168 +0,0 @@
{% extends "admin/change_list.html" %}
{% load i18n admin_modify adminmedia %}
{% block title %}{{ block.super }}{% endblock %}
{% block extrahead %}{{ block.super }}
<script type="text/javascript" src="../../jsi18n/"></script>
<script type="text/javascript" src="{{ EDITOR_ADMIN_MEDIA }}jquery.livequery.js"></script>
<script type="text/javascript" src="{{ EDITOR_ADMIN_MEDIA }}jquery.alerts.js"></script>
<script type="text/javascript" src="{{ EDITOR_ADMIN_MEDIA }}helper.js"></script>
<script type="text/javascript" src="{{ EDITOR_ADMIN_MEDIA }}listener.js"></script>
<script type="text/javascript" src="{{ EDITOR_ADMIN_MEDIA }}jquery.treeTable.js"></script>
<script type="text/javascript" src="{{ EDITOR_ADMIN_MEDIA }}jquery.json-1.3.js"></script>
<script type="text/javascript">
{% include "admin/editor/_messages.html" %}
ancestors = [{% for item in object_list %}'{{ item.parent_id|default_if_none:"0" }}'{% if not forloop.last %}, {% endif %}{% endfor %}];
tablestr = '';
{% for item, title, item_properties in tree_editor.object_list %}
tablestr += add_row({{ forloop.counter }}, {{ item.id }}, "{{ item.parent_id|default_if_none:"-1" }}", "{{ title|escapejs }}",
[{% for property in item_properties %}"{{ property|escapejs }}"{% if not forloop.last %}, {% endif %}{% endfor %}]);{% endfor %}
function add_row(node_id, item_id, parent_id, item_title, attrs) {
var str = '<tr id="node-' + node_id + '" class="item-id-' + item_id + ' ';
if (parseInt(parent_id) >= 0)
str += 'child-of-node-'+ancestors.indexOf(parent_id);
str += '">';
str += '<td><div class="wrap nohover">';
str += '<div class="insert-as-child"></div>';
str += '<span class="title-col"><a href="'+item_id+'/"><strong>'+item_title+'</strong></a><img class="move-node" src="{{ EDITOR_ADMIN_MEDIA }}img/icon_move.gif" /></span>';
str += '<div class="insert-as-sibling"></div>';
str += '</div></td>';
for (key in attrs)
str += attrs[key];
str += '<td><img class="del-page" src="{{ EDITOR_ADMIN_MEDIA }}img/icon_deletelink.gif"/></td></tr>';
return str;
}
$(document).ready(function() {
// build table
$("#sitetree tbody").append(tablestr);
// register
$("#sitetree").treeTable();
// configure draggable
$("#sitetree .title-col").draggable({
helper: function(){ return $(this).parent().clone(); } ,
handle: ".move-node",
opacity: .75,
refreshPositions: true,
revert: "invalid",
revertDuration: 300,
scroll: true
});
// configure droppable to insert as child
$("#sitetree .insert-as-child").each(function() {
$(this).droppable({
accept: ".title-col",
tolerance: "intersect",
drop: function(e, ui) {
handle_drop_event($(ui.draggable).parents("tr"), $(this).parents("tr"), "child")
},
over: function(e, ui) {
$(this).parent().removeClass("nohover").addClass("hover-as-child");
},
out: function(e, ui) {
$(this).parent().removeClass("hover-as-child").addClass("nohover");
}
});
});
// configure droppable to insert as sibling
$("#sitetree .insert-as-sibling").each(function() {
$(this).droppable({
accept: ".title-col",
tolerance: "intersect",
drop: function(e, ui) {
handle_drop_event($(ui.draggable).parents("tr"), $(this).parents("tr"), "sibling")
},
over: function(e, ui) {
var row = '<div style="background-color:#bcf; height:4px; width:100%; margin:-8px 0px 4px -5px; position:relative; z-index:10;"></div>'
$(row).insertBefore($(this).parent());
},
out: function(e, ui) {
$(this).parent().prev().remove();
}
});
});
$(".wrap").live('click',function() {
if ($(this).find(".expander").length > 0)
$(this).parents("tr").toggleBranch();
});
$(".save_tree").click(function(){
save_page_tree();
});
$(".del-page").click(function(){
handle_page_delete($(this).parents("tr"));
});
});
function expandall(yesno) {
if(yesno) {
var elems = $('#sitetree tr.collapsed');
if(elems.length)
elems.expand().removeClass('collapsed').addClass('expanded');
} else {
var elems = $('#sitetree tr.expanded');
for(var i=elems.length; i>=0; i--)
$(elems[i]).collapse().removeClass('expanded').addClass('collapsed');
}
return false;
}
</script>
<link rel="stylesheet" type="text/css" href="{{ EDITOR_ADMIN_MEDIA }}css/layout.css" />
<link rel="stylesheet" type="text/css" href="{{ EDITOR_ADMIN_MEDIA }}css/jquery.alerts.css" media="screen" />
<link href="{{ EDITOR_ADMIN_MEDIA }}css/jquery.treeTable.css" rel="stylesheet" type="text/css" />
{% endblock %}
{% block cols %}
13
{% endblock %}
{% block content %}
<div id="content-main" class="grid_13">
{% block object-tools %}
{% if has_add_permission %}
<ul class="object-tools">
<li class="active">Change Categories</li>
<li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>
{% endif %}
{% endblock %}
<input type="button" value="{% trans "Save tree" %}" class="save_tree" style="float:right;margin:0 1px 0 0" />
<div id="sitetree-wrapper" class="inner module" style="padding:10px">
<p align='right' style="font-size:11px; font-weight:700; margin:0;">
<a href="#" onclick="return expandall(1)">{% trans "Expand all" %}</a>
<a href="#" onclick="return expandall(0)">{% trans "Collapse all" %}</a>
</p>
<table id="sitetree" border="0">
<thead>
<tr id="table_header">
{% for header in result_headers %}
<th{% if forloop.first %} style="min-width:400px"{% endif %}>{{ header.text|capfirst }}
{% endfor %}
<th>{% trans "Delete" %}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
{% endblock %}