add.vm 14.5 KB
<link rel="stylesheet" href="/css/temp_style.css?v=1"/>
<script type="text/javascript" src="/js/common/jquery.min.js"></script>
<div class="page-header" id="navBar">
    <li><a href="/">后台管理系统</a><span class="divider">&gt;</span>
        <a href="/titan/templete">模板管理</a></li>
</div>
<div class="alert alert-danger" id="attrAlert" style="DISPLAY: none">
</div>
<div class="main">
    <form id="tempForm" action="/titan/templete/doAdd" method="post">
        <input type="hidden" name="useTemplete" id="useTemplete" value="1"/>

        <div class="title">
            <div>
                模板后台名称:<input type="text" id="name" name="name" value=""
                              maxlength="100"/>
                <a href="/titan/templete" class="backList"></a>
            </div>
            <div>
                模板前台名称:<input type="text" id="alias" name="alias" value=""
                              maxlength="5"/>
            </div>
            <div>
                模板内容:<input type="hidden" id="desc" name="desc" value=""/>
            </div>
        </div>
        <div>
            <div class="header clear">
                <p>模板编辑器</p>
                <a href="javascript:void(0);" class="back"></a>
            </div>
            <div id="tempedit" class="content">
                <ul class="images-list">
                    <li class="act" attr="1">
                        <img src="/img/templete/mo1.png"/>
                    </li>
                    <li attr="2">
                        <img src="/img/templete/mo2.png"/>
                    </li>
                    <li attr="3">
                        <img src="/img/templete/mo3.png"/>
                    </li>
                    <li attr="4">
                        <img src="/img/templete/mo4.png"/>
                    </li>
                </ul>
                <div class="clear"></div>
                <div class="box clear" id="content"></div>
            </div>
            <div id="umedit" style="display: none" >
                <div class="u-editor">
                    #parse("product/common/productDescUm.vm")
                </div>
            </div>
        </div>
        <button class="btn" id="addTemp"
                style="align-content: center; margin-left: 400px;">提交
        </button>
    </form>
    <form id="imageForm" action="/common/uploadImgNoMark"
          enctype="multipart/form-data" method="POST">
        <input name="image" type="file" id="uploadImg" value="上传图片"
               style="display: none"
               accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"/>
    </form>
    <input type="hidden" name="repeatSubmit" value="0"/>
