Skip to content

Commit

Permalink
Updated JS and HTML templates (sync with SonataDoctrineORMBundle)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrunch committed Sep 1, 2013
1 parent 72f168c commit 55bda56
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 111 deletions.
89 changes: 59 additions & 30 deletions Resources/views/CRUD/edit_mongo_association_script.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ This code manage the many-to-[one|many] association field popup
jQuery.ajax({
type: 'GET',
url: jQuery(this).attr('href'),
dataType: 'html',
success: function(html) {
field_dialog_{{ id }}.html(html);
Admin.log('[{{ id }}|field_dialog_form_list_link] callback success, attach valid js event');
field_dialog_{{ id }}.html(html);
field_dialog_form_list_handle_action_{{ id }}();
}
});
Expand All @@ -59,6 +63,38 @@ This code manage the many-to-[one|many] association field popup
field_dialog_{{ id }}.dialog('close');
}
// this function handle action on the modal list when inside a selected list
var field_dialog_form_list_handle_action_{{ id }} = function() {
Admin.log('[{{ id }}|field_dialog_form_list_handle_action] attaching valid js event');
Admin.add_filters(field_dialog_{{ id }});
// capture the submit event to make an ajax call, ie : POST data to the
// related create admin
jQuery('a', field_dialog_{{ id }}).on('click', field_dialog_form_list_link_{{ id }});
jQuery('form', field_dialog_{{ id }}).on('submit', function(event) {
event.preventDefault();
var form = jQuery(this);
Admin.log('[{{ id }}|field_dialog_form_list_handle_action] catching submit event, sending ajax request');
jQuery(form).ajaxSubmit({
type: form.attr('method'),
url: form.attr('action'),
dataType: 'html',
data: {_xml_http_request: true},
success: function(html) {
Admin.log('[{{ id }}|field_dialog_form_list_handle_action] form submit success, restoring event');
field_dialog_{{ id }}.html(html);
field_dialog_form_list_handle_action_{{ id }}();
}
});
});
}
// handle the add link
var field_dialog_form_list_{{ id }} = function(event) {
Expand Down Expand Up @@ -87,24 +123,7 @@ This code manage the many-to-[one|many] association field popup
Admin.add_filters(field_dialog_{{ id }});
// capture the submit event to make an ajax call, ie : POST data to the
// related create admin
jQuery('a', field_dialog_{{ id }}).live('click', field_dialog_form_list_link_{{ id }});
jQuery('form', field_dialog_{{ id }}).live('submit', function(event) {
event.preventDefault();
var form = jQuery(this);
jQuery(form).ajaxSubmit({
type: form.attr('method'),
url: form.attr('action'),
dataType: 'html',
data: {_xml_http_request: true},
success: function(html) {
field_dialog_{{ id }}.html(html);
}
});
});
field_dialog_form_list_handle_action_{{ id }}();
// open the dialog in modal mode
field_dialog_{{ id }}.dialog({
Expand All @@ -114,9 +133,11 @@ This code manage the many-to-[one|many] association field popup
resizable: true,
title: '{{ associationadmin.label|trans({}, associationadmin.translationdomain) }}',
close: function(event, ui) {
Admin.log('[{{ id }}|field_dialog_form_list] close callback, removing js event');
// make sure we have a clean state
jQuery('a', field_dialog_{{ id }}).die('click');
jQuery('form', field_dialog_{{ id }}).die('submit');
jQuery('a', field_dialog_{{ id }}).off('click');
jQuery('form', field_dialog_{{ id }}).off('submit');
},
zIndex: 9998
});
Expand Down Expand Up @@ -150,22 +171,22 @@ This code manage the many-to-[one|many] association field popup
// capture the submit event to make an ajax call, ie : POST data to the
// related create admin
jQuery('a', field_dialog_{{ id }}).live('click', field_dialog_form_action_{{ id }});
jQuery('form', field_dialog_{{ id }}).live('submit', field_dialog_form_action_{{ id }});
jQuery('a', field_dialog_{{ id }}).on('click', field_dialog_form_action_{{ id }});
jQuery('form', field_dialog_{{ id }}).on('submit', field_dialog_form_action_{{ id }});
// open the dialog in modal mode
field_dialog_{{ id }}.dialog({
height: 'auto',
width: 650,
width: 850,
modal: true,
autoOpen: true,
resizable: true,
title: '{{ associationadmin.label|trans({}, associationadmin.translationdomain) }}',
close: function(event, ui) {
Admin.log('[{{ id }}|field_dialog_form_add] dialog closed - removing `live` events');
Admin.log('[{{ id }}|field_dialog_form_add] dialog closed - removing events');
// make sure we have a clean state
jQuery('a', field_dialog_{{ id }}).die('click');
jQuery('form', field_dialog_{{ id }}).die('submit');
jQuery('a', field_dialog_{{ id }}).off('click');
jQuery('form', field_dialog_{{ id }}).off('submit');
},
zIndex: 9998
});
Expand All @@ -176,15 +197,20 @@ This code manage the many-to-[one|many] association field popup
// handle the post data
var field_dialog_form_action_{{ id }} = function(event) {
var element = jQuery(this);
// return if the link is an anchor inside the same page
if (this.nodeName == 'A' && (element.attr('href').length == 0 || element.attr('href')[0] == '#')) {
return;
}
event.preventDefault();
event.stopPropagation();
Admin.log('[{{ id }}|field_dialog_form_action] action catch', this);
initialize_popup_{{ id }}();
var element = jQuery(this);
if (this.nodeName == 'FORM') {
var url = element.attr('action');
var type = element.attr('method');
Expand Down Expand Up @@ -242,11 +268,13 @@ This code manage the many-to-[one|many] association field popup
jQuery('#field_widget_{{ id }}').closest('form').ajaxSubmit({
url: '{{ url('sonata_admin_retrieve_form_element', {
'elementId': id,
'subclass': sonata_admin.admin.getActiveSubclassCode(),
'objectId': sonata_admin.admin.root.id(sonata_admin.admin.root.subject),
'uniqid': sonata_admin.admin.root.uniqid,
'code': sonata_admin.admin.root.code
}) }}',
data: {_xml_http_request: true },
dataType: 'html',
type: 'POST',
success: function(html) {
jQuery('#field_container_{{ id }}').replaceWith(html);
Expand Down Expand Up @@ -367,7 +395,7 @@ This code manage the many-to-[one|many] association field popup
#}
// update the label
jQuery('#{{ id }}').live('change', function(event) {
jQuery('#{{ id }}').on('change', function(event) {
Admin.log('[{{ id }}] update the label');
Expand All @@ -379,6 +407,7 @@ This code manage the many-to-[one|many] association field popup
'uniqid': associationadmin.uniqid,
'code': associationadmin.code
})}}'.replace('OBJECT_ID', jQuery(this).val()),
dataType: 'html',
success: function(html) {
jQuery('#field_widget_{{ id }}').html(html);
}
Expand Down
14 changes: 7 additions & 7 deletions Resources/views/CRUD/edit_mongo_collection.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ file that was distributed with this source code.
<span id="field_widget_{{ id }}" >
{% if sonata_admin.edit == 'inline' %}
{% if sonata_admin.inline == 'table' %}

{% if form.children|length > 0 %}
<table class="table table-bordered">
<thead>
Expand All @@ -27,7 +26,9 @@ file that was distributed with this source code.
{% if field_name == '_delete' %}
<th>{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}</th>
{% else %}
<th>{{ nested_field.vars['sonata_admin'].admin.trans(nested_field.vars.label) }}</th>
<th {{ nested_field.vars['required'] ? 'class="required"' : '' }}>
{{ nested_field.vars['sonata_admin'].admin.trans(nested_field.vars.label) }}
</th>
{% endif %}
{% endfor %}
</tr>
Expand All @@ -36,7 +37,7 @@ file that was distributed with this source code.
{% for nested_group_field_name, nested_group_field in form.children %}
<tr>
{% for field_name, nested_field in nested_group_field.children %}
<td class="sonata-ba-td-{{ id }}-{{ field_name }}{% if nested_field.vars.errors|length > 0 %} error{% endif %}">
<td class="sonata-ba-td-{{ id }}-{{ field_name }} control-group{% if nested_field.vars.errors|length > 0 %} error{% endif %}">
{% if sonata_admin.field_description.associationadmin.formfielddescriptions[field_name] is defined %}
{{ form_widget(nested_field) }}

Expand All @@ -45,7 +46,7 @@ file that was distributed with this source code.
{{ form_widget(nested_field) }}
{% endif %}
{% if nested_field.vars.errors|length > 0 %}
<div class="sonata-ba-field-error-messages">
<div class="help-inline sonata-ba-field-error-messages">
{{ form_errors(nested_field) }}
</div>
{% endif %}
Expand Down Expand Up @@ -74,9 +75,7 @@ file that was distributed with this source code.
</div>
{% endif %}
{% else %}
{% for child in form.children %}
{{ form_widget(child) }}
{% endfor %}
{{ form_widget(form) }}
{% endif %}

</span>
Expand Down Expand Up @@ -151,6 +150,7 @@ file that was distributed with this source code.
</span>

<div style="display: none" id="field_dialog_{{ id }}">

</div>

{% include 'SonataDoctrineMongoDBAdminBundle:CRUD:edit_mongo_association_script.html.twig' %}
Expand Down
15 changes: 8 additions & 7 deletions Resources/views/CRUD/edit_mongo_one.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ file that was distributed with this source code.
{{ form_row(form.children[field_description.name])}}
{% endfor %}
{% else %}
<div id="field_container_{{ id }}">
<div id="field_container_{{ id }}" class="field-container">
{% if sonata_admin.edit == 'list' %}
<span id="field_widget_{{ id }}" >
{% if sonata_admin.admin.id(sonata_admin.value) %}
<span id="field_widget_{{ id }}" class="field-short-description">
{% if sonata_admin.field_description.associationadmin.id(sonata_admin.value) %}
{% render url('sonata_admin_short_object_information', {
'code': sonata_admin.field_description.associationadmin.code,
'objectId': sonata_admin.field_description.associationadmin.id(sonata_admin.value),
Expand All @@ -41,9 +41,10 @@ file that was distributed with this source code.
</span>
{% endif %}

<span id="field_actions_{{ id }}" >
<span id="field_actions_{{ id }}" class="field-actions">
<span class="btn-group">
{% if sonata_admin.edit == 'list' and sonata_admin.field_description.associationadmin.hasroute('list') and sonata_admin.field_description.associationadmin.isGranted('LIST') and btn_list %}

{% if sonata_admin.edit == 'list' and sonata_admin.field_description.associationadmin.hasRoute('list') and sonata_admin.field_description.associationadmin.isGranted('LIST') and btn_list %}
<a href="{{ sonata_admin.field_description.associationadmin.generateUrl('list') }}"
onclick="return start_field_dialog_form_list_{{ id }}(this);"
class="btn sonata-ba-action"
Expand All @@ -54,7 +55,7 @@ file that was distributed with this source code.
</a>
{% endif %}

{% if sonata_admin.field_description.associationadmin.hasRoute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') and btn_add %}
{% if sonata_admin.edit != 'admin' and sonata_admin.field_description.associationadmin.hasroute('create') and sonata_admin.field_description.associationadmin.isGranted('CREATE') and btn_add %}
<a href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
onclick="return start_field_dialog_form_add_{{ id }}(this);"
class="btn sonata-ba-action"
Expand All @@ -64,6 +65,7 @@ file that was distributed with this source code.
{{ btn_add|trans({}, btn_catalogue) }}
</a>
{% endif %}
</span>

{% if sonata_admin.field_description.associationadmin.hasRoute('delete') and sonata_admin.field_description.associationadmin.isGranted('DELETE') and btn_delete %}
<a href=""
Expand All @@ -75,7 +77,6 @@ file that was distributed with this source code.
{{ btn_delete|trans({}, btn_catalogue) }}
</a>
{% endif %}

</span>

<div class="container sonata-ba-modal sonata-ba-modal-edit-one-to-one" style="display: none" id="field_dialog_{{ id }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ This code manage the one-to-many association field popup
url: '{{ url('sonata_admin_append_form_element', {
'code': sonata_admin.admin.root.code,
'elementId': id,
'subclass': sonata_admin.admin.getActiveSubclassCode(),
'objectId': sonata_admin.admin.root.id(sonata_admin.admin.root.subject),
'uniqid': sonata_admin.admin.root.uniqid
} + sonata_admin.field_description.getOption('link_parameters', {})) }}',
type: "POST",
dataType: 'html',
data: { _xml_http_request: true },
success: function(html) {
if (!html.length) {
return;
}
jQuery('#field_container_{{ id }}').replaceWith(html); // replace the html
if(jQuery('input[type="file"]', form).length > 0) {
jQuery(form).attr('enctype', 'multipart/form-data');
Expand Down
8 changes: 4 additions & 4 deletions Resources/views/CRUD/list_mongo_many.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ file that was distributed with this source code.
#}

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% extends admin.getTemplate('base_list_field') %}

{% block field%}
{% if field_description.hasassociationadmin and field_description.associationadmin.hasRoute('edit') and field_description.associationadmin.isGranted('edit')%}
{% if field_description.hasassociationadmin and field_description.associationadmin.isGranted('EDIT') and field_description.associationadmin.hasRoute('edit') %}
{% for element in value%}
<a href="{{ field_description.associationadmin.generateObjectUrl('edit', element) }}">{{ element|render_relation_element(field_description) }}</a>
<a href="{{ field_description.associationadmin.generateObjectUrl(field_description.options.route.name, element, field_description.options.route.parameters) }}">{{ element|render_relation_element(field_description) }}</a>{% if not loop.last %}, {% endif %}
{% endfor %}
{% else %}
{% for element in value%}
{{ element|render_relation_element(field_description) }}
{{ element|render_relation_element(field_description) }}{% if not loop.last %}, {% endif %}
{% endfor %}
{% endif %}
{% endblock %}
12 changes: 5 additions & 7 deletions Resources/views/CRUD/list_mongo_one.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ file that was distributed with this source code.
#}

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{% if value %}
{% if field_description.hasAssociationAdmin and field_description.associationadmin.isGranted('EDIT') and field_description.associationadmin.hasRoute('edit') %}
<a href="{{ field_description.associationadmin.generateObjectUrl('edit', value) }}">{{ value|render_relation_element(field_description) }}</a>
{% else %}
{{ value|render_relation_element(field_description) }}
{% endif %}
{% if field_description.hasAssociationAdmin and field_description.associationadmin.id(value) and field_description.associationadmin.isGranted('EDIT') and field_description.associationadmin.hasRoute('edit') %}
<a href="{{ field_description.associationadmin.generateObjectUrl(field_description.options.route.name, value, field_description.options.route.parameters) }}">{{ value|render_relation_element(field_description) }}</a>
{% else %}
{{ value|render_relation_element(field_description) }}
{% endif %}
{% endblock %}
12 changes: 6 additions & 6 deletions Resources/views/CRUD/show_mongo_many.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ file that was distributed with this source code.

{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}

{% block value%}
{% block field%}
<ul class="sonata-ba-show-many-to-many">
{% if field_description.hasassociationadmin and field_description.associationadmin.hasRoute('edit') and field_description.associationadmin.isGranted('edit')%}
<ul>
{% for element in value%}
<li><a href="{{ field_description.associationadmin.generateObjectUrl('edit', element) }}">{{ element|render_relation_element(field_description) }}</a></li>
<li>
<a href="{{ field_description.associationadmin.generateObjectUrl(field_description.options.route.name, element, field_description.options.route.parameters) }}">{{ element|render_relation_element(field_description) }}</a>
</li>
{% endfor %}
</ul>
{% else %}
<ul>
{% for element in value%}
<li>{{ element|render_relation_element(field_description) }}</li>
{% endfor %}
</ul>
{% endif %}
</ul>
{% endblock %}
Loading

0 comments on commit 55bda56

Please sign in to comment.