{template 'common/header'}
<script type="text/javascript">
$(function() {
	$('.module').delegate('.media-description-button', 'click', function(){ //控制模块详细信息
		$(this).parents('.item').find('.media-description').toggle();
		return false;
	});
});
</script>
<style type="text/css">
small a{color:#999;}
.module{padding:15px;}
.form h4{margin-bottom:0;}
</style>
{template 'extension/module-tabs'}
<div class="main">
	{if $do == 'installed'}
	<div class="form">
		<h4>已安装的模块</h4>
	</div>
	<div class="module form-horizontal">
		{loop $modules $row}
		<div class="item">
			<div class="media">
				<div class="pull-right" style="width:230px;">
					<div class="input-prepend">
					</div>
					<div class="module-set">
						{if $row['version_error']}
						版本不兼容 <a href="{php echo create_url('extension/module/convert', array('id' => strtolower($row['name'])))}" style="color:red;">转换版本</a>
						{else}
						{if !$row['issystem']}
						<a onclick="return confirm('卸载模块会删其相关数据，确定吗？'); return false;" href="{php echo create_url('extension/module/uninstall', array('id' => $row['name']))}">卸载</a>
						{/if}
						{/if}
						<span class="upgrade-label" module="{$row['name']}" version="{$row['version']}">{if $row['upgrade']}<a href="{php echo create_url('extension/module/upgrade', array('id' => $row['name']));}" style="color:red;" title="来自本地文件更新">更新</a>{/if}</span>
						<a href="{php echo create_url('extension/module/permission', array('id' => $row['name']))}">访问权限</a>
						&nbsp;
					</div>
				</div>
				<img class="media-object img-rounded" src="./source/modules/{$row['name']}/icon.jpg" onerror="this.src='./resource/image/module-nopic-small.jpg'">
				<div class="media-body">
					<h4 class="media-heading">{$row['title']}<small>（标识：{$row['name']}&nbsp;&nbsp;&nbsp;作者：{$row['author']}）</small> <em class="upgrade-label-tips" module="{$row['name']}" style="color:red;display:none;">New</em></h4>
					<span>{$row['ability']}&nbsp;<a href="#" class="media-description-button">详细介绍</a></span >
				</div>
			</div>
			<div class="media-description">
				<b>功能介绍：</b>
				<span>{$row['description']}</span>
			</div>
		</div>
		{/loop}
	</div>
	<script type="text/javascript">
		$(function(){
			$.post('{php echo create_url('extension/module/check');}', {foo: 'upgrade'},function(dat){
				try {
					var ret = $.parseJSON(dat);
					$('.upgrade-label').each(function(){
						var n = $(this).attr('module');
						var v = $(this).attr('version');
						if(ret[n] && ret[n].version > v) {
							var tips = '';
							if(ret[n].from == 'local') {
								tips = '来自本地文件更新';
							} else {
								tips = '来自微擎云服务更新';
							}
							$(this).html('<a href="{php echo create_url('extension/module/upgrade')}&id=' + n + '" style="color:red;" title="' + tips + '">更新</a>');
							$('.upgrade-label-tips[module=' + n + ']').show();
						}
					});
				} catch(err) {}
			});
		});
	</script>
	{/if}
	{if $do == 'prepared'}
	<div class="form">
		<h4>已购买的模块</h4>
	</div>
	<div class="module form-horizontal" ng-controller="listInstallModules">
		<div class="item" ng-repeat="m in modules">
			<div class="media">
				<div class="pull-right" style="width:230px;">
					<div class="module-set">
						<a href="{php echo create_url('extension/module/install')}id={{m.name.toLowerCase()}}">安装</a>
						<a href="{php echo create_url('extension/module/permission')}id={{m.name.toLowerCase()}}">访问权限</a>
						&nbsp;
					</div>
				</div>
				<img class="media-object img-rounded gray" ng-src="./source/modules/{{m.name.toLowerCase()}}/icon.jpg" onerror="this.src='./resource/image/module-nopic-small.jpg'">
				<div class="media-body">
					<h4 class="media-heading">{{m.title}}<small>（标识：{{m.name}}&nbsp;&nbsp;&nbsp;作者：{{m.author}}）</small></h4>
					<span>{{m.ability}}&nbsp;<a href="#" class="media-description-button">详细介绍</a></span >
				</div>
			</div>
			<div class="media-description">
				<b>功能介绍：</b>
				<span>
					{{m.description}}
				</span>
			</div>
		</div>
	</div>
	<div class="form">
		<h4>未安装的模块(本地模块)</h4>
	</div>
	<div class="module form-horizontal">
		{loop $localUninstallModules $row}
		<div class="item" module-name="{$row['name']}">
			<div class="media">
				<div class="pull-right" style="width:230px;">
					<div class="module-set">
						{if $row['version_error']}
						版本不兼容 <a href="{php echo create_url('extension/module/convert', array('id' => strtolower($row['name'])))}" style="color:red;">转换版本</a>
						{else}
						<a href="{php echo create_url('extension/module/install', array('id' => strtolower($row['name'])))}">安装</a>
						{/if}
						<a href="{php echo create_url('extension/module/permission', array('id' => strtolower($row['name'])))}">访问权限</a>
						&nbsp;
					</div>
				</div>
				<img class="media-object img-rounded gray" src="./source/modules/{php echo strtolower($row['name']);}/icon.jpg" onerror="this.src='./resource/image/module-nopic-small.jpg'">
				<div class="media-body">
					<h4 class="media-heading">{$row['title']}<small>（标识：{$row['name']}&nbsp;&nbsp;&nbsp;作者：{$row['author']}）</small></h4>
					<span>{$row['ability']}&nbsp;<a href="#" class="media-description-button">详细介绍</a></span >
				</div>
			</div>
			<div class="media-description">
				<b>功能介绍：</b>
				<span>
					{$row['description']}
				</span>
			</div>
		</div>
		{/loop}
	</div>
	<script type="text/javascript">
		function listInstallModules($scope, $http) {
			$.post('{php echo create_url('extension/module/check');}', {foo: 'install'},function(dat){
				try {
					var ret = $.parseJSON(dat);
					if(!$.isArray(ret)) {
						return;
					}
					$.each(ret, function(){
						$('div.item[module-name=' + this.name + ']').remove();
					});
					$scope.$apply(function(){
						$scope.modules = ret;
					});
				} catch(err) {}
			});
		}
	</script>
	{/if}
</div>
{template 'common/footer'}
