delete unused js

This commit is contained in:
hmm 2014-09-02 15:44:55 +08:00
parent c55daae043
commit 89d9b0711f
31 changed files with 0 additions and 3886 deletions

View File

@ -231,21 +231,6 @@ body {
<script src="lib/other/jstree.min.js"></script>
<script src="lib/other/jquery.msgbox.min.js"></script>
<script src="lib/other/jquery.noty.packaged.min.js"></script>
<!--
<script src="script/editor/pluginEditor/editorFactory.js"></script>
<script src="script/editor/pluginEditor/dataFormat.js"></script>
<script src="script/editor/pluginEditor/containerFactory.js"></script>
<script src="script/editor/pluginEditor/dataCollect.js"></script>
<script src="script/editor/uiFactory.js"></script>
<script src="script/editor/jstreeFactory.js"></script>
<script src="script/editor/behavior.js"></script>
<script src="script/editor/usePlugin.js"></script>
<script src="script/editor/submitScript.js"></script>
<script src="script/editor/createScript.js"></script>
<script src="script/ScriptEditor/scriptModels.js"></script>
-->
<script src="script/scriptManager/scriptModels.js"></script>
<script src="script/scriptManager/editorFactory.js"></script>
<script src="script/scriptManager/containerFactory.js"></script>

View File

@ -226,23 +226,6 @@
<script src="lib/other/jquery.msgbox.min.js"></script>
<script src="lib/HashMap/HashMap.js"></script>
<script src="script/Share/getUrlVars.js"></script>
<!--
<script src="script/editor/pluginEditor/editorFactory.js"></script>
<script src="script/editor/pluginEditor/dataFormat.js"></script>
<script src="script/editor/pluginEditor/containerFactory.js"></script>
<script src="script/editor/pluginEditor/dataCollect.js"></script>
<script src="script/editor/uiFactory.js"></script>
<script src="script/editor/behavior.js"></script>
<script src="script/editor/usePlugin.js"></script>
<script src="script/editor/submitScript.js"></script>
<script src="script/editor/jstreeFactory.js"></script>
<script src="script/Share/getUrlVars.js"></script>
<script src="script/ScriptEditor/scriptEditor.js"></script>
<script src="script/ScriptEditor/scriptModels.js"></script>
<script src="script/ScriptEditor/scriptEditor.js"></script>
-->
<script src="script/scriptManager/editorFactory.js"></script>
<script src="script/scriptManager/dataFormat.js"></script>
<script src="script/scriptManager/containerFactory.js"></script>

View File

@ -1,155 +0,0 @@
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<meta charset="utf-8">
<title>Bench4Q</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description"
content="Bench4Q, a new method for QOS benchmarking.">
<link id="bs-css" href="lib/chrisma/css/bootstrap-cerulean.css"
rel="stylesheet">
<link
href="http://ajax.aspnetcdn.com/ajax/bootstrap/2.3.2/css/bootstrap-responsive.css"
rel="stylesheet">
<link rel="shortcut icon" href="image/bench4q.png">
<link href="lib/chrisma/css/charisma-app.css" rel="stylesheet">
<link href='lib/chrisma/css/opa-icons.css' rel='stylesheet'>
<!-- <link href="http://cdn.alloyui.com/2.5.0/aui-css/css/bootstrap.min.css"
rel="stylesheet"></link> -->
<link href='css/editor.css' rel='stylesheet'>
<!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- The fav icon -->
</head>
<body>
<fmt:bundle basename="i18n">
<jsp:include page="publiccontrol/navigatebar.jsp"></jsp:include>
<div class="container-fluid">
<div class="row-fluid">
<jsp:include page="publiccontrol/leftmenubar.jsp"></jsp:include>
<div class="tab span10">
<ul style="cursor: pointer" class="nav nav-tabs">
<li id="tow1" class="on" onclick='refresh();setTab("tow",1,3);'><a
href="#">View</a></li>
<li id="tow2" onclick='setTab("tow",2,3);'><a href="#">EditBehaviors</a></li>
<li id="tow3" onclick='setTab("tow",3,3);'><a href="#">EditPlugins</a></li>
</ul>
</div>
<div class="span10">
<div id="cont_tow_1" class="one block">
<div id="contents" class="span12">
<div id="codeEditor" class="view"></div>
</div>
<%-- <jsp:include page="publiccontrol/scriptEditRightMenuBar.jsp"></jsp:include> --%>
</div>
<div id="cont_tow_2" class="one" style="display: none">
<div class="all-plugins btn-group span12">
<a class="btn dropdown-toggle" href="#" data-toggle="dropdown">
<span class="hidden-phone"> All plug-ins </span> <span
class="caret"></span>
</a>
<ul class="dropdown-menu" id="allPlugins">
<li><a onclick="choosePlugin(this);">All</a></li>
<li class="divider"></li>
</ul>
</div>
<div class="row-fluid">
<div id="behaviors" class="all-behaviors span4">
<ul id="behaviorUl">
</ul>
</div>
<div class="span8">
<div id="showPluginMethodForm"></div>
<div id="action" style="display: none">
<button type="button" class="btn btn-primary" id="submit"
title="save edit">
<fmt:message key="script_edit_jsp_save"></fmt:message>
</button>
<button type="button" class="btn btn-primary" id="cancel"
title="cancel edit">
<fmt:message key="script_edit_jsp_cancel" />
</button>
<button type="button" class="btn btn-primary" id="validate"
title="validate edit">
<fmt:message key="script_edit_jsp_validate"></fmt:message>
</button>
</div>
</div>
</div>
</div>
<div id="cont_tow_3" class="one" style="display: none">
<div class="all-plugins btn-group span12">
<a class="btn dropdown-toggle" href="#" data-toggle="dropdown">
<span class="hidden-phone"> All plug-ins </span> <span
class="caret"></span>
</a>
<ul class="dropdown-menu" id="allPlugins">
<li><a onclick="choosePlugin(this);">All</a></li>
<li class="divider"></li>
</ul>
</div>
<div class="row-fluid">
<div id="usePlugins" class="all-behaviors span4">
<ul id="usePlugin">
</ul>
</div>
<div class="span8">
<div id="pluginParamArea"></div>
</div>
</div>
<div id="usePluginAction" style="float: right">
<button type="button" class="btn btn-primary" id="submitPlugin"
title="save edit">
<fmt:message key="script_edit_jsp_save"></fmt:message>
</button>
<button type="button" class="btn btn-primary" id="cancel"
title="cancel edit">
<fmt:message key="script_edit_jsp_cancel" />
</button>
<button type="button" class="btn btn-primary" id="validate"
title="validate edit">
<fmt:message key="script_edit_jsp_validate"></fmt:message>
</button>
</div>
</div>
</div>
</div>
</div>
<!-- </div> -->
<hr>
<jsp:include page="publiccontrol/footer.jsp"></jsp:include>
<script
src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js"></script>
<script src="lib/jquery/js/jquery-ui-1.10.4.js"></script>
<script
src='http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js'></script>
<script
src="http://ajax.aspnetcdn.com/ajax/bootstrap/2.3.1/bootstrap.min.js"></script>
<script src="lib/jqueryi18n/jquery.i18n.properties-1.0.9.js"></script>
<script src="script/base.js"></script>
<script src="lib/chrisma/js/jquery.cookie.js"></script>
<script src="lib/chrisma/js/theme.js"></script>
<script src="http://cdn.alloyui.com/2.5.0/aui/aui-min.js"></script>
<script src="lib/bootstrap/js/bootstrap-collapse.js"></script>
<script src="script/ScriptEditor/pluginCommon.js"></script>
<script src="script/ScriptEditor/paramInfosForm.js"></script>
<script src="script/ScriptEditor/pluginModel.js"></script>
<script src="script/ScriptEditor/xmlEditor.js"></script>
<script src="script/ScriptEditor/editScript.js"></script>
<script src="lib/other/jquery.noty.packaged.min.js"></script>
<script src="script/scriptManager/uiFactory.js"></script>
</fmt:bundle>
</body>
</html>

View File

@ -1,90 +0,0 @@
var Container = function() {
this.pluginListContainer = $("#pluginList");
this.usePluginContainer = $("#usePlugin");
this.pluginParamConfigContainer = $("#pluginParams");
this.behaviorListForPlugin = $("#pluginMethod");
this.usePluginModal=$("#insertPluginAreaPlugins")
this.useBehaviorListContainer = $("#behaviorArea");
this.behaviorParamConfigContianer = $("#showPluginMethod");
};
var ListContainer = function(container) {
this.conteiner = container;
};
Container.prototype.createALine = function(name, index, list) {
var div = document.createElement("div");
var p = document.createElement("p");
var i = document.createElement("i");
var textNode = document.createTextNode(name);
div.setAttribute("id", name);
i.setAttribute("class", "icon-hand-right");
p.setAttribute("id", index);
p.setAttribute("class", "");
if (list == "pluginMethodList") {
p.setAttribute("onClick", "showMethodDocument(this)");// loadMethodParams
} else if (list == "pluginChoosedList") {
p.setAttribute("onClick", "choosePlugin(this);");// 此处用于显示plugin文档
} else if (list == "editPluginChoosedList") {
p.setAttribute("onClick", "chooseEditPlugin(this);");
}
p.setAttribute("style", "cursor:pointer;width:85%");
p.appendChild(i);
p.appendChild(textNode);
div.appendChild(p);
return div;
};
Container.prototype.showChoosedLines = function(container, clickNode) {
var choosedNode = container.children();
for ( var i = 0; i < choosedNode.length; i++) {
if (i == clickNode) {
$(choosedNode[i]).find("p").attr("class", "visited");
} else {
$(choosedNode[i]).find("p").attr("class", "");
}
}
};
Container.prototype.showChoosedParamInfos = function(container, clickNode) {
var div = container.children();// pluginParams
for ( var j = 0; j < div.length; j++) {
if (div[j].getAttribute("id") == clickNode) {
$(div[j]).show();
} else {
$(div[j]).hide();
}
}
};
Container.prototype.createBehaviorWithPluginLines = function(behavior) {
this.behaviorParamConfigContianer.html("");
this.useBehaviorListContainer.html("");
for ( var j = 0; j < behavior.behaviorWithPluginList.length; j++) {
var div = this.createALine(behavior.behaviorWithPluginList[j], j,
"pluginMethodList");
if (j == behavior.clickPluginBehaviorNode) {
$(div).find("p").attr("class", "visited");
}
document.getElementById('behaviorArea').appendChild(div);
behavior.useParamInforsContainerInit(j);
}
};
Container.prototype.createParamInforsContainer = function(data, name, index) {
var documentHtml = "";
var boxHeader = "";
var paramHtml = "";
boxHeader = "<div class='box-header well' data-original-title> "
+ "<i class='icon-pencil left'></i>" + "<h2>sample:<i>" + name
+ "</i></h2></div>";
if (data != null) {
paramHtml = createPluginsOrBehaviorsForm(data, index);
}
documentHtml = "<div id='" + index + "' class='hide'><p class='hide'>"
+ name + "</p><div class='span12 box' style='margin-left:-2px;'>"
+ boxHeader + "<div class='box-content'>" + paramHtml + "</div>"
+ "</div></div>";
return documentHtml;
};

View File

@ -1,395 +0,0 @@
var pluginNameList = new Array();
var parameters = [];
var parameterList = [];
var usePluginParamInfosList = [];
var pluginList;
var behaviorChoosed;
var behaviorName;
var pluginName;
var plugin_id;
var behavior_id;
var usePlugin = "";
function loadUsePluigns(data) {
pluginNameList.splice(0, pluginNameList.length);
for ( var i = 0; i < data.usePlugins.length; i++) {
var flag = false;
var usePlugin = data.usePlugins[i];
for ( var j = 0; j < pluginNameList.length; j++) {
if (pluginNameList[j] == usePlugin.id) {
flag = true;
}
}
if (flag == false) {
pluginNameList.push(usePlugin.id);
usePluginParamInfosList.push(usePlugin.id);
usePluginParamInfosList[usePlugin.id] = usePlugin.parameters;
}
}
var ulNode = document.getElementById("allPlugins");
for ( var p = 0; p < pluginNameList.length; p++) {
createALi(ulNode, pluginNameList[p], "choosePlugin");
}
loadBehaviors("all");
pluginList = loadPluginList();
usePluginParamInfosContainerInit();
}
function createALi(ulNode, name, action) {
var textNode = document.createTextNode(name);
var li = document.createElement("li");
var divider = document.createElement("li");
var a = document.createElement("a");
divider.setAttribute("class", "divider");
if (action == "choosePlugin") {
a.setAttribute("onClick", "choosePlugin(this);");
} else if (action == "chooseBehavior") {
a.setAttribute("onClick", "chooseBehavior(this);");
} else if (action == "chooseUsePlugin") {
a.setAttribute("onClick", "chooseUsePlugin(this)");
}
a.appendChild(textNode);
li.appendChild(a);
ulNode.appendChild(li);
ulNode.appendChild(divider);
}
function chooseUsePlugin(selectedNode) {
document.getElementById("action").style.display = "none";
document.getElementById("pluginParamArea").innerHTML = "";
usePlugin = selectedNode.firstChild.nodeValue;
createUsePluginParamInfosPage(usePlugin);
}
function usePluginParamInfosContainerInit() {
var ul = document.getElementById("usePlugin");
for ( var i = 0; i < usePluginParamInfosList.length; i++) {
var usePluginName = usePluginParamInfosList.valueOf()[i];
createALi(ul, usePluginName, "chooseUsePlugin");
}
}
function choosePlugin(selectedNode) {
pluginName = selectedNode.firstChild.nodeValue;
if (pluginName == "All") {
loadBehaviors("all");
} else {
loadBehaviors("other");
}
}
function loadBehaviors(mark) {
var ul = document.getElementById("behaviorUl");
$(ul).html("");
$.each(modelData.pages, function(i, item) {
$.each(item.batches, function(i, item) {
var Id = item.Id;
if (mark == "other") {
$.each(item.behaviors, function(i, item) {
if (item.use == pluginName) {
var text = item.use + ":" + Id + "." + item.name + ":"
+ item.id;
createALi(ul, text, "");
}
});
} else if (mark == "all") {
$.each(item.behaviors, function(i, item) {
var text = item.use + ":" + Id + "." + item.name + ":"
+ item.id;
createALi(ul, text, "chooseBehavior");
});
}
});
});
}
function chooseBehavior(selectedNode) {
document.getElementById("action").style.display = "none";
document.getElementById("showPluginMethodForm").innerHTML = "";
var behaviorMethod = selectedNode.firstChild.nodeValue;
var bm = behaviorMethod.split(".");
plugin_id = bm[0].split(":")[1];
behavior_id = bm[1].split(":")[1];
behaviorName = bm[1].split(":")[0];
createBehaviorParamPage(behaviorMethod);
}
function createUsePluginParamInfosPage(usePluginName) {
var pluginHtml = "";
var index = 0;
for ( var i = 0; i < pluginList.length; i++) {
var pluginInfoModel = pluginList[i].pluginInfoModel;
if (pluginInfoModel.name == usePluginName) {
index = i;
var paramInfoModels = pluginInfoModel.paramInfoModels;
for ( var j = 0; j < paramInfoModels.length; j++) {
var paramInfoModel = paramInfoModels[j];
pluginHtml += createModelByType(
usePluginParamInfosList[usePluginName], paramInfoModel,
index);
}
}
}
document.getElementById("pluginParamArea").innerHTML = createAEditText(
pluginHtml, usePluginName, index);
}
function createBehaviorParamPage(behaviorData) {
var plugin = "", method = "";
var behaviorHTML = "";
var paramInfoModels = null, paramInfoModel = null;
var behaviorParameters = [];
$
.each(
modelData.pages,
function(i, item) {
$
.each(
item.batches,
function(i, item) {
if (item.Id == plugin_id) {
$
.each(
item.behaviors,
function(i,
item) {
if (item.id == behavior_id) {
plugin = item.use;
method = item.name;
$
.each(
item.parameters,
function(
i,
item) {
behaviorParameters
.push(item.key);
behaviorParameters[item.key] = item.value;
});
var behaviorList = loadBehaviorList(plugin
.split("_")[0]);// List<BehaviorInfoModel>
for ( var j = 0; j < behaviorList.length; j++) {
if (behaviorList[j].name == method) {
paramInfoModels = behaviorList[j].paramInfoModels;
break;
}
}
for ( var k = 0; k < paramInfoModels.length; k++) {
paramInfoModel = paramInfoModels[k];
behaviorHTML += createParamInfoModelWithParams(
paramInfoModel,
behaviorParameters,
behavior_id);
}
}
});
}
});
});
document.getElementById("showPluginMethodForm").innerHTML = createAEditText(
behaviorHTML, behaviorData, behavior_id);
document.getElementById("action").style.display = "block";
nfieldCount = 0;
}
// 生成页面显示
function createAEditText(behaviorHTML, behaviorData, behavior_id) {
var documentHtml = "";
var boxHeader = "";
boxHeader = "<div class='box-header well' data-original-title> "
+ "<i class='icon-pencil left'></i>" + "<h2>sample:<i>"
+ behaviorData + "</i></h2></div>";
documentHtml = "<div id='"
+ behavior_id
+ "' class=''><p class='hide'>"
+ behaviorData
+ "</p><div class='span10 box' style='margin-left:15px;margin-top:-2px;'>"
+ boxHeader + "<div class='box-content'>" + behaviorHTML
+ "</div></div></div>";
return documentHtml;
}
function createParamInfoModelWithParams(paramInfoModel, behaviorParameters,
behaviorIndex) {
var name = paramInfoModel.name;
var value = behaviorParameters[name];
return createModelByType(value, paramInfoModel, behaviorIndex);
}
var nfieldCount = 0;
function createModelByType(value, paramInfoModel, behaviorIndex) {
var paramTypeModel = paramInfoModel.paramTypeModel;
var type = paramTypeModel.type;
var fieldHTML = "";
if (type == "field") {
var size = paramTypeModel.size;
fieldHTML += createField(paramInfoModel.lable, paramInfoModel.name,
size, value, behaviorIndex);
} else if (type == "nfield") {
var size = paramTypeModel.size;
fieldHTML += createMultiField(paramInfoModel.lable,
paramInfoModel.name, size, value, nfieldCount);
nfieldCount++;
} else if (type == "table") {
var cols = paramTypeModel.cols;
fieldHTML += createTable(paramInfoModel.lable, paramInfoModel.name,
cols, value, behaviorIndex);
} else if (type == "checkBox") {
var rows = paramTypeModel.choiceModels;
fieldHTML += createCheckBox(paramInfoModel.lable, paramInfoModel.name,
rows, value, behaviorIndex);
} else if (type == "radioButton") {
var rows = paramTypeModel.choiceModels;// List<ChoiceModel>
fieldHTML += createRadioButton(paramInfoModel.lable,
paramInfoModel.name, rows, value, behaviorIndex);
} else if (type == "file") {
fieldHTML += createFile(paramInfoModel.lable, paramInfoModel.name,
value, behaviorIndex);
}
return fieldHTML;
}
function loadBehaviorList(plugin) {
var behaviors = null;
$.ajax({
type : "GET",
url : "loadBehaviorList",
data : "pluginName=" + plugin,
dataType : "json",
async : false,
success : function(response) {
if (!response.success) {
information(response.failedMessage);
return;
}
behaviors = response.behaviors;
}
});
return behaviors;
}
function loadPluginList() {
var pluginList = null;
$.ajax({
type : 'POST',
url : 'loadPluginUIList',
data : {},
dataType : 'json',
async : false,
success : function(response) {
if (!response.success) {
information(response.failedMessage);
return;
}
pluginList = response.pluginUIs;// List<PluginUIModel>pluginUIModels
}
});
return pluginList;
}
$('#submitPlugin').click(function() {
// 保存pluginParmas
var div = document.getElementById("pluginParamArea");
saveFormModification(div, "plugin");
});
function saveFormModification(div, type) {
var contents = div.lastChild.lastChild.childNodes;
var length = contents.length;
for ( var i = 0; i < length; i++) {
var node = contents[i];
var key = "", value = "", temp = "";
if ($(node).attr("class") == "Field sample_frame") {
key = node.lastChild.firstChild.nodeValue;
temp = $(node).find("input").val();
if (temp != "") {
value = temp;
}
} else if ($(node).attr("class") == "NField sample_frame") {
key = node.firstChild.firstChild.nodeValue.split(":")[0];
var fieldNode = $(node).find("table").children();
var fieldLength = $(fieldNode).length;
for ( var j = 0; j < fieldLength; j++) {
temp = $(fieldNode[j]).find("input").val();
if (temp != "") {
value += temp;
}
if (j != fieldLength - 1) {
value += ";";
}
}
} else if ($(node).attr("class") == "Table sample_frame") {
key = node.lastChild.firstChild.nodeValue;
var table = $(node).find("table");
var col = table.find("th").length;
var row = table.find("tbody").children().length;
var tbody = $(node).find("tbody");
for ( var m = 0; m < row; m++) {
for ( var n = 0; n < col; n++) {
var rowNode = $(tbody).children()[m];
var colNode = $(rowNode).children()[n];
temp = $(colNode).find("input").val();
if (temp != "") {
value += temp + "|";
}
}
if (value != "") {
value += ";";
}
}
} else if ($(node).attr("class") == "CheckBox sample_frame") {
key = node.lastChild.firstChild.nodeValue;
var id = $(node).attr("id");
$('input[name=' + id + ']:checked').each(function() {
temp = $(this).val();
if (temp != "") {
value += temp + ";";
}
});
}
parameterList.push(key);
parameterList[key] = value;
}
if (type == "plugin") {
modifyJsonDataOfPlugin();
} else if (type == "behavior") {
modifyJsonDataOfBehavior();
}
}
function modifyJsonDataOfPlugin() {
$.each(item.usePlugins,
function(i, item) {
if (item.id == usePlugin) {
for ( var i = 0; i < parameterList.length; i++) {
var key = parameterList.valueOf()[i];
var parameterModel = new ParameterModel(key,
parameterList[key]);
item.parameters[i] = parameterModel;
}
}
});
parameterList.splice(0, parameterList.length);
}
function modifyJsonDataOfBehavior() {
$.each(modelData.pages, function(i, item) {
$.each(item.batches, function(i, item) {
if (item.Id == plugin_id) {
$.each(item.behaviors, function(i, item) {
if (item.id == behavior_id) {
for ( var i = 0; i < parameterList.length; i++) {
var key = parameterList.valueOf()[i];
var parameterModel = new ParameterModel(key,
parameterList[key]);
item.parameters[i] = parameterModel;
}
}
});
}
});
});
parameterList.splice(0, parameterList.length);
}

View File

@ -1,380 +0,0 @@
function createPluginsOrBehaviorsForm(data, behaviorIndex) {
var paramInfoList = new Array();// ParamInfoModel
var fieldHTML = "";
for (var i = 0; i < data.length; i++) {
paramInfoList.push(data[i]);
}
var nfieldCount = 0;
for (var j = 0; j < paramInfoList.length; j++) {
var paramTypeModel = paramInfoList[j].paramTypeModel;
var methodParamModel = new ParamInfoModel(paramInfoList[j].name,
paramInfoList[j].label, paramTypeModel);
var type = paramTypeModel.type;
if (type == "field") {
var size = paramTypeModel.size;
var text = paramTypeModel.text;
fieldHTML += createField(methodParamModel.label,
methodParamModel.name, size, text, behaviorIndex);
} else if (type == "nfield") {
var size = paramTypeModel.size;
var text = paramTypeModel.text;
fieldHTML += createMultiField(methodParamModel.label,
methodParamModel.name, size, text, nfieldCount);
nfieldCount++;
} else if (type == "table") {
var cols = paramTypeModel.cols;
fieldHTML += createTable(methodParamModel.label,
methodParamModel.name, cols, null, behaviorIndex);
} else if (type == "checkBox") {
var rows = paramTypeModel.choiceModels;
fieldHTML += createCheckBox(methodParamModel.label,
methodParamModel.name, rows, null, behaviorIndex);
} else if (type == "radioButton") {
var rows = paramTypeModel.choiceModels;// List<ChoiceModel>
fieldHTML += createRadioButton(methodParamModel.label,
methodParamModel.name, rows, null, behaviorIndex);
} else if (type == "file") {
var text = paramTypeModel.text;
fieldHTML += createFile(methodParamModel.label,
methodParamModel.name, text, behaviorIndex);
}
}
return fieldHTML;
}
function createFile(label, name, text, behaviorIndex) {
var divNode=document.createElement("div");
var p=document.createElement("p");
var labelNode = document.createTextNode(label);
var div = document.createElement("div");
var nameNode = document.createTextNode(name);
var input=$(document.createElement("input"));
$(divNode).attr("class", "File sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class", "sample_sub_frame");
input.attr("type","file");
input.attr("id","file"+behaviorIndex);
p.appendChild(labelNode);
div.appendChild(nameNode);
$(div).append(input);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;
}
function createField(label, name, size, text, behaviorIndex) {
if (size == 0) {
size = 10;
}
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(label);
var div = document.createElement("div");
var nameNode = document.createTextNode(name);
var input = document.createElement("input");
$(divNode).attr("class", "Field sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class", "sample_sub_frame");
$(input).attr("type", "text");
$(input).attr("size", size);
$(input).attr("id", name + "_input");
if (text != null) {
$(input).attr("value", text);
}
p.appendChild(labelNode);
div.appendChild(nameNode);
div.appendChild(input);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;
}
function createMultiField(label, name, size, text, behaviorIndex) {
if (size == 0) {
size = 10;
}
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(name + ":" + label);
var div = document.createElement("div");
var addFieldButton = document.createElement("button");
var addFieldNode = document.createTextNode($.i18n.prop("addField"));
var removeFieldButton = document.createElement("button");
var removeFieldNode = document.createTextNode($.i18n.prop("removeField"));
var br = document.createElement("br");
var table = document.createElement("table");
$(divNode).attr("class", "NField sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class", "sample_sub_frame");
$(addFieldButton).attr("type", "submit");
$(addFieldButton).attr("class", "btn-large");
$(addFieldButton).attr("onClick",
"addField(" + size + "," + behaviorIndex + "," + null + ");");
$(removeFieldButton).attr("type", "submit");
$(removeFieldButton).attr("class", "btn-large");
$(removeFieldButton).attr("onClick", "removeField(this)");
$(table).attr("id", "addFieldTable_" + behaviorIndex);
$(table).attr("class", "table-margin");
if (text != null) {
var content = text.split(";");
for (var i = 0; i < content.length; i++) {
createAFieldLine(10, i, behaviorIndex, content[i]);
}
}
p.appendChild(labelNode);
addFieldButton.appendChild(addFieldNode);
removeFieldButton.appendChild(removeFieldNode);
div.appendChild(addFieldButton);
div.appendChild(removeFieldButton);
div.appendChild(br);
div.appendChild(table);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;
}
function getFieldCount(addId) {
return $("#addFieldTable_" + addId).children().length;
}
function createAFieldLine(size, field, addId, value) {
var data = "field_" + field + ":";
var newTrNode = document.createElement("tr");
var newTdNode1 = document.createElement("td");
var newTdNode2 = document.createElement("td");
newTdNode1.setAttribute("class", data);
var textNode = document.createTextNode(data);
var inputNode = document.createElement("input");
inputNode.setAttribute("type", "text");
inputNode.setAttribute("size", size);
if (value != null) {
inputNode.setAttribute("value", value);
}
newTdNode1.appendChild(textNode);
newTdNode2.appendChild(inputNode);
newTrNode.appendChild(newTdNode1);
newTrNode.appendChild(newTdNode2);
return newTrNode;
}
function addField(size, addId, value) {
var field = getFieldCount(addId);
var newTrNode = createAFieldLine(size, field, addId, value);
document.getElementById("addFieldTable_" + addId).appendChild(newTrNode);
}
function removeField(selectedNode) {
var table = selectedNode.nextSibling.nextSibling;
var deletedNode = table.lastChild;
table.removeChild(deletedNode);
}
function createTable(label, name, cols, value, behaviorIndex) {
var table_content = cols.split(";");// table分隔符
var col = table_content.length;
var tableWidth = 300 / col;
var tr = document.createElement("tr");
for (var i = 0; i < col; i++) {
var th = document.createElement("th");
var text = document.createTextNode(table_content[i]);
th.appendChild(text);
tr.appendChild(th);
}
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(label);
var div = document.createElement("div");
var nameNode = document.createTextNode(name);
var br1 = document.createElement("br");
var br2 = document.createElement("br");
var addColButton = document.createElement("button");
var addColNode = document.createTextNode($.i18n.prop("addCol"));
var removeColButton = document.createElement("button");
var removeColNode = document.createTextNode($.i18n.prop("removeCol"));
var table = document.createElement("table");
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
if (value != null) {
value = value.split("|;");// 一行的信息
var row = value.length - 1;
for (var m = 0; m < row; m++) {
var colValue = value[m].split("|");// 一行中的每列信息
var trNode = document.createElement("tr");
for (var n = 0; n < col; n++) {
var tdNode = document.createElement("td");
var input = document.createElement("input");
input.setAttribute("size", 10);
input.setAttribute("type", "text");
input.setAttribute("style", "width:" + tableWidth + "px;");
input.setAttribute("value", colValue[n]);
tdNode.appendChild(input);
trNode.appendChild(tdNode);
}
tbody.appendChild(trNode);
}
}
$(divNode).attr("class", "Table sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class", "sample_sub_frame");
$(addColButton).attr("type", "submit");
$(addColButton).attr("class", "btn-large");
$(addColButton).attr("onClick", "addCol(this)");
$(addColButton).attr("id", tableWidth);
$(removeColButton).attr("type", "submit");
$(removeColButton).attr("class", "btn-large");
$(removeColButton).attr("onClick", "removeCol(this)");
$(table).attr("class", behaviorIndex + "_operateTableCols");
$(table).attr("class", "table-margin");
p.appendChild(labelNode);
addColButton.appendChild(addColNode);
removeColButton.appendChild(removeColNode);
thead.appendChild(tr);
table.appendChild(thead);
table.appendChild(tbody);
div.appendChild(nameNode);
div.appendChild(br1);
div.appendChild(addColButton);
div.appendChild(removeColButton);
div.appendChild(br2);
div.appendChild(table);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;
}
function addCol(selectedNode) {
var tableWidth = $(selectedNode).attr("id");
var tbody = selectedNode.nextSibling.nextSibling.nextSibling.lastChild;
var length = tbody.previousSibling.firstChild.childNodes.length;
var tr = document.createElement("tr");
for (var i = 0; i < length; i++) {
var td = document.createElement("td");
var input = document.createElement("input");
input.setAttribute("size", 10);
input.setAttribute("type", "text");
input.setAttribute("style", "width:" + tableWidth + "px;");
td.appendChild(input);
tr.appendChild(td);
}
tbody.appendChild(tr);
}
function removeCol(selectedNode) {
var tbody = selectedNode.nextSibling.nextSibling.lastChild;
var removeNode = tbody.lastChild;
tbody.removeChild(removeNode);
}
function createCheckBox(label, name, rows, value, behaviorIndex) {
var valueList = new Array();
var defaultList = new Array();
for (var j = 0; j < rows.length; j++) {
valueList.push(rows[j].value);
defaultList.push(rows[j].defaultValue);
}
if (value != null) {
value = value.split(";");
for (var m = 0; m < value.length; m++) {
for (var n = 0; n < rows.length; n++) {
if (valueList[n] == value[m]) {
defaultList[n] = true;
break;
}
}
}
}
var divNode = document.createElement("div");
var p = document.createElement("p");
var div = document.createElement("div");
var br = document.createElement("br");
var divInput = document.createElement("div");
var labelNode = document.createTextNode(label);
var nameNode = document.createTextNode(name);
$(divNode).attr("class", "CheckBox sample_frame");
$(divNode).attr("id", "checkbox_" + name + "_" + behaviorIndex);
$(div).attr("class", "sample_sub_frame");
$(divInput).attr("class", "sample_sub_frame");
p.appendChild(labelNode);
for (var i = 0; i < rows.length; i++) {
var checkBoxNode = document.createElement("input");
var brInput = document.createElement("br");
checkBoxNode.setAttribute("type", "checkbox");
checkBoxNode.setAttribute("name", "checkbox");
checkBoxNode.setAttribute("value", valueList[i]);
if (defaultList[i] == true) {
checkBoxNode.setAttribute("checked", "checked");
}
var checkBoxValue = document.createTextNode(valueList[i]);
divInput.appendChild(checkBoxNode);
divInput.appendChild(checkBoxValue);
divInput.appendChild(brInput);
}
div.appendChild(nameNode);
div.appendChild(br);
div.appendChild(divInput);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;
}
function createRadioButton(label, name, rows, value, behaviorIndex) {
var valueList = new Array();
var defaultList = new Array();
for (var i = 0; i < rows.length; i++) {
var choiceModel = rows[i];
valueList.push(choiceModel.value);
defaultList.push(choiceModel.defaultValue);
}
if(value!=null){
for(var m=0;m<rows.length;m++){
if(valueList[m]==value){
defaultList[m]=true;
break;
}
}
}
var divNode = document.createElement("div");
var p = document.createElement("p");
var div = document.createElement("div");
var br = document.createElement("br");
var divInput = document.createElement("div");
var labelNode = document.createTextNode(label);
var nameNode = document.createTextNode(name);
$(divNode).attr("class", "RadioButton sample_frame");
$(divNode).attr("id", "radio_" + name + "_" + behaviorIndex);
$(div).attr("class", "sample_sub_frame");
$(divInput).attr("class", "sample_sub_frame");
p.appendChild(labelNode);
for (var i = 0; i < valueList.length; i++) {
var checkBoxNode = document.createElement("input");
var brInput = document.createElement("br");
checkBoxNode.setAttribute("type", "radio");
checkBoxNode.setAttribute("name", "radio");
checkBoxNode.setAttribute("value", valueList[i]);
if (defaultValue[i] == true) {
checkBoxNode.setAttribute("checked", "checked");
}
var checkBoxValue = document.createTextNode(valueList[i]);
divInput.appendChild(checkBoxNode);
divInput.appendChild(checkBoxValue);
divInput.appendChild(brInput);
}
div.appendChild(nameNode);
div.appendChild(br);
div.appendChild(divInput);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;
}

View File

@ -1,30 +0,0 @@
function getvars() {
var vars = [], hash;
var hashes = window.location.href.slice(
window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
$(function() {
var jsonData = getvars()['jsonData'];
if(jsonData!=null){
showScriptByJsonData(jsonData);
}
});

View File

@ -1,42 +0,0 @@
var collectScriptData;
//function setTab(name, m, n) {
// for (var i = 1; i <= n; i++) {
// var menu = document.getElementById(name + i);
// var showDiv = document.getElementById("cont_" + name + "_" + i);
// menu.className = i == m ? "on" : "";
// showDiv.style.display = i == m ? "block" : "none";
// }
//}
function getScriptObject(scriptId,usePlugin) {
$.post("getScript", {
scriptId : scriptId
}, function(data) {
if (!data.success) {
information("failed to get script:" + data.failedMessage);
return;
} else {
var scriptObj = eval("(" + data.script + ")");
usePlugin.initPluginAndPages(scriptObj);
}
}, "json");
}
$(function() {
var scriptId = getvars()['scriptId'];
var usePlugin = new UsePlugin("useBehaviorList");
getScriptObject(scriptId,usePlugin);
$("#scriptName").val(getvars()['name']);
$("#tabs").tabs();
$("#submitScript").click(function() {
var plugins = usePlugin.getPlugins();
var pages = usePlugin.getPages();
updateScript(scriptId,pages,plugins);
});
});

View File

@ -1,98 +0,0 @@
function BehaviorInfoModel(paramInfoModels,behaviorType,name){
this.paramInfoModels=paramInfoModels;
this.behaviorType=behaviorType;
this.name=name;
}
function ParamInfoModel(name,label,paramTypeModel){
this.name=name;
this.label=label;
this.paramTypeModel=paramTypeModel;
}
function ScenarioModel(scriptName,runScenarioModel){
this.scriptName=scriptName;
this.runScenarioModel=runScenarioModel;
}
function RunScenarioModel(poolSize,usePlugins,definedParameters,pages){
this.poolSize=poolSize;
this.usePlugins=usePlugins;
this.definedParameters=definedParameters;
this.pages=pages;
}
function PageModel(id,batches){
this.id = id;
this.batches=batches;
}
function BatchModel(id,parentId,childId,behaviors){
this.id=id;
this.parentId=parentId;
this.childId=childId;
this.behaviors=behaviors;
}
/**
* @param id
* @param use
* @param name
* @param type
* @param parameters
*/
function BehaviorModel(id, use, name, type, parameters) {
this.id = id;
this.use = use;
this.name = name;
this.type = type;
this.parameters = parameters;
}
function ParameterModel(key, value) {
this.key = key;
this.value = value;
}
/**
* @param id
* @param name
* @param nickName
* @param parameters
*/
function UsePluginModel(id, name, nickName, parameters) {
this.id = id;
this.name = name;
this.nickName = nickName;
this.parameters = parameters;
}
function PluginEditScriptRequestModel(behaviorModels, usePluginModels,
scriptName) {
this.behaviorModels = behaviorModels;
this.usePluginModels = usePluginModels;
this.scriptName = scriptName;
}
function MethodParamModel(name, lable, valueSeperator, fieldSeperator,
paramType, methodParamProperties) {
this.name = name;
this.lable = lable;
this.valueSeperator = valueSeperator;
this.fieldSeperator = fieldSeperator;
this.paramType = paramType;
this.methodParamProperties = methodParamProperties;
}
function MethodParamPropertyModel(key, value) {
this.key = key;
this.value = value;
}
function pluignChoosedModel(pluginName, index) {
this.pluginName = pluginName;
this.index = index;
}

View File

@ -1,197 +0,0 @@
var behaviors = new Array();
var usePluginList = new Array();
var pageList = new Array();
function submit(selectedNode) {
var scriptName = $(selectedNode.parentNode.parentNode).find("input").val();
saveBehaviorInfo();
savePluginInfo();
if (validateBehaviors(behaviors)) {
submitScriptWithScriptName(scriptName);
}
}
function saveBehaviorInfo() {
var children = document.getElementById("showPluginMethod").childNodes;
var length = children.length;
if (length != 0) {
saveParamInfoWithSubmit(children, length, "behavior");
}
}
function savePluginInfo() {
var pluginChildren = document.getElementById("pluginParams").childNodes;
var pluginLength = pluginChildren.length;
if (pluginLength != 0) {
saveParamInfoWithSubmit(pluginChildren, pluginLength, "plugin");
}
}
function validateBehaviors(behaviors) {
return (behaviors.length != 0 || behaviors != null);
}
function saveParamInfoWithSubmit(children, length, type) {
for ( var i = 0; i < length; i++) {
for ( var j = 0; j < length; j++) {
var node = children[j];
if ($(node).attr("id") == i) {
if (type == "behavior") {
saveABehavior(node);
} else if (type == "plugin") {
saveAPlugin(node);
}
break;
}
}
}
}
function saveAPlugin(node) {
var id = node.firstChild.firstChild.nodeValue;
var name = id.split("_")[0];
var div = node.lastChild.lastChild.childNodes;
var parameters = saveParamInfo(div);
var usePluginModel = new UsePluginModel(id, name, parameters);
usePluginList.push(usePluginModel);
}
function saveABehavior(node) {
var div = node.lastChild.lastChild.childNodes;
var behaviorIndex = 0;
var use = "", name = "", type = "";
var plugin_method = node.firstChild.firstChild.nodeValue.split(".");
name = plugin_method[1];
use = plugin_method[0];
if (use.split("_")[0] == "ConstantTimer") {
type = "TIMERBEHAVIOR";
} else {
type = "USERBEHAVIOR";
}
var parameters = saveParamInfo(div);
var behaviorModel = new BehaviorModel(behaviorIndex, use, name, type,
parameters);
behaviors.push(behaviorModel);
}
// 封装到parameters中保存参数
function saveParamInfo(div) {
var length = div.length;
var parameters = new Array();
for ( var i = 0; i < length; i++) {
var node = div[i];
var parameterModel;
var key = "", value = "", temp = "";
if ($(node).attr("class") == "Field sample_frame") {
key = node.lastChild.firstChild.nodeValue;
temp = $(node).find("input").val();
if (temp != "") {
value = temp;
}
} else if ($(node).attr("class") == "NField sample_frame") {
key = node.firstChild.firstChild.nodeValue.split(":")[0];
var fieldNode = $(node).find("table").children();
var fieldLength = $(fieldNode).length;
for ( var j = 0; j < fieldLength; j++) {
temp = $(fieldNode[j]).find("input").val();
if (temp != "") {
value += temp;
}
if (j != fieldLength - 1) {
value += ";";
}
}
} else if ($(node).attr("class") == "Table sample_frame") {
key = node.lastChild.firstChild.nodeValue;
var table = $(node).find("table");
var col = table.find("th").length;
var row = table.find("tbody").children().length;
var tbody = $(node).find("tbody");
for ( var m = 0; m < row; m++) {
for ( var n = 0; n < col; n++) {
var rowNode = $(tbody).children()[m];
var colNode = $(rowNode).children()[n];
temp = $(colNode).find("input").val();
if (temp != "") {
value += temp + "|";
}
}
if (value != "") {
value += ";";
}
}
} else if ($(node).attr("class") == "CheckBox sample_frame") {
key = node.lastChild.firstChild.nodeValue;
$('input[name= "checkbox"]:checked').each(function() {
temp = $(this).val();
if (temp != "") {
value += temp + ";";
}
});
} else if ($(node).attr("class") == "RadioButton sample_frame") {
key = node.lastChild.firstChild.nodeValue;
temp = $('input[name="radio"]:checked').val();
if (temp != "") {
value += temp + ";";
}
}
if (value != "") {
parameterModel = new ParameterModel(key, value);
parameters.push(parameterModel);
}
}
return parameters;
}
function makePageList(behaviors) {
var batch = new BatchModel(0, -1, -1, behaviors);
var batchList = new Array();
batchList.push(batch);
var page = new PageModel(batchList);
pageList.push(page);
}
function submitScriptByAjax(scriptModel) {
var formData = new FormData();
var filesDiv = $("input[type=file]");
console.log(filesDiv);
if (filesDiv.length != 0) {
for ( var i = 0; i < filesDiv.length; i++) {
formData.append("paramFiles", filesDiv[i].files[0],
filesDiv[i].files[0].name);
}
}
formData.append("content", JSON.stringify(scriptModel));
$.ajax({
url : "uploadScript",
type : "POST",
contentType : false,
processData : false,
data : formData,
success : function(data) {
information("upload success");
window.location.replace("script.jsp");
}
});
}
function submitScriptWithScriptName(scriptName) {
if (scriptName == null || scriptName == "") {
information("Please input scriptName.");
return;
}
if (behaviors.length == 0) {
information("Please save the behavior or fill in the form.");
return;
} else {
var n = behaviors.length;
information("you have save " + n + " behaviors");
}
makePageList(behaviors);
var runScenarioModel = new RunScenarioModel(0, usePluginList, null,
pageList);
var scriptModel = new ScenarioModel(scriptName, runScenarioModel);
submitScriptByAjax(scriptModel);
}

View File

@ -1,14 +0,0 @@
function createLineWithRadio(lineText, nameAttr) {
var textNode = document.createTextNode(lineText);
var divNode = document.createElement("div");
var inputNode = document.createElement("input");
var brNode = document.createElement("br");
inputNode.setAttribute("type", "radio");
inputNode.setAttribute("name", nameAttr);
inputNode.setAttribute("class", "chooseOnePlugin");
inputNode.setAttribute("value", lineText);
divNode.appendChild(inputNode);
divNode.appendChild(textNode);
divNode.appendChild(brNode);
return $(divNode).html() + "<br>";
}

View File

@ -1,140 +0,0 @@
var Behavior = function(containerManager, plugin) {
this.containerManager = containerManager;
this.plugin = plugin;
this.clickPluginBehaviorNode = -1;
this.insertLocation = "after";
this.behaviorList = [];// 存放所有方法及其对应的parameter
this.behaviorWithPluginList = new Array();
};
Behavior.prototype.setClickPluginBehaviorNode = function(
clickPluginBehaviorNode) {
this.clickPluginBehaviorNode = clickPluginBehaviorNode;
};
Behavior.prototype.usePluginListContainerInit = function(insertLocation,
container) {
var chooesedPluginHtml = "";
this.setInsertLocation(insertLocation);
for ( var i = 0; i < this.plugin.usePluginList.length; i++) {
chooesedPluginHtml += createLineWithRadio(this.plugin.usePluginList[i],
"plugin");
}
container.html(chooesedPluginHtml);// insertPluginAreaPlugins
};
Behavior.prototype.setInsertLocation = function(insertLocation) {
this.insertLocation = insertLocation;
};
Behavior.prototype.loadBehaviorList = function(plugin) {
var behaviors = null;
$.ajax({
type : "GET",
url : "loadBehaviorList",
data : "pluginName=" + plugin,
dataType : "json",
async : false,
success : function(response) {
if (!response.success) {
information(response.failedMessage);
return;
}
behaviors = response.behaviors;
}
});
return behaviors;
};
Behavior.prototype.getBehaviorListOfOnePlugin = function(pluginName) {
var behaviorHtml = "";
this.behaviorList.splice(0, this.behaviorList.length);
var behaviors = this.loadBehaviorList(pluginName.split("_")[0]);
for ( var i = 0; i < behaviors.length; i++) {
this.behaviorList.push(behaviors[i].name);
this.behaviorList[behaviors[i].name] = behaviors[i].paramInfoModels;
behaviorHtml += createLineWithRadio(behaviors[i].name, "method");
}
this.containerManager.behaviorListForPlugin.html(behaviorHtml);
};
Behavior.prototype.useBehaviorOfOnePluginContainerInit = function(plugin,
behaivor) {
var behaviorWithPlugin = plugin + "." + behaivor;
var length = this.behaviorWithPluginList.length;
var documentChild = this.containerManager.behaviorParamConfigContianer
.children();
if (this.insertLocation == "before") {
for ( var j = length - 1; j > parseInt(this.clickPluginBehaviorNode - 1); j--) {
information("j=" + j);
this.behaviorWithPluginList[j + 1] = this.behaviorWithPluginList[j];
$(documentChild[j]).attr("id", parseInt(j + 1));
}
this.behaviorWithPluginList[parseInt(this.clickPluginBehaviorNode)] = behaviorWithPlugin;
this
.setClickPluginBehaviorNode(parseInt(this.clickPluginBehaviorNode + 1));
} else if (this.insertLocation == "after") {
if (this.clickPluginBehaviorNode == parseInt(length - 1)
|| this.clickPluginBehaviorNode == -1) {
this.behaviorWithPluginList.push(behaviorWithPlugin);
} else {
for ( var j = parseInt(length - 1); j > parseInt(this.clickPluginBehaviorNode); j--) {
this.behaviorWithPluginList[j + 1] = this.behaviorWithPluginList[j];
$(documentChild[j]).attr("id", parseInt(j + 1));
}
this.behaviorWithPluginList[parseInt(this.clickPluginBehaviorNode + 1)] = behaviorWithPlugin;
}
}
$('#myModal_Behavior').modal('hide');
};
Behavior.prototype.createBehaviorWithPluginLines = function() {
this.containerManager.behaviorParamConfigContianer.html("");
this.containerManager.useBehaviorListContainer.html("");
for ( var j = 0; j < this.behaviorWithPluginList.length; j++) {
var div = this.containerManager.createALine(
this.behaviorWithPluginList[j], j, "pluginMethodList");
if (j == this.clickPluginBehaviorNode) {
$(div).find("p").attr("class", "visited");
}
document.getElementById('behaviorArea').appendChild(div);
this.useParamInforsContainerInit(j);
}
};
Behavior.prototype.useParamInforsContainerInit = function(index) {
var behaviorName = this.behaviorWithPluginList[index].split('.')[1];
document.getElementById("showPluginMethod").innerHTML += this.containerManager
.createParamInforsContainer(this.behaviorList[behaviorName],
this.behaviorWithPluginList[index], index);
};
Behavior.prototype.removeInsertPluginByClicked = function() {
var length = $('#behaviorArea').children().length;
for ( var i = parseInt(this.clickPluginBehaviorNode + 1); i < length; i++) {
this.behaviorWithPluginList[i - 1] = this.behaviorWithPluginList[i];
}
this.behaviorWithPluginList.splice(length - 1, 1);
if (this.behaviorWithPluginList.length == 0) {
this.setClickPluginBehaviorNode(-1);
}
};
Behavior.prototype.removeUseBehaviorWithPluginParamInfo = function() {
var removeDocumentNode = $("#showPluginMethod").children();
for ( var j = 0; j < length; j++) {
if ($(removeDocumentNode[j]).attr("id") == this.clickPluginBehaviorNode) {
document.getElementById("showPluginMethod").removeChild(
removeDocumentNode[j]);
}
}
};
Behavior.prototype.clearBehaviorWithPluginList = function() {
this.behaviorWithPluginList.splice(0, this.behaviorWithPluginList.length);
this.setClickPluginBehaviorNode(-1);
$('#behaviorArea').html("");
$('#showPluginMethod').html("");
$('#submitBehaviors').attr("class", "hide");
};

View File

@ -1,147 +0,0 @@
var Plugin = function(containerManager) {
this.pluginList = null;
this.pluginIndex = new HashMap();
this.usePluginList = new Array();
this.pluginParamInfoList = [];
this.clickPluginChoosedNodeIndex = 0;
this.clickPluginChoosedNodeName = "";
this.loadPluginNameList();
this.loadPluginUIList();
this.setPluginParamInfoList();
this.containerManager = containerManager;
};
Plugin.prototype.loadPluginNameList = function() {
var plugin = this;
$.ajax({
type : 'POST',
url : 'loadPluginName',
data : {},
dataType : 'json',
async : false,
success : function(response) {
if (!response.success) {
information(response.failedMessage);
return;
}
var pluginNameList = response.pluginNames;
for ( var i = 0; i < pluginNameList.length; i++) {
plugin.pluginIndex.put(pluginNameList[i], -1);
}
pluginListContainerInit($("#pluginList"), pluginNameList);
}
});
function pluginListContainerInit(container, pluginNameList) {
var pluginListHtmlContent = "";
for ( var i = 0; i < pluginNameList.length; i++) {
pluginListHtmlContent += createLineWithRadio(pluginNameList[i],
"plugin");
}
container.html(pluginListHtmlContent);
}
};
Plugin.prototype.loadPluginUIList = function() {
var plugin = this;
$.ajax({
type : 'POST',
url : 'loadPluginUIList',
data : {},
dataType : 'json',
async : false,
success : function(response) {
if (!response.success) {
information(response.failedMessage);
return;
}
plugin.pluginList = response.pluginUIs;// List<PluginUIModel>pluginUIModels
}
});
};
Plugin.prototype.addUsePlugin = function(item) {
this.pluginIndex.put(item, this.pluginIndex.get(item) + 1);
var pluginName = createUsePluginName(item, this.pluginIndex.get(item));
this.usePluginList.push(pluginName);
$("#usePlugin").append(
createLine(pluginName, usePluginList.length, "pluginChoosedList"));
function createUsePluginName(pluginName, index) {
return pluginName + '_' + index;
}
function createLine(name, index, list) {
var div = document.createElement("div");
var p = document.createElement("p");
var i = document.createElement("i");
var textNode = document.createTextNode(name);
div.setAttribute("id", name);
i.setAttribute("class", "icon-hand-right");
p.setAttribute("id", index);
p.setAttribute("class", "");
if (list == "pluginMethodList") {
p.setAttribute("onClick", "showMethodDocument(this)");// loadMethodParams
} else if (list == "pluginChoosedList") {
p.setAttribute("onClick", "choosePlugin(this);");// 此处用于显示plugin文档
} else if (list == "editPluginChoosedList") {
p.setAttribute("onClick", "chooseEditPlugin(this);");
}
p.setAttribute("style", "cursor:pointer;width:85%");
p.appendChild(i);
p.appendChild(textNode);
div.appendChild(p);
return $(div);
}
};
Plugin.prototype.setClickPluginChoosedNodeIndex = function(selectedNode) {
this.clickPluginChoosedNodeIndex = $(selectedNode).attr("id");
};
Plugin.prototype.setClickPluginChoosedNodeName = function(selectedNode) {
this.clickPluginChoosedNodeName = selectedNode.lastChild.nodeValue;
};
Plugin.prototype.setPluginParamInfoList = function() {
for ( var i = 0; i < this.pluginList.length; i++) {
var pluginInfoModel = this.pluginList[i].pluginInfoModel;
this.pluginParamInfoList.push(pluginInfoModel.name);
this.pluginParamInfoList[pluginInfoModel.name] = pluginInfoModel.paramInfoModels;
}
};
Plugin.prototype.usePluginParamInfosContainerInit = function(item) {
var data = this.pluginParamInfoList[item];
document.getElementById("pluginParams").innerHTML += this.containerManager
.createParamInforsContainer(data,
this.usePluginList[this.usePluginList.length - 1],
this.usePluginList.length - 1);
};
Plugin.prototype.removeUsePluginByClicked = function(container) {
for ( var i = parseInt(this.clickPluginChoosedNodeIndex + 1); i < this.usePluginList.length; i++) {
this.usePluginList[i - 1] = this.usePluginList[i];
}
this.usePluginList.splice(length - 1, 1);
};
Plugin.prototype.removeUsePluginParamInfos = function() {
var removeDocumentNode = document.getElementById("pluginParams").childNodes;
for ( var i = 0; i < removeDocumentNode.length; i++) {
if ($(removeDocumentNode[i]).attr("id") == this.clickPluginChoosedNodeIndex) {
document.getElementById("pluginParams").removeChild(
removeDocumentNode[i]);
break;
}
}
};
Plugin.prototype.clearUsePluginContainer = function() {
this.usePluginList.splice(0, this.usePluginList.length);
for ( var i = 0; i < this.pluginNameList.length; i++) {
this.pluginIndex.put(this.pluginNameList[i], 0);
}
};

View File

@ -1,61 +0,0 @@
//var modelData;
//var editor;
//
//function setTab(name, m, n) {
// for ( var i = 1; i <= n; i++) {
// var menu = document.getElementById(name + i);
// var showDiv = document.getElementById("cont_" + name + "_" + i);
// menu.className = i == m ? "on" : "";
// showDiv.style.display = i == m ? "block" : "none";
// }
//}
//
//function getScript(scriptId) {
//
// $.post("getScriptXml", {
// scriptId : scriptId
// }, function(data) {
// if (!data.success) {
// alert("failed to get script:" + data.failedMessage);
// return;
// } else {
// YUI().use('aui-ace-editor', function(Y) {
// editor = new Y.AceEditor({
// boundingBox : '#codeEditor',
// mode : 'xml',
// value : data.script ,
// height : '500',
// width : '800'
// }).render();
// editor.set("showPrintMargin",false);
// editor.set("width",1000);
// });
//
//
// }
//
// }, "json")
//}
//
//$(function() {
// var scriptId = getvars()['scriptId'];
// getScript(scriptId);
//
// $("#tabs").tabs();
//
// $("#submitScript").click(function() {
// var script = editor.getSession().getValue();
//
// $.post("updateScript", {
// scriptId : scriptId,
// script : vkbeautify.xmlmin(script)
// }, function(data) {
// if (data.success) {
// alert($.i18n.prop("script-save"))
// } else {
// alert($.i18n.prop('fail'));
// }
//
// });
// });
//});

View File

@ -1,66 +0,0 @@
var ContainerFactory = function() {
};
ContainerFactory.prototype.createEditorContainer = function(header, id,
containerInfo) {
var container = document.createElement("div");
$(container).addClass("containerBox");
if (id != null) {
$(container).attr("id", id);
}
var containerHeader = document.createElement("p");
$(containerHeader).addClass("header");
var img = document.createElement("img");
$(containerHeader).append(img);
$(containerHeader).append(document.createTextNode(header));
$(container).append(containerHeader);
for ( var i = 0; i < containerInfo.length; i++) {
if (containerInfo[i].children == null) {
this.appendEdtiors(container, containerInfo[i].label,
containerInfo[i].name, containerInfo[i].paramTypeModel);
}
else {
$(container).append(
this.createEditorContainer(containerInfo[i].name, null,
containerInfo[i].children));
}
}
return container;
};
ContainerFactory.prototype.appendEdtiors = function(container, label, name,
editorInfo) {
var editorFactory = new EditorFactory();
if (editorInfo.type.toLowerCase() == "field") {
$(container).append(
editorFactory.createField(label, name, editorInfo.size, name));
} else if (editorInfo.type.toLowerCase() == "nfield") {
$(container).append(
editorFactory.createMultiField(label, name, editorInfo.size,
name));
} else if (editorInfo.type.toLowerCase() == "table") {
$(container).append(
editorFactory.createTable(label, name, editorInfo.cols, name));
} else if (editorInfo.type.toLowerCase() == "file") {
$(container).append(
editorFactory.createFile(lable, name, editorInfo.size, name));
} else if (editorInfo.type.toLowerCase() == "date") {
$(container).append(
editorFactory.createDate(label, name, editorInfo.size, name));
} else if (editorInfo.type.toLowerCase() == "select") {
$(container).append(
editorFactory.createSelect(label, name, editorInfo.size,
editorInfo.options, name));
} else {
information("no such editor type:" + editorInfo.type);
}
};

View File

@ -1,164 +0,0 @@
var Parameter = function(key, value) {
this.key = key;
this.value = value;
}
var DataCollector = function() {
};
DataCollector.prototype.fieldData = function(editor) {
editor = $(editor.children('.field'));
var name = editor.children("label").html();
var value = editor.children("input").val();
if (value == null || value == "") {
information("please input data in " + editor.attr("id"));
return;
}
return new Parameter(name, value);
};
DataCollector.prototype.dateData = function(editor) {
var name = editor.children("label").html();
var value = editor.children("input").val();
if (value == null || value == "") {
information("please input data in " + editor.attr("id"));
return;
}
return new Parameter(name, value);
};
DataCollector.prototype.multiFieldData = function(editor) {
var editorArray = editor.children(".field");
if (ediotrArray.size == 0) {
information("please input data in " + editor.attr("id"));
return;
}
var name = editor.attr("id")
var value = "";
for ( var i = 0; i < editorArray.length; i++) {
var filedValue = $(editorArray[i]).children("input").val();
if (filedValue == null || filedValue == "") {
information("please input data in" + editor.attr("id"));
return;
}
value += fieldVlaue + ";";
}
value = value.substring(0, value.length - 1);
return new Parameter(name, value);
};
DataCollector.prototype.tableData = function(editor) {
var editorArray = editor.find("tbody").children("tr");
var name = editor.attr("id");
var value = "";
for ( var i = 0; i < editorArray.length; i++) {
var tdArray = $(editorArray[i]).children("td");
var trValue = "";
for ( var j = 1; j < tdArray.length; j++) {
trValue += $(tdArray[j]).children("input").val() + "|";
}
trValue = trValue.substring(0, trValue.length - 1);
value += trValue + ";";
}
value = value.substring(0, value.length - 1);
return new Parameter(name, value);
};
DataCollector.prototype.selectData = function(editor) {
var name = editor.attr("id");
var value = editor.children("select").val();
return new Parameter(name, value);
};
DataCollector.prototype.getUnitParams = function(paramEditors) {
var params = new Array();
for ( var i = 0; i < paramEditors.length; i++) {
var editor = $(paramEditors[i]);
var editorType = editor.attr("editorType");
if (editorType == "field") {
params.push(this.fieldData(editor));
} else if (editorType == "date") {
params.push(this.dateData(editor));
} else if (editorType == "multiField") {
params.push(this.multiFieldData(deditor));
} else if (editorType == "table") {
params.push(this.tableData(editor));
} else if (editorType == "select") {
params.push(this.selectData(editor));
}
}
return params;
};
var BehaviorData = function(name, usePlugin, type, parameters) {
this.name = name;
this.type = type;
this.use = usePlugin;
this.parameters = parameters;
};
function getBehaviorNames(usePlugins) {
var behaviorNames = new Array();
var behaviorName = "Send";
for ( var i = 0; i < usePlugins.length; i++) {
behaviorNames.push(usePlugins[i].id + "_" + behaviorName);
}
return behaviorNames;
};
function getBehaviorDatas(behaviorNames) {
var behaviors = new Array();
var behaviorEditor = $("#behaviors").children(".containerBox");
var type = "USERBEHAVIOR";
for ( var i = 0; i < behaviorNames.length; i++) {
behaviors.push(getBehaviorData(behaviorEditor, behaviorNames[i], type));
}
return behaviors;
function getBehaviorData(editor, behaviorName, type) {
var paramEditors = editor.find(".editor");
var names = behaviorName.split("_");
var usePlugin = names[0];
var behavior = names[1];
var dataCollector = new DataCollector();
var params = dataCollector.getUnitParams(paramEditors);
var behavior = new BehaviorData(behavior, usePlugin, type, params);
return behavior;
}
;
};
var PluginData = function(id, name, params) {
this.id = id;
this.name = name;
this.parameters = params;
}
function getPluginDatas() {
var pluginContainers = $("#devices").children(".containerBox");
var separators = $("#devices").children(".separator");
var plugins = new Array();
var pluginCount = -1;
var pluginName = "hbase";
for ( var i = 0; i < pluginContainers.length; i++) {
var deviceSize = $(separators[i]).children("input").val();
if (deviceSize == null || deviceSize == "") {
information("no device config");
return [];
}
var dataCollector = new DataCollector();
var params = dataCollector.getUnitParams($(pluginContainers[i]).find(".editor"));
for ( var j = 1; j <= deviceSize; j++) {
pluginCount++;
var id=pluginName+pluginCount;
plugins.push(new PluginData(id, pluginName,params));
}
}
return plugins;
}

View File

@ -1,51 +0,0 @@
var DeviceFactory = function(deviceEditorInfo, container, behaviorEditorInfo) {
this.deviceEditorInfo = deviceEditorInfo;
this.container = container;
this.behaviorEditorInfo = behaviorEditorInfo;
};
DeviceFactory.prototype.createDevice = function(header, id) {
var deviceSizeConfig = this.createDeviceSizeConfig();
var containerFactory = new ContainerFactory();
var deviceContainer = containerFactory.createEditorContainer(header, id,
this.deviceEditorInfo);
var behaviorFactory = new BehaviorFactory(this.container);
behaviorFactory.createBehavior("Device Data Sender", "behavior",
this.behaviorEditorInfo);
this.container.prepend(deviceContainer);
this.container.prepend(deviceSizeConfig);
};
DeviceFactory.prototype.createDeviceSizeConfig = function() {
var deviceSizeConfig = document.createElement("div");
$(deviceSizeConfig).addClass("separator");
var label = document.createElement("label");
$(label).html("Device Size:");
var input = document.createElement("input");
$(input).attr("type", "text");
$(deviceSizeConfig).append(label);
$(deviceSizeConfig).append(input);
return deviceSizeConfig;
}
var BehaviorFactory = function(container) {
this.container = container;
};
BehaviorFactory.prototype.createBehavior = function(header, id, editorInfo) {
var title = this.createTitle();
var containerFactory = new ContainerFactory();
var editorContainer = containerFactory.createEditorContainer(header, id,
editorInfo);
this.container.prepend(editorContainer)
this.container.prepend(title);
};
BehaviorFactory.prototype.createTitle = function() {
var title = document.createElement("div");
$(title).addClass("separator");
$(title).attr("style", "color:#4183c4")
$(title).html("Configure Device Data Sender")
return title;
}

View File

@ -1,233 +0,0 @@
var EditorFactory = function() {
};
EditorFactory.prototype.createBaseEditor = function(label, id) {
if (label == null) {
label = "";
}
var containerBox = document.createElement("div");
$(containerBox).addClass("containerBox");
var boxHeader = document.createElement("div");
var p = document.createElement("p")
$(p).html(label)
$(boxHeader).append(p);
$(boxHeader).addClass("header")
$(containerBox).append(boxHeader);
var boxBody = document.createElement("div");
$(boxBody).addClass("editor");
$(boxBody).attr("id", id);
$(containerBox).append(boxBody);
return containerBox;
}
EditorFactory.prototype.createField = function(label, name, size, id) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "field");
$(div).children(".editor").append(this.createFieldLine(size, name));
return div;
}
EditorFactory.prototype.createMultiField = function(label, name, size, id) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "multiField");
$(div).children(".editor").append(this.createFieldLine(size, name));
var editorFactory = this;
var addFieldButton = document.createElement("button");
$(addFieldButton).html("add")
$(addFieldButton).attr("type", "submit");
$(addFieldButton).click(
{
editorFactory : editorFactory
},
function(event) {
event.preventDefault()
$(event.data.editorFactory.createFieldLine(size, name))
.insertBefore($(this));
});
var removeFieldButton = document.createElement("button");
$(removeFieldButton).html("remove")
$(removeFieldButton).attr("type", "submit");
$(removeFieldButton).click(function(event) {
event.preventDefault();
$(this).parent().children(".field").last().remove();
});
$(div).children(".editor").append(addFieldButton).append(removeFieldButton);
return div;
}
EditorFactory.prototype.createFieldLine = function(size, name) {
if (size == null || size <= 0) {
size = 150;
}
var fieldDiv = document.createElement("div");
$(fieldDiv).addClass("field");
var fieldName = document.createElement("label");
$(fieldName).html(name);
var field = document.createElement("input");
$(field).attr("type", "text");
$(field).attr("style", "width:" + size + "px");
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
}
EditorFactory.prototype.createFile = function(label, name, size, id) {
if (size == null || size <= 0) {
size = 150;
}
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "file");
var fileEditor = document.createElement("div");
var fieldName = document.createElement("label");
$(fieldName).html(name);
var file = document.createElement("input");
$(file).attr("type", "file");
$(file).attr("style", "width:" + size + "px");
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).children(".editor").append(fileEditor);
return div;
}
EditorFactory.prototype.createTable = function(label, name, cols, id) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "table");
var headers = getHeaders(cols);
$(div).children(".editor").append(createTable(cols, name, headers));
var addButton = document.createElement("button");
$(addButton).html("add");
$(addButton).click(
{
headers : headers,
fieldName : name
},
function(event) {
event.preventDefault();
$(this).parent().children("table").children("tbody").append(
createTr(event.data.headers, event.data.fieldName));
});
var deleteButton = document.createElement("button");
$(deleteButton).html("remove");
$(deleteButton).click(
function(event) {
event.preventDefault();
$(this).parent().children("table").children("tbody").children(
"tr").last().remove();
});
$(div).children(".editor").append(addButton);
$(div).children(".editor").append(deleteButton);
return div;
function getHeaders(col) {
var headers = new Array();
headers.push("name:");
var cols = col.split(";");
for ( var i = 0; i < cols.length; i++) {
headers.push(cols[i]);
}
return headers;
}
function createTable(cols, name, headers) {
var table = document.createElement("table");
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
$(thead).append(createHeader(headers));
$(tbody).append(createTr(headers, name));
$(table).append(thead);
$(table).append(tbody);
return table;
}
function createHeader(headers) {
var tr = document.createElement("tr");
for ( var i = 0; i < headers.length; i++) {
var th = document.createElement("th");
$(th).append(document.createTextNode(headers[i]));
$(th).attr("style", "width:" + 100 / headers.length + "%")
$(tr).append(th);
}
return tr;
}
function createTr(headers, name) {
var tr = document.createElement("tr");
var td = document.createElement("td");
$(td).attr("style", "width:" + 100 / headers.length + "%")
$(td).html(name);
$(tr).append(td);
for ( var i = 1; i < headers.length; i++) {
var input = document.createElement("input");
$(input).attr("type", "text");
var td = document.createElement("td");
$(td).attr("style", "width:" + 100 / headers.length + "%")
$(td).append(input);
$(tr).append(td);
}
return tr;
}
}
EditorFactory.prototype.createSelect = function(label, name, size, options, id) {
if (size == null || size <= 0) {
size = 150;
}
if (options == null || options.length <= 0) {
information("no options in:" + name);
}
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "select");
var nameLabel = document.createElement("label");
$(nameLabel).html(name);
$(div).children(".editor").append(nameLabel);
var select = document.createElement("select");
$(select).attr("style", "width:" + size + "px");
for ( var i = 0; i < options.length; i++) {
var option = document.createElement("option");
$(option).attr("value", options[i]);
$(option).html(options[i]);
$(select).append(option);
}
$(div).children(".editor").append(select);
return div;
}
EditorFactory.prototype.createDate = function(label, name, size, id) {
if (size == null || size < 0) {
size = 150
}
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType","date");
var dateLabel = document.createElement("label");
$(dateLabel).html(name);
var date = document.createElement("input");
$(date).attr("type", "date");
$(div).children(".editor").append(dateLabel);
$(div).children(".editor").append(date);
return div;
}
function createContainer(id, name) {
var edtiorFactory = new EditorFactory();
var div = document.createElement("div");
$(div).attr("id", id);
$(div).append(edtiorFactory.createMultiField("test", "name", 150, "test"));
$(div).append(edtiorFactory.createFile("file", "file name", 150, "file"));
$(div).append(
edtiorFactory.createField("field", "field name", 150, "field"));
$(div).append(
edtiorFactory.createTable("table", "input", "td1;td1;td3", "id"));
$(div).append(
edtiorFactory.createSelect("select", "select", 150, [ 1, 2, 3 ],
"oo"));
$(div).append(edtiorFactory.createDate("date", "date", 150, "dateid"));
return div;
}
$(function() {
$('#test').append(createContainer("test", "test"));
});

View File

@ -1,120 +0,0 @@
function dataTransfer(serverData) {
var Container = function(name, children) {
this.name = name;
this.children = children;
};
var editorInfos = new Array();
var paramInfos = serverData.paramInfoModels;
var groupInfos = serverData.groupModels;
if (serverData.paramInfoModels != null) {
for ( var i = 0; i < paramInfos.length; i++) {
editorInfos.push(paramInfos[i]);
}
}
if (serverData.groupModels != null) {
for ( var i = 0; i < groupInfos.length; i++) {
var container = new Container(groupInfos[i].name,
dataTransfer(groupInfos[i]));
editorInfos.push(container);
}
}
return editorInfos;
}
function initDevice(){
var pluginData;
var behaviorData;
var pluginName="hbase";
$.ajax({
type: "GET",
url:"/getPlugin/" + pluginName,
dataType: "json",
async: false,
success: function (data) {
if(data.success){
pluginData=dataTransfer(data.pluginInfo );
}
else{
information(data.failedMessage);
}
}
});
$.ajax({
type: "GET",
url:"loadBehaviorList",
data:{pluginName:pluginName},
dataType: "json",
async: false,
success: function (data) {
if(data.success){
behaviorData=dataTransfer(data.behaviors[0]);
}
else{
information(data.failedMessage);
}
}
});
var deviceFactory=new DeviceFactory(pluginData,$("#devices"),behaviorData);
deviceFactory.createDevice("device config",
"device");
return deviceFactory;
}
function createSeparator(){
var div=document.create
}
$(function() {
$("#behaviorPanel").hide();
var deviceFactory=initDevice();
$("#add-device").click(
{
deviceFactory : deviceFactory,
},
function(event) {
event.preventDefault();
event.data.deviceFactory.createDevice("device config",
"device");
});
$("#remove-device").click(function(event) {
event.preventDefault();
if ($("#devices").children(".containerBox").length <= 1) {
return;
}
$("#devices").children(".containerBox").last().remove();
$("#devices").children(".separator").last().remove();
});
$("#start").click(function(event){
var plugins=getPluginDatas();
var behaviorNames=getBehaviorNames(plugins);
var behaviors=getBehaviorDatas(behaviorNames);
$.ajax({
type: "POST",
url: 'deviceScript',
dataType: "json",
async: false,
contentType:"application/json",
data: JSON.stringify({usePlugins:plugins,behaviors:behaviors,name:"script"}),
success: function (data) {
if(data.success){
return ;
}
else{
information(data.failedMessage);
}
}
});
});
});

