-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Ajout d'une interface de merge pour les contenus #4151
Changes from 29 commits
d19997d
12e6167
1d6c888
9fb78c1
2ff88ac
520c8bd
a86b075
d64117f
615f5d4
fa17b76
4ecf63c
89eda18
d209ad7
405f17c
6b78028
2b19e0d
68ecbb1
14e987a
8be724e
0977079
c465f32
cbfe255
1daa48a
25276f0
1ec13cc
9335ccc
1e40465
f64b319
e81dc71
9a62434
0541a3e
b091f73
20bf699
a199b20
f30e30d
f32e2ba
185cc00
4e2dbfb
7f2c913
3c735ff
f411710
3227078
6b73cfc
6033f61
e5fe212
42d52aa
43a76af
7e12347
516583f
dd0444c
ed5e0cf
c30ad5f
ca9952d
e61d8cf
588b3a9
32e5899
868945a
ab60b13
8feb1ec
aa4afcc
ba88ccc
e924cc3
21141ef
42b4996
696bb81
868f7c3
ef875a5
dc5c9e4
9b94737
0d19446
c0d07af
59cd3d4
39ead6e
b4567b8
d00b293
c80d546
63075aa
fba3423
f64ec59
5863c8c
c7e8103
2602d09
cbf62b2
fcd9eee
3571d27
3df61ec
782c8aa
21ee83f
1623c63
dd97dde
af4f552
08a2c30
909b53e
af170c0
b95cc17
88a9290
21255b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
(function($, undefined) { | ||
"use strict"; | ||
|
||
$(document).ready(function () { | ||
|
||
/** | ||
* Sets up the merge interface (using mergely) in the $div Object. Data is generally retrieved from a form field | ||
* or an aditionnal div exposing the old data, also generated in the form. | ||
* @param {Object} $div - The base object used to set up the interface. Generally created in forms files. | ||
* @param {Object} $left - The object from which we will pick the content to put in the left hand side (lhs) of the editor. | ||
* @param {Object} $right - The object from which we will pick the content to put in the right hand side (rhs) of the editor. | ||
*/ | ||
function mergelySetUp($div, $left, $right) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L’accolade doit être sur la même ligne que |
||
$div.mergely({ | ||
width: "auto", | ||
height: 400, | ||
sidebar: false, | ||
cmsettings: { readOnly: false, lineNumbers: true, lineWrapping: true }, | ||
lhs: function(setValue) { | ||
setValue($left.html()); | ||
}, | ||
rhs: function(setValue) { | ||
setValue($right.html()); | ||
} | ||
}); | ||
} | ||
|
||
mergelySetUp($(".compare-introduction"),$("#your_introduction"),$("#id_introduction")); | ||
mergelySetUp($(".compare-conclusion"),$("#your_conclusion"),$("#id_conclusion")); | ||
mergelySetUp($(".compare-text"),$("#your_text"),$("#id_text")); | ||
|
||
$("#compare-editor-lhs").append("Votre Version"); | ||
$("#compare-editor-rhs").append("La version courante"); | ||
|
||
|
||
/** | ||
* Merge content | ||
*/ | ||
$(".merge-btn").on("click", function(e){ | ||
|
||
e.stopPropagation(); | ||
e.preventDefault(); | ||
|
||
var button = $(this); | ||
|
||
Array.from(this.classList).forEach(function(element){ | ||
if (element.indexOf("need-to-merge-") >= 0) { | ||
|
||
// Cut the string to get the ending part | ||
var substring = element.substring(14); | ||
|
||
var $intro = $("#id_" + substring); | ||
var $toMerge = $(".compare-" + substring).mergely("get","rhs"); | ||
$intro.val($toMerge); | ||
|
||
// Confirmation message | ||
var msg = "<div class='alert-box success alert-merge'>" + | ||
"<span>Le contenu a bien été validé.</span>" + | ||
"<a href='#close-alert-box' class='close-alert-box ico-after cross white'>Masquer l'alerte</a>" + | ||
"</div>"; | ||
|
||
button.before(msg); | ||
|
||
setTimeout(function() { | ||
$(".alert-merge").fadeOut("fast"); | ||
}, 2000); | ||
|
||
} | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
})(jQuery); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,26 +151,57 @@ def __init__(self, *args, **kwargs): | |
self.helper.form_class = 'content-wrapper' | ||
self.helper.form_method = 'post' | ||
|
||
self.helper.layout = Layout( | ||
Field('title'), | ||
self.helper.layout = Layout(Field('title')) | ||
|
||
if kwargs.get('data', None) is not None: | ||
old_intro = kwargs.get('data').get('introduction') | ||
if old_intro is None: | ||
old_intro = '' | ||
|
||
self.helper.layout.append(Layout(Field('introduction', css_class='hidden'))) | ||
self.helper.layout.append(Layout(HTML('<div id = "your_introduction" class = "hidden" >' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pas d’espaces autour des ' = ' |
||
old_intro + '</div>'))) | ||
self.helper.layout.append(Layout(HTML('<div id = "compare" class = "compare-introduction"></div>'))) | ||
|
||
self.helper.layout.append(Layout( | ||
ButtonHolder(StrictButton(_(u'Valider cette version'), type='merge', name='merge', \ | ||
css_class='btn btn-submit merge-btn need-to-merge-introduction')))) | ||
|
||
old_conclusion = kwargs.get('data').get('conclusion') | ||
if old_conclusion is None: | ||
old_conclusion = '' | ||
|
||
self.helper.layout.append(Layout(Field('conclusion', css_class='hidden'))) | ||
self.helper.layout.append(Layout(HTML('<div id = "your_conclusion" class = "hidden" >' + old_conclusion + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. préféer utiliser '...{0}'.format(...) ici There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem ailleurs |
||
'</div>'))) | ||
self.helper.layout.append(Layout(HTML('<div id = "compare" class="compare-conclusion"></div>'))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pas d’espaces autour du |
||
|
||
self.helper.layout.append(Layout( | ||
ButtonHolder(StrictButton(_(u'Valider cette version'), type='merge', name='merge', \ | ||
css_class='btn btn-submit merge-btn need-to-merge-conclusion')))) | ||
else: | ||
|
||
self.helper.layout.append(Layout( | ||
Field('introduction', css_class='md-editor preview-source'), | ||
ButtonHolder(StrictButton(_(u'Aperçu'), type='preview', name='preview', | ||
css_class='btn btn-grey preview-btn'),), | ||
HTML('{% if form.introduction.value %}{% include "misc/previsualization.part.html" \ | ||
with text=form.introduction.value %}{% endif %}'), | ||
Field('conclusion', css_class='md-editor preview-source'), | ||
ButtonHolder(StrictButton(_(u'Aperçu'), type='preview', name='preview', | ||
css_class='btn btn-grey preview-btn'),), | ||
css_class='btn btn-grey preview-btn'),))) | ||
HTML('{% if form.conclusion.value %}{% include "misc/previsualization.part.html" \ | ||
with text=form.conclusion.value %}{% endif %}'), | ||
|
||
self.helper.layout.append(Layout( | ||
Field('msg_commit'), | ||
Field('last_hash'), | ||
ButtonHolder( | ||
StrictButton( | ||
_(u'Valider'), | ||
artragis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type='submit'), | ||
) | ||
) | ||
)) | ||
|
||
|
||
class ContentForm(ContainerForm): | ||
|
@@ -232,7 +263,7 @@ class ContentForm(ContainerForm): | |
widget=forms.CheckboxSelectMultiple() | ||
) | ||
|
||
def _create_layout(self, hide_help): | ||
def _create_layout(self, hide_help, **kwargs): | ||
html_part = HTML(_(u"<p>Demander de l'aide à la communauté !<br>" | ||
u"Si vous avez besoin d'un coup de main, " | ||
u"sélectionnez une ou plusieurs catégories d'aide ci-dessous " | ||
|
@@ -245,21 +276,64 @@ def _create_layout(self, hide_help): | |
Field('description'), | ||
Field('tags'), | ||
Field('type'), | ||
Field('image'), | ||
Field('image')) | ||
|
||
if kwargs.get('data', None) is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ce code ressemble beaucoup à ce qu'il y a plus haut. Il faudra trouver une solution (mixin ?) pour factoriser ça. |
||
old_intro = kwargs.get('data').get('introduction') | ||
if old_intro is None: | ||
old_intro = '' | ||
|
||
self.helper.layout.append(Layout(Field('introduction', css_class='hidden'))) | ||
self.helper.layout.append(Layout(HTML('<div id = "your_introduction" class = "hidden" >' + | ||
old_intro + '</div>'))) | ||
self.helper.layout.append(Layout(HTML('<div id = "compare" class = "compare-introduction"></div>'))) | ||
|
||
self.helper.layout.append(Layout( | ||
ButtonHolder(StrictButton(_(u'Valider cette version'), type='merge', name='merge', \ | ||
css_class='btn btn-submit merge-btn need-to-merge-introduction')))) | ||
|
||
old_conclusion = kwargs.get('data').get('conclusion') | ||
if old_conclusion is None: | ||
old_conclusion = '' | ||
|
||
self.helper.layout.append(Layout(Field('conclusion', css_class='hidden'))) | ||
self.helper.layout.append(Layout(HTML('<div id = "your_conclusion" class = "hidden" >' + old_conclusion + | ||
'</div>'))) | ||
self.helper.layout.append(Layout(HTML('<div id = "compare" class="compare-conclusion"></div>'))) | ||
|
||
self.helper.layout.append(Layout( | ||
ButtonHolder(StrictButton(_(u'Valider cette version'), type='merge', name='merge', \ | ||
css_class='btn btn-submit merge-btn need-to-merge-conclusion')))) | ||
else: | ||
|
||
self.helper.layout.append(Layout( | ||
Field('introduction', css_class='md-editor preview-source'), | ||
ButtonHolder(StrictButton(_(u'Aperçu'), type='preview', name='preview', | ||
css_class='btn btn-grey preview-btn'),), | ||
HTML('{% if form.introduction.value %}{% include "misc/previsualization.part.html" \ | ||
with text=form.introduction.value %}{% endif %}'), | ||
Field('conclusion', css_class='md-editor preview-source'), | ||
ButtonHolder(StrictButton(_(u'Aperçu'), type='preview', name='preview', | ||
css_class='btn btn-grey preview-btn'),), | ||
css_class='btn btn-grey preview-btn'),))) | ||
HTML('{% if form.conclusion.value %}{% include "misc/previsualization.part.html" \ | ||
with text=form.conclusion.value %}{% endif %}'), | ||
with text=form.conclusion.value %}{% endif %}') | ||
|
||
self.helper.layout.append(Layout( | ||
Field('last_hash'), | ||
Field('licence'), | ||
Field('subcategory', template='crispy/checkboxselectmultiple.html'), | ||
) | ||
HTML(_(u"<p>Demander de l'aide à la communauté !<br>" | ||
u"Si vous avez besoin d'un coup de main, " | ||
u"sélectionnez une ou plusieurs catégories d'aide ci-dessous " | ||
u'et votre contenu apparaîtra alors sur <a href=' | ||
u'"{% url "content:helps" %}" ' | ||
u'alt="aider les auteurs">la page d\'aide</a>.</p>')), | ||
Field('helps'), | ||
Field('msg_commit'), | ||
ButtonHolder( | ||
StrictButton('Valider', type='submit'), | ||
), | ||
)) | ||
|
||
if not hide_help: | ||
self.helper.layout.append(html_part) | ||
|
@@ -275,7 +349,7 @@ def __init__(self, *args, **kwargs): | |
self.helper = FormHelper() | ||
self.helper.form_class = 'content-wrapper' | ||
self.helper.form_method = 'post' | ||
self._create_layout(for_tribune) | ||
self._create_layout(for_tribune, **kwargs) | ||
|
||
if 'type' in self.initial: | ||
self.helper['type'].wrap( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il faudrait réindenter ce fichier comme le reste, avec des espaces et non des tabulations.