refactor script edit code in plugin-new.js and behaviorsForm.js
This commit is contained in:
parent
f03bd61207
commit
afc30d0052
|
@ -16,27 +16,29 @@ function createBehaviorsForm(data, behaviorIndex) {
|
|||
+ ",paramTypeModel=" + paramTypeModel);
|
||||
if (type == "field") {
|
||||
var size = paramTypeModel.size;
|
||||
var text = paramTypeModel.text;
|
||||
alert("text="+text);
|
||||
fieldHTML += createField(methodParamModel.lable,
|
||||
methodParamModel.name, size, behaviorIndex);
|
||||
methodParamModel.name, size, text, behaviorIndex);
|
||||
} else if (type == "nfield") {
|
||||
var size = paramTypeModel.size;
|
||||
var text = paramTypeModel.text;
|
||||
alert("text="+text);
|
||||
fieldHTML += createMultiField(methodParamModel.lable,
|
||||
methodParamModel.name, size, nfieldCount);
|
||||
methodParamModel.name, size, text, nfieldCount);
|
||||
nfieldCount++;
|
||||
} else if (type == "table") {
|
||||
var cols = paramTypeModel.cols;
|
||||
alert("cols=" + cols);
|
||||
fieldHTML += createTable(methodParamModel.lable,
|
||||
methodParamModel.name, cols, behaviorIndex);
|
||||
} else if (type == "choiceBox") {
|
||||
} else if (type == "checkBox") {
|
||||
var rows = paramTypeModel.choiceModels;
|
||||
alert("rows.length"+rows.length);
|
||||
fieldHTML += createCheckBox(methodParamModel.lable,
|
||||
methodParamModel.name, rows, behaviorIndex);
|
||||
} else if (type == "radioButton") {
|
||||
var rows = paramTypeModel.choiceModels;// List<ChoiceModel>
|
||||
// choiceModels;
|
||||
alert("rows.length="+rows.length);
|
||||
fieldHTML += createRadioButton(methodParamModel.lable,
|
||||
methodParamModel.name, rows, behaviorIndex);
|
||||
}
|
||||
|
@ -45,10 +47,10 @@ function createBehaviorsForm(data, behaviorIndex) {
|
|||
return fieldHTML;
|
||||
}
|
||||
|
||||
function createField(label, name, size, behaviorIndex) {
|
||||
function createField(label, name, size, text, behaviorIndex) {
|
||||
alert("createField");
|
||||
if (size == 0) {
|
||||
size = 20;
|
||||
size = 10;
|
||||
}
|
||||
var divNode = document.createElement("div");
|
||||
var p = document.createElement("p");
|
||||
|
@ -63,6 +65,9 @@ function createField(label, name, size, behaviorIndex) {
|
|||
$(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);
|
||||
|
@ -72,11 +77,12 @@ function createField(label, name, size, behaviorIndex) {
|
|||
return divNode.outerHTML;
|
||||
}
|
||||
|
||||
function createMultiField(label, name, size, behaviorIndex) {
|
||||
function createMultiField(label, name, size, text, behaviorIndex) {
|
||||
alert("createMultField");
|
||||
if (size == 0) {
|
||||
size = 20;
|
||||
size = 10;
|
||||
}
|
||||
|
||||
var divNode = document.createElement("div");
|
||||
var p = document.createElement("p");
|
||||
var labelNode = document.createTextNode(name + ":" + label);
|
||||
|
@ -100,7 +106,24 @@ function createMultiField(label, name, size, behaviorIndex) {
|
|||
$(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++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
p.appendChild(labelNode);
|
||||
addFieldButton.appendChild(addFieldNode);
|
||||
removeFieldButton.appendChild(removeFieldNode);
|
||||
|
@ -154,6 +177,7 @@ function createTable(label, name, cols, behaviorIndex) {
|
|||
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");
|
||||
td_content.appendChild(text_content);
|
||||
tr_content.appendChild(td_content);
|
||||
|
@ -211,6 +235,7 @@ function addCol(selectedNode) {
|
|||
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");
|
||||
td.appendChild(input);
|
||||
tr.appendChild(td);
|
||||
|
|
|
@ -375,14 +375,18 @@ function submit(selectedNode) {
|
|||
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);
|
||||
|
@ -393,11 +397,10 @@ function saveParamInfoWithSubmit(children, length, type) {
|
|||
for (var j = 0; j < length; j++) {
|
||||
var node = children[j];
|
||||
if ($(node).attr("id") == i) {
|
||||
var div = node.lastChild.firstChild.nextSibling.childNodes;
|
||||
if (type == "behavior") {
|
||||
saveABehavior(div);
|
||||
saveABehavior(node);
|
||||
} else if (type == "plugin") {
|
||||
saveAPlugin(div);
|
||||
saveAPlugin(node);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -405,24 +408,24 @@ function saveParamInfoWithSubmit(children, length, type) {
|
|||
}
|
||||
}
|
||||
|
||||
// 未完
|
||||
function saveAPlugin(div) {
|
||||
function saveAPlugin(node) {
|
||||
var id = node.firstChild.firstChild.nodeValue;
|
||||
var name = id.split("_")[0];
|
||||
var div = node.lastChild.lastChild.childNodes;
|
||||
alert("div.length=" + div.length);
|
||||
var parameters = saveParamInfo(div);
|
||||
// 获得id和name值
|
||||
var id = this.id;
|
||||
var name = this.name;
|
||||
// 构造usePluginModel
|
||||
var usePluginModel = new UsePluginModel(id, name, parameters);
|
||||
usePluginList.push(usePluginModel);
|
||||
}
|
||||
|
||||
function saveABehavior(div) {
|
||||
var behaviorIndex = 0, use = "", name = "", type = "";
|
||||
var plugin_method = div[0].parentNode.parentNode.previousSibling.firstChild.nodeValue
|
||||
.split(".");
|
||||
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] == "timer") {
|
||||
if (use.split("_")[0] == "ConstantTimer") {
|
||||
type = "TIMERBEHAVIOR";
|
||||
} else {
|
||||
type = "USERBEHAVIOR";
|
||||
|
@ -439,8 +442,8 @@ function saveParamInfo(div) {
|
|||
var parameters = new Array();
|
||||
for (var i = 0; i < length; i++) {
|
||||
var node = div[i];
|
||||
var nodeId = $(node).attr("id").split("_");
|
||||
behaviorIndex = nodeId[0];
|
||||
// var nodeId = $(node).attr("id").split("_");
|
||||
// behaviorIndex = nodeId[0];
|
||||
var parameterModel;
|
||||
var key = "", value = "", temp = "";
|
||||
if ($(node).attr("class") == "Field sample_frame") {
|
||||
|
@ -483,7 +486,6 @@ function saveParamInfo(div) {
|
|||
}
|
||||
} else if ($(node).attr("class") == "CheckBox sample_frame") {
|
||||
key = node.lastChild.firstChild.nodeValue;
|
||||
/* var id = $(node).attr("id"); */
|
||||
$('input[name= "checkbox"]:checked').each(function() {
|
||||
temp = $(this).val();
|
||||
if (temp != "") {
|
||||
|
|
Loading…
Reference in New Issue