View File

@ -1,434 +0,0 @@
function BehaviorViewModel(pluginModel, method, id) {
this.pluginModel = pluginModel;
this.method = method;
this.id = id;
this.getBehaviorName = function() {
return pluginModel.nickName + "_" + method + "_" + id;
}
}
/**
* @param id
* @param parentId
* @param childId
*/
function BatchViewModel(id, parentId, childId) {
this.id = id;
this.parentId = parentId;
this.childId = childId;
}
function Behavior(usePlugin, containerId) {
// var containerId = "useBehaviorList";
var usePlugin = usePlugin;
var behaviorMap = new HashMap();
var behaviorEditorMap = new HashMap();
var batchMap = new HashMap();
var index = 1;
var paramDataCollector = new DataCollector();
var behavior = this;
// init tree node container
jstreeCreate(containerId);
$("#addBehavior").click(function() {
// selected node's type
var selectedNodes = jstreeSelectedNodes(containerId);
if (!selectedNodes.length) {
// add page
showPage();
} else {
var currNode = selectedNodes[0];
var currNodeType = currNode.data;
if (currNodeType == "page") {
// add page
showPage();
} else if (currNodeType == "batch") {
// add batch
showBatch();
} else {
// add behavior
showPluginList();
}
}
$("#selectBehavior").modal('show');
$("#addBehavior").addClass("clicked");
});
$("#insertChildNode").click(function() {
var selectedNodes = jstreeSelectedNodes(containerId);
if (!selectedNodes.length) {
return;
} else {
var currNode = selectedNodes[0];
var currNodeType = currNode.data;
if (currNodeType == "page") {
// add batch
showBatch();
} else if (currNodeType == "batch") {
// add behavior
showPluginList();
} else {
// other container behavior;
}
}
$("#selectBehavior").modal('show');
$("#insertChildNode").addClass("clicked");
});
$("#useBehaviorList").bind(
"select_node.jstree",
function(node, selected, event) {
var type = selected.node.data;
if (type == "page" || type == "batch") {
$("#insertChildDiv").removeClass("hide");
updateBehaviorEditors();
} else {
$("#insertChildDiv").addClass("hide");
updateBehaviorEditors();
$("#behaviorEditor").append(
behaviorEditorMap.get(selected.node.id));
$("#behaviorEditor").attr("behavior", selected.node.id);
}
});
$("#selectBehavior")
.on(
"click",
"div[name='behavior_usePlugin']",
function() {
var pluginName = $(
"#selectBehavior input[name='behavior_usePlugin']:checked")
.val();
if (pluginName == "page" || pluginName == "batch") {
return;
}
$.post("loadBehaviorList", {
pluginName : pluginName
}, function(data) {
if (!data.success) {
information("fail");
return;
}
$("#pluginMethod").html("");
var dataBehaviors = data.behaviors.sort(function(a,
b) {
return a.name.localeCompare(b.name);
});
createRadioGroupByAttribute(dataBehaviors, "name",
"name", "name", "method", "pluginMethod")
});
});
$("#selectBehavior #ok")
.click(
function() {
var usePluginId = $(
"#usePlugins input[name='behavior_usePlugin']:checked")
.attr("id");
var method = $(
"#pluginMethod input[name='method']:checked")
.val();
var pluginId = usePluginId.split("_")[2];
// get add type, insert or add
var pos;
if ($("#insertChildNode").hasClass("clicked")) {
pos = "last";
} else {
pos = "after";
}
// deal page and batch
if (pluginId == "page") {
// add page to web
createPageViewModel(index, pos);
jstreeSelectNode(containerId, index);
} else if (pluginId == "batch") {
// var batchViewModel = new BatchViewModel(index,
// -1, -1);
// batchMap.put(batchViewModel.id, batchViewModel);
// // add batch to web
// jstreeCreateNode("useBehaviorList", "batch",
// "batch",
// batchViewModel.id, pos);
createBatchViewModel(index, -1, -1, pos);
jstreeSelectNode(containerId, index);
} else {
if (pluginId == undefined || method == undefined) {
return;
}
// var pluginModel =
// usePlugin.getUsePluginMap().get(
// pluginId);
//
// var behaviorViewModel = new BehaviorViewModel(
// pluginModel, method, index);
//
// jstreeCreateNode("useBehaviorList",
// behaviorViewModel.method, behaviorViewModel
// .getBehaviorName(),
// behaviorViewModel.id, pos);
// createBehaviorEditor(behaviorViewModel);
//
// // add behavior id to plugin which used
// pluginModel.behaviors.push(behaviorViewModel);
// behaviorMap.put(behaviorViewModel.id,
// behaviorViewModel);
createBehaviorViewModel(index, pluginId, method,
pos, index);
}
if (pos == "last") {
$("#insertChildNode").removeClass("clicked");
} else {
$("#addBehavior").removeClass("clicked");
}
$("#selectBehavior").modal('hide');
$("#usePlugins").html("");
$("#pluginMethod").html("");
index++;
});
$("#selectBehavior #cancel").click(function() {
if ($("#insertChildNode").hasClass("clicked")) {
$("#insertChildNode").removeClass("clicked")
} else {
$("#addBehavior").removeClass("clicked");
pos = "after";
}
$("#selectBehavior").modal('hide');
$("#usePlugins").html("");
$("#pluginMethod").html("");
});
$("#removeBehavior").click(function() {
// selected node's type
var selectedNodes = jstreeSelectedNodes(containerId);
if (!selectedNodes.length) {
return;
}
var currNode = selectedNodes[0];
// delete behavior from plugin
var pluginModel = behaviorMap.get(currNode.id).pluginModel;
for (var i = 0; i < pluginModel.behaviors; i++) {
if (pluginModel.behaviors[i].id == currNode.id) {
pluginModel.behaviors.splice(i, 1);
break;
}
}
behavior.deleteBehaviorNode(currNode.id);
});
this.deleteBehaviorNode = function(behaviorId) {
behaviorMap.remove(behaviorId);
behaviorEditorMap.remove(behaviorId);
// delete node from tree
jstreeDeleteNode(containerId, behaviorId);
$("#behaviorEditor").html("");
$("#behaviorEditor").attr("behavior", "");
}
$("#clearBehavior").click(function() {
$("#insertChildDiv").addClass("hide");
// delete from pluginModel
var keys = behaviorMap.getKeys();
for (var i = 0; i < keys.length; i++) {
var pluginModel = behaviorMap.get(keys[i]).pluginModel;
pluginModel.behaviors = [];
}
behavior.clearBehaviorNode();
})
this.clearBehaviorNode = function() {
behaviorMap.clear();
behaviorEditorMap.clear();
// clear tree
jstreeClearNode(containerId);
index = 1;
$("#behaviorEditor").html("");
$("#behaviorEditor").attr("behavior", "");
}
function updateBehaviorEditors() {
if ($("#behaviorEditor").attr("behavior") == undefined
|| $("#behaviorEditor").attr("behavior") == "") {
return;
}
behaviorEditorMap.put($("#behaviorEditor").attr("behavior"), $(
"#behaviorEditor div:first").clone(true))
$("#behaviorEditor").attr("behavior", "")
$("#behaviorEditor").html("");
}
function createBehaviorEditor(behaviorModel, selectedId, parameters) {
var pluginName = behaviorModel.pluginModel.name;
var methodName = behaviorModel.method;
var containerFactory = new ContainerFactory();
$.post("getPluginMethod" + "/" + pluginName + "/" + methodName, {},
function(data) {
if (data.success) {
var methodData = dataTransfer(data.method, parameters);
var generator = containerFactory.createEditorContainer(
methodName, "generator", methodData);
$(generator).addClass("generator");
behaviorEditorMap.put(behaviorModel.id, generator);
if (selectedId == behaviorModel.id)
jstreeSelectNode(containerId, behaviorModel.id);
} else {
return;
}
});
}
function getBehaviorType(pluginName) {
if (pluginName == "ConstantTimer") {
return "TIMERBEHAVIOR";
} else {
return "USERBEHAVIOR";
}
}
function showPluginList() {
$("#usePlugins").html("");
var keys = usePlugin.getUsePluginMap().getKeys();
for (var i = 0; i < keys.length; i++) {
var pluginModel = usePlugin.getUsePluginMap().get(keys[i]);
$("#usePlugins").append(
createRadio("behavior_plugin_" + pluginModel.id,
pluginModel.nickName, "behavior_usePlugin",
pluginModel.name));
}
}
function showPage() {
$("#usePlugins").html("");
$("#usePlugins").append(
createRadio("behavior_plugin_page", "page",
"behavior_usePlugin", "page"));
}
function showBatch() {
$("#usePlugins").html("");
$("#usePlugins").append(
createRadio("behavior_plugin_batch", "batch",
"behavior_usePlugin", "batch"));
}
this.getPages = function() {
updateBehaviorEditors();
var treeObj = $("#" + containerId).jstree(true);
var nodeIds = treeObj.get_node('#').children;
var idModelMap = new HashMap();
var tempNodeList = new Array();
var pages = new Array();
tempNodeList = tempNodeList.concat(nodeIds);
var currNodeId;
while ((currNodeId = tempNodeList.shift()) != undefined) {
var currNode = treeObj.get_node(currNodeId);
buildModel(idModelMap, pages, currNode);
if (treeObj.is_parent(currNodeId)) {
tempNodeList = tempNodeList.concat(currNode.children);
}
}
return pages;
}
function buildModel(idModelMap, pages, currNode) {
if (currNode.data == "page") {
var pageModel = new PageModel(currNode.id, new Array());
pages.push(pageModel);
idModelMap.put(pageModel.id, pageModel);
} else if (currNode.data == "batch") {
var batchViewModel = batchMap.get(currNode.id);
var batchModel = new BatchModel(batchViewModel.id,
batchViewModel.parentId, batchViewModel.childId,
new Array());
var pageModel = idModelMap.get(currNode.parents[0]);
pageModel.batches.push(batchModel);
idModelMap.put(batchModel.id, batchModel);
} else {
var behaviorView = behaviorMap.get(currNode.id);
var behaviorEditor = behaviorEditorMap.get(behaviorView.id);
var params = paramDataCollector.getUnitParams($(behaviorEditor)
.find(".editor"));
var behaviorModel = new BehaviorModel(behaviorView.id,
behaviorView.pluginModel.id, behaviorView.method,
getBehaviorType(behaviorView.pluginModel.name), params);
var batchModel = idModelMap.get(currNode.parents[0]);
batchModel.behaviors.push(behaviorModel);
idModelMap.put(behaviorModel.id, behaviorModel);
}
}
this.initBehaviorList = function(pages) {
// init page, batch, behavior
for (var i = 0; i < pages.length; i++) {
// create page
var page = pages[i];
createPageViewModel(page.id, "after");
// update index
updateIndex(page.id);
// init batch
initBatch(page.id, page.batches);
}
index += 1;
}
function initBatch(parentNode, batches) {
for (var i = 0; i < batches.length; i++) {
var batch = batches[i];
createBatchViewModel(batch.id, batch.parentId, batch.childId,
"last", parentNode);
updateIndex(batch.id);
// init behavior
initBehavior(batch.id, batch.behaviors);
}
}
function initBehavior(parentNode, behaviors) {
var selectedId = behaviors[0].id;
for (var i = 0; i < behaviors.length; i++) {
var behavior = behaviors[i];
updateIndex(behavior.id);
createBehaviorViewModel(behavior.id, behavior.use, behavior.name,
"last", selectedId, behavior.parameters, parentNode);
}
}
function createPageViewModel(id, pos) {
jstreeCreateNode(containerId, "page", "page", id, pos);
}
function createBatchViewModel(id, parentId, childId, pos, parentNode) {
var batchViewModel = new BatchViewModel(id, parentId, childId);
batchMap.put(batchViewModel.id, batchViewModel);
// add batch to web
jstreeCreateNode(containerId, "batch", "batch", batchViewModel.id, pos,
parentNode);
}
function createBehaviorViewModel(id, pluginId, method, pos, selectedId,
parameters, parentNode) {
var pluginModel = usePlugin.getUsePluginMap().get(pluginId);
var behaviorViewModel = new BehaviorViewModel(pluginModel, method, id);
jstreeCreateNode("useBehaviorList", behaviorViewModel.method,
behaviorViewModel.getBehaviorName(), behaviorViewModel.id, pos,
parentNode);
createBehaviorEditor(behaviorViewModel, selectedId, parameters);
// add behavior id to plugin which used
pluginModel.behaviors.push(behaviorViewModel);
behaviorMap.put(behaviorViewModel.id, behaviorViewModel);
}
function updateIndex(id) {
if (index < id) {
index = id;
}
}
}

