add html5 form validation and fix JS for theme submission (bug 830988)

This commit is contained in:
Chris Van 2013-02-25 13:58:02 -08:00
Родитель 30cf1f007d
Коммит aeed99fb8b
9 изменённых файлов: 47 добавлений и 29 удалений

Просмотреть файл

@ -518,10 +518,13 @@ class NewPersonaForm(AddonFormBase):
type=amo.ADDON_PERSONA, weight__gte=0)
cats = sorted(cats, key=lambda x: x.name)
self.fields['category'].choices = [(c.id, c.name) for c in cats]
self.fields['header'].widget.attrs['data-upload-url'] = reverse(
'devhub.personas.upload_persona', args=['persona_header'])
self.fields['footer'].widget.attrs['data-upload-url'] = reverse(
'devhub.personas.upload_persona', args=['persona_footer'])
for field in ('header', 'footer'):
self.fields[field].widget.attrs = {
'data-upload-url': reverse('devhub.personas.upload_persona',
args=['persona_%s' % field]),
'data-allowed-types': 'image/jpeg|image/png'
}
def clean_name(self):
return clean_name(self.cleaned_data['name'])

Просмотреть файл

@ -205,6 +205,7 @@ def create_persona_preview_image(src, dst, img_basename, **kw):
@set_modified_on
def save_persona_image(src, dst, img_basename, **kw):
"""Creates a JPG of a Persona header/footer image."""
log.info('[1@None] Saving persona image: %s' % dst)
img = ImageCheck(storage.open(src))
if not img.is_image():

Просмотреть файл

@ -176,7 +176,7 @@
{{ ngettext('Comma-separated, minimum of {0} character.',
'Comma-separated, minimum of {0} characters.',
amo.MIN_TAG_LENGTH)|f(amo.MIN_TAG_LENGTH) }}
{{ _('Example: pop, hen, yum. Limit 20.') }}
{{ _('Example: dark, cinema, noir. Limit 20.') }}
</div>
{% if restricted_tags %}
<div class="edit-addon-details">

Просмотреть файл

@ -14,7 +14,7 @@
(None, _('Create'))]) }}
<h1>{{ title }}</h1>
<div class="island hero prettyform" id="submit-persona">
<form action="" method="post">
<form method="post">
{{ csrf() }}
{{ form.unsaved_data }}
<fieldset>
@ -29,15 +29,15 @@
{{ ngettext('Comma-separated, minimum of {0} character.',
'Comma-separated, minimum of {0} characters.',
amo.MIN_TAG_LENGTH)|f(amo.MIN_TAG_LENGTH) }}
{{ _('Example: pop, hen, yum. Limit 20.') }}
{{ _('Example: dark, cinema, noir. Limit 20.') }}
</span>
</li>
<li class="row c">
{{ pretty_field(form.summary, label=_('Describe your Theme.'),
tooltip=_("A short explanation of your add-on's
tooltip=_("A short explanation of your theme's
basic functionality that is displayed in
search and browse listings, as well as at
the top of your add-on's details page."),
the top of your theme's details page."),
tag=None, opt=True) }}
<div class="note">
{{ some_html_tip() }}
@ -204,7 +204,7 @@
</div>
</div>
</fieldset>
<p><button>{{ _('Submit Theme') }}</button></p>
<p><button class="button prominent" disabled type="submit">{{ _('Submit Theme') }}</button></p>
</form>
</div>
</section>

Просмотреть файл

@ -243,18 +243,18 @@ urlpatterns = decorate(write, patterns('',
url('^addon/%s/' % ADDON_ID, include(detail_patterns)),
url('^app/%s/' % amo.APP_SLUG, include(app_detail_patterns)),
url('^app/%s/submit/' % ADDON_ID, include(submit_apps_patterns)),
url('^theme/%s/' % ADDON_ID, include(theme_detail_patterns)),
url('^ajax/addon/%s/' % ADDON_ID, include(ajax_patterns)),
# Personas submission.
url('^persona/submit$', views.submit_persona,
# Themes submission.
url('^theme/submit$', views.submit_persona,
name='devhub.personas.submit'),
url('^persona/%s/submit/done$' % ADDON_ID, views.submit_persona_done,
url('^theme/%s/submit/done$' % ADDON_ID, views.submit_persona_done,
name='devhub.personas.submit.done'),
url('^persona/submit/upload/'
url('^theme/submit/upload/'
'(?P<upload_type>persona_header|persona_footer)$',
views.ajax_upload_image, name='devhub.personas.upload_persona'),
url('^theme/%s/' % ADDON_ID, include(theme_detail_patterns)),
# Add-on SDK page
url('builder$', views.builder, name='devhub.builder'),

Просмотреть файл

@ -311,7 +311,7 @@ textarea {
}
.checkboxes,
.radios {
display: inline-block;
display: block;
margin-bottom: 1em;
ul {
margin-top: 10px;
@ -319,7 +319,7 @@ textarea {
li {
margin-bottom: 5px;
label {
padding: 0 0 4px;
padding: 0 0 4px 1px;
width: auto;
text-align: left;
input {

Просмотреть файл

@ -96,7 +96,7 @@ ul.license {
}
.title,
.author {
background: fadeOut(#fff, 40%);
background: rgba(255,255,255,.6);
clear: left;
display: block;
float: left;

Просмотреть файл

@ -40,6 +40,19 @@ $(function() {
if (!$('#submit-persona, #addon-edit-license').length) {
return;
}
function checkValid(form) {
if (form) {
$(form).find('button[type=submit]').attr('disabled', !form.checkValidity());
}
}
$(document).delegate('input, select, textarea', 'change keyup paste', function(e) {
checkValid(e.target.form);
});
$('form').each(function() {
checkValid(this);
});
initLicense();
if (!$('#addon-edit-license').length) {
initCharCount();
@ -100,7 +113,6 @@ function initLicense() {
function initPreview() {
function hex2rgb(hex) {
var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
return {
@ -184,7 +196,7 @@ function initPreview() {
var accentcolor = $d.find('#id_accentcolor').attr('data-rgb'),
textcolor = $d.find('#id_textcolor').val();
$preview.find('.title, .author').css({
'background-color': format('rgba({0}, 0.7)', accentcolor),
'background-color': format('rgba({0}, .7)', accentcolor),
'color': textcolor
});
}
@ -204,7 +216,7 @@ function initPreview() {
}});
$('#id_name').bind('change keyup paste blur', _.throttle(function() {
$('#persona-preview-name').text($(this).val() || gettext("Your Persona's Name"));
$('#persona-preview-name').text($(this).val() || gettext("Your Theme's Name"));
}, 250)).trigger('change');
$('#submit-persona').submit(function() {
postUnsaved(POST);

Просмотреть файл

@ -12,21 +12,23 @@
{% macro pretty_field(field, label=None, tooltip=None, tag='li', req=None,
opt=False, choice=None, class='row') %}
{% if tag %}
<{{ tag }} class="{{ class }}{{ ' error' if field.errors }}">
{% endif %}
{% if choice == None %}
{% set choice = field|is_choice_field %}
{% endif %}
{% if req == None %}
{% set req = field.field.required %}
{% endif %}
{% set attrs = {'required': ''} if req else {} %}
{% if tag %}
<{{ tag }} class="{{ class }}{{ ' error' if field.errors }}">
{% endif %}
<label class="{{ class }}{{ ' choice' if choice }}" for="{{ field.auto_id }}">
{% if choice %}
{{ field.as_widget() -}}
{{ field.as_widget(attrs=attrs) -}}
{% endif %}
{{- label or field.label }}
{% if req == None %}
{% set req = field.field.required %}
{% endif %}
{% if req %}
{{ required() -}}
{% endif %}
@ -41,7 +43,7 @@
{% endif %}
</label>
{% if not choice %}
{{ field.as_widget() }}
{{ field.as_widget(attrs=attrs) }}
{% endif %}
{{ field.errors }}
{% if tag %}