Skip to content

Commit

Permalink
adding visible new button to field, creating new embed mode for new form
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhuang committed May 30, 2013
1 parent f876153 commit 99982d5
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 64 deletions.
8 changes: 5 additions & 3 deletions deme_django/cms/forms.py
Expand Up @@ -48,9 +48,11 @@ def render(self, name, value, attrs=None):
ajax_query_string = '&'.join('ability=' + urlquote(ability) for ability in self.required_abilities)
ajax_url = reverse('item_type_url', kwargs={'viewer': model.__name__.lower(), 'format': 'json'}) + '?' + ajax_query_string
result = """
<input type="hidden" name="%(name)s" value="%(value)s" data-input-id="%(id)s" data-ajax-url="%(ajax_url)s" class="ajax-model-choice-widget">
<input id="%(id)s" name="%(name)s_search" value="%(initial_search)s">
""" % {'name': name, 'value': value, 'id': attrs.get('id', ''), 'ajax_url': ajax_url, 'initial_search': initial_search}
<div class="input-group">
<input type="hidden" name="%(name)s" value="%(value)s" data-model-name="%(model_name)s" data-input-id="%(id)s" data-ajax-url="%(ajax_url)s" class="ajax-model-choice-widget">
<input type="text" id="%(id)s" name="%(name)s_search" value="%(initial_search)s">
</div>
""" % {'name': name, 'value': value, 'id': attrs.get('id', ''), 'ajax_url': ajax_url, 'initial_search': initial_search, 'model_name': model.__name__.lower()}
# see /javascripts/deme/ajax-model-choice-widget.js for implementation
#TODO fail in more obvious way if attrs['id'] is not set
return result
Expand Down
24 changes: 24 additions & 0 deletions deme_django/cms/templates/embed.html
@@ -0,0 +1,24 @@
{% load item_tags %}<!DOCTYPE html>
<html lang="en-us" class="embed">
<head>
<title>{% block title %}{% endblock %}</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<link href="{% media_url "css/deme.css" %}" rel="stylesheet">
<script type="text/javascript" src="{% media_url "javascripts/jquery-1.7.2.min.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/respond.min.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/jquery-1.7.2.min.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/jquery.cookie.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/jquery-ui-1.8.21.custom.min.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/bootstrap.min.js" %}"></script>
<link href="{% media_url "stylesheets/smoothness/jquery-ui-1.8.21.custom.css" %}" media="all" rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="{% media_url "javascripts/grid.locale-en.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/jquery.jqGrid.min.js" %}"></script>
<link href="{% media_url "stylesheets/ui.jqgrid.css" %}" media="all" rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="{% media_url "javascripts/deme/jqgrid-helpers.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/deme/ajax-model-choice-widget.js" %}"></script>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
61 changes: 2 additions & 59 deletions deme_django/cms/templates/item/new.html
@@ -1,63 +1,6 @@
{% extends layout %}
{% load item_tags %}
{% block content %}

{% if is_html %}
<script type="text/javascript" src="{% media_url "javascripts/tinymce/jscripts/tiny_mce/tiny_mce.js" %}"></script>
<script type="text/javascript">
$(document).ready(function () {
tinyMCE.init({
// General options
mode: "exact",
elements: "body",
theme : "advanced",
plugins : "table,advimage,advlink,media,paste,fullscreen,xhtmlxtras,searchreplace",

// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,|,search,replace",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,cite,abbr,acronym,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap,media,|,fullscreen",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
convert_urls : false,
});
});
</script>
{% endif %}

<div style="border: thin solid #aaa; background: #eee; padding: 10px; margin-bottom: 10px;">
{% for item_type in item_types %}
<span>[
{% ifequal item_type.item_type accepted_item_type %}
<b>New {{ item_type.name|capfirst }}</b>
{% else %}
<a href="{% url item_type_url viewer=item_type.viewer,action="new" %}?{{ query_string }}">New {{ item_type.name|capfirst }}</a>
{% endifequal %}
]</span>
{% endfor %}
</div>

<div>
{% if form %}
<form method="post" enctype="multipart/form-data" action="{% url item_type_url viewer=viewer_name,action="create" %}?{% if add_to_collection %}add_to_collection={{ add_to_collection|urlencode }}&{% endif %}{% if redirect %}redirect={{ redirect|urlencode }}{% endif %}" class="item_form">
<table cellspacing="0">
{{ form.as_table }}
</table>
<div>
<button type="button" onclick="$('#permission_editor').toggle();"><img src="{{ "permissions"|icon_url:16 }}" /> <span>Permissions</span></button>
</div>
<div id="permission_editor" style="display: none;">
{% new_item_permission_editor item %}
</div>
<button type="submit"><img src="{{ "checkbox"|icon_url:16 }}" /> <span>Create {{ accepted_item_type_name }}</span></button>
</form>
{% else %}
You do not have permission to create {{ accepted_item_type_name_plural }}.
{% endif %}
</div>


{% endblock content %}
{% include "item/new_bare.html" %}

{% endblock content %}
57 changes: 57 additions & 0 deletions deme_django/cms/templates/item/new_bare.html
@@ -0,0 +1,57 @@
{% load item_tags %}
{% if is_html %}
<script type="text/javascript" src="{% media_url "javascripts/tinymce/jscripts/tiny_mce/tiny_mce.js" %}"></script>
<script type="text/javascript">
$(document).ready(function () {
tinyMCE.init({
// General options
mode: "exact",
elements: "body",
theme : "advanced",
plugins : "table,advimage,advlink,media,paste,fullscreen,xhtmlxtras,searchreplace",

// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,|,search,replace",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,cite,abbr,acronym,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap,media,|,fullscreen",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
convert_urls : false,
});
});
</script>
{% endif %}

<div style="border: thin solid #aaa; background: #eee; padding: 10px; margin-bottom: 10px;">
{% for item_type in item_types %}
<span>[
{% ifequal item_type.item_type accepted_item_type %}
<b>New {{ item_type.name|capfirst }}</b>
{% else %}
<a href="{% url item_type_url viewer=item_type.viewer,action="new" %}?{{ query_string }}">New {{ item_type.name|capfirst }}</a>
{% endifequal %}
]</span>
{% endfor %}
</div>

<div>
{% if form %}
<form method="post" enctype="multipart/form-data" action="{% url item_type_url viewer=viewer_name,action="create" %}?{% if add_to_collection %}add_to_collection={{ add_to_collection|urlencode }}&{% endif %}{% if redirect %}redirect={{ redirect|urlencode }}{% endif %}" class="item_form">
<table cellspacing="0">
{{ form.as_table }}
</table>
<div>
<button type="button" onclick="$('#permission_editor').toggle();"><img src="{{ "permissions"|icon_url:16 }}" /> <span>Permissions</span></button>
</div>
<div id="permission_editor" style="display: none;">
{% new_item_permission_editor item %}
</div>
<button type="submit"><img src="{{ "checkbox"|icon_url:16 }}" /> <span>Create {{ accepted_item_type_name }}</span></button>
</form>
{% else %}
You do not have permission to create {{ accepted_item_type_name_plural }}.
{% endif %}
</div>

5 changes: 5 additions & 0 deletions deme_django/cms/templates/item/new_embed.html
@@ -0,0 +1,5 @@
{% extends "embed.html" %}
{% block title %}{{ action_title }}{% endblock %}
{% block content %}
{% include "item/new_bare.html" %}
{% endblock content %}
6 changes: 5 additions & 1 deletion deme_django/cms/views.py
Expand Up @@ -370,14 +370,18 @@ def type_new_html(self, form=None):
form_initial = self.get_populated_field_dict(self.accepted_item_type)
form_class = self.get_form_class_for_item_type(self.accepted_item_type, True)
form = form_class(initial=form_initial)
template = loader.get_template('item/new.html')
self.context['form'] = form
self.context['is_html'] = issubclass(self.accepted_item_type, HtmlDocument)
self.context['redirect'] = self.request.GET.get('redirect')
self.context['add_to_collection'] = self.request.GET.get('add_to_collection')
item_types = [{'viewer': x.__name__.lower(), 'name': x._meta.verbose_name, 'name': x._meta.verbose_name, 'item_type': x} for x in all_item_types() if self.accepted_item_type in x.__bases__ + (x,)]
item_types.sort(key=lambda x:x['name'].lower())
self.context['item_types'] = item_types
is_true = lambda value: bool(value) and value.lower() not in ('false', '0')
if (is_true(self.request.GET.get('modal'))):
template = loader.get_template('item/new_embed.html')
else:
template = loader.get_template('item/new.html')
return HttpResponse(template.render(self.context))

@require_POST
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -27,5 +27,11 @@ $(function() {
});
},
});

// set up new button
var newbtn = $('<span class="input-group-btn"><button class="btn btn-default">New</button></span>').insertAfter(search_input);
newbtn.click(function(e){
e.preventDefault();
})
});
});

0 comments on commit 99982d5

Please sign in to comment.