Skip to content

Commit

Permalink
Merge 0d08ba0 into c4d3dd3
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed May 24, 2020
2 parents c4d3dd3 + 0d08ba0 commit 1e9bc37
Show file tree
Hide file tree
Showing 13 changed files with 588 additions and 51 deletions.
27 changes: 27 additions & 0 deletions assets/js/inplace-fields.js
@@ -0,0 +1,27 @@
/* ===== Zeste de Savoir ==================================================== */
/* Show and hide in-place forms */
/* ========================================================================== */

(function($) {
'use strict'

/* Edit title */
function toggleDisplayTitle(e) {
$('#title-show').toggleClass('hidden')
$('#title-edit').toggleClass('hidden')
e.preventDefault()
}

$('#show-title-edit').on('click', toggleDisplayTitle)
$('#hide-title-edit').on('click', toggleDisplayTitle)

/* Edit subtitle */
function toggleDisplaySubtitle(e) {
$('#subtitle-show').toggleClass('hidden')
$('#subtitle-edit').toggleClass('hidden')
e.preventDefault()
}

$('#show-subtitle-edit').on('click', toggleDisplaySubtitle)
$('#hide-subtitle-edit').on('click', toggleDisplaySubtitle)
})(jQuery)
1 change: 1 addition & 0 deletions assets/scss/main.scss
Expand Up @@ -92,6 +92,7 @@
@import "pages/stats";
@import "pages/tutorial-help";
@import "pages/tutorial-history";
@import "pages/content-edit";

