Skip to content

Commit

Permalink
Merge 7de59b0 into 06e1c63
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Mar 28, 2015
2 parents 06e1c63 + 7de59b0 commit f2a71be
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
14 changes: 14 additions & 0 deletions Resources/public/javascript/admin.js
Expand Up @@ -20,3 +20,17 @@ function mainMenuDropShadow() {
var scrollPercent = 100 * this.scrollTop / this.scrollHeight / (1 - this.clientHeight / this.scrollHeight);
isNaN(scrollPercent) || scrollPercent >= 100 ? headerFooter.removeClass('drop-shadow') : headerFooter.addClass('drop-shadow');
}

function enhanceNullableDatetimeFields() {
var fnNullDates = function() {
var checkbox = $(this);
checkbox.parents('.null-control').siblings('select').each(function() {
$(this).prop('disabled', checkbox.is(':checked'))
});
};
$('.field_datetime .null-control')
.each(function () {
$(this).appendTo($(this).siblings('.form-inline'));
})
.find(':checkbox').bind('change', fnNullDates).each(fnNullDates);
}
8 changes: 8 additions & 0 deletions Resources/public/stylesheet/admin.css
Expand Up @@ -706,6 +706,10 @@ body.new form textarea {
body.new form .form-inline select + select {
margin-left: .5em;
}
body.new form .field_datetime .form-inline .null-control {
display: inline-block;
margin-left: 5px;
}

/* -------------------------------------------------------------------------
EDIT PAGE
Expand All @@ -716,6 +720,10 @@ body.edit form textarea {
body.edit form .form-inline select + select {
margin-left: .5em;
}
body.edit form .field_datetime .form-inline .null-control {
display: inline-block;
margin-left: 5px;
}

/* -------------------------------------------------------------------------
SHOW PAGE
Expand Down
31 changes: 21 additions & 10 deletions Resources/views/edit.html.twig
Expand Up @@ -17,24 +17,33 @@
{{ form_start(form, { attr: { id: 'edit-form', novalidate: 'novalidate' } }) }}
<div id="form">
{% for field in form.children if field.vars.name != '_token' %}
{% set _field_metadata = entity_fields[field.vars.name] %}
<div class="form-group {% if not field.vars.valid %}has-error{% endif %}">
{% if _field_metadata['fieldType'] == 'association' %}
{{ easyadmin_render_field_for_edit_view(item, _field_metadata) }}
{% set _field_configuration = entity_fields[field.vars.name] %}
{% set _field_type = _field_configuration['fieldType'] %}
<div class="form-group field_{{ _field_type|lower|default('default') }} {% if not field.vars.valid %}has-error{% endif %}">
{% if _field_type == 'association' %}
{{ easyadmin_render_field_for_edit_view(item, _field_configuration) }}
{% else %}
{% set field_label = _field_metadata['label']|default(null) %}
{% set field_label = _field_configuration['label']|default(null) %}
{{ form_label(field, field_label|trans(_trans_parameters), { label_attr: { class: 'col-sm-2 control-label' } }) }}

<div class="col-sm-10 {% if _field_metadata['fieldType'] == 'checkbox' %}col-sm-offset-2{% endif %}">
{% set widget_attributes = { attr: { class: _field_metadata['class']|default(null) }, label: _field_metadata['label']|trans } %}
<div class="col-sm-10 {% if _field_type == 'checkbox' %}col-sm-offset-2{% endif %}">
{% set widget_attributes = { attr: { class: _field_configuration['class']|default(null) }, label: _field_configuration['label']|trans } %}
{{ form_widget(field, widget_attributes) }}
{% if _field_type in ['datetime', 'datetimetz', 'date', 'time'] and _field_configuration['nullable'] %}
<div class="null-control">
<label>
<input type="checkbox" {% if field.vars.data is null %}checked="checked" {% endif %}>
Null
</label>
</div>
{% endif %}
{{ form_errors(field) }}

{% if _field_metadata['help'] is defined %}
<span class="help-block">{{ _field_metadata['help'] }}</span>
{% if _field_configuration['help'] is defined %}
<span class="help-block">{{ _field_configuration['help'] }}</span>
{% endif %}

{% if _field_metadata['fieldType'] == 'collection' %}
{% if _field_type == 'collection' %}
{% set add_item_javascript %}
$(function() {
if(event.preventDefault) event.preventDefault(); else event.returnValue = false;
Expand Down Expand Up @@ -147,6 +156,8 @@
$('#delete-form').trigger('submit');
});
});
enhanceNullableDatetimeFields();
});
</script>
{% endblock %}
19 changes: 15 additions & 4 deletions Resources/views/new.html.twig
Expand Up @@ -18,23 +18,32 @@
<div id="form">
{% for field in form.children if field.vars.name != '_token' %}
{% set _field_configuration = entity_fields[field.vars.name] %}
<div class="form-group field_{{ _field_configuration['fieldType']|lower|default('default') }} {% if not field.vars.valid %}has-error{% endif %}">
{% if _field_configuration['fieldType'] == 'association' %}
{% set _field_type = _field_configuration['fieldType'] %}
<div class="form-group field_{{ _field_type|lower|default('default') }} {% if not field.vars.valid %}has-error{% endif %}">
{% if _field_type == 'association' %}
{{ easyadmin_render_field_for_new_view(item, _field_configuration) }}
{% else %}
{% set field_label = _field_configuration['label']|default(null) %}
{{ form_label(field, field_label|trans, { label_attr: { class: 'col-sm-2 control-label' } }) }}

<div class="col-sm-10 {% if _field_configuration['fieldType'] == 'checkbox' %}col-sm-offset-2{% endif %}">
<div class="col-sm-10 {% if _field_type == 'checkbox' %}col-sm-offset-2{% endif %}">
{% set widget_attributes = { attr: { class: _field_configuration['class']|default(null) }, label: entity_fields[field.vars.name]['label']|trans } %}
{{ form_widget(field, widget_attributes) }}
{% if _field_type in ['datetime', 'datetimetz', 'date', 'time'] and _field_configuration['nullable'] %}
<div class="null-control">
<label>
<input type="checkbox" {% if field.vars.data is null %}checked="checked" {% endif %}>
Null
</label>
</div>
{% endif %}
{{ form_errors(field) }}

{% if _field_configuration['help'] is defined %}
<span class="help-block">{{ _field_configuration['help'] }}</span>
{% endif %}

{% if _field_configuration['fieldType'] == 'collection' %}
{% if _field_type == 'collection' %}
{% set add_item_javascript %}
$(function() {
if(event.preventDefault) event.preventDefault(); else event.returnValue = false;
Expand Down Expand Up @@ -103,6 +112,8 @@
<script type="text/javascript">
$(function() {
$('#new-form').areYouSure({ 'message': 'You haven\'t saved the changes made on this form.' });
enhanceNullableDatetimeFields();
});
</script>
{% endblock %}

0 comments on commit f2a71be

Please sign in to comment.