docker_project.jsp 43.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@page import="com.ui.contants.ProjectConstant"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>项目发布</title>
    <link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
    <link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
    <link href="<%=basePath%>css/style.default.css" rel="stylesheet">
    <link href="<%=basePath%>css/morris.css" rel="stylesheet">
    <link rel="stylesheet" href="<%=basePath %>js/select2/dist/css/select2.css"/>
    <script>
        var contextPath = '<%=basePath %>';
    </script>

    <style>
        .select2-selection.select2-selection--single {
            min-height:40px;
        }
        .select2-container--default .select2-selection--single .select2-selection__rendered{
            line-height:38px;
        }
    </style>
</head>

<body style="background-color: #444444;font-size: 14px">

<!-- 头部 -->
<div id="head">
</div>
<div id="content">
    <div id="breadcrumb">
        <a href="#" title="Go to Home" class="tip-bottom"><i
                class="icon-home"></i> Home</a> <a href="#" class="current">项目发布Docker</a>
    </div>
    <div>
        <!-- query panel -->
        <form class="form-bordered">
            <div class="form-group">
                <label class="col-sm-1 control-label">操作选择</label>

                <div class="col-sm-8" style="display: inline">
                    <div class="rdio rdio-default" style="display: inline">
                        <input type="radio" name="operate" id="operatedeploy" value="Deploy" checked="checked" onclick="operateChange()"/>
                        <label for="operatedeploy">发布</label>
                    </div>

                    <div class="rdio rdio-default"  style="display:inline;margin-left:30px;">
                        <input type="radio" name="operate" value="Rollback" id="operateback" onclick="operateChange()"/>
                        <label for="operateback">回滚</label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-1 control-label">发布环境</label>

                <div class="col-sm-8">
                    <c:forEach items="${environments }" var="envi" varStatus="enviStatus">
                        <div class="rdio rdio-default">
                            <input type="radio" name="environments" id="${envi }" value="${envi }" onclick="blurEnv()"
                                    <c:choose>
                                        <c:when test="${releaseWorkJob_environment!=null}">
                                            <c:set var="envi_comm">${envi},</c:set>
                                            <c:if test="${fn:containsIgnoreCase(releaseWorkJob_environment,envi_comm)}">checked="checked"</c:if>
                                        </c:when>
                                        <c:otherwise>
                                            <c:if test="${enviStatus.index==0}">checked="checked"</c:if>
                                        </c:otherwise>
                                    </c:choose>
                            />
                            <label for="${envi }">${envi }</label>
                        </div>
                        <div id="div_cluster_${envi}" style="margin-left:50px;"></div>
                    </c:forEach>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-1 control-label">项目类别</label>

                <div class="col-sm-8">
                    <c:forEach items="${projectTypes }" var="projType" varStatus="projTypeStatus">
                        <div class="rdio rdio-default"  style='display: inline'>
                            <input type="radio" name="projectTypes" id="${projType.key }" value="${projType.key }"
                                   onclick="getProjects()"

                                    <c:choose>
                                        <c:when test="${releaseWorkJob_projectType!=null}">
                                            <c:if test="${fn:containsIgnoreCase(releaseWorkJob_projectType,projType.key)}">checked="checked"</c:if>
                                        </c:when>
                                        <c:otherwise>
                                            <c:if test="${projTypeStatus.index==0}">checked="checked"</c:if>
                                        </c:otherwise>
                                    </c:choose>


                            />
                            <label for="${projType.key }">${projType.value }</label>&nbsp;&nbsp;&nbsp;
                        </div>
                    </c:forEach>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-1 control-label">项目选择</label>

                <div class="col-sm-8" id="project-div">
                </div>
            </div>

            <div class="form-group" id="branch-div">
                <label class="col-sm-1 control-label">发布方式</label>
                <div class="col-sm-1" style="width: 110px;"  >
                    <select id="projectDeployType"  name="projectDeployType">
                        <c:forEach items="${projectDeployTypes }" var="projectDeployType" varStatus="projectDeloyTypeStatus">
                            <option value="${projectDeployType.key }">${projectDeployType.value }</option>
                        </c:forEach>
                    </select>
                </div>
                <div class="col-sm-7">
                    <div id="git_deploy_type_div" class="deploy_type_div_class">
                        <input name="branch" type="text" class="form-control"
                               value="${releaseWorkJob_branch}"
                               style="width: 300px"/>
                    </div>
                    <div id="image_deploy_type_div" class="deploy_type_div_class" style="display: none;width:600px;" >
                        <select id='imagesList' data-placeholder='Choose One'  class="form-control">
                            <option value="${releaseWorkJob_imageFile}">${releaseWorkJob_imageFile}</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group" id="uploadCDN_div" class="deploy_type_div_class" style="display: none">
                <label class="col-sm-1 control-label">上传CDN</label>

                <div class="col-sm-1" style="width: 110px;">
                    <select id="uploadCDN" name="uploadCDN"   class="form-control" style="width: 100px;height:40px">
                        <option value="0" <c:if test="${releaseWorkJob_uploadCDN == '0' }">selected</c:if>  >否</option>
                        <option value="1" <c:if test="${releaseWorkJob_uploadCDN == '1' }">selected</c:if>  >是</option>
                    </select>
                </div>
                <div class="col-sm-7" style="width: 200px;">
                    <input id="cdnBranch" name="cdnBranch" type="text" value="${releaseWorkJob_cdnBranch}"  class="form-control"  style="padding-left:10px;float:left" placeHolder="上传cdn的分支"/>
                </div>
            </div>

            <div class="form-group" id="rollback-div" style="display: none">
                <label class="col-sm-1 control-label">回滚版本选择</label>

                <div class="col-sm-8" id="select-rollbackList-div">

                </div>
            </div>

            <div class="form-group" id="workid-div">
                <label class="col-sm-1 control-label">关联工单</label>
                <div class="col-sm-8">
                    <input name="workid" type="text" class="form-control"
                           value="${releaseWorkJob_id}"
                           style="width: 300px" placeholder="填写 release0 可以不关联工单号"/>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-1 control-label">确认操作</label>

                <div class="col-sm-8">
                    <button type="button" id="submit-btn" onclick="comfirmSubmit()" class="btn btn-primary">提交</button>
                </div>
            </div>

        </form>
    </div>