</div>
<script type="text/javascript" src="/assets/js/jQuery-Form.js"></script>
<script type="text/javascript">
    $(function () {
        var m1 = '<div class="m-1 m-hover" id="m-1"><div class="left">'
                +'<div class="img-end"><span class="icon-img"></span></div></div>'
                +'<div class="right" style="margin: 15px 0 0 0;">'
                +'<input class="m-1-in" type="text" placeholder="请在这里输入标题" /><span class="m-1-input">1/7</span>'
                +'<textarea class="m-1-textarea" >请在这里输入文字....</textarea><span class="m-1-text">1/96</span></div><div class="coloe">×</div></div>';

        var m2 = '<div class="m-2 m-hover" id="m-2"> <input type="text" class="m-1-in" placeholder="请在这里输入标题" /><span class="m-1-input">1/7</span>'
                +'<textarea class="m-1-textarea" >请在这里输入文字....</textarea> <span class="m-1-text">1/250</span>'
                +'<div class="img-end"><span class="icon-img"></span></div><div class="coloe">×</div></div>';

        var m3 = '<div class="m-3 m-hover" id="m-3"><div class="right">'
                +'<input class="m-1-in" type="text" placeholder="请在这里输入标题" /><span class="m-1-input">1/7</span>'
                +'<textarea class="m-1-textarea" >请在这里输入文字....</textarea><span class="m-1-text">1/250</span></div><div class="images">'
                +'<div style="top:5px;z-index: 0;left: 30px" class="img-end">'
                +'<span class="icon-img"></span></div>'
                +'<div style="top:220px;z-index: 1;left: 230px;" class="img-end">'
                +'<span class="icon-img"></span></div>'
                +'<div style="top:5px;z-index: 2;right: 30px;" class="img-end">'
                +'<span class="icon-img"></span></div></div>'
                +'<textarea class="m-1-textarea" class="left">请在这里输入文字....</textarea><span class="m-1-text">1/250</span><div class="coloe">×</div></div>';

        var m4 = '<div class="m-4 m-hover clear" id="m-4">'
                +'<input class="title m-1-in" type="text" placeholder="请在这里输入标题" /><span class="m-1-input">1/7</span>'
                +'<ul class="left"><li><textarea class="m-1-textarea" class="left">请在这里输入文字....</textarea><span class="m-1-text">1/30</span>'
                +'<div class="img-end"><span class="icon-img"></span></div></li>'
                +'<li><textarea class="m-1-textarea" class="left">请在这里输入文字....</textarea><span class="m-1-text">1/30</span>'
                +'<div class="img-end"><span class="icon-img"></span></div></li></ul>'
                +'<ul  class="right"><li><textarea class="m-1-textarea" class="left">请在这里输入文字....</textarea><span class="m-1-text">1/30</span>'
                +'<div class="img-end"><span class="icon-img"></span></div></li><li>'
                +'<textarea class="m-1-textarea" class="left">请在这里输入文字....</textarea><span class="m-1-text">1/30</span>'
                +'<div class="img-end"><span class="icon-img"></span></div></div></li></ul><div class="coloe">×</div></div>';

        var m5 = '<div class="m-1  m-hover" id="m-1"><div class="right">'
                +'<input class="m-1-in" type="text" placeholder="请在这里输入标题" /><span class="m-1-input">1/7</span>'
                +'<textarea class="m-1-textarea" >请在这里输入文字....</textarea><span class="m-1-text">1/96</span>'
                +'</div><div class="left"><div class="img-end">'
                +'<span class="icon-img"></span></div></div><div class="coloe">×</div></div>';
        $("#content").append(m1).append("<div class=\"add-mroe\">模板不够用 添加更多</div>");
        var index = 0;
        var key = "m";
        $('.images-list li').click(function () {
            index = $(this).index();
            $('.images-list li').removeClass('act');
            $(this).addClass('act');
            var userTemp = $(this).attr("attr");
            $("#useTemplete").val(userTemp);
            $(".m-hover").remove();
            if (index == 0) {
                isOne = false;
            }
            if (isOne && index == 0) {
                index = 4;
                isOne = false;
            } else if (!isOne && index == 0) {
                index = 0;
                isOne = true;
            }
            ;
            key = key + (index + 1);
            $('.add-mroe').before(eval(key));
            key = "m";
        });
        var isOne = true;
        $('.add-mroe').click(function () {
            var page = index;
            if (isOne && page == 0) {
                page = 4;
                isOne = false;
            } else if (!isOne && page == 0) {
                page = 0;
                isOne = true;
            }
            ;
            key = key + (page + 1);
            $(this).before(eval(key));
            key = "m";
//            var imgList = $(".img-end");
//            if (imgList) {
//                $.each(imgList, function (i, n) {
//                    $(n).bind("click", function () {
//                        $("#uploadImg").click();
//                        selectObject = $(n);
//                    });
//                });
//            }
        });

        $('.m-hover').live({
            mouseenter: function () {
                $(this).find('.coloe').show();
            },
            mouseleave: function () {
                $(this).find('.coloe').hide();
            }
        });

        $('.coloe').live('click', function () {
            $(this).parent().remove();
        });
        $('input').live("blur", function(){
            if($(this).val().trim()=="") {
                $(this).val('请在这里输入标题');
            }
        });
        $('input').live("focus", function(){
            if($(this).val().trim()=="请在这里输入标题") {
                $(this).val("");
            }
        });
        $('textarea').live("blur", function(){
            if($(this).val().trim()=="") {
                $(this).val('请在这里输入文字....');
            }
        });
        $('textarea').live("focus", function(){
            if($(this).val().trim()=="请在这里输入文字....") {
                $(this).val("");
            }
        });


        //数字检测
        var munString = function(view){
            var next = view.next().html();
            next = next.split('/')[1];
            var index = parseInt(next);
            var mun = view.val().length;
            if(mun <= index){
                view.next().html(mun +'/'+index);
            }else{
                var str = view.val().substring(0, index);
                view.val(str);
                view.next().html(index +'/'+index);
            };
        };

        $('.m-1-textarea').live("keyup",function(){
            munString($(this));
        });
        $('.m-1-in').live("keyup",function(){
            munString($(this));
        });
        $(".back").toggle(function () {
                    $("#tempedit").hide();
                    $("#umedit").show();
                    $("#useTemplete").val(-1)
                    $(this).removeClass("back").addClass("compile");
                }, function () {
                    $("#umedit").hide();
                    $("#tempedit").show();
                    var userTemp = $('.images-list .act').attr("attr");
                    $("#useTemplete").val(userTemp)
                    $(this).removeClass("compile").addClass("back");
                }
        );

        var selectObject;
        $(".img-end").live("click", function () {
            $("#uploadImg").click();
            selectObject = $(this);
        });
        $('#uploadImg').live('change', function () {
            //请求地址
            jQuery("#imageForm").ajaxSubmit(function (result) {
                result = $(result)[6].data;
                result = result.replace(/\n/g,"").replace(/\r/g,"");
                result = eval('(' + result + ')');
                console.log(result);
                if ((/http:/).test(result.url)) {
                    selectObject.empty();
                    selectObject.append("<img src=\"" + result.url + "\" width=\"100%\" height=\"100%\" />");
                } else {
                    fun(result.state);
                }
                jQuery("#imageForm").resetForm();
            });
        });

        var fun = function (msg) {
            alert(msg);
        };

        $("#addTemp").click(function () {
            var name = $("#name").val().replace(/(^\s*)|(\s*$)/g, "");
            var alias = $("#alias").val().replace(/(^\s*)|(\s*$)/g, "");
            $("#name").val(name);
            $("#alias").val(alias);
            var regexname = /^[0-9a-zA-Z\u4e00-\u9fa5/()()&《》【】\+=\]\[]+$/g;
            var regexalias = /^[\u4e00-\u9fa5]+$/g;
            var regexdesc = /^[0-9a-zA-Z\u4e00-\u9fa5/()()&《》【】\+=\]\[]+$/g;
            var message = "请输入合法的分类名称(中文汉字、英文字母(含大小写)、数字、“/,(),&,《》,【】,[],=,+”)";
            var attrAlert = $("div.alert");
            if (name == "" || !regexname.test(name)) {
                alert(message);
                return false;
            }
            if (alias == "" || !regexalias.test(alias)) {
                alert("前台名称请输入中文!");
                return false;
            }
            if (alias.length > 5) {
                alert("前台名称不能超过5个字");
                return false;
            }
            if ($("#content").is(":visible")==true){
                var nouploadimg = $(".icon-img");
                if (nouploadimg && 1 <= nouploadimg.length) {
                    alert("图片必须上传");
                    return false;
                }
            }
            var status = $("#useTemplete").val();
            var desc = "";
            if (parseInt(status) >0) {
                $("#content").find(".coloe").remove();
                $("#content").find(".add-mroe").remove();
                $("#content").find(".m-1-text").remove();
                $("#content").find(".m-1-input").remove();
                $("#content").find("input").each(function () {
                    var html = '<div class="title"><span class="icon-left"></span>'
                            +'<h3>'+$(this).val()+'</h3>'
                            +'<span class="icon-right"></span><div></div><p>Diligroup</p></div>'
                    $(this).replaceWith(html);
//                    if($(this).hasClass("title")){
//                        $(this).replaceWith("<p class=\"font_desc_text title\">" +  + "</p>");
//                    }else {
//                        $(this).replaceWith("<p class=\"font_desc_text\">" + $(this).val() + "</p>");
//                    }
                });
                $("#content").find("textarea").each(function () {
//                    $(this).replaceWith("<p class=\"font_desc_textarea\">" + $(this).val() + "</p>");
                    $(this).replaceWith('<p class="m-text">' + $(this).val() + '</p>');
                });
                desc = $("#content").html();
            }
            if (parseInt(status) == -1) {
                desc = um.getContent();
            }
            var desc = desc.replace(/(^\s*)|(\s*$)/g, "");
            $("#desc").val(desc);
//            if(desc==""){
//                $("#content").append("<div class=\"add-mroe\">模板不够用    添加更多</div>");
//                alert(message);
//                return false;
//            }

            var rs = $("input[name='repeatSubmit']").val();
            if(rs==0) {
                $("input[name='repeatSubmit']").val("1");
                $("#tempForm").submit();
            }else{
                alert("请不要重复提交");
                return false;
            }
        });
    });

    //
</script>