{#
This file is part of EC-CUBE

Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.

http://www.ec-cube.co.jp/

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}
<script>
$(function() {
    var currentPlugin = null;
    var modal = $('#officialPluginDeleteModal');
    modal.on('show.bs.modal', function(e) {
        currentPlugin = $(e.relatedTarget).data();
    });
    $('#officialPluginDeleteButton').on('click', function() {

        var footer = $('div.modal-footer', modal).hide();
        var message = $('div.modal-body p', modal).text('「' + currentPlugin.name + ' (' + currentPlugin.version + ')」を削除中。この処理には数分かかる場合があります。画面をリロードせずにこのままお待ち下さい。')
        var progress = $('div.progress', modal).show();
        $.ajax({url: currentPlugin['deleteUrl'], type: 'delete'}).then(
            function(data) {
                message.text('削除が完了しました。');
                $('#deleteLog').text(data.log);
                $('#deleteLogPane').show();
                progress.hide();
                footer.show().find('button').toggle();
            },
            function(res) {
                if (res.responseJSON.message) {
                    message.text(res.responseJSON.message);
                } else {
                    message.text('削除に失敗しました。');
                }
                if (res.responseJSON.log) {
                    $('#deleteLog').text(res.responseJSON.log);
                }
                progress.hide();
                $('#deleteLogPane').show();
                footer.show().find('button').toggle();
            }
        );
    });
});
</script>
{% if Plugins|length > 0 %}
    <div class="card-body p-0">
        <table class="table table-sm">
            <thead>
            <tr>
                <th class="border-top-0 pl-3 pt-2 pb-2">{{ 'admin.store.plugin_table_official.901'|trans }}</th>
                <th class="border-top-0 pt-2 pb-2">{{ 'admin.store.unregistered_plugin_table.942'|trans }}</th>
                <th class="border-top-0 pt-2 pb-2">{{ 'admin.store.unregistered_plugin_table.943'|trans }}</th>
                <th class="border-top-0 pt-2 pb-2">{{ 'admin.store.plugin_table.901'|trans }}</th>
                <th class="border-top-0 pt-2 pb-2">{{ 'admin.store.plugin_table_official.905'|trans }}</th>
                <th class="border-top-0 pt-2 pb-2">&nbsp;</th>
            </tr>
            </thead>
            <tbody>
            {% for key,Plugin in Plugins %}
                {% set pluginDetail = officialPluginsDetail[key]|default(NULL) %}
                <tr class="{% if Plugin.enabled == false %}active{% endif %}">
                    <td class="align-middle pl-3">
                        <a href="#" target="_blank" class="plugin-image pr-3">
                            <img height="60" src="{{ pluginDetail ? pluginDetail.image : asset('noimage_plugin_list.png', 'save_image') }}" alt="">
                        </a>
                        <span>{{ Plugin.name }}</span>
                    </td>
                    <td class="align-middle" style="width: 136px">{{ Plugin.version }}</td>
                    <td class="align-middle"><p class="mb-0">{{ Plugin.code }}</p></td>
                    <td class="align-middle">
                        {% if Plugin.id %}
                            {% if Plugin.enabled %}
                                <span class="text-success">{{ 'common.enabled'|trans }}</span>
                            {% else %}
                                <span class="text-secondary">{{ 'common.disabled'|trans }}</span>
                            {% endif %}
                        {% endif %}
                    </td>
                    <td class="align-middle">
                        {% if pluginDetail %}
                            {% if Plugin.id %}
                                {% if pluginDetail.update_status == 3 %}
                                    <a href="{{ url('admin_store_plugin_update_confirm', {'id': Plugin.id}) }}"
                                       class="btn btn-ec-regular">{{ 'admin.store.plugin_table_official.916'|trans }}</a>
                                    <ul class="plugin-meta dl-horizontal">
                                        <li class="plugin-version">{{ 'admin.store.plugin_table_official.917'|trans({'%version%' : pluginDetail.version}) }}</li>
                                        <li class="plugin-version">
                                            {% set versions = '' %}
                                            {% for version in pluginDetail.supported_versions %}
                                                {% set versions = versions ~ version %}
                                                {%- if loop.last == false%}{% set versions = versions ~ ',' %}{% endif -%}
                                            {% endfor %}
                                            {{ 'admin.store.plugin_table_official.918'|trans({'%versions%' : versions}) }}
                                        </li>
                                        <li class="plugin-update">{{ 'admin.store.plugin_table_official.919'|trans({'%update_date%' : pluginDetail.update_date|time_ago}) }}</li>
                                    </ul>
                                {% else %}
                                    <p class="mb-0">{{ 'admin.store.plugin_table_official.920'|trans }}。</p>
                                {% endif %}
                            {% else %}
                                <a href="{{ url('admin_store_plugin_install_confirm', {'id': Plugin.source}) }}" class="btn btn-ec-regular">{{ 'admin.store.plugin.install'|trans }}</a>
                            {% endif %}
                        {% endif %}
                    </td>
                    <td class="align-middle">
                        {% if Plugin.id %}
                            <div class="col-12 col-xs-11 col-md-10 col-lg-8 pull-right text-center">
                                <div class="row">
                                    <div class="col-4 px-0">
                                        {% if Plugin.enabled == false %}
                                            <a href="#"
                                               data-toggle="modal"
                                               data-target="#officialPluginDeleteModal"
                                               data-id="{{ Plugin.id }}"
                                               data-delete-url="{{ url('admin_store_plugin_api_uninstall', { id: Plugin.id }) }}"
                                               data-name="{{ Plugin.name }}"
                                               data-version="{{ Plugin.version }}"
                                               class="btn btn-ec-actionIcon">
                                                <i class="fa fa-close fa-lg text-secondary" data-tooltip="true" data-placement="top" title="{{ 'admin.common.delete'|trans }}"></i>
                                            </a>

                                        {% endif %}
                                    </div>
                                    <div class="col-4 px-0">
                                        {% if Plugin.enabled %}
                                            <a href="{{ url('admin_store_plugin_disable', { id : Plugin.id }) }}" {{ csrf_token_for_anchor() }}
                                               class="btn btn-ec-actionIcon"
                                               data-method="post" data-confirm="false">
                                                <i class="fa fa-pause fa-lg text-secondary" data-tooltip="true"
                                                   data-placement="top" title="{{ 'admin.store.plugin_table_official.925'|trans }}"></i>
                                            </a>
                                        {% else %}
                                            <a href="{{ url('admin_store_plugin_enable', { id : Plugin.id }) }}" {{ csrf_token_for_anchor() }}
                                               class="btn btn-ec-actionIcon"
                                               data-method="post" data-confirm="false">
                                                <i class="fa fa-play fa-lg text-secondary" data-tooltip="true"
                                                   data-placement="top" title="{{ 'admin.store.plugin_table_official.924'|trans }}"></i>
                                            </a>
                                        {% endif %}
                                    </div>
                                    <div class="col-4 pl-0">
                                        {% if configPages[Plugin.code] is defined %}
                                            <a class="btn btn-ec-actionIcon" href="{{ configPages[Plugin.code] }}">
                                                <i class="fa fa-cog fa-lg text-secondary" data-tooltip="true"
                                                   data-placement="top" title="{{ 'admin.store.plugin_table_official.906'|trans }}"></i>
                                            </a>
                                        {% endif %}
                                    </div>
                                </div>
                            </div>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    {% if officialPluginsDetail|length == 0 %}
    <p class="ml-3">{{ 'admin.store.plugin.help'|trans }}</p>
    {% endif %}
{% else %}
    <div class="card-body">
        <div class="text-danger">
            {{ 'admin.store.plugin_table_official.923'|trans }}
        </div>
    </div>
{% endif %}

