Skip to content

Commit

Permalink
Disable unavailable features, and fix the ajax submit
Browse files Browse the repository at this point in the history
  • Loading branch information
issackelly committed Mar 25, 2011
1 parent 4ffd579 commit 2bbb103
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 48 deletions.
2 changes: 1 addition & 1 deletion servee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION = (0, 6, 0, "a", 1) # following PEP 386
DEV_N = "5"
DEV_N = "8"

# cribbed from pinax
# https://github.com/pinax/pinax/raw/master/LICENSE
Expand Down
27 changes: 18 additions & 9 deletions servee/frontendadmin/options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.admin.options import ModelAdmin, StackedInline, TabularInline
from django.http import HttpResponse
from django.http import HttpResponse, HttpResponseRedirect

class ServeeModelAdmin(ModelAdmin):
"""
Expand Down Expand Up @@ -60,13 +60,23 @@ def __init__(self, *args, **kwargs):
"admin/object_history.html",
]

#def response_change(self, request, obj):
# """
# Act differently during frontendadmin(ajax) just reload the page.
# """
# if request.is_ajax():
# return HttpResponse("<script type='text/javascript'>window.location.reload(true);</script>")
# return super(ServeeModelAdmin, self).response_change(request, obj)
def response_change(self, request, obj):
"""
Act differently during frontendadmin(ajax) just reload the page.
"""

# in these cases, the redirect is good
if list(set(request.POST) & set(["_addanother", "_saveasnew", "_continue"])):
return super(ServeeModelAdmin, self).response_change(request, obj)

# we want to override the default save case in the frontend
ref = request.META.get("HTTP_REFERER")
print ref.find("/servee/")
if ref and (ref.find("/servee/") == -1):
if request.is_ajax():
return HttpResponse("<script type='text/javascript'>window.location.reload(true);</script>")
elif request.FILES:
return HttpResponseRedirect(ref)

def change_view(self, *args, **kwargs):
"""
Expand All @@ -76,7 +86,6 @@ def change_view(self, *args, **kwargs):
kwargs["extra_context"] = {}
kwargs["extra_context"].update({
"insert_classes": self.admin_site.insert_classes,
"form_url": "derp"
})
return super(ServeeModelAdmin, self).change_view(*args, **kwargs)

Expand Down
10 changes: 10 additions & 0 deletions servee/frontendadmin/templates/servee/_submit_line.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load i18n %}
<div class="scrollidentifier"></div>
<div class="submit-row" {% if is_popup %}style="overflow: auto;"{% endif %}>
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" {{ onclick_attrib }}/>{% endif %}
{% if show_delete_link %}<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>{% endif %}
<!-- unsupported currently -->
<!--{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" {{ onclick_attrib }}/>{%endif%}-->
<!--{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" {{ onclick_attrib }} />{% endif %}-->
<!--{% if show_save_and_continue %}<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" {{ onclick_attrib }}/>{% endif %}-->
</div>
27 changes: 26 additions & 1 deletion servee/frontendadmin/templates/servee/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,32 @@
$(".submit-row").css("position", "relative");
$(".submit-row").css("bottom", $(".scrollidentifier").offset());
}
});
});

var $base = $("#{{ opts.module_name }}_form");
var $par = $base.parent();
load_wysiwyg($base);
$base.submit(function(e){
if($base.find("[type=file]").length == 0){
$.ajax({
"url": $base.attr("action"),
"type": $base.attr("method"),
"data": $base.serialize(),
success: function(data, text){
//Fracking tinymce destroy bug....

t = {};
t.keyNav = {};
t.keyNav.destroy = function(){};

$par.html(data);
},
});

e.preventDefault();
return false;
}
});
});
</script>
{% endblock %}
Expand Down
9 changes: 0 additions & 9 deletions servee/frontendadmin/templates/servee/submit_line.html

This file was deleted.

2 changes: 1 addition & 1 deletion servee/frontendadmin/templatetags/servee_admin_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def submit_row_frontendadmin(context):
'is_popup': is_popup,
'show_save': True
}
submit_row = register.inclusion_tag('servee/submit_line.html', takes_context=True)(submit_row_frontendadmin)
submit_row = register.inclusion_tag('servee/_submit_line.html', takes_context=True)(submit_row_frontendadmin)
28 changes: 1 addition & 27 deletions servee/wysiwyg/tinymce/templates/wysiwyg/_wysiwyg_of_choice.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,2 @@
<script type="text/javascript" src="{{ STATIC_URL }}tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}servee/wysiwyg/js/tinymce.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var $base = $("#{{ opts.module_name }}_form");
var $par = $base.parent();
load_wysiwyg($base);
$base.submit(function(e){
if($base.attr("enctype") != "multipart/form-data"){
$.ajax({
"url": $base.attr("action"),
"type": $base.attr("method"),
"data": $base.serialize(),
"success": function(data, text){
//Fracking tinymce destroy bug....
t = {};
t.keyNav = {};
t.keyNav.destroy = function(){};
$par.html(data);
}
});

e.preventDefault();
return false;
}
});
});
</script>
<script type="text/javascript" src="{{ STATIC_URL }}servee/wysiwyg/js/tinymce.js"></script>

0 comments on commit 2bbb103

Please sign in to comment.