mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-18 12:11:11 +00:00
Merge branch 'feature/streamfield' of github.com:torchbox/wagtail into feature/streamfield
This commit is contained in:
commit
26d6022752
5 changed files with 158 additions and 48 deletions
|
|
@ -10,6 +10,8 @@ For example, they don't assume the presence of a 'delete' button - it's up to th
|
|||
var self = {};
|
||||
self.prefix = prefix;
|
||||
self.container = $('#' + self.prefix + '-container');
|
||||
self.menu = $('.stream-menu', self.container);
|
||||
|
||||
var indexField = $('#' + self.prefix + '-order');
|
||||
|
||||
self.delete = function() {
|
||||
|
|
@ -28,6 +30,7 @@ For example, they don't assume the presence of a 'delete' button - it's up to th
|
|||
self.container.fadeOut();
|
||||
};
|
||||
self._markAdded = function() {
|
||||
self.menu.addClass('closed');
|
||||
self.container.hide();
|
||||
self.container.slideDown();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@
|
|||
listMemberTemplates[childBlock.name] = template;
|
||||
}
|
||||
|
||||
$('.stream-menu').addClass('stream-menu-closed');
|
||||
$(document).on('mouseover','.stream-menu',function(){
|
||||
$(this).removeClass('stream-menu-closed');
|
||||
}).on('mouseout', '.stream-menu', function(){
|
||||
$(this).addClass('stream-menu-closed')
|
||||
});
|
||||
|
||||
|
||||
return function(elementPrefix) {
|
||||
var sequence = Sequence({
|
||||
'prefix': elementPrefix,
|
||||
|
|
|
|||
|
|
@ -192,74 +192,116 @@
|
|||
padding-left:0;
|
||||
padding-right:0;
|
||||
}
|
||||
|
||||
/* Object controls */
|
||||
.stream-controls{
|
||||
position:absolute;
|
||||
z-index:1;
|
||||
right:1em;
|
||||
top:1em;
|
||||
color:white;
|
||||
overflow:hidden;
|
||||
@include border-radius(2px);
|
||||
|
||||
li{
|
||||
background-color: $color-teal;
|
||||
float:left;
|
||||
cursor:pointer;
|
||||
margin-right:1px;
|
||||
|
||||
&:last-child{
|
||||
margin-right:0;
|
||||
}
|
||||
}
|
||||
|
||||
.disabled{
|
||||
display:none;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.fields > li > .field > label{
|
||||
display:none;
|
||||
}
|
||||
.sequence{
|
||||
position:relative;
|
||||
@include clearfix;
|
||||
margin:1em 0;
|
||||
border:1px solid lighten($color-grey-4, 3%);
|
||||
padding:0 1.5em;
|
||||
|
||||
.sequence{ /* YUK! */
|
||||
padding:0 1.5em;
|
||||
margin:1em 0;
|
||||
border:1px solid lighten($color-grey-4, 3%);
|
||||
}
|
||||
}
|
||||
|
||||
.sequence-inner{
|
||||
overflow:hidden;
|
||||
|
||||
.sequence-inner{ /* YUK! */
|
||||
@include column(10);
|
||||
}
|
||||
}
|
||||
|
||||
.sequence-member{
|
||||
@include clearfix;
|
||||
position:relative;
|
||||
padding:1em 1.5em;
|
||||
border-bottom:1px solid lighten($color-grey-4, 3%);
|
||||
margin:0 -1.5em;
|
||||
|
||||
.inner{
|
||||
@include clearfix;
|
||||
}
|
||||
|
||||
.inner > .struct-block > label{
|
||||
display:block;
|
||||
width:100%;
|
||||
float:none;
|
||||
}
|
||||
}
|
||||
.sequence-inner{
|
||||
@include column(10);
|
||||
|
||||
&:nth-of-type(1){
|
||||
@include column(12);
|
||||
padding:0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.struct-block > ul > li{ /* duplicates forms.scss ln.568 */
|
||||
@include clearfix();
|
||||
padding-top:0.5em;
|
||||
padding-bottom:1.2em;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Object controls */
|
||||
.stream-controls{
|
||||
position:absolute;
|
||||
z-index:1;
|
||||
right:1em;
|
||||
top:1em;
|
||||
color:white;
|
||||
overflow:hidden;
|
||||
@include border-radius(2px);
|
||||
|
||||
li{
|
||||
background-color: $color-teal;
|
||||
float:left;
|
||||
cursor:pointer;
|
||||
margin-right:1px;
|
||||
|
||||
&:last-child{
|
||||
margin-right:0;
|
||||
}
|
||||
}
|
||||
|
||||
.disabled{
|
||||
display:none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Menu of other blocks to be added at each position */
|
||||
.stream-menu{
|
||||
position:relative;
|
||||
overflow:hidden;
|
||||
|
||||
ul{
|
||||
@include clearfix;
|
||||
padding:1em;
|
||||
background-color:$color-grey-5;
|
||||
}
|
||||
|
||||
&.stream-menu-closed{
|
||||
ul{
|
||||
height:0px;
|
||||
}
|
||||
|
||||
&:before{
|
||||
margin-top:-0.5em;
|
||||
font-family:wagtail;
|
||||
content:"B";
|
||||
width:2em;
|
||||
height:2em;
|
||||
display:block;
|
||||
position:relative;
|
||||
left:0;right:0;
|
||||
margin:auto;
|
||||
z-index:5;
|
||||
color:$color-teal;
|
||||
font-size:1.7em;
|
||||
line-height:2em;
|
||||
text-align:center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* special panel for the publishing fields, requires a bit more pizzazz */
|
||||
&.publishing{
|
||||
h2:before{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<ul class="stream-menu">
|
||||
{% for child_block in child_blocks %}
|
||||
<li style="display: inline;"><button type="button" id="{{ prefix }}-add-{{ child_block.name }}">{{ child_block.name }}</button></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="stream-menu">
|
||||
<ul>
|
||||
{% for child_block in child_blocks %}
|
||||
<li style="display: inline;"><button type="button" id="{{ prefix }}-add-{{ child_block.name }}">{{ child_block.name }}</button></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
|||
55
wagtail/wagtailadmin/tests/test_blocks.py
Normal file
55
wagtail/wagtailadmin/tests/test_blocks.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import unittest
|
||||
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from wagtail.wagtailadmin import blocks
|
||||
|
||||
|
||||
class TestFieldBlock(unittest.TestCase):
|
||||
def test_charfield_render(self):
|
||||
block = blocks.FieldBlock(forms.CharField())
|
||||
html = block.render("Hello world!")
|
||||
|
||||
self.assertEqual(html, "Hello world!")
|
||||
|
||||
def test_charfield_render_form(self):
|
||||
block = blocks.FieldBlock(forms.CharField())
|
||||
html = block.render_form("Hello world!")
|
||||
|
||||
self.assertIn('<div class="field char_field">', html)
|
||||
self.assertIn('<input id="" name="" type="text" value="Hello world!" />', html)
|
||||
|
||||
def test_charfield_render_form_with_prefix(self):
|
||||
block = blocks.FieldBlock(forms.CharField())
|
||||
html = block.render_form("Hello world!", prefix='foo')
|
||||
|
||||
self.assertIn('<input id="foo" name="foo" type="text" value="Hello world!" />', html)
|
||||
|
||||
def test_charfield_render_form_with_error(self):
|
||||
block = blocks.FieldBlock(forms.CharField())
|
||||
html = block.render_form("Hello world!", error=ValidationError("This field is required."))
|
||||
|
||||
self.assertIn('This field is required.', html)
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_choicefield_render(self):
|
||||
block = blocks.FieldBlock(forms.ChoiceField(choices=(
|
||||
('choice-1', "Choice 1"),
|
||||
('choice-2', "Choice 2"),
|
||||
)))
|
||||
html = block.render('choice-2')
|
||||
|
||||
self.assertEqual(html, "Choice 2")
|
||||
|
||||
def test_choicefield_render_form(self):
|
||||
block = blocks.FieldBlock(forms.ChoiceField(choices=(
|
||||
('choice-1', "Choice 1"),
|
||||
('choice-2', "Choice 2"),
|
||||
)))
|
||||
html = block.render_form('choice-2')
|
||||
|
||||
self.assertIn('<div class="field choice_field">', html)
|
||||
self.assertIn('<select id="" name="">', html)
|
||||
self.assertIn('<option value="choice-1">Choice 1</option>', html)
|
||||
self.assertIn('<option value="choice-2" selected="selected">Choice 2</option>', html)
|
||||
Loading…
Reference in a new issue