<div class="modal fade" id="officialPluginDeleteModal" tabindex="-1" role="dialog"
     aria-labelledby="officialPluginDeleteModal" aria-hidden="true"
     data-keyboard="false" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title font-weight-bold">
                    {{ 'admin.store.plugin.popup.delete.confirm.title'|trans }}</h5>
            </div>
            <div class="modal-body text-left">
                <p class="text-left">{{ 'admin.store.plugin.popup.delete.confirm.message'|trans }}</p>
                <div class="progress" style="display: none">
                    <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 100%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
                <div id="deleteLogPane" style="display: none;">
                    <div class="d-inline-block collapsed" data-toggle="collapse" href="#deleteLog" aria-expanded="false" aria-controls="deleteLog">
                        <a><i class="fa font-weight-bold mr-1 fa-plus-square-o"></i><span class="font-weight-bold">ログを確認</span></a>
                    </div>
                    <pre class="collapsed collapse" id="deleteLog"></pre>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-ec-sub" type="button" data-dismiss="modal">{{ 'admin.common.cancel'|trans }}</button>
                <button id="officialPluginDeleteButton" class="btn btn-ec-delete" type="button">{{ 'admin.common.delete'|trans }}</button>
                <button class="btn btn-ec-sub" style="display: none" onclick="location.reload(true);">完了</button>
            </div>
        </div>
    </div>
</div>
