<!DOCTYPE html>
<html dir="ltr" lang="zh-TW">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<title>管理後臺</title>
<meta name="robots" content="noindex, nofollow" />
<link href="less/page.less" rel="stylesheet/less">
<link href="css/main.css" rel="stylesheet">
<link href="css/page.css" rel="stylesheet">
<script src="/jquery/jquery-1.10.js"></script>
<script src="/jquery/jquery-ui-1.11.2.min.js"></script>
<script src="ckfinder/ckfinder.js"></script>
<!-- 瀏覽用燈箱片效果 -->
<link href="/jquery/fancybox-3.0/dist/jquery.fancybox.css" rel="stylesheet">
<script src="/jquery/fancybox-3.0/dist/jquery.fancybox.min.js"></script>
<script>
	if('<?# alertMsg ?>' != ''){
		alert('<?# alertMsg ?>');
		if('<?# goBack ?>' == 'Y') history.back();
	}
	if('<?# locationHref ?>' != '') location.href = '<?# locationHref ?>';
</script>
</head>
<body>
	<?# sidePage ?>
	<div class="pos_rel" id="content">
		<?# header ?>
		<form id="form1" name="form1" method="post">
			<div class="row mt_10 mb_5 h3 page_title"><?# page_name ?></div>
			<div class="card">
				<div class="pos_rel bg_g_100 tabs_warp" id="tabs_warp">
					<div class="tabs_list">
						<a class="tabs_item" href="index.php">控制台</a>
						<a class="tabs_item" data-action="true" href="javascript:void(0);"><?# page_name ?></a>
					</div>
				</div>
				<div class="card_body form_box">
                    <div class="d_flex form_list">
                        <label>內頁顯示</label>
                        <p class="d_flex flex_wrap">
                            <font class="mr_3 d_block el-checkbox"><input type="checkbox" id="chkAll" name="chkAll"><span class="el-checkbox-style"></span><span>全選</span></font>
                            <font class="mr_3 d_block el-checkbox"><input type="checkbox" name="smallPictureShow[]" value="40"><span class="el-checkbox-style"></span><span>文章</span></font>
                            <font class="mr_3 d_block el-checkbox"><input type="checkbox" name="smallPictureShow[]" value="50"><span class="el-checkbox-style"></span><span>產品</span></font>
                            <font class="mr_3 d_block el-checkbox"><input type="checkbox" name="smallPictureShow[]" value="60"><span class="el-checkbox-style"></span><span>最新消息</span></font>
                            <font class="mr_3 d_block el-checkbox"><input type="checkbox" name="smallPictureShow[]" value="70"><span class="el-checkbox-style"></span><span>問與答</span></font>
                            <font class="mr_3 d_block el-checkbox"><input type="checkbox" name="smallPictureShow[]" value="80"><span class="el-checkbox-style"></span><span>相本</span></font>
                            <font class="mr_3 d_block el-checkbox"><input type="checkbox" name="smallPictureShow[]" value="90"><span class="el-checkbox-style"></span><span>聯絡表單</span></font>
                            <font class="mr_3 d_block el-checkbox"><input type="checkbox" name="smallPictureShow[]" value="100"><span class="el-checkbox-style"></span><span>訂單</span></font>
                        </p>
                    </div>
                    <div class="d_flex form_list"><a class="btn btn_success" data-action="add" href="javascript:void(0);">新增</a></div>
                    <ul class="pos_rel" id="image_list">
                        <php:repeater id="listP">
                        <template>
                        <li class="mr_4 ml_4 pos_rel mb_5 d_md_flex flex_wrap border">
                            <h5 class="mt_4 mr_4 ml_4 col_12">小廣告<?# NO ?></h5>
                            <div class="col_md_6 d_flex form_list">
                                <label>圖片</label>
                                <p class="d_flex upBox">
                                    <a class="img_box"></a>
                                    <font class="col_12 in_group">
                                        <input type="text" name="Image[]" data-action="Image" value="<?# Image ?>" />
                                        <b class="group"><a class="btn btn_dark" href="javascript:void(0);" data-action="upimage"><svg class="fa"><use xlink:href="svg/icons.svg#folder"></use></svg></a></b>
                                    </font>
                                </p>
                            </div>
                            <div class="col_md_6 d_flex form_list"><label>標題</label><input type="text" name="Title[]" value="<?# Title ?>" /></div>
                            <div class="col_12 d_flex form_list"><label>超連結</label><input type="text" name="Link[]" value="<?# Link ?>" /></div>
                            <div class="col_12 form_list"><label>描述</label><textarea name="DanDesc[]"><?# DanDesc ?></textarea></div>
                            <a class="pos_abs remove" href="javascript:void(0);" data-action="delete"><svg class="fa"><use xlink:href="svg/icons.svg#close"></use></svg></a>
                        </li>
                        </template>
                        </php:repeater>
                    </ul>
					<?# add_btn ?>
				</div>
			</div>
            <div class="row mt_5 d_flex start_box"><a class="mr_2 btn btn_info" id="btnOK" href="javascript:void(0);">送出</a></div>
		</form>
		<?# footer ?>
	</div>