View File

@ -1,11 +0,0 @@
$(function() {
$("#tabs").tabs();
var usePlugin = new UsePlugin("useBehaviorList");
// usePlugin.getPluginList();
$("#submitScript").click(function() {
var plugins = usePlugin.getPlugins();
var pages = usePlugin.getPages();
submitScript(pages,plugins);
});
});

View File

@ -1,110 +0,0 @@
/**
* @param containerId the id of jstree container
* @param data
* @param name the name of new node
* @param id the id of new node
* @param pos the position of new node to the parent node,maybe "last" which means the childnode of the selected
* node,"after" or "before" means the sibling node of the selected node
*/
function jstreeCreateNode(containerId,data,name,id,pos,parentNode){
var treeObj = $("#"+containerId).jstree(true);
if(parentNode == null || parentNode == undefined){
parentNode = treeObj.get_selected();
if(!parentNode.length){
parentNode=null;
}
else{
parentNode = parentNode[0];
}
}
var childNode = null;
var type = data;
if(type!="page" && type!="batch")
type = "default";
childNode = treeObj.create_node(parentNode,{text:name,id:id,data:data,type:type},pos);
if(childNode) {
treeObj.open_node(parentNode);
}
}
/**
* delete current node
* @param containerId the id of jstree container
*/
function jstreeDeleteNode(containerId,nodeId){
var treeObj = $("#"+containerId).jstree(true);
// var parentNode = treeObj.get_selected();
// if(!parentNode.length){return false;}
treeObj.delete_node(nodeId);
return treeObj.element.context.id;
}
/**
* delete all node
* @param containerId the id of jstree container
*/
function jstreeClearNode(containerId){
var treeObj = $("#"+containerId).jstree(true);
var nodes = treeObj.get_children_dom("#");
while(nodes.length){
treeObj.delete_node(nodes);
nodes = treeObj.get_children_dom("#");
}
}
/**
* @param containerId the id of jstree container
* @param node the id of to be selected node
*/
function jstreeSelectNode(containerId,node){
var treeObj = $("#"+containerId).jstree(true);
treeObj.deselect_all();
treeObj.select_node(node);
}
/**
* @param containerId the id of jstree container
*/
function jstreeSelectedNodes(containerId){
var treeObj = $("#"+containerId).jstree(true);
return treeObj.get_selected(true);
}
function jstreeRenameNode(containerId, node, text){
var treeObj = $("#"+containerId).jstree(true);
treeObj.rename_node(node,text);
}
/**
* @param containerId the id of jstree container
*/
function jstreeCreate(containerId){
$("#"+containerId).jstree({
"core" : {
"animation" : 0,
"check_callback" : true,
"themes" : { "stripes" : true }
},
"types" : {
"#" : { "max_depth" : 4, "valid_children" : ["page","default"] },
"page" : { "icon" : false, "valid_children" : ["batch"] },
"batch" : { "icon" : false, "valid_children" : ["default"] },
"default" : { "icon" : false, "valid_children" : [] }
},
"contextmenu" : {
"items" : function(node) {
var tmp = $.jstree.defaults.contextmenu.items();
delete tmp.create;
delete tmp.ccp;
delete tmp.remove;
if(containerId == "useBehaviorList"){
delete tmp.rename;
}
return tmp;
}
},
"plugins" : [ "contextmenu","types","dnd","wholerow" ]
})
return $("#"+containerId).jstree(true);
}

View File

@ -1,76 +0,0 @@
var ContainerFactory = function() {
};
ContainerFactory.prototype.createEditorContainer = function(header, id,
containerInfo) {
var container = document.createElement("div");
$(container).addClass("containerBox");
if (id != null) {
$(container).attr("id", id);
}
var containerHeader = document.createElement("p");
$(containerHeader).addClass("containerHeader");
$(containerHeader).append(document.createTextNode(header));
$(container).append(containerHeader);
for ( var i = 0; i < containerInfo.length; i++) {
if (containerInfo[i].label == null) {
containerInfo[i].label = "";
}
if (containerInfo[i].name == null) {
containerInfo[i].name == "";
}
if (containerInfo[i].children == null) {
this.appendEdtiors(container, containerInfo[i].label,
containerInfo[i].nameCN, containerInfo[i].name,
containerInfo[i].paramTypeModel,containerInfo[i].value == null ?"":containerInfo[i].value);
} else {
$(container).append(
this.createEditorContainer(containerInfo[i].nameCN, null,
containerInfo[i].children));
}
}
return container;
};
ContainerFactory.prototype.appendEdtiors = function(container, label, name, id,
editorInfo, value) {
var editorFactory = new EditorFactory();
if (editorInfo.type.toLowerCase() == "field") {
$(container).append(
editorFactory.createField(label, name, editorInfo.size, id,value));
} else if (editorInfo.type.toLowerCase() == "nfield") {
$(container).append(
editorFactory
.createMultiField(label, name, editorInfo.size, id,value));
} else if (editorInfo.type.toLowerCase() == "table") {
$(container).append(
editorFactory.createTable(label, name, editorInfo.cols, id,value));
} else if (editorInfo.type.toLowerCase() == "file") {
$(container).append(
editorFactory.createFile(lable, name, editorInfo.size, id,value));
} else if (editorInfo.type.toLowerCase() == "date") {
$(container).append(
editorFactory.createDate(label, name, editorInfo.size, id,value));
} else if (editorInfo.type.toLowerCase() == "select") {
$(container).append(
editorFactory.createSelect(label, name, editorInfo.size,
editorInfo.options, id,value));
} else if (editorInfo.type.toLowerCase() == "checkbox") {
$(container).append(
editorFactory.createCheckBox(label, name,
editorInfo.choiceModels, id,value));
} else {
information("no such editor type:" + editorInfo.type);
}
};

