<title>已装应用</title>
  
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>应用管理</cite></a>
    <a><cite>已装应用</cite></a>
  </div>
</div>


<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">应用管理</div>
        <div class="layui-card-body">
          <div class="layui-tab layui-tab-brief" lay-filter="J_tabLi">
            <ul class="layui-tab-title">
              <li class="layui-this" lay-href="plugin/manage">已安装</li>
              <li lay-href="plugin/local">本地安装</li>
            </ul>
            <div class="layui-tab-content">
            	<div class="layui-tab-item layui-show">
            		<table id="J_table_plugin_list" lay-filter="J_table_plugin_list" url="{:url('/plugin/update')}"></table>
            	</div>
            </div>
          </div>
        </div>

  </div>
</div>
  </div>
</div>

<script type="text/html" id="J_table_switch">
  <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|关闭" lay-filter="J_checkbox_enable" value="{{ d.id }}" {{ d.status == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="J_table_menu">
  <input type="checkbox" name="menu" lay-skin="switch" lay-text="开启|关闭" lay-filter="J_checkbox_enable" value="{{ d.id }}" {{ d.menu == 1 ? 'checked' : '' }} {{# if(!d.menushow){ }}disabled{{# } }}>
</script>

<script type="text/html" id="J_table_name">
  {{# if(d.home){ }}
  <a href="/{{d.alias}}/index/index" class="layui-table-link" target="_blank">{{d.name}}</a>
  {{# }else{ }}
  {{d.name}}
  {{# } }}
</script>

<script type="text/html" id="J_table_tool">
  {{# if(d.setter){ }}
      <a href="{{d.alias}}/manage/index" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="set" name="{{d.alias}}" title="{{d.name}}">设置</a>
  {{# }else{ }}
      <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled">设置</button>
  {{# } }}
      <button class="layui-btn layui-btn-danger layui-btn-xs" name="{{d.alias}}" lay-event="uninstall">卸载</button>
</script>

<script>
;!function(){
  var $ = layui.$
  ,admin = layui.admin
  ,table = layui.table;

  //执行渲染
table.render({
  elem: '#J_table_plugin_list'
  ,url: '{:url('/plugin/list')}'
  ,cols: [[
      {field:'logo',title:'Logo',width:110,align:'center',templet:'<div><img style="display: inline-block;height: 100%;" src="{{d.logo}}"/></div>'}
      ,{field:'name',title:'插件名称',minWidth:200,templet:'#J_table_name'}
      ,{field:'intro',title:'介绍',minWidth:300}
      ,{field:'author',title:'开发者',width:100,align:'center'}
      ,{field:'version',title:'版本',width:100,align:'center'}
      ,{field:'menu',title:'左侧菜单',width:100,align:'center',templet:'#J_table_menu'}
      ,{field:'status',title:'状态',width:100,align:'center',templet:'#J_table_switch'}
      ,{title:'操作',width:120,align:'center',toolbar:'#J_table_tool'}
  ]]
  ,height: 'auto'
  ,page: true
  ,limit: 20
  ,text: {
  	none: '暂无数据'
  }
});
  
  var action = {
  	set: function(addonids){
	    var title = $(this).prop('title'),href = $(this).attr('href');
	    layer.open({
	        type: 2
	        ,title: title
	        ,shade: 0
	        ,area: ['auto','auto']
	        ,offset: ['50px', '220px']
	        ,move: false
	        ,content: '{:request()->baseFile()}/'+href
	        ,success: function(layero, index){
				var width = $('#LAY_app_body').width(),height = $(window).height(),high = height - 50;
				$('#layui-layer'+index).css({width:width+'px'});
				$('#layui-layer-iframe'+index).css({height:high+'px'});
			}
	      });
  	},
  	uninstall: function(addonids){
	    var _this = $(this);
	    $.get('{:url('/plugin/uninstall')}',{addonids:addonids},function(res){
			var org_text = _this.text();
  	  	  	_this.text(org_text.replace(/(\u4e2d\u002e\u002e\u002e)$/, ''));
  	  	  	_this.removeProp('disabled').removeClass('layui-btn-disabled');
  	  	  	layer.msg(res.msg,{time: 2000},function(){
  	  	  		if(res.code===0){
  	  	  			window.location.reload();
  	  	  		}
  	  	  	});
	    },'json');
  	}
  };

	table.on("tool(J_table_plugin_list)", function(obj){
		event.preventDefault();
		var plugin = $(this).prop('name');
		if(obj.event!='set'){
			var textnode = document.createTextNode('\u4e2d\u002e\u002e\u002e');
  			this.appendChild(textnode);
  			$(this).prop('disabled',true).addClass('layui-btn-disabled');
		}
		action[obj.event] ? action[obj.event].call(this,plugin) : '';
	});

}();
</script>