<?php if(!defined('IN_SDCMS')) exit;?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<title>内容管理</title>
<link rel="stylesheet" href="{WEB_ROOT}public/css/ui.css">
<link rel="stylesheet" href="{WEB_ROOT}public/admin/css/layout.css">
<script>var ue_url="{U('upload/imagelist','type=0&multiple=1&iseditor=1')}",web_root="{WEB_ROOT}";</script>
<script src="{WEB_ROOT}public/js/jquery.js"></script>
<script src="{WEB_ROOT}public/js/ui.js"></script>
<script src="{WEB_ROOT}public/js/dropzone.js"></script>
<script src="{WEB_ROOT}public/js/sortable.min.js"></script>
<script src="{WEB_ROOT}public/admin/js/base.js"></script>
<script src="{WEB_ROOT}public/ueditor/ueditor.config.js"></script>
<script src="{WEB_ROOT}public/ueditor/ueditor.all.min.js"></script>
</head>

<body>
    <div class="position">当前位置：<a href="{U('lists')}">内容管理</a>{get_page_postion($classid)}</div>
    <div class="border">
        <!---->
        <form class="ui-form" method="post">
            <div class="form-group row">
                <label class="col-left col-form-label text-right">组图：</label>
                <div class="col-right col-right-full">
                	<!---->
                    <div class="btn-group mt-sm">
                    <a class="btn-group-item dropzone-more ui-icon-cloud-upload" config="t1" url="{U('upload/upfile','type=1&thumb=0&water='.C('water_piclist').'')}" maxsize="{C('upload_image_max')}" title="上传">上传</a>
                    <a class="btn-group-item fm-choose ui-icon-select" data-name="t1" data-url="{U('upload/imagelist','type=1&multiple=1')}" data-type="0" data-multiple="1" title="选择">选择</a>
                    </div>
                    <div class="imagelist">
                    <ul id="list_t1">
                        {php $picdata=jsdecode($piclist,1)}
                        {if is_array($picdata)}
                            {foreach $picdata as $num=>$val}
                            <li num="{$num}">
                                <div class="preview">
                                    <input type="hidden" name="t1[{$num}][image]" value="{$val['image']}">
                                    <u href="{$val['image']}" class="lightbox" data-title="{deal_strip($val['desc'])}"><img src="{$val['image']}" /></u>
                                </div>
                                <div class="intro">
                                    <textarea name="t1[{$num}][desc]" class="form-ip" placeholder="图片描述...">{deal_strip($val['desc'])}</textarea>
                                </div>
                                <div class="action"><a href="javascript:;" class="img-left"><i class="ui-icon-left"></i>左移</a><a href="javascript:;" class="img-right"><i class="ui-icon-right"></i>右移</a><a href="javascript:;" class="img-del"><i class="ui-icon-delete"></i>删除</a></div>
                            </li>
                            {/foreach}
                        {/if}
                    </ul>
                    </div>
                    <!---->
                </div>
            </div>
            <div class="form-group row">
                <label class="col-left col-form-label text-right">内容：</label>
                <div class="col-right-full">
                    <script id="t0" name="t0" type="text/plain" style="height:260px;">{$content}</script>
                    <script>UE.getEditor('t0',{serverUrl:"{U('upload/index')}"});</script>
					<input type="button" class="btn btn-info editor_savepic mt-sm" data-url="{U('upload/outimage')}" data-name="t0" value="保存编辑器中外部图片">
                </div>
            </div>
			
			<div class="form-group row">
                <label class="col-left col-form-label"></label>
                <div class="col-right">
                    <button type="submit" class="btn btn-info mr-sm">保存</button>
                    {if $isdel==1}
                    <button type="button" class="btn isdel" data-url="{U('delpage','classid='.$classid.'')}">删除内容</button>
                    {else}
                    <button type="button" class="btn ui-back">返回</button>
                    {/if}
                </div>
            </div>

        </form>
        <!---->
    </div>

<script>
$(function()
{
	Sortable.create($("#list_t1")[0],{animation:400});
	$(".ui-form").form(
	{
		type:2,
		result:function(form)
		{
			UE.getEditor('t0').sync();
			$("#t0").val(UE.getEditor('t0').getContent());
			$.ajax(
			{
                type:'post',
                cache:false,
                dataType:'json',
                url:'{THIS_LOCAL}',
                data:$(form).serialize(),
                error:function(e){alert(e.responseText);},
                success:function(d)
                {
                    if(d.state=='success')
                    {
                        sdcms.success(d.msg);
                        setTimeout(function(){location.href='{THIS_LOCAL}';},1500);
                    }
                    else
                    {
                        sdcms.error(d.msg);
                    }
                }
            });
		}
	});
	$(".isdel").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialog(
		{
			'title':"操作提示",
			'text':"确定要删除？不可恢复！",
			'oktheme':'btn-info',
			'ok':function(e)
			{
				$.ajax(
				{
                    url:url,type:'post',dataType:'json',
					error:function(e){alert(e.responseText);},
                    success:function(d)
                    {
                        e.close();
                        if(d.state=='success')
                        {
                            sdcms.success(d.msg);
                            setTimeout(function(){location.href='{THIS_LOCAL}';},1000);
                        }
                        else
                        {
                            sdcms.error(d.msg);
                        }
                    }
                });
			}
		});
    });

});
$(".dropzone-more").dropzone(
{
	maxFiles:50,
	success:function(file,data,that)
	{
		data=jQuery.parseJSON(data);
        this.removeFile(file);
		if(data.state=="success")
		{
			var name=$(that).attr("config");
			var num=1;
			$("#list_"+name+" li").each(function()
			{
				var max=parseInt($(this).attr("num"));
				if (max>=num)
				{
					num=max+1;
				}
			});
			var html='';
			html+='<li num="'+num+'">';
			html+='	<div class="preview">';
			html+='		<input type="hidden" name="'+name+'['+num+'][image]" value="'+data.msg+'">';
			html+='		<u href="'+data.msg+'" class="lightbox"><img src="'+data.msg+'" /></u>';
			html+='	</div>';
			html+='	<div class="intro">';
			html+='		<textarea name="'+name+'['+num+'][desc]" class="form-ip" placeholder="图片描述..."></textarea>';
			html+='	</div>';
			html+='	<div class="action"><a href="javascript:;" class="img-left"><i class="ui-icon-left"></i>左移</a><a href="javascript:;" class="img-right"><i class="ui-icon-right"></i>右移</a><a href="javascript:;" class="img-del"><i class="ui-icon-delete"></i>删除</a></div>';
			html+='</li>';
			$("#list_"+name).append(html);
			Sortable.create($("#list_"+name)[0],{animation:400});
		}
		else
		{
			sdcms.error("上传失败："+data.msg);
		}
	},
	sending:function(file)
	{
		sdcms.loading("正在上传，请稍等");
	},
	totaluploadprogress:function(progress)
	{
		$.progress((Math.round(progress*100)/100)+"%");
	},
	queuecomplete:function(progress)
	{
		$.progress('close');
	},
	error:function(file,msg)
	{
		sdcms.error(msg);
	}
});
</script>
</body>
</html>