function insertTr(){ var innerHTML = ""; innerHTML += ''; innerHTML += ''; innerHTML += ''; innerHTML += ''; innerHTML += ''; return innerHTML; } function insertOperator(){ var innerHTML = ""; innerHTML += ''; innerHTML += 'ANDOR'; innerHTML += ''; innerHTML += ''; innerHTML += ''; return innerHTML; } function getConditionsHTML(){ var conditions = ""; var trs = $('#div2 table tr'); var size = trs.size(); for(var index = 0 ; index < size ; index++ ){ var tr = trs.get(index); var selects = $('select',tr); var input = $('input',tr); if(index != (size - 1)){ var secondTr = trs.get(++index); var op = $('.btn-primary',secondTr).text(); conditions += "

" + $(selects[0]).val() + " " + $('option:selected',selects[1]).text() + " " + $(input).val() + " " + op + "

"; }else{ conditions += "

" + $(selects[0]).val() + " " + $('option:selected',selects[1]).text() + " " + $(input).val() + "

"; } } return conditions; } function getConditions(){ var conditions = []; $('input[type="url"]').each(function(i){ var name = $(this).attr("name"); if(name && $(this).val()){ var op = "and"; if(name == "1"){ op = "or"; } var condition = getCondition("url",op,name,$(this).val(),i); conditions.push(condition); } }); var trs = $('#div2 table tr'); var size = trs.size(); for(var index = 0 ; index < size ; index++ ){ var tr = trs.get(index); var selects = $('select',tr); var input = $('input',tr); if(index != (size - 1)){ var secondTr = trs.get(++index); var tmpOp = $('.btn-primary',secondTr).text(); var op = ""; if(tmpOp == "AND"){ op = "and"; }else if(tmpOp == "OR"){ op = "or"; } var condition = getCondition($(selects[0]).val(),op,$(selects[1]).val(),$(input).val(),3); conditions.push(condition); }else{ var condition = getCondition($(selects[0]).val(),"and",$(selects[1]).val(),$(input).val(),3); conditions.push(condition); } } var condition = getCondition("percent","and",1,$(".add-on:eq(3)").text(),4); conditions.push(condition); if(conditions.length == 2){ var firstCondition = conditions[0]; firstCondition["operator"] = "and"; } return conditions; } function getCondition(name,operator,comparator,text,seq){ var condition = { "name":name, "operator":operator, "comparator":comparator, "text":text, "seq":seq } return condition; } function getConvertionGoals(){ var goals = []; $('#div3 div').each(function(){ var name = $("input:eq(0)",$(this)); var url = $("input:eq(1)",$(this)); var goal = { "name":name.val(), "text":url.val() }; goals.push(goal); }); return goals; } $(document).ready(function() { $('#ckall').click(function() { if ($('#ckall').is(':checked')) { $(".table input[type='checkbox']").prop( 'checked', true); } else { $(".table input[type='checkbox']").prop( 'checked', false); } }); $("#btnSuspend").click(function() { var checkbox = $(".table input[type='checkbox']:checked"); var id = ""; for ( var i = 0; i < checkbox.length; i++) { id = id + $(":nth-child(2)",$(checkbox[i]).closest('tr')).html() + "-"; } url = window.location.href; index = url.indexOf("&suspend"); if (index != -1) { window.location.href = url .substring(0, index) + "&suspend=-1&ids=" + id; } else { if (url.indexOf("?") == -1) { url = url + '?'; } window.location.href = url + "&suspend=-1&ids=" + id; } loaction.reload(); }); $("#btnResume").click(function() { var checkbox = $(".table input[type='checkbox']:checked"); var id = ""; for ( var i = 0; i < checkbox.length; i++) { id = id + $(":nth-child(2)",$(checkbox[i]).closest('tr')).html() + "-"; } url = window.location.href; index = url.indexOf("&suspend"); if (index != -1) { window.location.href = url .substring(0, index) + "&suspend=1&ids=" + id; } else { if (url.indexOf("?") == -1) { url = url + '?'; } window.location.href = url + "&suspend=1&ids=" + id; } loaction.reload(); }); $('#addVistorCondition').click(function(){ var tr = $(insertTr()); $('a',tr).click(function(){ var index = $(this).closest("tr").index(); if(index > 0){ $(this).closest("tr").prev().remove(); $(this).closest("tr").remove(); }else if(index == 0){ $(this).closest("tr").next().remove(); $(this).closest("tr").remove(); } }); if($('#div2 tbody tr:last').size() == 0){ $('#div2 tbody').html(tr); }else{ var innerHTML = $(insertOperator()); $('a',innerHTML).click(function(){ $('a',innerHTML).toggleClass("btn-primary"); }); $('#div2 tbody tr:last').after(innerHTML); $('#div2 tbody tr:last').after(tr); } }); var goalCounter = 1; $('#addConvertionGoal').click(function(e){ var innerHtml = []; innerHtml.push('
'); innerHtml.push(''); innerHtml.push(' triggers when visitor '); innerHtml.push(''); innerHtml.push(''); innerHtml.push('
'); var line = $(innerHtml.join("")); $('a',line).click(function(){ $(this).closest("div").remove(); }); $('#div3').append(line); goalCounter += 1; }); }); (function(w) { var abtest = { "httpError" : function(xhr, textStatus, errorThrown) { // 去掉按钮disable abtest.alertError('抱歉啦', '抱歉,网络发生错误了,请刷新页面试试...'); }, "alertError" : function(title, errorMsg) { // 显示错误消息 $('#errorMsgModal > div[class="modal-header"] > h3').text(title); $('#errorMsgModal > div[class="modal-body"] > p').text(errorMsg); $('#errorMsgModal').modal('show'); } }; w.abtest = abtest; }(window || this));