View File

@ -1,161 +0,0 @@
var Parameter = function(key, value) {
this.key = key;
this.value = value;
}
var DataCollector = function() {
};
DataCollector.prototype.validate = function(value) {
if (value == null || value == "") {
information($.i18n.prop('dataCollect-input'));
return false;
}
return true;
}
DataCollector.prototype.checkBoxData = function(editor) {
var name = editor.attr("id");
var choice = editor.find("input[type='checkbox']");
var value = choice.is(':checked');
return new Parameter(name, value);
}
DataCollector.prototype.fieldData = function(editor) {
var name = $(editor).attr("id");
editor = $(editor.children('.field'));
var value = editor.children("input").val();
// if (!this.validate(value)) {
// return false;
// }
return new Parameter(name, value);
};
DataCollector.prototype.dateData = function(editor) {
var name = editor.attr("id");
var value = editor.children("input").val();
// if (!this.validate(value)) {
// return false;
// }
return new Parameter(name, value);
};
DataCollector.prototype.multiFieldData = function(editor) {
var editorArray = editor.children(".field");
if (editorArray.size == 0) {
information($.i18n.prop('dataCollect-input'));
return;
}
var name = editor.attr("id")
var value = "";
for ( var i = 0; i < editorArray.length; i++) {
var fieldValue = $(editorArray[i]).children("input").val();
if (fieldValue == "") {
continue;
}
value += fieldValue + ";";
}
value = value.substring(0, value.length - 1);
// if (!this.validate(value)) {
// return false;
// }
return new Parameter(name, value);
};
DataCollector.prototype.tableData = function(editor) {
var thArray = editor.find("thead").children("th");
var editorArray = editor.find("tbody").children("tr");
var name = editor.attr("id");
var value = "";
for ( var i = 0; i < editorArray.length; i++) {
var tdArray = $(editorArray[i]).children("td");
var trValue = "";
for ( var j = 1; j < tdArray.length; j++) {
if ($(tdArray[j]).children("input").val() == undefined
|| $(tdArray[j]).children("input").val() == "") {
continue;
}
trValue += thArray[j] + "=" + $(tdArray[j]).children("input").val()
+ "|";
}
trValue = trValue.substring(0, trValue.length - 1);
value += trValue + ";";
}
value = value.substring(0, value.length - 1);
// if (!this.validate(value)) {
// return false;
// }
return new Parameter(name, value);
};
DataCollector.prototype.selectData = function(editor) {
var name = editor.attr("id");
var value = editor.children("select").val();
// if (!this.validate(value)) {
// return false;
// }
return new Parameter(name, value);
};
DataCollector.prototype.getUnitParams = function(paramEditors) {
var params = new Array();
for ( var i = 0; i < paramEditors.length; i++) {
var editor = $(paramEditors[i]);
var editorType = editor.attr("editorType");
var data;
if (editorType == "field") {
data = this.fieldData(editor);
if (!data) {
return;
}
params.push(data);
} else if (editorType == "date") {
data = this.dateData(editor);
if (!data) {
return;
}
params.push(data);
} else if (editorType == "multiField") {
data = this.multiFieldData(editor)
if (!data) {
return;
}
params.push(data);
} else if (editorType == "table") {
data = this.tableData(editor);
if (!data) {
return;
}
params.push(data);
} else if (editorType == "select") {
data = this.selectData(editor);
if (!data) {
return;
}
params.push(data);
} else if (editorType == "checkBox") {
data = this.checkBoxData(editor);
if (!data) {
return;
}
params.push(data);
} else {
information($.i18n.prop('dataCollect-errorType'));
}
}
return params;
};
var UsePluginModel = function(id, name, parameters) {
this.id = id;
this.name = name;
this.parameters = parameters;
}

