{% extends 'TopxiaAdminBundle::layout.html.twig' %}

{% set menu = 'admin_app_center' %}

{% set script_controller = 'app/center' %}

{% block main %}

  <div class="mbl btn-group">

      <a href="{{ url('admin_app_center', {postStatus: 'all' }) }}" type="button" class="btn btn-default btn-sm {% if type == 'all'%} btn-primary{% endif %}">全部</a>

      <a href=" {{ url('admin_app_center', {postStatus: 'theme' }) }}" type="button" class="btn btn-default btn-sm {% if type == 'theme'%}btn-primary{% endif %}">主题</a>

      <a href=" {{ url('admin_app_center', {postStatus: 'app' }) }}" type="button" class="btn btn-default btn-sm {% if type == 'app'%}btn-primary{% endif %}">应用</a>
  </div>


  <div class="checkbox-group appTypeChoices" RepeatDirection="Horizontal" id="appTypeChoices" name="appTypeChoices" style="float:right;margin-top:-45px;">
      <div class="sortedCourses">
      <input type="checkbox" name="appTypeChoices" id="installedApps" 
         value="installedApps"  {% if appTypeChoices|default(null)  == 'installedApps' %} data-url="{{path('admin_app_center',{postStatus: type,showType:'unhidden'})}}"  checked  {% else %} data-url="{{path('admin_app_center',{postStatus: type,showType:'hidden'}) }}" {% endif %}>
         隐藏已购应用
      <input type="hidden" name="type" value= '{{type}}' id="type">
      </div>
  </div>


  {% if status|default(null) == 'error' %}
    <div class="alert alert-danger">AccessKey或者SecretKey设置不正确，会影响到系统正常的运行，<a href="{{path('admin_setting_cloud')}}">请修改设置。</a></div>
  {% elseif  status|default(null) == 'unlink' %}
    <div class="alert alert-danger">您的服务器无法连接到更新服务器，请检查网络连接状况。</div>
  {% else %}
  <table class="table table-striped table-hover" id="app-table-container">
    <thead>

    </thead>
    <tbody>

      {% if type == 'all' %}
      {% set apps = apps %}
      {% elseif type == 'theme'%}
      {% set apps = theme %}
      {% elseif type == 'app' %}
      {% set apps = allApp %}
      {% endif  %}

      {% for app in apps %}
        {% set installedApp = installedApps[app.code]|default(null) %}

           {% if appTypeChoices|default(null)  == 'installedApps' %}

                         {% if app.purchased|default(false) == true or installedApp %}
                            
                            {% if installedApp %}
                            {% else %}
                            {% include 'TopxiaAdminBundle:App:app-detail.html.twig'  %}
                            <div class="right-info pull-right">
                            <a href="#" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_app_package_update_modal', {id:app.latestPackageId, type:'install'})}}" class="btn btn-primary app-btn" data-keyboard="false" data-backdrop="static">安装</a>
                            </div>
                              </td>
                            </tr>
                            {% endif %}
                         {% else %}

                          {% include 'TopxiaAdminBundle:App:app-detail.html.twig'  %}
                            <div class="right-info pull-right">
                              {% if app.userAccess|default(null) == "impossible" %}
                                <a href="http://open.edusoho.com" class="user-access" target=_blank>商业专属</a>
                              {% else %}
                                  {% if app.price == 0 %}
                                   <a href="#" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_app_package_update_modal', {id:app.latestPackageId, type:'install'})}}" class="btn btn-primary app-btn" data-keyboard="false" data-backdrop="static">安装</a>
                                  {% else %}
                                     <a href="http://open.edusoho.com/app/{{ app.code }}" class="btn btn-warning app-btn" target="_blank">购买</a>
                                  {% endif %}
                                    <p class="mtm"><span class="text-muted">价格：</sapn><span class="price"> ¥ {% if app.price > 0 %}{{ app.price}}{% else %}免费{% endif %}</sapn></p>
                                {% endif %}
                            </div>
                              </td>
                            </tr>
                         {% endif %}                

            {% else %}
              {% include 'TopxiaAdminBundle:App:app-detail.html.twig'  %}
              <div class="right-info pull-right">

                 {% if app.purchased|default(false) == true or installedApp %}
            
                    {% if installedApp %}
                      <a href="javascript:;" class="btn btn-default disabled app-btn">已购买</a>
                    {% else %}
                      <a href="#" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_app_package_update_modal', {id:app.latestPackageId, type:'install'})}}" class="btn btn-primary app-btn" data-keyboard="false" data-backdrop="static">安装</a>
                    {% endif %}
                    
                    <p class="mtm"><span class="text-muted">价格：</sapn><span class="price"> ¥ {% if app.price > 0 %}{{ app.price}}{% else %}免费{% endif %}</sapn></p>
                 {% else %}
                    {% if app.userAccess|default(null) == "impossible" %}
                      <a href="http://www.edusoho.com/product/system" class="user-access" target=_blank>商业专属</a>
                    {% else %}
                      {% if app.price == 0 %}
                       <a href="#" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_app_package_update_modal', {id:app.latestPackageId, type:'install'})}}" class="btn btn-primary app-btn" data-keyboard="false" data-backdrop="static">安装</a>
                      {% else %}
                         <a href="http://open.edusoho.com/app/{{ app.code }}" class="btn btn-warning app-btn" target="_blank">购买</a>
                      {% endif %}
                        <p class="mtm"><span class="text-muted">价格：</sapn><span class="price"> ¥ {% if app.price > 0 %}{{ app.price}}{% else %}免费{% endif %}</sapn></p>
                    {% endif %}
                 {% endif %} 
               
              </div> 
                </td>
              </tr>
                {% endif %}

      {% endfor %}
    </tbody>
  </table>
  {% endif %}
{% endblock %}