edit_page.twig 4.19 KB
Newer Older
Johan Cwiklinski's avatar
Johan Cwiklinski committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
{#
 * ---------------------------------------------------------------------
 * GLPI - Gestionnaire Libre de Parc Informatique
 * Copyright (C) 2015-2018 Teclib' and contributors.
 *
 * http://glpi-project.org
 *
 * based on GLPI - Gestionnaire Libre de Parc Informatique
 * Copyright (C) 2003-2014 by the INDEPNET Development Team.
 *
 * ---------------------------------------------------------------------
 *
 * LICENSE
 *
 * This file is part of GLPI.
 *
 * GLPI is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GLPI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GLPI. If not, see <http://www.gnu.org/licenses/>.
 * ---------------------------------------------------------------------
 #}
{% set parent_tpl = 'glpi_page' %}
{% if contents is defined %}
   {% set parent_tpl = 'legacy' %}
{% endif %}
{% extends parent_tpl ~ ".twig" %}

{% block title %}{{ __('Edit %1$s')|format(page_title) }}{% endblock %}
{% block content %}
<div class="content">
   {% if contents is defined %}
      {{ contents|raw }}
   {% else %}
   <div class="row">
Alexandre Delaunay's avatar
Alexandre Delaunay committed
44
      <ul class="nav nav-pills flex-column glpi-tabs" role="tablist" aria-orientation="vertical">
Johan Cwiklinski's avatar
Johan Cwiklinski committed
45 46 47 48 49 50
        {% for tab, entry in item.getTabs() %}
            {% if entry is not iterable %}
                {% set label = entry %}
            {% else %}
                {% set label = entry.label %}
            {% endif %}
Alexandre Delaunay's avatar
Alexandre Delaunay committed
51 52 53 54 55 56
         <li class="nav-item">
            <a href="{{ path_for('update-asset', {'action': 'edit', 'itemtype': item.getType(), 'id': item.fields.id, 'tab': tab}) }}"
                class="nav-link{% if current_tab == tab %} active{% endif %}"
                data-toggle="tab"
                data-target="#{{ tab }}">
               {{ label }}
Johan Cwiklinski's avatar
Johan Cwiklinski committed
57
            {% if entry.count is defined %}
Alexandre Delaunay's avatar
Alexandre Delaunay committed
58 59 60
               <span class="pull-right-container">
                  <span class="badge badge-{% if entry.count == 0 %}light{% else %}info{% endif %} float-right">{{ entry.count }}</span>
               </span>
Johan Cwiklinski's avatar
Johan Cwiklinski committed
61
            {% endif %}
Alexandre Delaunay's avatar
Alexandre Delaunay committed
62 63
            </a>
         </li>
Johan Cwiklinski's avatar
Johan Cwiklinski committed
64
        {% endfor %}
Alexandre Delaunay's avatar
Alexandre Delaunay committed
65
      </ul>
Alexandre Delaunay's avatar
Alexandre Delaunay committed
66
      <div class="tab-content">
Johan Cwiklinski's avatar
Johan Cwiklinski committed
67
        {% for tab, entry in item.getTabs() %}
Johan Cwiklinski's avatar
Johan Cwiklinski committed
68
         <div id="{{ tab }}" class="tab-pane{% if current_tab == tab %} active{% endif %}"{% if current_tab == tab %} data-loaded="true"{% endif %}>
Johan Cwiklinski's avatar
Johan Cwiklinski committed
69 70 71
            {% if tab == item.getType() ~ '__main' %}
                {% include "elements/form.twig" with {'glpi_form': glpi_form} %}
            {% endif %}
Johan Cwiklinski's avatar
Johan Cwiklinski committed
72
         </div>
Johan Cwiklinski's avatar
Johan Cwiklinski committed
73
        {% endfor %}
Johan Cwiklinski's avatar
Johan Cwiklinski committed
74 75
      </div>
   </div>
Johan Cwiklinski's avatar
Johan Cwiklinski committed
76
    {% endif %}
Johan Cwiklinski's avatar
Johan Cwiklinski committed
77 78 79 80 81 82 83
</div>
{% endblock %}

{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
   $(function() {
84
      $('.nav a[data-toggle="tab"]').on('click', function (e) {
Johan Cwiklinski's avatar
Johan Cwiklinski committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
         e.preventDefault();

         var _this = $(this);
         var _tabid = _this.attr('data-target');
         var _target = $(_tabid);
         var _loaded = _target.data('loaded');

         var _url = '{{ path_for('ajax-tab', {'itemtype': item.getType(), 'id': item.fields.id, 'tab': 'PLACEBO'}) }}'
            .replace(/PLACEBO/, _tabid.replace(/^#/, ''));
         if (!_loaded) {
            _target.load(_url, function(){
               _target.data('loaded', true);

               _bindSimpleSelect(_tabid + ' .forSelect2:not([data-ajax_url])');
               _bindAjaxSelect(_tabid + ' .forSelect2[data-ajax_url]');
               _bindLabelSelect(_tabid);

               _this.tab('show');

                $.ajax({
                    url: '{{ path_for('messages') }}',
                    method: "GET",
                    success: function (message) {
                        $('body').append(message);
                        _initFlashMessage();
                    }
                });
            });
         } else {
            _this.tab('show');
         }
      });
   });
</script>
{% endblock %}