View File

@ -1,43 +0,0 @@
function dataTransfer(serverData,valueList) {
var Container = function(name, children) {
this.name = name;
this.children = children;
};
var valueMap = getParameterMap(valueList);
var editorInfos = new Array();
var paramInfos = serverData.paramInfoModels;
var groupInfos = serverData.groupModels;
if (paramInfos != null) {
for ( var i = 0; i < paramInfos.length; i++) {
var value = valueMap.get(paramInfos[i].name);
paramInfos[i].value = value;
editorInfos.push(paramInfos[i]);
}
}
if (serverData.groupModels != null) {
for ( var i = 0; i < groupInfos.length; i++) {
var container = new Container(groupInfos[i].name,
dataTransfer(groupInfos[i]));
editorInfos.push(container);
}
}
var editorInfos = editorInfos.sort(function(a, b) {
return a.name.localeCompare(b.name);
});
return editorInfos;
}
function getParameterMap(parameters){
var paramMap = new HashMap();
if(parameters != null && parameters != undefined){
for(var i=0;i<parameters.length;i++){
paramMap.put(parameters[i].key,parameters[i].value);
}
}
return paramMap;
}

View File

@ -1,282 +0,0 @@
var EditorFactory = function() {
};
EditorFactory.prototype.createBaseEditor = function(label, id) {
if (label == null) {
label = "";
}
var containerBox = document.createElement("div");
$(containerBox).addClass("containerBox");
var boxHeader = document.createElement("div");
var p = document.createElement("p")
$(p).html(label)
$(boxHeader).append(p);
$(boxHeader).addClass("containerHeader")
$(containerBox).append(boxHeader);
var boxBody = document.createElement("div");
$(boxBody).addClass("editor");
$(boxBody).attr("id", id);
$(containerBox).append(boxBody);
return containerBox;
}
EditorFactory.prototype.createCheckBox = function(label, name, choices, id,
value) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "checkBox");
for (var i = 0; i < choices.length; i++) {
var choice = this.createChoice(choices[i].value,
choices[i].defaultValue, name);
$(div).children(".editor").append(choice);
}
return div;
}
EditorFactory.prototype.createChoice = function(value, defaultValue, name,
value) {
var div = document.createElement("div");
var input = document.createElement("input");
$(input).attr("type", "checkbox");
$(input).attr("name", name);
if (defaultValue) {
$(input).attr("checked", "checked");
}
$(div).append(input);
var label = document.createElement("label");
$(label).html(value);
$(div).append(label);
return div;
}
EditorFactory.prototype.createField = function(label, name, size, id, value) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "field");
$(div).children(".editor").append(this.createFieldLine(size, name, value));
return div;
}
EditorFactory.prototype.createMultiField = function(label, name, size, id,
value) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "multiField");
if (value != null) {
var values = value.split(";");
for (var i = 0; i < values.length; i++) {
$(div).children(".editor").append(
this.createFieldLine(size, name, values[i]));
}
}
var editorFactory = this;
var addFieldButton = document.createElement("button");
$(addFieldButton).html("add")
$(addFieldButton).attr("type", "submit");
$(addFieldButton).click(
{
editorFactory : editorFactory
},
function(event) {
event.preventDefault()
$(event.data.editorFactory.createFieldLine(size, name))
.insertBefore($(this));
});
var removeFieldButton = document.createElement("button");
$(removeFieldButton).html("remove")
$(removeFieldButton).attr("type", "submit");
$(removeFieldButton).click(function(event) {
event.preventDefault();
$(this).parent().children(".field").last().remove();
});
$(div).children(".editor").append(addFieldButton).append(removeFieldButton);
return div;
}
EditorFactory.prototype.createFieldLine = function(size, name, value) {
var fieldDiv = document.createElement("div");
$(fieldDiv).addClass("field");
var fieldName = document.createElement("label");
$(fieldName).html(name);
var field = document.createElement("input");
$(field).attr("type", "text");
// $(field).attr("maxlength", size);
$(field).attr("value", value);
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
}
EditorFactory.prototype.createFile = function(label, name, size, id, value) {
if (size == null || size <= 0) {
size = 150;
}
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "file");
var fileEditor = document.createElement("div");
var fieldName = document.createElement("label");
$(fieldName).html(name);
var file = document.createElement("input");
$(file).attr("type", "file");
// $(field).attr("maxlength", size);
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).children(".editor").append(fileEditor);
return div;
}
EditorFactory.prototype.createTable = function(label, name, cols, id, value) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "table");
var headers = getHeaders(cols);
$(div).children(".editor").append(createTable(cols, name, headers, value));
var addButton = document.createElement("button");
$(addButton).html("add");
$(addButton).click(
{
headers : headers,
fieldName : name
},
function(event) {
event.preventDefault();
$(this).parent().children("table").children("tbody").append(
createTr(event.data.headers, event.data.fieldName));
});
var deleteButton = document.createElement("button");
$(deleteButton).html("remove");
$(deleteButton).click(
function(event) {
event.preventDefault();
$(this).parent().children("table").children("tbody").children(
"tr").last().remove();
});
$(div).children(".editor").append(addButton);
$(div).children(".editor").append(deleteButton);
return div;
function getHeaders(col) {
var headers = new Array();
// headers.push("name:");
if(col != null){
var cols = col.split(";");
for (var i = 0; i < cols.length; i++) {
headers.push(cols[i]);
}
}
return headers;
}
function createTable(cols, name, headers, value) {
value==null?value="":value;
var values = value.split(";");
var table = document.createElement("table");
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
$(thead).append(createHeader(headers));
for (var i = 0; i < values.length; i++) {
$(tbody).append(createTr(headers, name, values[i]));
}
$(table).append(thead);
$(table).append(tbody);
return table;
}
function createHeader(headers) {
var tr = document.createElement("tr");
for (var i = 0; i < headers.length; i++) {
var th = document.createElement("th");
$(th).append(document.createTextNode(headers[i]));
$(th).attr("style", "width:" + 100 / headers.length + "%")
$(tr).append(th);
}
return tr;
}
function createTr(headers, name, value) {
value == null? value="":value;
var values = value.split("|");
var tr = document.createElement("tr");
// var td = document.createElement("td");
// $(td).attr("style", "width:" + 100 / headers.length + "%")
// $(td).html(name);
// $(tr).append(td);
for (var i = 0; i < headers.length; i++) {
var input = document.createElement("input");
$(input).attr("type", "text");
$(input).attr("style","width:"+"90%");
$(input).val(values[i]);
var td = document.createElement("td");
$(td).attr("style", "width:" + 100 / headers.length + "%")
$(td).append(input);
$(tr).append(td);
}
return tr;
}
}
EditorFactory.prototype.createSelect = function(label, name, size, options, id,
value) {
if (size == null || size <= 0) {
size = 150;
}
if (options == null || options.length <= 0) {
information("no options in:" + name);
}
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "select");
var nameLabel = document.createElement("label");
$(nameLabel).html(name);
$(div).children(".editor").append(nameLabel);
var select = document.createElement("select");
$(select).attr("style", "width:" + size + "px");
for (var i = 0; i < options.length; i++) {
var option = document.createElement("option");
$(option).attr("value", options[i]);
$(option).html(options[i]);
$(select).append(option);
}
$(div).children(".editor").append(select);
return div;
}
EditorFactory.prototype.createDate = function(label, name, size, id, value) {
if (size == null || size < 0) {
size = 150
}
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "date");
var dateLabel = document.createElement("label");
$(dateLabel).html(name);
var date = document.createElement("input");
$(date).attr("type", "date");
$(div).children(".editor").append(dateLabel);
$(div).children(".editor").append(date);
return div;
}
function createContainer(id, name) {
var edtiorFactory = new EditorFactory();
var div = document.createElement("div");
$(div).attr("id", id);
$(div).append(edtiorFactory.createMultiField("test", "name", 150, "test"));
$(div).append(edtiorFactory.createFile("file", "file name", 150, "file"));
$(div).append(
edtiorFactory.createField("field", "field name", 150, "field"));
$(div).append(
edtiorFactory.createTable("table", "input", "td1;td1;td3", "id"));
$(div).append(
edtiorFactory.createSelect("select", "select", 150, [ 1, 2, 3 ],
"oo"));
$(div).append(edtiorFactory.createDate("date", "date", 150, "dateid"));
return div;
}