</div>

<!-- 初始化确认页面  -->
<div class="modal fade" id="confirmSubmitDivId" tabindex="-1" role="dialog" aria-labelledby="confirmSubmitLabel"
     aria-hidden="true" style="padding-top: 10%">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <%--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>--%>
                <h2 class="modal-title" id="confirmSubmitLabel">
                    <span style="font-weight: bold;"> 确认提交</span>
                </h2>
            </div>
            <div class="modal-body">
                <form class="bs-example bs-example-form"  role="form"
                       method="post">
                    <div class="input-group">
                        <span class="input-group-addon">操作类型</span>
                        <input type="text" name="operate_name" class="form-control" readonly="readonly">
                    </div>
                    <br>

                    <div class="input-group">
                        <span class="input-group-addon">发布环境</span>
                        <input type="text" name="environment_name" class="form-control" readonly="readonly">
                    </div>
                    <br>

                    <div class="input-group">
                        <span class="input-group-addon">发布集群</span>
                        <input type="hidden" name="clusters_name" >
                        <input type="text" name="clusters_text" class="form-control" readonly="readonly">
                    </div>
                    <br>

                    <div class="input-group">
                        <span class="input-group-addon">工程名称</span>
                        <input type="hidden" name="project_id" class="form-control" readonly="readonly">
                        <input type="text" name="project_name" class="form-control" readonly="readonly">
                    </div>
                    <br>

                    <div class="input-group">
                        <span class="input-group-addon">发布方式</span>
                        <input type="hidden" name="project_deploy_type" >
                        <input type="text" name="project_deploy_type_name" class="form-control" readonly="readonly">
                    </div>
                    <br>


                    <div class="input-group" id="comfirm_deploy_content_div_git">
                        <span class="input-group-addon">分支名称</span>
                        <input type="text" name="branch_name" class="form-control" readonly="readonly">
                    </div>
                    <div class="input-group" id="comfirm_deploy_content_div_image">
                        <span class="input-group-addon">镜像文件</span>
                        <input type="text" name="image_file_name" class="form-control" readonly="readonly">
                    </div>
                    <br>

                    <div class="input-group">
                        <span class="input-group-addon">关联工单</span>
                        <input type="text" name="workid_name" class="form-control" readonly="readonly">
                    </div>
                    <br>
                    <div class="input-group">
                        <span class="input-group-addon">回滚文件</span>
                        <input type="text" name="rollbackfile_name" class="form-control" readonly="readonly">
                    </div>

                    <div class="modal-footer">
                        <button id="confirmBtn" type="button" class="btn btn-primary" onclick="deployOrRollback()">确认</button>
                        <button id="cancelBtn" type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>