</body>
</html>
<script>
	$(function(){
		$('#chkAll').click(function(){
			var id = $(this).val();
			
			if($(this).eq(0).prop("checked") == true){
				$('input:checkbox[name="smallPictureShow[]"]').each(function(){
					$(this).prop("checked", true);
				});
			}else{
				$('input:checkbox[name="smallPictureShow[]"]').each(function(){
					$(this).prop("checked", false);
				});
			}
		});
		var smallP = '<?# smallPictureShow ?>';
		var arySP = smallP.split(',');
		var num = 0;
		$('input:checkbox[name="smallPictureShow[]"]').each(function(a,b){
			if(arySP.indexOf($(b).val()) >= 0){
				$(b).prop('checked', true);
				num++
			}
		});
		if(num == '7') $('#chkAll').prop('checked', true);
		
		$('.card_body a[data-action="add"]').on('click', function(){
			var li = $('<li></li>').addClass('mr_4 ml_4 pos_rel mb_5 d_md_flex flex_wrap border');
			var h5 = $('<h5></h5>').addClass('mt_4 mr_4 ml_4 col_12').text('小廣告-新');
			
			var div1 = $('<div></div>').addClass('col_md_6 d_flex form_list');
			var div1_label = $('<label></label>').text('圖片');
			var div1_upBox = $('<p></p>').addClass('d_flex upBox');
			var div1_upBox_a = $('<a></a>').addClass('img_box').html('<img src="images/upImgBg.png">');
			var div1_upBox_group = $('<font></font>').addClass('col_12 in_group').html('<input type="text" name="Image[]" data-action="Image" /><b class="group"><a class="btn btn_dark" href="javascript:void(0);" data-action="upimage"><svg class="fa"><use xlink:href="svg/icons.svg#folder"></use></svg></a></b>');
			div1.append(div1_label).append(div1_upBox.append(div1_upBox_a).append(div1_upBox_group));
			
			var div2 = $('<div></div>').addClass('col_md_6 d_flex form_list').html('<label>標題</label><input type="text" name="Title[]" />');
			var div3 = $('<div></div>').addClass('col_12 d_flex form_list').html('<label>超連結</label><input type="text" name="Link[]" />');
			var div4 = $('<div></div>').addClass('col_12 form_list').html('<label>描述</label><textarea name="DanDesc[]"></textarea>');
			var remove = $('<a></a>').addClass('pos_abs remove').attr('href', 'javascript:void(0);').attr('data-action', 'delete').html('<svg class="fa"><use xlink:href="svg/icons.svg#close"></use></svg>');
			
			$('#image_list').append(li.append(h5).append(div1).append(div2).append(div3).append(div4).append(remove));
			
			if($('#image_list li').length == 1) $('.add_btn').attr('class', 'd_flex form_list add_btn');
		});
		
		$('#image_list').on('click', 'a[data-action="upimage"]', function(){
			selectFileWithCKFinder($(this).parent().prev(), 'Images');
		});
		$('#image_list').on('change', 'input:text[name="Image[]"]', function(){
			ImageChange($(this));
		});
		$('#image_list').on('click', 'a[data-action="delete"]', function(){
			$(this).parents('li').remove();
			if($('#image_list li').length == 0) $('.add_btn').attr('class', 'd_none form_list add_btn');
		});

		$('#image_list').sortable({
			opacity: 0.6,
			cursor: 'move'
		});
		$('#image_list').disableSelection();
		
		$('#btnOK').click(function(){
			$('#form1').submit();
		});
	});
</script>