View File

@ -1,74 +0,0 @@
function CollectScriptData(behavior) {
this.scriptDataModel = behavior;
var collector = this;
this.getRunScenarioModel = function(){
}
}
//
//var ParameterModel = function(key, value) {
// this.key = key;
// this.value = value;
//}
//var UsePluginModel = function(id, name, parameters) {
// this.id = id;
// this.name = name;
// this.parameters = parameters;
//}
//var BehaviorModel = function(id, use, name, type, parameters) {
// this.id = id;
// this.name = name;
// this.type = type;
// this.use = use;
// this.parameters = parameters;
//}
//var ScenarioModel = function(usePlugins, behaviors) {
// this.usePlugins = usePlugins;
// this.behaviors = behaviors;
//}
function submitScript(pages,usePlugins) {
var scriptName = $("#scriptName").val();
if (scriptName == undefined || scriptName == "") {
information("need a script name!")
return;
}
var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages);
$.ajax({
type : "POST",
url : "submitScriptCreated" + "/" + scriptName,
data :{runScenarioModelStr: JSON.stringify(runScenarioModel)},//JSON.stringify(runScenarioModel),
// dataType : "json",
// contentType : "application/json",
success : function(data) {
if (!data.success) {
return;
} else {
information("success");
}
}
});
}
function updateScript(scriptId, pages, usePlugins){
var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages);
$.ajax({
type : "POST",
url : "updateScript",
data :{scriptId:scriptId, runScenarioModelStr: JSON.stringify(runScenarioModel)},//JSON.stringify(runScenarioModel),
// dataType : "json",
// contentType : "application/json",
success : function(data) {
if (!data.success) {
return;
} else {
information("success");
}
}
});
}

View File

@ -1,49 +0,0 @@
function createRadioGroup(items,name,containerId){
for ( var i = 0; i < items.length; i++) {
var radio = createRadio(items[i],items[i],name,items[i]);
$("#" + containerId).append(radio);
}
}
/**
* @param id synchronize the radio, label and div
* @param text show in the web
* @param name this is same in a radio group
* @param value
* @returns
*/
function createRadio (id,text,name,value) {
var line = $("<div style='cursor:pointer;' name='"+name+"'>");
line.click(function(){
document.getElementById(id).checked = true;
})
var input = $("<input type='radio' name="+name+" id="+id+">");
input.attr("value",value);
input.attr("text",text);
var span = $("<label for="+id+" style='cursor:pointer;'>");
span.html(text);
line.append(input);
line.append(span);
line.addClass("line");
return line;
}
/**
* @param items
* @param textAttr the key of text which is show in the web
* @param valueAttr the key of value which is store in the web
* @param idAttr
* @param name
* @param containerId
*/
function createRadioGroupByAttribute(items,textAttr,valueAttr,idAttr, name,containerId){
for ( var i = 0; i < items.length; i++) {
var radio = createRadio(items[i][idAttr],items[i][textAttr],name,items[i][valueAttr]);
$("#" + containerId).append(radio);
}
}
function information(text){
noty({text: text,type:'error',layout:'top'});
setTimeout("document.body.removeChild(noty_top_layout_container)",2000);
}

View File

@ -1,231 +0,0 @@
function UsePluginViewModel(id, name, nickName) {
this.id = id;
this.name = name;
this.nickName = nickName;
this.behaviors = new Array();
}
function UsePlugin(behaviorListContainerId) {
var containerId = "usePluginList";
// var usePlugin = this;
var behavior = new Behavior(this,"useBehaviorList");
var paramDataCollector = new DataCollector();
var containerFactory = new ContainerFactory();
var index = 1;
var usePluginEditorMap = new HashMap();
var map = new HashMap();
//init plugin list
getPluginList();
//init tree
jstreeCreate(containerId);
$("#addPlugin").click(function() {
$("#addPlugin").addClass("clicked");
$("#selectUsePlugin").modal('show');
});
$("#selectUsePlugin #ok").click(
function() {
var pluginName = $(
"#pluginList div input[name='plugins']:checked").val();
if (pluginName == undefined) {
return;
}
var pluginModel = new UsePluginViewModel(index, pluginName, pluginName+"_"+index);
//create plugin node
jstreeCreateNode(containerId, pluginModel.name,
pluginModel.nickName, pluginModel.id, "after");
map.put(pluginModel.id, pluginModel);
updateUsePlugin();
createEditor(pluginModel,pluginModel.id);
index++;
$("#selectUsePlugin").modal('hide');
});
$("#selectUsePlugin #cancel").click(function() {
$("#selectUsePlugin").modal('hide');
});
$("#removePlugin").click(function() {
$.confirm("Are you sure to delete this plugin and those behaviors which use this plugin?",function(b){
if(b){
var pluginNodes = jstreeSelectedNodes(containerId);
if (!pluginNodes.length) {
return;
}
var currNodeId = pluginNodes[0].id;
var behaviors = map.get(currNodeId).behaviors;
jstreeDeleteNode(containerId,currNodeId);
//delete behavior
for(var i=0;i<behaviors.length;i++)
{
behavior.deleteBehaviorNode(behaviors[i].id);
}
map.remove(currNodeId);
usePluginEditorMap.remove(currNodeId);
$("#pluginEditor").attr("usePlugin", "");
$("#pluginEditor").html("");
}
});
});
$("#clearPlugin").click(function() {
$.confirm("Are you sure to delete this plugin and those behaviors which use this plugin?",function(b){
if(b){
map.clear();
usePluginEditorMap.clear();
jstreeClearNode(containerId);
behavior.clearBehaviorNode();
index = 1;
$("#pluginEditor").attr("usePlugin", "");
$("#pluginEditor").html("");
}
});
});
function getPluginList() {
var usePlugin = this;
$.post("loadPluginName", {}, function(data) {
if (data.success) {
createRadioGroup(data.pluginNames, "plugins", "pluginList");
} else {
return;
}
});
}
function createEditor(pluginModel, selectedId, parameters) {
$.post("getPlugin" + "/" + pluginModel.name, {}, function(data) {
if (data.success) {
var pluginData = dataTransfer(data.plugin,parameters);
createEditorByData(pluginModel,pluginData);
// var generator = containerFactory.createEditorContainer(
// pluginModel.name, "generator", pluginData);
// $(generator).attr("pluginName", pluginModel.nickName);
// $(generator).addClass("generator");
// usePluginEditorMap.put(pluginModel.id, generator);
//select this new node
if(selectedId == pluginModel.id)
jstreeSelectNode(containerId, pluginModel.id);
} else {
return;
}
});
}
function updateUsePlugin() {
if ($("#pluginEditor").attr("usePlugin") == undefined
|| $("#pluginEditor").attr("usePlugin") == "") {
return;
}
usePluginEditorMap.put($("#pluginEditor").attr("usePlugin"), $(
"#pluginEditor div:first").clone());
$("#pluginEditor").attr("usePlugin", "");
$("#pluginEditor").html("");
}
$("#usePluginList").on(
"click",
"div[name='usePlugin']",
function() {
var usePluginId = $(
"#usePluginList input[name='usePlugin']:checked").attr(
"id");
if (usePluginId == undefined) {
return;
}
updateUsePlugin();
$("#pluginEditor").append(usePluginEditorMap.get(usePluginId));
$("#pluginEditor").attr("usePlugin", usePluginId);
});
$("#usePluginList").bind("select_node.jstree",
function(node, selected, event) {
var usePluginId = selected.node.id;
if (usePluginId == undefined) {
return;
}
updateUsePlugin();
$("#pluginEditor").append(usePluginEditorMap.get(usePluginId));
$("#pluginEditor").attr("usePlugin", usePluginId);
});
//listen usePlugin rename
$("#usePluginList").bind("rename_node.jstree", function(event, data) {
var pluginModel = map.get(data.node.id);
pluginModel.nickName = data.text;
//change behavior name which use this plugin
for (var i=0;i<pluginModel.behaviors.length;i++) {
var behaviorView = pluginModel.behaviors[i];
jstreeRenameNode(behaviorListContainerId, behaviorView.id, behaviorView.getBehaviorName());
}
});
//this is for behavior
this.getUsePluginMap = function() {
return map;
}
this.getContainerId = function(){
return containerId;
}
//this is for submit
this.getPlugins = function() {
updateUsePlugin();
var keys = map.getKeys();
var usePlugins = new Array();
for ( var i = 0; i < keys.length; i++) {
var id = keys[i];
var usePluginViewModel = map.get(id);
var usePluginContainer = usePluginEditorMap.get(id);
var params = paramDataCollector.getUnitParams($(
usePluginContainer).find(".editor"));
usePlugins.push(new UsePluginModel(usePluginViewModel.id, usePluginViewModel.name,usePluginViewModel.nickName, params));
}
return usePlugins;
}
this.getPages = function(){
return behavior.getPages();
}
this.initPluginAndPages = function(scriptObj){
initPluginList(scriptObj.usePlugins);
behavior.initBehaviorList(scriptObj.pages);
}
function initPluginList(usePlugins){
//init plugin
var selectedId = usePlugins[0].id;
for(var i=0;i < usePlugins.length;i++){
var usePlugin = usePlugins[i];
createUsePlugin(usePlugin,selectedId);
if(index < usePlugin.id){
index = usePlugin.id;
}
}
index +=1;//this is new id
}
function createUsePlugin(usePlugin,selectedId){
//add to map
var pluginModel = new UsePluginViewModel(usePlugin.id, usePlugin.name, usePlugin.nickName);
map.put(pluginModel.id, pluginModel);
//add to editor map
createEditor(pluginModel,selectedId, usePlugin.parameters);
//add to tree
jstreeCreateNode("usePluginList",usePlugin.name,usePlugin.nickName,usePlugin.id,"after");
}
function createEditorByData(pluginModel,pluginData){
var generator = containerFactory.createEditorContainer(
pluginModel.name, "generator", pluginData);
$(generator).attr("pluginName", pluginModel.nickName);
$(generator).addClass("generator");
usePluginEditorMap.put(pluginModel.id, generator);
}
}