refactor script edit code in plugin-new.js and behaviorsForm.js
This commit is contained in:
parent
f03bd61207
commit
afc30d0052
|
@ -5,7 +5,7 @@ function createBehaviorsForm(data, behaviorIndex) {
|
|||
for (var i = 0; i < data.length; i++) {
|
||||
paramInfoList.push(data[i]);
|
||||
}
|
||||
var nfieldCount=0;
|
||||
var nfieldCount = 0;
|
||||
for (var j = 0; j < paramInfoList.length; j++) {
|
||||
var paramTypeModel = paramInfoList[j].paramTypeModel;
|
||||
var methodParamModel = new ParamInfoModel(paramInfoList[j].name,
|
||||
|
@ -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);
|
||||
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);
|
||||
// choiceModels;
|
||||
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);
|
||||
|
@ -226,13 +251,13 @@ function removeCol(selectedNode) {
|
|||
|
||||
function createCheckBox(label, name, rows, behaviorIndex) {
|
||||
alert("createCheckBox");
|
||||
var valueList=new Array();
|
||||
var defaultList=new Array();
|
||||
for(var j=0; j<rows.length;j++){
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
var divNode = document.createElement("div");
|
||||
var p = document.createElement("p");
|
||||
var div = document.createElement("div");
|
||||
|
@ -246,14 +271,14 @@ function createCheckBox(label, name, rows, behaviorIndex) {
|
|||
$(divInput).attr("class", "sample_sub_frame");
|
||||
p.appendChild(labelNode);
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
alert("value="+valueList[i]+",defaultValue="+defaultList[i]);
|
||||
alert("value=" + valueList[i] + ",defaultValue=" + defaultList[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");
|
||||
if (defaultList[i] == true) {
|
||||
checkBoxNode.setAttribute("checked", "checked");
|
||||
}
|
||||
var checkBoxValue = document.createTextNode(valueList[i]);
|
||||
divInput.appendChild(checkBoxNode);
|
||||
|
@ -297,7 +322,7 @@ function createRadioButton(label, name, rows, behaviorIndex) {
|
|||
checkBoxNode.setAttribute("type", "radio");
|
||||
checkBoxNode.setAttribute("name", "radio");
|
||||
checkBoxNode.setAttribute("value", valueList[i]);
|
||||
if(defaultValue[i]==true){
|
||||
if (defaultValue[i] == true) {
|
||||
checkBoxNode.setAttribute("checked", "checked");
|
||||
}
|
||||
var checkBoxValue = document.createTextNode(valueList[i]);
|
||||
|
|
|
@ -343,11 +343,11 @@ function createAPage(data, name, index) {
|
|||
alert("createAPage");
|
||||
var documentHtml = "";
|
||||
var boxHeader = "";
|
||||
var fieldHTML="";
|
||||
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){
|
||||
if (data != null) {
|
||||
fieldHTML = createBehaviorsForm(data, index);
|
||||
}
|
||||
documentHtml = "<div id='" + index + "' class='hide'><p class='hide'>"
|
||||
|
@ -375,13 +375,17 @@ function submit(selectedNode) {
|
|||
function saveBehaviorInfo() {
|
||||
var children = document.getElementById("showPluginMethod").childNodes;
|
||||
var length = children.length;
|
||||
saveParamInfoWithSubmit(children, length, "behavior");
|
||||
if (length != 0) {
|
||||
saveParamInfoWithSubmit(children, length, "behavior");
|
||||
}
|
||||
}
|
||||
|
||||
function savePluginInfo() {
|
||||
var pluginChildren = document.getElementById("pluginParams").childNodes;
|
||||
var pluginLength = pluginChildren.length;
|
||||
saveParamInfoWithSubmit(pluginChildren, pluginLength, "plugin");
|
||||
if (pluginLength != 0) {
|
||||
saveParamInfoWithSubmit(pluginChildren, pluginLength, "plugin");
|
||||
}
|
||||
}
|
||||
|
||||
function validateBehaviors(behaviors) {
|
||||
|
@ -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