form
This commit is contained in:
parent
44d90ab942
commit
688925acc0
|
@ -8,13 +8,18 @@ app:
|
|||
title: 'About'
|
||||
|
||||
form:
|
||||
error:
|
||||
not_blank: 'This value should not be blank bro!'
|
||||
title:
|
||||
placeholder: 'Title'
|
||||
cipher:
|
||||
alert: 'By enabling cipher, fork will be not possible.'
|
||||
label: 'Cipher: %value%'
|
||||
choice:
|
||||
yes: 'Yes'
|
||||
no: 'No'
|
||||
type:
|
||||
label: 'Language: %value%'
|
||||
choice:
|
||||
xml: 'HTML/XML'
|
||||
css: 'CSS'
|
||||
|
|
|
@ -14,9 +14,22 @@ class HomeController
|
|||
{
|
||||
public function indexAction(Request $request, Application $app)
|
||||
{
|
||||
$form = new CreateGistForm($app['form.factory'], $app['translator']);
|
||||
$data = array(
|
||||
'type' => 'xml',
|
||||
'cipher' => 'no',
|
||||
);
|
||||
|
||||
$form = new CreateGistForm($app['form.factory'], $app['translator'], $data);
|
||||
$form = $form->build();
|
||||
|
||||
if ($request->isMethod('post')) {
|
||||
$form->submit($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $app['twig']->render(
|
||||
'Home/index.html.twig',
|
||||
array(
|
||||
|
|
|
@ -15,11 +15,11 @@ abstract class AbstractForm
|
|||
|
||||
protected $translator;
|
||||
|
||||
public function __construct(FormFactory $formFactory, Translator $translator)
|
||||
public function __construct(FormFactory $formFactory, Translator $translator, array $data = array())
|
||||
{
|
||||
$this->translator = $translator;
|
||||
|
||||
$this->builder = $formFactory->createBuilder('form');
|
||||
$this->builder = $formFactory->createBuilder('form', $data);
|
||||
}
|
||||
|
||||
abstract public function build(array $options = array());
|
||||
|
|
|
@ -34,7 +34,9 @@ class CreateGistForm extends AbstractForm
|
|||
'rows' => 10,
|
||||
),
|
||||
'constraints' => array(
|
||||
new NotBlank(),
|
||||
new NotBlank(array(
|
||||
'message' => $this->translator->trans('form.error.not_blank'),
|
||||
)),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -57,8 +59,8 @@ class CreateGistForm extends AbstractForm
|
|||
array(
|
||||
'required' => true,
|
||||
'choices' => array(
|
||||
0 => $this->translator->trans('form.cipher.choice.no'),
|
||||
1 => $this->translator->trans('form.cipher.choice.yes'),
|
||||
'no' => $this->translator->trans('form.cipher.choice.no'),
|
||||
'yes' => $this->translator->trans('form.cipher.choice.yes'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
|
|
@ -2,84 +2,76 @@
|
|||
|
||||
{% block body %}
|
||||
<div class="row">
|
||||
{{ form(form) }}
|
||||
<form action="{{ path('home') }}" method="post">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<input type="text" class="form-control" id="name" placeholder="Title">
|
||||
{{ form_widget(form.title) }}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p class="text-primary">
|
||||
<p class="text-primary hide" id="cipher-alert">
|
||||
<span class="glyphicon glyphicon-info-sign"></span>
|
||||
En activant le chiffrement, le code déposé ne pourra pas être forké.
|
||||
{{ 'form.cipher.alert'|trans }}
|
||||
</p>
|
||||
<div class="btn-toolbar">
|
||||
<div class="btn-group" id="languages">
|
||||
<div class="btn-group" id="options">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
Language XML
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
|
||||
<span id="type-label" data-tpl="{{ 'form.type.label'|trans }}">
|
||||
</span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<ul class="dropdown-menu">
|
||||
{% for item in form.type.vars.choices %}
|
||||
<li>
|
||||
<a href="html">HTML/XML</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="css">CSS</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript">JAVASCRIPT</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="php">PHP</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="sql">SQL</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="yaml">YAML</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="perl">PERL</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="c">C/C++</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="asp">ASP</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="python">PYTHON</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="bash">BASH</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="actionscript">ACTION SCRIPT</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="texte">TEXT</a>
|
||||
<input
|
||||
{% if item.value == form.type.vars.value %}checked{% endif %}
|
||||
data-id="#type-label" type="radio" class="hide"
|
||||
data-title="{{ item.label }}"
|
||||
value="{{ item.value }}"
|
||||
name="form[type]"
|
||||
id="type-{{ loop.index }}" />
|
||||
|
||||
<a href="#">
|
||||
<label for="type-{{ loop.index }}">
|
||||
{{ item.label }}
|
||||
</label>
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
Chiffrement : non
|
||||
<span id="cipher-label" data-tpl="{{ 'form.cipher.label'|trans }}">
|
||||
</span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
{% for item in form.cipher.vars.choices %}
|
||||
<li>
|
||||
<a href="html">oui</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="css">non</a>
|
||||
<input
|
||||
{% if item.value == form.cipher.vars.value %}checked{% endif %}
|
||||
data-id="#cipher-label" type="radio" class="hide cipher-input"
|
||||
data-title="{{ item.label }}"
|
||||
value="{{ item.value }}"
|
||||
name="form[cipher]"
|
||||
id="cipher-{{ loop.index }}" />
|
||||
|
||||
<a href="#">
|
||||
<label for="cipher-{{ loop.index }}">
|
||||
{{ item.label }}
|
||||
</label>
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<textarea rows="10" id="code" class="form-control"></textarea>
|
||||
{{ form_errors(form.content) }}
|
||||
{{ form_widget(form.content) }}
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" class="btn btn-primary" value="Envoyer">
|
||||
|
@ -87,5 +79,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ form_widget(form._token) }}
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -43,12 +43,12 @@
|
|||
</nav>
|
||||
<div class="container-fluid" id="container">
|
||||
{% block body %}{% endblock %}
|
||||
</div>
|
||||
{% block js %}
|
||||
<script src="{{ web_path }}components/jquery/dist/jquery.min.js"></script>
|
||||
<script src="{{ web_path }}components/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script src="{{ web_path }}components/select2-dist/dist/js/select2.full.min.js"></script>
|
||||
<script src="{{ web_path }}app/js/app.js></script>
|
||||
<script src="{{ web_path }}app/js/app.js"></script>
|
||||
{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -12,7 +12,7 @@ body {
|
|||
border: #333;
|
||||
}
|
||||
|
||||
#code {
|
||||
#form_content {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
|
@ -43,3 +43,4 @@ body {
|
|||
.panel-heading .actions {
|
||||
margin-top: -5px;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,31 @@
|
|||
$('textarea').on('keyup change', function() {
|
||||
$(this).attr('rows', Math.max(10, $(this).val().split("\n").length));
|
||||
});
|
||||
|
||||
$('#options input').change(function() {
|
||||
var $input = $(this);
|
||||
|
||||
var $label = $($input.data('id'));
|
||||
|
||||
$label.html($label.data('tpl').replace('%value%', $input.data('title')));
|
||||
});
|
||||
|
||||
$('#options li, #options a').click(function() {
|
||||
$(this).find('label').trigger('click');
|
||||
});
|
||||
|
||||
$('#options label').click(function(e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
$('#options input:checked').each(function() {
|
||||
$(this).trigger('change');
|
||||
});
|
||||
|
||||
$('.cipher-input').change(function() {
|
||||
if ($('.cipher-input:checked').val() === 'yes') {
|
||||
$('#cipher-alert').removeClass('hide');
|
||||
} else {
|
||||
$('#cipher-alert').addClass('hide');
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue