<extend name="Public:base" />
<block name="content">
<div class="page-header">
		<h1>
			轮播图
			<small>
				<i class="icon-double-angle-right"></i>
				{$crumbs}
			</small>
		</h1>
	</div>
<div class="row">
	<div class="col-xs-12">
		<div class="alert alert-block alert-success">
			注意：如果新增PC首页头部广告有尺寸要求<br/>
			PC首页头部广告需要6条广告，按照排序由低到高依次尺寸为：<br/>
			1:&nbsp;290*190  &nbsp;2:&nbsp;470*250&nbsp;3:&nbsp;316*272&nbsp;4:&nbsp;290*270&nbsp;5:&nbsp;470*210&nbsp;6:&nbsp;322*192
			<br/><br/>
			PC滚动广告参考尺寸：1920*600
			<br/><br/>
			PC关于我们广告图 参考尺寸：1200*294
			
		</div>
	</div>
	
	<div class="col-xs-12">	
		<form class="form-horizontal"  id="validation-form" method="post" action='{$action}'>
			<notempty name="Think.get.id">
			<input name="slider_id" type="hidden" value="{$Think.get.id}" />
			</notempty>
			
			<div class="form-group required">
                <label class="col-sm-2 control-label" for="input-image">图片：</label>
                
                <div class="col-sm-10" id="thumb">
                  <a href="#" id="thumb-image" data-toggle="image" class="img-thumbnail">
                  	<img osctype="image" <if condition="isset($slider['image'])"> 
						src="__ROOT__{$thumb_image}" 
						<else /> 
						src="__ROOT__/Common/image/no_image_100x100.jpg" 
						</if>  />
						</a>
                  <input osctype="image_input" type="hidden" name="image" value="<?php echo $slider['image']; ?>" id="input-image" />
           		 </div>
            </div>  
			
			
			<div class="form-group required">
						<label class="col-sm-2 control-label" for="input-slider_name">名称：</label>
						<div class="col-sm-10">
							<input id="input-nslider_name" class="form-control" type="text" placeholder="名称" name="slider_name"  value="{$slider.slider_name|default=''}" />
						</div>
			</div>
			<div class="form-group required">
						<label class="col-sm-2 control-label" for="input-name2">链接：</label>
						<div class="col-sm-10">
							<select  name="type">
								<option value="">请选择广告位置</option>
								<?php foreach($type_config as $key => $val){ ?>
									<option value="<?php echo $key;?>" <?php if($slider['type'] == $key ){ ?> selected<?php } ?>><?php echo $val;?></option>
								<?php } ?>
							</select>
						</div>
			</div>
			
			<div class="form-group required">
						<label class="col-sm-2 control-label" for="input-name2">链接：</label>
						<div class="col-sm-10">
							<input id="input-name2" class="form-control" type="text" placeholder="链接" name="url"  value="{$slider.url|default=''}" />
						</div>
			</div>
			
			<div class="form-group required">
						<label class="col-sm-2 control-label" for="input-name2">排序：</label>
						<div class="col-sm-10">
							<input id="input-name2" class="form-control" type="text" placeholder="排序" name="sort_order"  value="{$slider.sort_order|default=''}" />
						</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-1 control-label no-padding-left"> </label>	
				<div class="col-sm-11">
					<input name="send" type="submit" value="提交" class="btn btn-primary" />
				</div>
			</div>
		</form>
	</div>
</div>
</block>

<block name="jquery">
<script src="__PUBLIC__/js/jquery/jquery-1.10.2.min.js"></script>

</block>	

<block name="javascript">
<script src="__PUBLIC__/fileupload/jquery.ui.widget.js"></script>
<script src="__PUBLIC__/fileupload/jquery.fileupload.js"></script>
<script>
$(function(){
		// Image Manager
	$(document).delegate('a[data-toggle=\'image\']', 'click', function(e) {
		e.preventDefault();
	
		var element = this;
	
		$(element).popover({
			html: true,
			placement: 'right',
			trigger: 'manual',
			content: function() {
				return '<button type="button" id="button-image" class="btn btn-primary"><i class="icon-edit"></i></button> <button type="button" id="button-clear" class="btn btn-danger"><i class="icon-trash"></i></button>';
			}
		});
		
		$(element).popover('toggle');		
	
		$('#button-image').on('click', function() {
			$('#modal-image').remove();
			
			$('#form-upload').remove();
			
			$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input osctype="btn_upload_image" type="file" name="file" /></form>');
	
			$('#form-upload input[name=\'file\']').trigger('click');
			
			$(element).popover('hide');
			
			$('[osctype="btn_upload_image"]').fileupload({
				
	        	dataType: 'json',
	            url: "{:U('Image/upload_image',array('dir'=>'slider'))}",
	            add: function(e, data) {
	                $parent = $('#thumb');
	                $input = $parent.find('[osctype="image_input"]');
	                $img = $parent.find('[osctype="image"]');
	                data.formData = {old_product_image:$input.val()};
	                $img.attr('src', "__IMG__/loading.gif");
	                data.submit();
	            },
	            done: function (e,data) {
					
	            	var image=data.result;
	            	
	            	
	                $parent = $('#thumb');
	                $input = $parent.find('[osctype="image_input"]');
	                $img = $parent.find('[osctype="image"]');
	                if(image) {
	                   // $img.prev('i').hide();
	                    $img.attr('src', '__ROOT__'+image.image_thumb);
	                    $img.show();
	                    $input.val(image.image);
	                } else {
	                    alert('上传失败');
	                }
	            }
   		 });
			
			
			
		});
	
		$('#button-clear').on('click', function() {
			$(element).find('img').attr('src', $(element).find('img').attr('data-placeholder'));
			
			$(element).parent().find('input').attr('value', '');
	
			$(element).popover('hide');
		});
	});
	
	
	
	
});
</script>
</block>