|
@@ -2,62 +2,83 @@
|
|
|
{% spaceless %}
|
|
|
|
|
|
{% set locale = app.request.locale %}
|
|
|
- {# SE AGREGA UNA VERSION DE SELECT2 MAS NUEVA QUE LA DE SONATA ADMIN #}
|
|
|
- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
|
|
- <link href="{{ asset('bundles/baseadmin/vendor/select2/select2.css') }}" rel="stylesheet" />
|
|
|
- <link href="{{ asset('bundles/baseadmin/vendor/select2-bootstrap-css/select2-bootstrap.css') }}" rel="stylesheet" />
|
|
|
- <script src="{{ asset('bundles/baseadmin/vendor/select2/select2.min.js') }}"></script>
|
|
|
- <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/i18n/{{ locale }}.js"></script>
|
|
|
-
|
|
|
- <script type="text/javascript">
|
|
|
- $(function () {
|
|
|
- var getAjaxListData = function (params) {
|
|
|
- return {
|
|
|
- q: params.term,
|
|
|
- p: params.page
|
|
|
- };
|
|
|
- };
|
|
|
-
|
|
|
- {% if id is not defined %}
|
|
|
- {% set id = 'clientId' %}
|
|
|
- {% endif %}
|
|
|
-
|
|
|
- {% if ajax_url is not defined %}
|
|
|
- {% set ajax_url = 'ajax_client_list' %}
|
|
|
- {% endif %}
|
|
|
-
|
|
|
-
|
|
|
- $('select[id$="{{ id }}"]').select2({
|
|
|
- theme: "bootstrap",
|
|
|
- width: '100%',
|
|
|
- ajax: {
|
|
|
- url: '{{ path(ajax_url) }}',
|
|
|
- dataType: 'json',
|
|
|
- delay: 250,
|
|
|
- data: getAjaxListData,
|
|
|
- cache: true
|
|
|
- },
|
|
|
- language: "{{ locale }}",
|
|
|
- debug: true,
|
|
|
- minimumInputLength: 3
|
|
|
- });
|
|
|
- });
|
|
|
- </script>
|
|
|
<div class="clearfix">
|
|
|
- {{ block('choice_widget') }}
|
|
|
+ <input type="text" id="{{ id }}_search" name="{{ name }}_search" maxlength="255" class="form-control">
|
|
|
+ {{ block('hidden_widget') }}
|
|
|
+
|
|
|
{% if create is not defined %}
|
|
|
- {% set create = true %}
|
|
|
+ {% set create = true %}
|
|
|
{% endif %}
|
|
|
{% if create %}
|
|
|
- {% set url = remote_client_url() %}
|
|
|
- {% if url != '#' %}
|
|
|
- <div class="pull-right">
|
|
|
- <a href="{{ url }}" class="btn btn-link" target="_blank" title="{{ 'link.create_client'|trans({}, 'WebserviceBundle') }}">
|
|
|
- <i class="fa fa-plus-circle" aria-hidden="true"></i>
|
|
|
- </a>
|
|
|
- </div>
|
|
|
- {% endif %}
|
|
|
+ {% set url = remote_client_url() %}
|
|
|
+ {% if url != '#' %}
|
|
|
+ <div class="pull-right">
|
|
|
+ <a href="{{ url }}" class="btn btn-link" target="_blank"
|
|
|
+ title="{{ 'link.create_client'|trans({}, 'WebserviceBundle') }}">
|
|
|
+ <i class="fa fa-plus-circle" aria-hidden="true"></i>
|
|
|
+ </a>
|
|
|
+ </div>
|
|
|
+ {% endif %}
|
|
|
{% endif %}
|
|
|
+
|
|
|
+ <script type="text/javascript">
|
|
|
+ $(function () {
|
|
|
+ {% if id is not defined %}
|
|
|
+ {% set id = 'clientId' %}
|
|
|
+ {% endif %}
|
|
|
+
|
|
|
+ {% if ajax_url is not defined %}
|
|
|
+ {% set ajax_url = 'ajax_client_list' %}
|
|
|
+ {% endif %}
|
|
|
+
|
|
|
+ {% if ajax_url_data is not defined %}
|
|
|
+ {% set ajax_url_data = '/ajax_client_data' %}
|
|
|
+ {% endif %}
|
|
|
+
|
|
|
+ $('input[id="{{ id }}_search"]').autocomplete({
|
|
|
+ minLength: 3,
|
|
|
+ source: function (request, response) {
|
|
|
+ $.ajax({
|
|
|
+ url: '{{ path(ajax_url) }}',
|
|
|
+ type: "GET",
|
|
|
+ data: {
|
|
|
+ q: request.term
|
|
|
+ },
|
|
|
+ success: function (data) {
|
|
|
+ response($.map(data.results, function (el) {
|
|
|
+ return {
|
|
|
+ label: el.text,
|
|
|
+ value: el.id
|
|
|
+ };
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ select: function (event, ui) {
|
|
|
+ this.value = ui.item.label;
|
|
|
+ $('input[id="{{ id }}"]').val(ui.item.value);
|
|
|
+ if (typeof(callbackClientId) === typeof (Function)) {
|
|
|
+ callbackClientId(ui.item.value);
|
|
|
+ }
|
|
|
+ event.preventDefault();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if ($('input[id="{{ id }}"]').val() > 0) {
|
|
|
+ // carga el nombre cuando se esta modificando
|
|
|
+ $.ajax({
|
|
|
+ url: '{{ ajax_url_data }}',
|
|
|
+ data: {
|
|
|
+ q: $('input[id="{{ id }}"]').val()
|
|
|
+ },
|
|
|
+ success: function (result) {
|
|
|
+ if (result != null && result.results != null && result.results.length > 0) {
|
|
|
+ $('input[id="{{ id }}_search"]').val(result.results[0].name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ </script>
|
|
|
</div>
|
|
|
{% endspaceless %}
|
|
|
{% endblock %}
|