/*-------------------------
10. High pixel ratio (retina)
Expand Down
80 changes: 80 additions & 0 deletions assets/scss/pages/_content-edit.scss
@@ -0,0 +1,80 @@
#show-title-edit, #show-subtitle-edit {
font-size: 1.5rem;
cursor: pointer;
}

#title-edit, #subtitle-edit {
height: 100%;

form {
box-sizing: border-box;
height: 100%;
}

.control-label {
display: none;
}

.control-group, .controls {
display: inline;
box-sizing: border-box;
width: 50%;
}

input {
box-sizing: border-box;
display: inline-block;
vertical-align: middle;
width: 50%;
margin: 0;
padding: 0;
font-weight: normal;
}

button.btn, button.btn-submit, button.link, button {
box-sizing: border-box;
display: inline-block;
vertical-align: middle;
height: 100%;
float: none;
cursor: pointer;
margin: 0 5px 0 0;
}

button.link {
box-sizing: border-box;
color: lighten($color-primary, 20%);
transition: color $transition-duration ease, text-decoration $transition-duration ease;
text-decoration: underline;

&:hover {
color: darken($color-secondary, 15%);
text-decoration: none;
}
}
}


#title-edit {
input {
height: 3.8rem;
color: $color-primary;
}

button.btn, button.btn-submit, button.link, button {
font-size: 1.5rem;
line-height: 3.8rem;
}
}

#subtitle-edit {
input {
height: 2.3rem;
color: #999;
}

button.btn, button.btn-submit, button.link, button {
font-size: 1.5rem;
line-height: 2.3rem;
}
}
40 changes: 30 additions & 10 deletions templates/tutorialv2/view/content.html
Expand Up @@ -28,23 +28,43 @@
</p>
{% else %}
<p class="license">
<a href="#edit-license" class="open-modal">Choisissez la licence de votre publication !</a>
<a href="#edit-license" class="open-modal">{% trans "Choisissez la licence de votre publication !" %}</a>
</p>
{% endif %}
{% crispy form_edit_license %}

<h1 {% if content.image %}class="illu"{% endif %}>
{% if content.image %}
<img src="{{ content.image.physical.tutorial_illu.url }}" alt="">
{% endif %}
{{ content.title }}
<div class="title-show" id="title-show">
{% if content.image %}
<img src="{{ content.image.physical.tutorial_illu.url }}" alt="">
{% endif %}
{{ content.title }}
<button id="show-title-edit" class="link btn-inline">{% trans "Modifier le titre" %}</button>
</div>

<div class="title-edit hidden" id="title-edit">
{% spaceless %}{% crispy form_edit_title %}{% endspaceless %}
</div>
</h1>

{% if content.description %}
<h2 class="subtitle">
{{ content.description }}
</h2>
{% endif %}
<h2 class="subtitle">
<div class="subtitle-show" id="subtitle-show">
{% if content.description %}
{{ content.description }}
{% endif %}
<button id="show-subtitle-edit" class="link btn-inline">
{% if content.description %}
{% trans "Modifier le sous-titre" %}
{% else %}
{% trans "Ajouter un sous-titre" %}
{% endif %}
</button>
</div>
<div class="title-subtitle hidden" id="subtitle-edit">
{% spaceless %}{% crispy form_edit_subtitle %}{% endspaceless %}
</div>
</h2>


{% if can_edit %}
{% include 'tutorialv2/includes/tags_authors.part.html' with content=content add_author=True online=False %}
Expand Down
72 changes: 64 additions & 8 deletions zds/tutorialv2/forms.py
Expand Up @@ -245,13 +245,6 @@ def __init__(self, *args, **kwargs):


class ContentForm(ContainerForm):

description = forms.CharField(
label=_('Description'),
max_length=PublishableContent._meta.get_field('description').max_length,
required=False,
)

tags = forms.CharField(
label=_('Tag(s) séparés par une virgule (exemple: python,django,web)'),
max_length=64,
Expand Down Expand Up @@ -311,7 +304,6 @@ def _create_layout(self, hide_help):
self.helper.layout = Layout(
IncludeEasyMDE(),
Field('title'),
Field('description'),
Field('tags'),
Field('type'),
Field('image'),
Expand Down Expand Up @@ -414,6 +406,70 @@ def _create_layout(self):
)


class EditContentTitleForm(forms.Form):
title = forms.CharField(
label=_('Titre'),
max_length=PublishableContent._meta.get_field('title').max_length,
required=True,
error_messages={'required': _('Le titre ne peut pas être vide.'),
'invalid_slug': _("Ce titre n'est pas autorisé, son slug est invalide !"),
'max_length': _('Ce titre est trop long.')}
)

def __init__(self, content, *args, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)

self.helper = FormHelper()
self.helper.form_class = 'content-wrapper'
self.helper.form_method = 'post'
self.helper.form_id = 'title-edit-form'
self.helper.form_action = reverse('content:edit-title', kwargs={'pk': content.pk})
self.previous_page_url = reverse('content:view', kwargs={'pk': content.pk, 'slug': content.slug})
self._create_layout()

def _create_layout(self):
self.helper.layout = Layout(
Field('title'),
StrictButton(_('Enregistrer'), type='submit', css_class='btn-submit'),
StrictButton(_('Annuler'), css_class='link', id='hide-title-edit')
)

def clean(self):
cleaned_data = super(EditContentTitleForm, self).clean()
try:
slugify_raise_on_invalid(cleaned_data.get('title'))
except InvalidSlugError:
self.add_error('title', self.declared_fields['title'].error_messages['invalid_slug'])
return cleaned_data


class EditContentSubtitleForm(forms.Form):
subtitle = forms.CharField(
label=_('Sous-titre'),
max_length=PublishableContent._meta.get_field('description').max_length,
required=False,
error_messages={'max_length': _('Le sous-titre est trop long.')}
)

def __init__(self, content, *args, **kwargs):
super(forms.Form, self).__init__(*args, **kwargs)

self.helper = FormHelper()
self.helper.form_class = 'content-wrapper'
self.helper.form_method = 'post'
self.helper.form_id = 'subtitle-edit-form'
self.helper.form_action = reverse('content:edit-subtitle', kwargs={'pk': content.pk})
self.previous_page_url = reverse('content:view', kwargs={'pk': content.pk, 'slug': content.slug})
self._create_layout()

def _create_layout(self):
self.helper.layout = Layout(
Field('subtitle'),
StrictButton(_('Enregistrer'), type='submit', css_class='btn-submit'),
StrictButton(_('Annuler'), css_class='link', id='hide-subtitle-edit')
)


class ExtractForm(FormWithTitle):

text = forms.CharField(
Expand Down
1 change: 0 additions & 1 deletion zds/tutorialv2/tests/tests_models.py
Expand Up @@ -451,7 +451,6 @@ def test_publication_and_attributes_consistency(self):
True)
self.client.post(reverse('content:edit', args=[article.pk, article.slug]), {
'title': old_title + 'bla',
'description': old_description + 'bla',
'type': 'ARTICLE',
'licence': article.licence.pk,
'subcategory': SubCategoryFactory().pk,
Expand Down

0 comments on commit 1e9bc37

Please sign in to comment.