refactor code of script edit

This commit is contained in:
zhengyingying 2014-04-23 21:48:20 +08:00
parent 184a0042cf
commit 7b5208eb8e
10 changed files with 997 additions and 212 deletions

View File

@ -1 +1 @@
masterAddress=127.0.0.1:7979/
masterAddress=133.133.12.1:7979/

View File

@ -100,7 +100,7 @@ body {
<div class=" span4 button-div">
<div>
<button type="submit" class="btn btn-primary btn-width"
id="addPlugin" onClick="addPlugin();">
id="addPlugin">
<fmt:message key="plugin_jsp_add" />
</button>
</div>
@ -206,7 +206,7 @@ body {
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-width"
onClick="pluginFinish();" id="pluginFinish">
id="pluginFinish">
<fmt:message key="plugin_jsp_finish" />
</button>
<button type="button" class="btn btn-primary btn-width"
@ -269,11 +269,15 @@ body {
<script src="lib/chrisma/js/jquery.cookie.js"></script>
<script src="lib/chrisma/js/theme.js"></script>
<script src="script/base.js"></script>
<script src="script/pluginModel.js"></script>
<script src="script/ScriptEditor/ContainerManager.js"></script>
<script src="script/ScriptEditor/usePluginEditor.js"></script>
<script src="script/ScriptEditor/scriptEditor.js"></script>
<!-- <script src="script/pluginModel.js"></script>
<script src="script/pluginCommon.js"></script>
<script src="script/plugin-new.js"></script>
<script src="script/submitPluginMessage.js"></script>
<script src="script/behaviorsForm.js"></script>
<script src="script/behaviorsForm.js"></script> -->
</fmt:bundle>
</body>
</html>

View File

@ -0,0 +1,52 @@
var Container=function(){
this.pluginListContainer=$("#choosePlugin");
this.usePluginContainer= $("#pluginArea");
this.pluginParamConfigContainer=$("#pluginParams");
this.behaviorListForPlugin=$("#pluginMethod");
this.usePluginModal=$("#insertPluginAreaPlugins");
this.useBehaviorListContainer=$("#behaviorArea");
this.behaviorParamConfigContianer=$("#showPluginMethod");
};
var ListContainer=function(container){
this.conteiner=container;
};
Container.prototype.createLineWithRadio=function(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>";
};
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", index);
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;
};

View File

@ -0,0 +1,24 @@
$(document).ready(function() {
pluginEditor();
function pluginEditor() {
var container=new Container();
var plugin = new Plugin(container);
pluginEditorInit();
$("#addPlugin").click(function(e) {
$("#myModal_Plugin").modal('show');
});
$("#pluginFinish").click(function(e) {
var usePluginContainer = $("#pluginArea");
plugin.addUsePlugin();
plugin.usePluginContainerInit(usePluginContainer);
$("#myModal_Plugin").modal('hide');
});
function pluginEditorInit() {
var pluginListContainer = $("#choosePlugin");
plugin.pluginListContainerInit(pluginListContainer);
}
}
});

View File

@ -0,0 +1,482 @@
var Plugin = function(containerManager) {
this.pluginList = null;
this.pluginNameList = null;
this.pluginIndex = new HashMap();
this.usePluginList = new Array();
this.loadPluginNameList();
this.loadPluginList();
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) {
alert(response.failedMessage);
return;
}
plugin.pluginNameList = response.data;
for (var i = 0; i < plugin.pluginNameList.length; i++) {
plugin.pluginIndex.put(plugin.pluginNameList[i], 0);
}
}
});
};
Plugin.prototype.loadPluginList = function() {
var plugin = this;
$.ajax({
type : 'POST',
url : 'loadPluginUIList',
data : {},
dataType : 'json',
async : false,
success : function(response) {
if (!response.success) {
alert(response.failedMessage);
return;
}
plugin.pluginList = response.data;
}
});
};
Plugin.prototype.pluginListContainerInit = function(container) {
var pluginListHtmlContent = "";
for (var j = 0; j < this.pluginNameList.length; j++) {
pluginListHtmlContent += this.containerManager.createLineWithRadio(
this.pluginNameList[j], "plugin");
}
container.html(pluginListHtmlContent);
$("input:radio").click(function() {
$(this).attr("checked", "checked");
});
};
Plugin.prototype.addUsePlugin = function() {
var item = $("input[type='radio']:checked").val();
this.pluginIndex.put(item, this.pluginIndex.get(item) + 1);
this.usePluginList.push(this.createUsePluginName(item, this.pluginIndex
.get(item)));
};
Plugin.prototype.usePluginContainerInit = function(container) {
for (var i = 0; i < this.usePluginList.length; i++) {
var pluginName = this.usePluginList[i];
var div = this.containerManager
.createALine(pluginName, i, "pluginChoosedList");
container.append(div);
}
};
Plugin.prototype.configPluginContainerInit = function(container) {
};
Plugin.prototype.deleteUsePlugin = function(pluginName) {
for (var i = 0; i < this.usePluginList.length; i++) {
if (this.usePluginList[i] == pluginName) {
this.usePluginList.slice(i, 1);
}
}
};
Plugin.prototype.createUsePluginName = function(pluginName, index) {
return pluginName + '_' + index;
};
// function createPluginChoosedLines() {
// document.getElementById('pluginArea').innerHTML = "";
//
// }
// var pluginChoosedList = new Array();
// var pluginIndex = new HashMap();
// var pluginList = new Array();
// var pluginMethodList = new Array();
// var usePluginList = new Array();
// var pageList = new Array();
// var behaviors = new Array();
// var behaviorList = [];// 存放所有方法及其对应的parameter
// var pluginParamList = [];// 一个plug-in名一个paramInfoModels list
// var clickPluginMethodNode = -1;
// var clickPluginChoosedNode = 0;
// var place = "";
// var parameters = [];
//
// 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";
// }
// }
//
// $(document).ready(function() {
// loadPluginList();
// loadPluginParams();
// });
//
// function showScriptByJsonData(jsonData) {
// getPluginName(jsonData);
// getBehaviorInfo(jsonData);
// createPluginChoosedLines();
// createPluginMethodLines();
// }
//
// function getPluginName(jsonData) {
// for (var i = 0; i < jsonData.usePlugins.length; i++) {
// var name = jsonData.usePlugins[i].name;
// pluginChoosedList.push(name);
// var aPluginIndex = pluginIndex.get(name);
// pluginIndex.put(name, aPluginIndex + 1);
// var data = getParamInfoModelList(name.split("_")[0]);// paramInfoModels
// document.getElementById("pluginParams").innerHTML += createAEditText(
// data, name, i);
// }
// }
//
// function loadBehaviorParamInfos(behaviorMethod) {
// $.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) {
// parameters.push(item.key);
// parameters[item.key] = item.value;
// });
// }
// });
// }
// });
// });
// }
//
// function getBehaviorInfo(jsonData) {
// var paramInfoModels;
// $
// .each(
// jsonData.pages,
// function(i, item) {
// $
// .each(
// item.batches,
// function(i, item) {
// $
// .each(
// item.behaviors,
// function(i, item) {
// pluginMethodList
// .push(text);
// plugin = item.use;
// method = item.name;
// var text = plugin
// + "."
// + methods;
// parameters
// .splice(
// 0,
// parameters.length);
// $
// .each(
// item.parameters,
// function(
// i,
// item) {
// parameters
// .push(item.key);
// parameters[item.key] = item.value;
// });
// var data = "";
// loadBehaviorList(plugin);
// for (var i = 0; i < data.length; i++) {
// if (data[i].name == item.name) {
// paramInfoModels = data[i].paramInfoModels;
// document
// .getElementById("showPluginMethod").innerHTML += createAEditText(
// paramInfoModels,
// text,
// item.id);
// createForm(item.id);
// }
// }
// });
// });
// });
// }
//
// function getParamInfoModelList(plugin) {
// return pluginParamList[plugin];
// }
//
// function pluginFinish() {
// $('#myModal_Plugin').modal('hide');
// var pluginName;
// var item = $("input[type='radio']:checked").val();
// var aPluginIndex = pluginIndex.get(item);
// pluginIndex.put(item, aPluginIndex + 1);
// pluginName = item + "_" + aPluginIndex;
// pluginChoosedList.push(pluginName);
// createPluginChoosedLines();
// var data = getParamInfoModelList(item);// paramInfoModels
// document.getElementById("pluginParams").innerHTML += createAEditText(data,
// pluginName, pluginChoosedList.length - 1);
// }
//
// function choosePlugin(selectedNode) {
// clickPluginChoosedNode = $(selectedNode).attr("id");
// var pluginChoosedNode = $('#pluginArea').children();
// var div = document.getElementById("pluginParams").childNodes;
// showChoosedPluginInfo(pluginChoosedNode, div);
// }
//
// function showChoosedPluginInfo(pluginChoosedNode, div) {
// // 显示选中
// showChoosedPluginLine(pluginChoosedNode);
// // 显示文档
// showChoosedPluginParamInfos(div);
//
// }
//
// function showChoosedPluginLine(pluginChoosedNode) {
// for (var i = 0; i < pluginChoosedNode.length; i++) {
// if (i == clickPluginChoosedNode) {
// $(pluginChoosedNode[i]).find("p").attr("class", "visited");
//
// } else {
// $(pluginChoosedNode[i]).find("p").attr("class", "");
// }
// }
// }
//
// function showChoosedPluginParamInfos(div) {
// for (var j = 0; j < div.length; j++) {
// if (div[j].getAttribute("id") == clickPluginChoosedNode) {
// $(div[j]).show();
// } else {
// $(div[j]).hide();
// }
// }
// }
//
// function removePluginByClicked() {
// var length = pluginChoosedList.length;
// for (var i = parseInt(clickPluginChoosedNode + 1); i < length; i++) {
// pluginChoosedList[i - 1] = pluginChoosedList[i];
// }
// pluginChoosedList.splice(length - 1, 1);
// createPluginChoosedLines();
// }
//
// function clearPluginChoosedList() {
// pluginChoosedList.splice(0, pluginChoosedList.length);
// for (var i = 0; i < pluginList.length; i++) {
// pluginIndex.put(pluginList[i], 0);
// }
// document.getElementById('pluginArea').innerHTML = "";
// }
//
// function insert() {
// place = "before";
// insertPlugin();
// }
//
// function insertAfter() {
// place = "after";
// insertPlugin();
// }
//
// function insertPlugin() {
// document.getElementById("pluginMethod").innerHTML = "";
// $('#myModal_Behavior').modal('show');
// var chooesedPluginHtml = "";
// for (var i = 0; i < pluginChoosedList.length; i++) {
// chooesedPluginHtml += createLineWithRadio(pluginChoosedList[i],
// "plugin");
// }
// $("#insertPluginAreaPlugins").html(chooesedPluginHtml);
// }
//
// $('#insertPluginAreaPlugins').click(function() {
// var pluginName = $("input[type='radio']:checked").val();
// getBehaviorList(pluginName);
// });
// function loadBehaviorList(plugin) {
// var behaviors = null;
// $.ajax({
// type : "POST",
// url : "loadBehaviorList",
// data : "pluginName=" + plugin,
// dataType : "json",
// async : false,
// success : function(response) {
// if (!response.success) {
// alert(response.failedMessage);
// return;
// }
// behaviors = response.data;
// }
// });
// return behaviors;
// }
// function getBehaviorList(pluginName) {
// var methodHtml = "";
// var type = pluginName.split("_");
// var plugin = type[0];
// behaviorList.splice(0, behaviorList.length);
// var behaviors = loadBehaviorList(plugin);
// for (var i = 0; i < behaviors.length; i++) {
// behaviorList.push(behaviors[i].name);
// behaviorList[behaviors[i].name] = behaviors[i].paramInfoModels;
// methodHtml += createLineWithRadio(behaviors[i].name, "method");
// }
// document.getElementById("pluginMethod").innerHTML = methodHtml;
// }
//
// function behaviorFinish() {
// var plugin = $("input[name='plugin']:checked").val();
// var method = $("input[name='method']:checked").val();
// if (plugin != null && plugin != "" && method != null && method != "") {
// showPluginMethodLine(plugin, method);
// } else {
// alert("The plugin or the method shouldn't be null!");
// $('#myModal_Behavior').modal('hide');
// }
// }
//
// var mark;
// function showPluginMethodLine(plugin, method) {
// var behaviorData = plugin + "." + method;
// var length = pluginMethodList.length;
// var documentChild = document.getElementById("showPluginMethod").childNodes;
// if (place == "before") {
// for (var j = length - 1; j >= clickPluginMethodNode; j--) {
// pluginMethodList[j + 1] = pluginMethodList[j];
// $(documentChild[j]).attr("id", parseInt(j + 1));
// }
// mark = clickPluginMethodNode;
// clickPluginMethodNode = parseInt(clickPluginMethodNode + 1);
// pluginMethodList[mark] = behaviorData;
// } else if (place == "after") {
// mark = parseInt(clickPluginMethodNode + 1);
// if (clickPluginMethodNode == parseInt(length - 1)
// && clickPluginMethodNode != -1) {
// pluginMethodList.push(behaviorData);
// } else {
// for (var j = parseInt(length - 1); j >= mark; j--) {
// pluginMethodList[j + 1] = pluginMethodList[j];
// $(documentChild[j]).attr("id", parseInt(j + 1));
// }
// pluginMethodList[mark] = behaviorData;
// }
// }
// $('#insertBefore').attr("class", "show");
// $('#myModal_Behavior').modal('hide');
// createPluginMethodLines();
// }
//
// function createPluginMethodLines() {
// document.getElementById("showPluginMethod").innerHTML = "";
// document.getElementById('behaviorArea').innerHTML = "";
// for (var j = 0; j < pluginMethodList.length; j++) {
// var div = createALine(pluginMethodList[j], j, "pluginMethodList");
// if (j == clickPluginMethodNode) {
// $(div).find("p").attr("class", "visited");
// }
// document.getElementById('behaviorArea').appendChild(div);
// loadMethodParams(pluginMethodList[j], j);
// }
// }
//
// function showMethodDocument(selectedNode) {
// clickPluginMethodNode = parseInt($(selectedNode).attr("id"));
// var length = $("#showPluginMethod").children().length;
// var behaviorAreaChild = $('#behaviorArea').children();
// var div = $("#showPluginMethod").children();
// for (var i = 0; i < length; i++) {
// if (behaviorAreaChild[i].getAttribute("id") != clickPluginMethodNode) {
// $(behaviorAreaChild[i]).find("p").attr("class", "");
// } else {
// $(behaviorAreaChild[i]).find("p").attr("class", "visited");
// }
// }
// for (var j = 0; j < length; j++) {
// if (div[j].getAttribute("id") == clickPluginMethodNode) {
// $(div[j]).show();
// } else {
// $(div[j]).hide();
// }
// }
// $('#submitBehaviors').attr("class", "show");
// }
//
// function removeInsertPluginByClicked() {
// var length = $('#behaviorArea').children().length;
// var removeDocumentNode =
// document.getElementById("showPluginMethod").childNodes;
// for (var i = parseInt(clickPluginMethodNode + 1); i < length; i++) {
// pluginMethodList[i - 1] = pluginMethodList[i];
// }
// pluginMethodList.splice(length - 1, 1);// js Array remove element
// createPluginMethodLines();
// for (var j = 0; j < length; j++) {
// if ($(removeDocumentNode[j]).attr("id") == clickPluginMethodNode) {
// document.getElementById("showPluginMethod").removeChild(
// removeDocumentNode[j]);
// }
// }
// }
//
// function clearPluginMethodList() {
// pluginMethodList.splice(0, pluginMethodList.length);
// document.getElementById('behaviorArea').innerHTML = "";
// document.getElementById("showPluginMethod").innerHTML = "";
// $('#submitBehaviors').attr("class", "hide");
// }
//
// function loadMethodParams(behaviorData, behaviorIndex) {
// var temp = behaviorData.split('.');
// var method = temp[1];
// var data = behaviorList[method];// data 为List<ParamInfoModel>
// document.getElementById("showPluginMethod").innerHTML += createAEditText(
// data, behaviorData, behaviorIndex);
// }
//
// // 生成页面显示
// function createAEditText(data, name, index) {
// var documentHtml = "";
// var boxHeader = "";
// var fieldHTML = "";
// 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) {
// fieldHTML = 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'>" + fieldHTML + "</div>"
// + "</div></div>";
// return documentHtml;
// }
//
// function cancelBehavior(selectedNode) {
// var divNode = selectedNode.parentNode.parentNode.parentNode;
// $(divNode).hide();
// }
//
// $('#pluginCancel').click(function() {
// $('#myModal_Plugin').modal('hide');
// });
//
// $('#behaviorCancel').click(function() {
// $('#myModal_Behavior').modal('hide');
// });

View File

@ -25,15 +25,15 @@ function createPluginsOrBehaviorsForm(data, behaviorIndex) {
} else if (type == "table") {
var cols = paramTypeModel.cols;
fieldHTML += createTable(methodParamModel.lable,
methodParamModel.name, cols, behaviorIndex);
methodParamModel.name, cols,null, behaviorIndex);
} else if (type == "checkBox") {
var rows = paramTypeModel.choiceModels;
fieldHTML += createCheckBox(methodParamModel.lable,
methodParamModel.name, rows, behaviorIndex);
methodParamModel.name, rows, null, behaviorIndex);
} else if (type == "radioButton") {
var rows = paramTypeModel.choiceModels;// List<ChoiceModel>
fieldHTML += createRadioButton(methodParamModel.lable,
methodParamModel.name, rows, behaviorIndex);
methodParamModel.name, rows,null, behaviorIndex);
}else if(type=="file"){
var text=paramTypeModel.text;
fieldHTML+=createFile(methodParamModel.lable,
@ -46,6 +46,62 @@ function createPluginsOrBehaviorsForm(data, behaviorIndex) {
function createFile(label,name,text,behaviorIndex){
}
function createForm(behaviorIndex) {
var formNode = document.getElementById(behaviorIndex);
var contents = formNode.lastChild.lastChild.childNodes;
var contentLength = contents.length;
for (var j = 0; j < contentLength; j++) {
var type = $(contents[j]).attr("class");
if (type == "Field sample_frame") {
var key = contents[j].lastChild.firstChild.nodeValue;
var value = parameters[key];
if (value != "" && value != null) {
$(contents[j].lastChild.lastChild).val(value);
}
} else if (type == "NField sample_frame") {
var key = contents[j].firstChild.firstChild.nodeValue.split(":")[0];
var value = parameters[key];
if (value == null) {
addField(20, behaviorIndex);
} else {
value = value.split(";");
var fieldLength = value.length;
for (var t = 0; t < fieldLength; t++) {
addField(20, behaviorIndex);
$($(contents[j]).find("table").children()[t]).find("input")
.val(value[t]);
}
}
} else if (type == "Table sample_frame") {
var key = contents[j].lastChild.firstChild.nodeValue;
var value = parameters[key];
if (value != "" && value != null) {
value = parameters[key].split("|;");
var table = $(contents[j]).find("table");
var col = table.find("th").length;
var row = value.length - 1;
var tbody = $(contents[j]).find("tbody");
for (var m = 0; m < row; m++) {
var input = value[m].split("|");
if (m != 0) {
var selectedNode = contents[j].lastChild.firstChild.nextSibling.nextSibling;
addCol(selectedNode);
}
for (var n = 0; n < col; n++) {
var rowNode = $(tbody).children()[m];
var colNode = $(rowNode).children()[n];
$(colNode).find("input").val(input[n]);
}
}
}
} else if (type == "CheckBox sample_frame") {
} else if (type = "RadioButton sample_frame") {
}
}
}
function createField(label, name, size, text, behaviorIndex) {
if (size == 0) {
@ -98,7 +154,7 @@ function createMultiField(label, name, size, text, behaviorIndex) {
$(addFieldButton).attr("type", "submit");
$(addFieldButton).attr("class", "btn-large");
$(addFieldButton).attr("onClick",
"addField(" + size + "," + behaviorIndex + ");");
"addField(" + size + "," + behaviorIndex +","+ null+");");
$(removeFieldButton).attr("type", "submit");
$(removeFieldButton).attr("class", "btn-large");
$(removeFieldButton).attr("onClick", "removeField(this)");
@ -107,19 +163,7 @@ function createMultiField(label, name, size, text, behaviorIndex) {
if (text != null) {
var content=text.split(";");
for (var i = 0; i < content.length; i++) {
var tr = document.createElement("tr");
var td1 = document.createElement("td");
var td2 = document.createElement("td");
var textNode = document.createTextNode("field_" + i + ":");
var input = document.createElement("input");
$(input).attr("type", "text");
$(input).attr("size", size);
$(input).attr("value", content[i]);
td1.appendChild(textNode);
td2.appendChild(input);
tr.appendChild(td1);
tr.appendChild(td2);
table.appendChild(tr);
addField(10,behaviorIndex,content[i]);
}
}
p.appendChild(labelNode);
@ -135,7 +179,7 @@ function createMultiField(label, name, size, text, behaviorIndex) {
}
var field;
function addField(size, addId) {
function addField(size, addId,value) {
field = $("#addFieldTable_" + addId).children().length;
var data = "field_" + field + ":";
field = field + 1;
@ -147,7 +191,9 @@ function addField(size, addId) {
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);
@ -161,26 +207,27 @@ function removeField(selectedNode) {
table.removeChild(deletedNode);
}
function createTable(label, name, cols, behaviorIndex) {
function createTable(label, name, cols,value, behaviorIndex) {
var table_content = cols.split(";");// table分隔符
var tableWidth=400/table_content.length;
var col=table_content.length;
var tableWidth=400/col;
var tr = document.createElement("tr");
for (var i = 0; i < table_content.length; i++) {
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 tr_content = document.createElement("tr");
for (var j = 0; j < table_content.length; j++) {
var td_content = document.createElement("td");
var text_content = document.createElement("input");
text_content.setAttribute("size", 10);
text_content.setAttribute("type", "text");
text_content.setAttribute("style", "width:"+tableWidth+"px;");
td_content.appendChild(text_content);
tr_content.appendChild(td_content);
}
// var tr_content = document.createElement("tr");
// for (var j = 0; j < table_content.length; j++) {
// var td_content = document.createElement("td");
// var text_content = document.createElement("input");
// text_content.setAttribute("size", 10);
// text_content.setAttribute("type", "text");
// text_content.setAttribute("style", "width:"+tableWidth+"px;");
// td_content.appendChild(text_content);
// tr_content.appendChild(td_content);
// }
var divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(label);
@ -196,12 +243,20 @@ function createTable(label, name, cols, behaviorIndex) {
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
value=value.split("|;");//一行的信息
var row=value.length;
var input=null;
for(var m=0;m<row;m++){
input=value[m].split("|");
addCol(addColButton,input);
}
$(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("onClick", "addCol("+this+","+input+")");
$(addColButton).attr("id",tableWidth);
$(removeColButton).attr("type", "submit");
$(removeColButton).attr("class", "btn-large");
@ -228,7 +283,7 @@ function createTable(label, name, cols, behaviorIndex) {
}
function addCol(selectedNode) {
function addCol(selectedNode,rowValue) {
var tableWidth=$(selectedNode).attr("id");
var tbody = selectedNode.nextSibling.nextSibling.nextSibling.lastChild;
var length = tbody.previousSibling.firstChild.childNodes.length;
@ -239,6 +294,9 @@ function addCol(selectedNode) {
input.setAttribute("size", 10);
input.setAttribute("type", "text");
input.setAttribute("style", "width:"+tableWidth+"px;");
if(rowValue!=null){
input.setAttribute("value",rowValue[i]);
}
td.appendChild(input);
tr.appendChild(td);
}
@ -251,7 +309,7 @@ function removeCol(selectedNode) {
tbody.removeChild(removeNode);
}
function createCheckBox(label, name, rows, behaviorIndex) {
function createCheckBox(label, name, rows,value ,behaviorIndex) {
var valueList = new Array();
var defaultList = new Array();
for (var j = 0; j < rows.length; j++) {
@ -295,7 +353,7 @@ function createCheckBox(label, name, rows, behaviorIndex) {
}
function createRadioButton(label, name, rows, behaviorIndex) {
function createRadioButton(label, name, rows,value, behaviorIndex) {
var valueList = new Array();
var defaultList = new Array();
for (var i = 0; i < rows.length; i++) {

View File

@ -88,7 +88,8 @@ function chooseBehavior(selectedNode) {
plugin_id = bm[0].split(":")[1];
behavior_id = bm[1].split(":")[1];
behaviorName = bm[1].split(":")[0];
loadBehaviorParamInfos(behaviorMethod);
// loadBehaviorParamInfos(behaviorMethod);
createBehaviorParamPage(behaviorMethod);
}
function loadBehaviorParamInfos(behaviorMethod) {
@ -112,6 +113,136 @@ function loadBehaviorParamInfos(behaviorMethod) {
loadBehaviorParameters(plugin, method, behaviorMethod);
}
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 += createParamInfoModelWithBehaviorParams(
paramInfoModel,
behaviorParameters,behavior_id);
}
}
});
}
});
});
document.getElementById("showPluginMethodForm").innerHTML = createAEditText(
behaviorHTML, behaviorData, behavior_id);
document.getElementById("action").style.display = "block";
}
// 生成页面显示
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 createParamInfoModelWithBehaviorParams(paramInfoModel,
behaviorParameters,behaviorIndex) {
var name = paramInfoModel.name;
var value = behaviorParameters[name];
return createModelByType(value, paramInfoModel,behaviorIndex);
}
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 filedHTML;
}
function loadBehaviorList(plugin){
var behaviors=null;
$.ajax({
type : "POST",
url : "loadBehaviorList",
data:"pluginName="+plugin,
dataType : "json",
async : false,
success : function(response) {
if (!response.success) {
alert(response.failedMessage);
return;
}
behaviors=response.data;
}
});
return behaviors;
}
function loadBehaviorParameters(plugin, method, behaviorData) {
if (plugin.indexOf("_") >= 0) {
plugin = plugin.split("_")[0];
@ -159,62 +290,6 @@ function loadBehaviorParameters(plugin, method, behaviorData) {
});
}
function createForm(behaviorIndex) {
var formNode = document.getElementById(behaviorIndex);
var contents = formNode.lastChild.lastChild.childNodes;
var contentLength = contents.length;
for (var j = 0; j < contentLength; j++) {
var type = $(contents[j]).attr("class");
if (type == "Field sample_frame") {
var key = contents[j].lastChild.firstChild.nodeValue;
var value = parameters[key];
if (value != "" && value != null) {
$(contents[j].lastChild.lastChild).val(value);
}
} else if (type == "NField sample_frame") {
var key = contents[j].firstChild.firstChild.nodeValue.split(":")[0];
var value = parameters[key];
if (value == null) {
addField(20, behaviorIndex);
} else {
value = value.split(";");
var fieldLength = value.length;
for (var t = 0; t < fieldLength; t++) {
addField(20, behaviorIndex);
$($(contents[j]).find("table").children()[t]).find("input")
.val(value[t]);
}
}
} else if (type == "Table sample_frame") {
var key = contents[j].lastChild.firstChild.nodeValue;
var value = parameters[key];
if (value != "" && value != null) {
value = parameters[key].split("|;");
var table = $(contents[j]).find("table");
var col = table.find("th").length;
var row = value.length - 1;
var tbody = $(contents[j]).find("tbody");
for (var m = 0; m < row; m++) {
var input = value[m].split("|");
if (m != 0) {
var selectedNode = contents[j].lastChild.firstChild.nextSibling.nextSibling;
addCol(selectedNode);
}
for (var n = 0; n < col; n++) {
var rowNode = $(tbody).children()[m];
var colNode = $(rowNode).children()[n];
$(colNode).find("input").val(input[n]);
}
}
}
} else if (type == "CheckBox sample_frame") {
} else if (type = "RadioButton sample_frame") {
}
}
}
function saveFormModification() {
var div = document.getElementById("showPluginMethodForm").firstChild;
var contents = div.lastChild.lastChild.childNodes;
@ -298,11 +373,6 @@ function modifyJsonData() {
parameterList.splice(0, parameterList.length);
}
var clickPluginChoosedNode=0;
function editPlugin(){
alert("editPlugin");
for(var i=0;i<pluginNameList.length;i++){
var div=createALine(pluginNameList[i], i, "editPluginChoosedList");
document.getElementById("editPluginArea").appendChild(div);
}
function editPlugin() {
window.location.href("plugin.jsp?jsonData=" + modelData);
}

View File

@ -8,8 +8,9 @@ var behaviors = new Array();
var behaviorList = [];// 存放所有方法及其对应的parameter
var pluginParamList = [];// 一个plug-in名一个paramInfoModels list
var clickPluginMethodNode = -1;
var clickPluginChoosedNode = 0;
var place = "";
var parameters = [];
function setTab(name, m, n) {
for (var i = 1; i <= n; i++) {
@ -25,21 +26,89 @@ $(document).ready(function() {
loadPluginParams();
});
function loadPluginList() {
$.post("loadPluginName", {}, function(data) {
if (!data.success) {
alert(data.failedMessage);
function loadPluginList (){
$.post("loadPluginName", {}, function(response) {
if (!response.success) {
alert(response.failedMessage);
return;
}
data = data.data;// List<String> pluginList
for (var i = 0; i < data.length; i++) {
pluginList.push(data[i]);
pluginIndex.put(data[i], 0);
pluginList=response.data;
for(var i=0;i<pluginList.length;i++){
pluginIndex.put(pluginList[i], 0);
}
});
});
};
function showScriptByJsonData(jsonData) {
getPluginName(jsonData);
getBehaviorInfo(jsonData);
createPluginChoosedLines();
createPluginMethodLines();
}
function getPluginName(jsonData) {
for (var i = 0; i < jsonData.usePlugins.length; i++) {
var name = jsonData.usePlugins[i].name;
pluginChoosedList.push(name);
var aPluginIndex = pluginIndex.get(name);
pluginIndex.put(name, aPluginIndex + 1);
var data = getParamInfoModelList(name.split("_")[0]);// paramInfoModels
document.getElementById("pluginParams").innerHTML += createAEditText(data,
name, i);
}
}
function loadBehaviorParamInfos(behaviorMethod) {
$.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) {
parameters.push(item.key);
parameters[item.key] = item.value;
});
}
});
}
});
});
}
function getBehaviorInfo(jsonData) {
var paramInfoModels;
$.each(jsonData.pages, function(i, item) {
$.each(item.batches, function(i, item) {
$.each(item.behaviors, function(i, item) {
pluginMethodList.push(text);
plugin = item.use;
method = item.name;
var text = plugin + "." + methods;
parameters.splice(0, parameters.length);
$.each(item.parameters, function(i, item) {
parameters.push(item.key);
parameters[item.key] = item.value;
});
var data="";
loadBehaviorList(plugin);
for (var i = 0; i < data.length; i++) {
if(data[i].name==item.name){
paramInfoModels = data[i].paramInfoModels;
document.getElementById("showPluginMethod").innerHTML += createAEditText(
paramInfoModels, text, item.id);
createForm(item.id);
}
}
});
});
});
}
function loadPluginParams() {
$
.post(
@ -53,8 +122,8 @@ function loadPluginParams() {
data = data.data;// List<PluginUIModel>pluginUIModels
for (var i = 0; i < data.length; i++) {
var pluginInfoModel = data[i].pluginInfoModel;
list.push(pluginInfoModel.name);
list[pluginInfoModel.name] = pluginInfoModel.paramInfoModels;
pluginParamList.push(pluginInfoModel.name);
pluginParamList[pluginInfoModel.name] = pluginInfoModel.paramInfoModels;
}
});
}
@ -87,6 +156,29 @@ function createLineWithRadio(lineText, nameAttr) {
return $(divNode).html() + "<br>";
}
function createALine(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", index);
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;
}
function getParamInfoModelList(plugin) {
return pluginParamList[plugin];
}
@ -102,10 +194,46 @@ function pluginFinish() {
pluginChoosedList.push(pluginName);
createPluginChoosedLines();
var data = getParamInfoModelList(item);// paramInfoModels
document.getElementById("pluginParams").innerHTML += createAPage(data,
document.getElementById("pluginParams").innerHTML += createAEditText(data,
pluginName, pluginChoosedList.length - 1);
}
function choosePlugin(selectedNode) {
clickPluginChoosedNode = $(selectedNode).attr("id");
var pluginChoosedNode = $('#pluginArea').children();
var div = document.getElementById("pluginParams").childNodes;
showChoosedPluginInfo(pluginChoosedNode, div);
}
function showChoosedPluginInfo(pluginChoosedNode, div) {
// 显示选中
showChoosedPluginLine(pluginChoosedNode);
// 显示文档
showChoosedPluginParamInfos(div);
}
function showChoosedPluginLine(pluginChoosedNode) {
for (var i = 0; i < pluginChoosedNode.length; i++) {
if (i == clickPluginChoosedNode) {
$(pluginChoosedNode[i]).find("p").attr("class", "visited");
} else {
$(pluginChoosedNode[i]).find("p").attr("class", "");
}
}
}
function showChoosedPluginParamInfos(div) {
for (var j = 0; j < div.length; j++) {
if (div[j].getAttribute("id") == clickPluginChoosedNode) {
$(div[j]).show();
} else {
$(div[j]).hide();
}
}
}
function createPluginChoosedLines() {
document.getElementById('pluginArea').innerHTML = "";
for (var j = 0; j < pluginChoosedList.length; j++) {
@ -154,41 +282,46 @@ function insertPlugin() {
}
$('#insertPluginAreaPlugins').click(function() {
var item = $("input[type='radio']:checked").val();
showInsertPlugin(item);
var pluginName = $("input[type='radio']:checked").val();
getBehaviorList(pluginName);
});
function showInsertPlugin(pluginName) {
getMethodList(pluginName);
}
function getMethodList(methodData) {
var methodHtml = "";
var type = methodData.split("_");
var plugin = type[0];
$.post("loadBehaviorList", {
pluginName : plugin
}, function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
function loadBehaviorList(plugin){
var behaviors=null;
$.ajax({
type : "POST",
url : "loadBehaviorList",
data:"pluginName="+plugin,
dataType : "json",
async : false,
success : function(response) {
if (!response.success) {
alert(response.failedMessage);
return;
}
behaviors=response.data;
}
data = data.data;// List<BehaviorInfoModel> behaviorInfoModels
for (var i = 0; i < data.length; i++) {
behaviorList.push(data[i].name);
behaviorList[data[i].name] = data[i].paramInfoModels;
methodHtml += createLineWithRadio(data[i].name, "method");
}
document.getElementById("pluginMethod").innerHTML = methodHtml;
});
return behaviors;
}
function getBehaviorList(pluginName) {
var methodHtml = "";
var type = pluginName.split("_");
var plugin = type[0];
behaviorList.splice(0, behaviorList.length);
var behaviors=loadBehaviorList(plugin);
for (var i = 0; i < behaviors.length; i++) {
behaviorList.push(behaviors[i].name);
behaviorList[behaviors[i].name] = behaviors[i].paramInfoModels;
methodHtml += createLineWithRadio(behaviors[i].name, "method");
}
document.getElementById("pluginMethod").innerHTML = methodHtml;
}
function behaviorFinish() {
var plugin = $("input[name='plugin']:checked").val();
var method = $("input[name='method']:checked").val();
if (plugin != null && plugin != "" && method != null && method != "") {
showPluginMethod(plugin, method);
showPluginMethodLine(plugin, method);
} else {
alert("The plugin or the method shouldn't be null!");
$('#myModal_Behavior').modal('hide');
@ -196,7 +329,7 @@ function behaviorFinish() {
}
var mark;
function showPluginMethod(plugin, method) {
function showPluginMethodLine(plugin, method) {
var behaviorData = plugin + "." + method;
var length = pluginMethodList.length;
var documentChild = document.getElementById("showPluginMethod").childNodes;
@ -288,12 +421,12 @@ function loadMethodParams(behaviorData, behaviorIndex) {
var temp = behaviorData.split('.');
var method = temp[1];
var data = behaviorList[method];// data 为List<ParamInfoModel>
document.getElementById("showPluginMethod").innerHTML += createAPage(data,
behaviorData, behaviorIndex);
document.getElementById("showPluginMethod").innerHTML += createAEditText(
data, behaviorData, behaviorIndex);
}
// 生成页面显示
function createAPage(data, name, index) {
function createAEditText(data, name, index) {
var documentHtml = "";
var boxHeader = "";
var fieldHTML = "";

View File

@ -1,69 +1,31 @@
var clickPluginChoosedNode = 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];
function createALine(name, index, list) {
alert("createALine");
var div = document.createElement("div");
var p = document.createElement("p");
var i = document.createElement("i");
var textNode = document.createTextNode(name);
div.setAttribute("id", index);
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;
return vars;
}
function choosePlugin(selectedNode) {
clickPluginChoosedNode = $(selectedNode).attr("id");
var pluginChoosedNode = $('#pluginArea').children();
var div = document.getElementById("pluginParams").childNodes;
showChoosedPluginInfo(pluginChoosedNode,div);
}
function chooseEditPlugin(selectedNode){
clickPluginChoosedNode = $(selectedNode).attr("id");
var pluginChoosedNode = $('#editPluginArea').children();
// var div = document.getElementById("editPluginParams").childNodes;
showChoosedPluginLine(pluginChoosedNode);
}
function showChoosedPluginInfo(pluginChoosedNode,div){
// 显示选中
showChoosedPluginLine(pluginChoosedNode);
// 显示文档
showChoosedPluginParamInfos(div);
}
function showChoosedPluginLine(pluginChoosedNode){
alert("showChoosedPluginLine");
for (var i = 0; i < pluginChoosedNode.length; i++) {
if (i == clickPluginChoosedNode) {
$(pluginChoosedNode[i]).find("p").attr("class", "visited");
} else {
$(pluginChoosedNode[i]).find("p").attr("class", "");
}
$(function() {
var jsonData = getvars()['jsonData'];
if(jsonData!=null){
showScriptByJsonData(jsonData);
}
}
});
function showChoosedPluginParamInfos(div){
for (var j = 0; j < div.length; j++) {
if (div[j].getAttribute("id") == clickPluginChoosedNode) {
$(div[j]).show();
} else {
$(div[j]).hide();
}
}
}

View File

@ -28,7 +28,7 @@ function replace(keyArray, replaceArray) {
for ( var i = 0; i < keyArray.length; i++) {
for ( var j = 0; j < replaceArray.length; j++) {
if (keyArray[i] == replaceArray[j].oldWord)
keyArray[i] = replaceArray[j].newWord
keyArray[i] = replaceArray[j].newWord;
}
}
}