<!-- 初始化确认页面  end -->

</body>
<script type="text/javascript">
    var default_releaseWorkJob_branch="${releaseWorkJob_branch}";
    var default_releaseWorkJob_project="${releaseWorkJob_project}";
    var default_releaseWorkJob_enviCount = "${releaseWorkJob_enviCount}";
    var default_releaseWorkJob_environment="${releaseWorkJob_environment}";
</script>
<script src="<%=basePath%>js/jquery-2.1.4.min.js"></script>
<script src="<%=basePath %>js/jquery-plugin/jquery.extend.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<script src="<%=basePath %>js/select2/dist/js/select2.full.js"></script>
<script src="<%=basePath%>js/custom.js"></script>
<script src="<%=basePath %>/js/unicorn.js"></script>
<script src="<%=basePath %>js/layer/v311/layer.js" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>script/common/genarate_left_panel.js?v=<%=ProjectConstant.MENU_VERSION %>"></script>
<script type="text/javascript">
    $("#li_project").addClass("active open");
    $("#li_dockerRelease").addClass("active");
</script>

</html>
<script type="text/javascript">
    var global_all_clusters=${clusters};
    jQuery(document).ready(function () {
        $("#projectDeployType").select2({
            width:"110px"
        });

        $("#projectDeployType").on("change",function(){
            var val = $(this).val();
            deployTypeOnchange(val);
        });

        $("#projectDeployType").prop("disabled", true);

        if("${releaseWorkJob_id}".length>0){
            $('#projectDeployType').val(['${releaseWorkJob_projectDeployType}']).trigger('change');
        }

        $('#imagesList').select2({
            width:"100%"
        });

        getProjects();
    });
    
    function deployTypeOnchange(val) {
        $(".deploy_type_div_class").hide();
        $("#"+val+"_deploy_type_div").show();

        if(val=="image"){
            //$("#uploadCDN_div").show();

            if("${releaseWorkJob_id}".length>0){
                $("#projectDeployType").prop("disabled", true);
                return ;
            }

            $("#imagesList").select2("val", "");
            $('#imagesList').select2().empty();
            //加载项目的镜像
            var dockerModelProjectId = $('input[name="project1"]:checked').val() ;
            var list=[];
            if(dockerModelProjectId){
                $.ajax({
                    type: 'post',
                    url: contextPath + "dockerBuild/getDeployImageList",
                    data: {
                        projectId:dockerModelProjectId
                    },
                    dataType: 'json',
                    success: function (data) {
                        if(data){
                            $('#imagesList').select2({
                                width:"100%",
                                data: JSON.parse(data)
                            });
                        }
                    },
                    error: function (e) {
                        alert("从后台获取数据出错");
                    }
                });
            }else{
                $('#imagesList').select2({
                    width:"100%",
                    data: list
                });
            }
        }else{
            //$("#uploadCDN").val(0);
            $("#uploadCDN_div").hide();//隐藏当前区域

        }
    }

    function reloadDeployImage(){
        if("${releaseWorkJob_id}".length>0){
            $("#projectDeployType").prop("disabled", true);
            return ;
        }
        deployTypeOnchange($("#projectDeployType").val());
    }

    /**
     * 操作变更
     */
    function operateChange() {
        getProjects();
        var operate = $("input[name='operate']:checked").val();
        if ("Rollback" == operate) {
            //隐藏Branch输入框
            document.getElementById("branch-div").style.display = "none";
            //展示 回滚选择框
            document.getElementById("rollback-div").style.display = "";


        } else {
            //展示Branch输入框
            document.getElementById("branch-div").style.display = "";
            //隐藏 回滚选择框
            document.getElementById("rollback-div").style.display = "none";
        }
    }

    /**
     * 根据操作获取当前的项目列表
     */
    function getProjects() {
        $("#div_cluster_yoho-online").empty();
        $("#div_cluster_yoho-gray").empty();
        var operate = $("input[name='operate']:checked").val();
        $.ajax({
            type: 'post',
            url: contextPath + "dockerBuild/getProjects",
            data: {
                projectType:$("input[name='projectTypes']:checked").val()
             },
            dataType: 'json',
            success: function (data) {
                var obj = eval("(" + data + ")");
                if ("Deploy" == operate) {//发布多选框 ,现在修改成单选框了
                    var order1HTML="";
                    var order1num = 1;
                    for (var i = 0; i < obj.length; i++) {
                        var projectId = obj[i].id;
                        var name = obj[i].projectName;
                        var cluster_online = obj[i].dockerOnlineClusterId;
                        if(!cluster_online){
                            cluster_online="";
                        }
                        var cluster_gray = obj[i].dockerGrayClusterId;
                        if(!cluster_gray){
                            cluster_gray="";
                        }
                        var checkstr="";
                        if(default_releaseWorkJob_project!=null&&default_releaseWorkJob_project.indexOf(name+",")>=0){
                            checkstr = " checked ";
                        }
                        order1HTML += "<div class='rdio rdio-primary' style='display: inline'>";
                        order1HTML += " <input name='project1' onclick='resetCls_deploy()' type='radio' " + checkstr ;
                        order1HTML += " supportDeployType='"+obj[i].supportDeployType+"' ";
                        order1HTML += " cluster_online='"+cluster_online+"' cluster_gray='"+cluster_gray+"'  id='" + name + "' value='" + projectId + "'/>";
                        order1HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
                        if (order1num % 4 == 0) {
                            order1HTML += "</br>";
                        }
                        order1num += 1;
                    }
                    document.getElementById("project-div").innerHTML = order1HTML ;
                    branchdefault();
                    workiddefault();
                    //存在默认值,触发选中事件
                    if(default_releaseWorkJob_project!=null&&default_releaseWorkJob_project.length>0){
                        //存在选中的值
                        $('input[name="project1"]:checked').each(function () {
                            resetCls_deploy();
                            return false;//跳出循环
                        });
                    }
                }else{
                    var order1HTML="";
                    var order1num = 1;
                    for (var i = 0; i < obj.length; i++) {
                        var projectId = obj[i].id;
                        var name = obj[i].projectName;
                        var cluster_online = obj[i].dockerOnlineClusterId;
                        if(!cluster_online){
                            cluster_online="";
                        }
                        var cluster_gray = obj[i].dockerGrayClusterId;
                        if(!cluster_gray){
                            cluster_gray="";
                        }
                        var checkstr="";
                        if(i==0){
                            checkstr = " checked ";
                        }
                        order1HTML += "<div class='rdio rdio-primary' style='display: inline'>";
                        order1HTML += " <input onchange='getRollbackList()' name='project' type='radio' " + checkstr ;
                        order1HTML += " cluster_online='"+cluster_online+"' cluster_gray='"+cluster_gray+"' id='" + name + "' value='" + projectId + "'/>";
                        order1HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
                        if (order1num % 4 == 0) {
                            order1HTML += "</br>";
                        }
                        order1num += 1;
                    }
                    document.getElementById("project-div").innerHTML = order1HTML ;
                    getRollbackList();
                }


                if(default_releaseWorkJob_enviCount!=null&&default_releaseWorkJob_enviCount>=2){
                    alert("提醒:工单的发布环境为"+default_releaseWorkJob_environment+"当前只选中一个!");
                }
            },
            error: function (e) {
                alert("从后台获取数据出错");
            }
        });
    }
    
    function blurEnv() {
        var environment = $("input[name='environments']:checked").val();
        if(environment=="yoho-online"){
            $("#div_cluster_yoho-gray [name='dockerGrayClusterId']").removeAttr("checked");
            $("#div_cluster_yoho-online [name='dockerOnlineClusterId']").prop("checked", true);;
        }else{
            $("#div_cluster_yoho-online [name='dockerOnlineClusterId']").removeAttr("checked");
            //选中第一个
            //$("#div_cluster_yoho-gray [name='dockerGrayClusterId']").eq(0).attr("checked",'true');
            $("#div_cluster_yoho-gray [name='dockerGrayClusterId']").prop("checked", true);
        }
    }
    function resetCls_deploy(){
        resetCls("project1");
    }
    function resetCls(checkbox_projectName){
        var cluster_online=new Array();
        var cluster_gray=new Array();
        var index=0;
        $('input[name="'+checkbox_projectName+'"]:checked').each(function () {
            if(index==0){
                if($(this).attr("cluster_online")){
                    cluster_online=$(this).attr("cluster_online").split(",");
                }
                if($(this).attr("cluster_gray")){
                    cluster_gray=$(this).attr("cluster_gray").split(",");
                }
            }else{
                //多选,取交集
                if(cluster_online.length>0){
                    cluster_online=intersectArray(cluster_online,$(this).attr("cluster_online").split(","));
                }

                if(cluster_gray.length>0){
                    cluster_gray=intersectArray(cluster_gray,$(this).attr("cluster_gray").split(","));
                }
            }
            index++;
        });
        var environment = $("input[name='environments']:checked").val();

        var supportDeployType =$('input[name="'+checkbox_projectName+'"]:checked').attr("supportDeployType");
        if(supportDeployType!=null){
            supportDeployType = $.trim(supportDeployType);
        }else{
            supportDeployType="";
        }
        var htmlContent="";
        for(var i=0;i<cluster_online.length;i++){
            var key=cluster_online[i];
            var checkedFlag="";
            if(i>=0&&environment=="yoho-online"){
                checkedFlag=" checked ";
            }
            htmlContent += '<div class="ckbox ckbox-primary"  style="display: inline">'
                +' <input readonly disabled type="checkbox" id="dockerOnlineClusterId_'+key+'" name="dockerOnlineClusterId" '
                +checkedFlag
                +' value="'+key+'"/>'
                +' <label  for="dockerOnlineClusterId_' + key + '">'+global_all_clusters[key]+'</label>&nbsp;&nbsp;&nbsp;</div>';
        }
        $("#div_cluster_yoho-online").html(htmlContent);

        //重置变量
        htmlContent="";
        for(var i=0;i<cluster_gray.length;i++){
            var key=cluster_gray[i];
            var checkedFlag="";
            if(i>=0&&environment=="yoho-gray"){
                checkedFlag=" checked ";
            }
            htmlContent += '<div class="ckbox ckbox-primary"  style="display: inline">'
                +' <input readonly disabled type="checkbox" id="dockerGrayClusterId_'+key+'" name="dockerGrayClusterId" '
                +checkedFlag
                +' value="'+key+'"/>'
                +' <label for="dockerGrayClusterId_'+key+'">'+global_all_clusters[key]+'</label>&nbsp;&nbsp;&nbsp;</div>';
        }
        $("#div_cluster_yoho-gray").html(htmlContent);

        //重置--发布方式
        var array_deploy_type_value="";
        $("#projectDeployType").prop("disabled", true);//下拉不可用
        if(supportDeployType.length<=0){
            array_deploy_type_value="git";
        }else if(supportDeployType.split(",").length==1){
            array_deploy_type_value=supportDeployType;
        }else{
            //下拉可用
            $("#projectDeployType").prop("disabled", false);
        }
        if(array_deploy_type_value.length>0){
            $('#projectDeployType').val([array_deploy_type_value]).trigger('change');
        }else{
            reloadDeployImage();
        }

    }

    function getRollbackList(){
        resetCls("project");

        var projectId = $("input[name='project']:checked").val();
        var environment = $("input[name='environments']:checked").val();
        $.ajax({
            url: contextPath + 'dockerBuild/getRollbackList?projectId=' + projectId + "&environment=" + environment,
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                document.getElementById("select-rollbackList-div").innerHTML = "";
                if ("failed" == data) {
                    return;
                }

                var list = eval("(" + data + ")");
                //动态生成rollbackList的select组件
                var innerHTMLContext = "<select id='rollbackList' data-placeholder='Choose One' style='width:350px;'>";
                for (var i = 0; i < list.length; i++) {
                    innerHTMLContext += "<option value='" + list[i] + "'>" + list[i] + "</option>";
                }
                innerHTMLContext += "</select>";
                document.getElementById("select-rollbackList-div").innerHTML = innerHTMLContext;

                jQuery('#rollbackList').select2({
                    minimumResultsForSearch: -1
                });
            },
            error: function (e) {
                alert("该项目暂无备份,无法回滚");
            }
        });
    }

    function branchdefault() {
        var operate = $("input[name='operate']:checked").val();
        if (operate == "Deploy") {
            if(default_releaseWorkJob_branch!=null&&default_releaseWorkJob_branch.length>0){
                $("input[name='branch']").val(default_releaseWorkJob_branch);
                return;
            }
            //var environment = $("input[name='environments']:checked").val();
            $("input[name='branch']").val("master");
        }
    }
    
    function workiddefault() {
        var default_releaseWorkJob_workId="${releaseWorkJob_id}";
        if(default_releaseWorkJob_workId!=null&&default_releaseWorkJob_workId.length>0){
            $("input[name='workid']").val(default_releaseWorkJob_workId);
            return;
        }
        $("input[name='workid']").val("release0");
    }

    //打开提交的确认界面
    function comfirmSubmit() {
        //判断是否为jenkins-deploy,若是则直接部署
//        var projectTypes =$("input[name='projectTypes']:checked").val()
//        if("jenkins-deploy"==projectTypes){
//            var param_jenkins={};
//            param_jenkins.project_id=$('input[name="project1"]:checked').val();
//            param_jenkins.environment_name=$("input[name='environments']:checked").val();
//            param_jenkins.image_file_name=$("#imagesList").val();
//            useJenkinsDeploy(param_jenkins);
//            return;
//        }

        var operate = $("input[name='operate']:checked").val();
        var environment = $("input[name='environments']:checked").val();
        var projectDeployType = $("#projectDeployType").val();
        //获取集群,基本上从后台读取了
        var clustersName=new Array();
        var clustersText=new Array();
        if (""==environment) {
            alert("请选择发布环境");
            return;
        }

//        if("yoho-online"==environment){
//            $('input[name="dockerOnlineClusterId"]:checked').each(function () {
//                clustersName.push($(this).val());//向数组中添加元素
//                clustersText.push($(this).next().text());
//            });
//        }else{
//            $('input[name="dockerGrayClusterId"]:checked').each(function () {
//                clustersName.push($(this).val());//向数组中添加元素
//                clustersText.push($(this).next().text());
//            });
//        }

        var projects = new Array();
        var projectNames = new Array();
        if ("Deploy" == operate) {//发布
            $('input[name="project1"]:checked').each(function () {
                projects.push($(this).val());//向数组中添加元素
                projectNames.push($(this).next().text());
            });

            if (projects.length == 0) {
                alert("请选择项目");
                return;
            }

            $("#comfirm_deploy_content_div_git").hide();
            $("#comfirm_deploy_content_div_image").hide();

            var branch = $("input[name='branch']").val();
            var imageFile=$("#imagesList").val();
//            var uploadCDN = $("#uploadCDN").val();
//            var cdnBranch = $("#cdnBranch").val();
            if(projectDeployType=="image"){
                $("#comfirm_deploy_content_div_image").show();
                branch="";
                if (!imageFile) {
                    alert("请填写镜像文件");
                    return;
                }
//                if(uploadCDN==1){
//                    if(!cdnBranch){
//                        alert("请填写上传CDN分支");
//                        return;
//                    }
//                }
            }else if(projectDeployType=="git"){
                $("#comfirm_deploy_content_div_git").show();
                if (!branch) {
                    alert("请填写分支名称");
                    return;
                }
                imageFile="";
            }else{
                alert("请填写发布方式");
                return;
            }


            var workid = $("input[name='workid']").val();
            if (workid == "") {
                alert("请填写关联工单号");
                return;
            }

            $("input[name='operate_name']").val(operate);
            $("input[name='project_id']").val(projects);
            $("input[name='project_name']").val(projectNames);
            $("input[name='environment_name']").val(environment);
            $("input[name='clusters_name']").val(clustersName);
            $("input[name='clusters_text']").val(clustersText);
            $("input[name='project_deploy_type']").val(projectDeployType);
            $("input[name='project_deploy_type_name']").val($("#projectDeployType").find("option:selected").text());
            $("input[name='branch_name']").val(branch);
            $("input[name='image_file_name']").val(imageFile);
            $("input[name='workid_name']").val(workid);
            $('#confirmSubmitDivId').modal('show');
        }else{
            var project = $("input[name='project']:checked").val();
            var projectName = $("input[name='project']:checked").next().text();
            var rollbackfile = $("#rollbackList option:selected").val();
            if (project == "") {
                alert("请选择回滚项目");
                return;
            }
            var workid = $("input[name='workid']").val();
            if (workid == "") {
                alert("请填写关联工单号");
                return;
            }
            if (typeof(rollbackfile) == "undefined" || rollbackfile == "") {
                alert("请选择回滚版本");
                return;
            }
            $("input[name='operate_name']").val(operate);
            $("input[name='project_id']").val(project);
            $("input[name='project_name']").val(projectName);
            $("input[name='environment_name']").val(environment);
            $("input[name='clusters_name']").val(clustersName);
            $("input[name='clusters_text']").val(clustersText);
            $("input[name='rollbackfile_name']").val(rollbackfile);
            $("input[name='branch_name']").val("");
            $("input[name='workid_name']").val(workid);
            $('#confirmSubmitDivId').modal('show');
        }
    }
    
    function deployOrRollback() {
        var operate = $("input[name='operate']:checked").val();
        if ("Deploy" == operate) {//发布
//            beginDeploy();
            useJenkinsDeploy();
        }else {
            rollback();
        }
    }

    function useJenkinsDeploy() {
        var param={};
        param.project_id=$("input[name='project_id']").val();
        param.environment_name=$("input[name='environment_name']").val();
        param.image_file_name=$("input[name='image_file_name']").val();
        param.branch_name=$("input[name='branch_name']").val();
        param.workid_name=$("input[name='workid_name']").val();

//        param.operate_name=$("input[name='operate_name']").val();
//        param.project_name=$("input[name='project_name']").val();
//        param.project_deploy_type=$("input[name='project_deploy_type']").val();
//        param.workid_name=$("input[name='workid_name']").val();
//        param.clusters_name=$("input[name='clusters_name']").val();
//        param.clusters_text=$("input[name='clusters_text']").val();
        $.ajax({
            url: contextPath + "dockerBuild/jenkinsDeploy",
            type: "post",
            dataType: "json",
            data: param ,
            success: function (response) {
                if(response!=null&&(response.code==200)){
                    param.buildId=response.data;
                    GobalStandardPost( contextPath+ "dockerBuild/toBuildViewNew",param);
                }else{
                    mirrorFail(response.message);
                }
            }
        });
    }

    function rollback(){
        $("#confirmBtn").attr("disabled","disabled");
        $("#cancelBtn").attr("disabled","disabled");
        var param={};
        param.operate_name=$("input[name='operate_name']").val();
        param.project_id=$("input[name='project_id']").val();
        param.project_name=$("input[name='project_name']").val();
        param.environment_name=$("input[name='environment_name']").val();
        param.rollbackImageStore=$("input[name='rollbackfile_name']").val();
        param.workid_name=$("input[name='workid_name']").val();
        param.clusters_name=$("input[name='clusters_name']").val();
        param.clusters_text=$("input[name='clusters_text']").val();

        $.ajax({
            url: contextPath + "dockerBuild/rollback",
            type: "post",
            dataType: "json",
            data: param ,
            success: function (response) {
                if(response!=null&&(response.code==200)){
                    param.buildIds=response.data;
                    GobalStandardPost( contextPath+ "dockerBuild/toBuildView",param);
                }else{
                    //失败
                    if(response==null){
                        mirrorFail("回滚失败!");
                    }else{
                        mirrorFail(response.message);
                    }

                }
            },
            error: function (e) {
                mirrorFail(e);
            }
        });

    }

    function mirrorAndDeploy(param) {
        $("#confirmBtn").attr("disabled","disabled");
        $("#cancelBtn").attr("disabled","disabled");

        var layerMirror=layer.open( {
            type:3,
            //area: ['800px', '500px'],
            content:"准备发布,通知Jenkins制作镜像",
            time: 0 //不自动关闭
        });

        $.ajax({
            url: contextPath + "dockerBuild/mirrorAndDeploy",
            type: "post",
            dataType: "json",
            data: param ,
            success: function (response) {
                if(response!=null&&(response.code==200||response.code==2000)){
                    //成功(或者部分成功),进入刷新进度界面
                    param.buildIds=response.data;
                    param.failMsg=response.message;
                    GobalStandardPost( contextPath+ "dockerBuild/toBuildView",param);
                }else{
                    layer.close(layerMirror);
                    //失败
                    if(response==null){
                        mirrorFail("发布失败!");
                    }else{
                        mirrorFail(response.message);
                    }

                }
            },
            error: function (e) {
                layer.close(layerMirror);
                mirrorFail(e);
            }
        });
    }

    function beginDeploy(){
        var param={};
        param.operate_name=$("input[name='operate_name']").val();
        param.project_id=$("input[name='project_id']").val();
        param.project_name=$("input[name='project_name']").val();
        param.environment_name=$("input[name='environment_name']").val();
        param.project_deploy_type=$("input[name='project_deploy_type']").val();
        param.branch_name=$("input[name='branch_name']").val();
        param.image_file_name=$("input[name='image_file_name']").val();
        param.workid_name=$("input[name='workid_name']").val();
        param.clusters_name=$("input[name='clusters_name']").val();
        param.clusters_text=$("input[name='clusters_text']").val();
//        param.uploadCDN = $("#uploadCDN").val();
//        param.cdnBranch = $("#cdnBranch").val();
        console.log(param);
        //三个node项目发布灰度环境时,自动启用灰度,发布online环境时,自动关闭灰度
        param.az2AutoSwitchOnlineCheck="";
        mirrorAndDeploy(param);
//        if("yohoblk-wap"==param.project_name||"yohobuywap-node"==param.project_name||"yohobuy-node"==param.project_name){
//            $('#confirmSubmitDivId').modal('hide');
//            if(param.environment_name.indexOf("gray")<0){
//                //发布线上环境,则在发布成功后,自动切到online
//                param.az2AutoSwitchOnlineCheck="az2AutoSwitchOnlineCheck";
//                mirrorAndDeploy(param);
//            }else{
//                //发布灰度环境,自动启用灰度
//                var dialog = $("<div>").appendTo($("body"));
//                dialog.dialog({
//                    title: "你确定执行发布吗",
//                    backdrop: "static",
//                    content: "发布开始前会自动启用az2-"+param.project_name+"灰度环境,确定发布?",
//                    buttons: [{
//                        text: "否",
//                        className: "btn-danger",
//                        onclick: function () {
//                            dialog.dialog("hide");
//                            $('#confirmSubmitDivId').modal('show');
//                        }
//                    }, {
//                        text: "是",
//                        className: "btn-success",
//                        onclick: function () {
//                            dialog.dialog("hide");
//
//                            var layerSwitch=layer.open( {
//                                type:3,
//                                //area: ['800px', '500px'],
//                                content:"灰度环境切换中",
//                                time: 0 //不自动关闭
//                            });
//
//                            $.ajax({
//                                type: "post",
//                                url: contextPath+"/dockerBuild/switchDockerNodeAz2",
//                                data: {
//                                    env:param.environment_name,
//                                    branch:param.branch_name,
//                                    project_name: param.project_name,
//                                    onlineOrGray:"gray"
//                                },
//                                dataType: "json",
//                                success: function(resp){
//                                    layer.close(layerSwitch);
//                                    if(resp.code==200){
//                                        mirrorAndDeploy(param);
//                                    }else{
//                                        localAlert("错误","az2切换灰度环境失败:"+resp.message);
//                                    }
//                                },
//                                error: function(){
//                                    layer.close(layerSwitch);
//                                    localAlert("错误","az2切换灰度环境异常");
//
//                                }
//                            });
//
//                        }
//                    }]
//                });
//            }
//
//        }else{
//            mirrorAndDeploy(param);
//        }
    }


    function mirrorFail(msg) {
        console.log(msg);
        $("#confirmBtn").removeAttr("disabled");
        $("#cancelBtn").removeAttr("disabled");
        alert(JSON.stringify(msg));
    }


    function intersectArray(a, b){
        return Array.intersect(a, b);
    }

    Array.prototype.indexOf = Array.prototype.indexOf || function (searchElement, fromIndex) {
        var index = -1;
        fromIndex = fromIndex * 1 || 0;
        for (var k = 0, length = this.length; k < length; k++) {
            if (k >= fromIndex && this[k] === searchElement) {
                index = k;
                break;
            }
        }
        return index;
    };

    Array.prototype.filter = Array.prototype.filter || function (fn, context) {
        var arr = [];
        if (typeof fn === "function") {
            for (var k = 0, length = this.length; k < length; k++) {
                fn.call(context, this[k], k, this) && arr.push(this[k]);
            }
        }
        return arr;
    };

    // 数组去重
    Array.prototype.unique = function() {
        var n = {}, r = [];
        for (var i = 0; i < this.length; i++) {
            if (!n[this[i]]) {
                n[this[i]] = true;
                r.push(this[i]);
            }
        }
        return r;
    };

    Array.intersect = function(arr1, arr2) {
        if(Object.prototype.toString.call(arr1) === "[object Array]" && Object.prototype.toString.call(arr2) === "[object Array]") {
            return arr1.filter(function(v){
                return arr2.indexOf(v)!==-1
            })
        }
    };

</script>