add nickname to plugin model in web

This commit is contained in:
hmm 2014-08-18 16:16:33 +08:00
parent f2c6b9db43
commit 1688254000
7 changed files with 96 additions and 84 deletions

View File

@ -240,6 +240,8 @@ body {
<script src="script/editor/usePlugin.js"></script>
<script src="script/editor/submitScript.js"></script>
<script src="script/editor/createScript.js"></script>
<!-- <script src="script/editor/jquery.js"></script>-->
<script src="script/editor/jstree.js"></script>
</fmt:bundle>

View File

@ -59,9 +59,7 @@ function Behavior() {
var behaviorName = usePluginName + "_" + method + "_"
+ behavior.index;
behavior.index++;
//???在这里初始化
jstreeCreate("useBehaviorList");
//??
if ($("#addBehavior").hasClass("clicked")) {
var pos = "last";
behavior.appendBehavior(behaviorName);
@ -78,7 +76,6 @@ function Behavior() {
jstreeCreateNode("useBehaviorList",behaviorName,behavior.index,pos);
$("#insertBehaviorAfter").removeClass("clicked");
}
//将原先修改的保存起来
behavior.updateBehaviorEditors();
behavior.createBehaviorEditor(behaviorName);
$("#selectBehavior").modal('hide');
@ -142,7 +139,6 @@ function Behavior() {
$("#behaviorEditor").html("");
}
//获取behavior的参数
this.createBehaviorEditor = function(behaviorName) {
var pluginName = this.getPluginName(behaviorName);

View File

@ -1,7 +1,6 @@
$(function() {
$("#tabs").tabs();
var usePlugin = new UsePlugin();
//初始化所有可选的插件
usePlugin.getPluginList();
var behavior = new Behavior();
var collectScriptData = new CollectScriptData(usePlugin, behavior);

View File

@ -25,7 +25,7 @@ ContainerFactory.prototype.createEditorContainer = function(header, id,
this.appendEdtiors(container, containerInfo[i].label,
containerInfo[i].nameCN, containerInfo[i].name,
containerInfo[i].paramTypeModel);
containerInfo[i].paramTypeModel,containerInfo[i].value);
} else {
$(container).append(

View File

@ -1,10 +1,13 @@
function dataTransfer(serverData) {
function dataTransfer(serverData,otherData) {
var Container = function(name, children) {
this.name = name;
this.children = children;
};
var editorInfos = new Array();
// if(otherData != undefined){
// editorInfos.push(otherData);
// }
var paramInfos = serverData.paramInfoModels;
var groupInfos = serverData.groupModels;
if (paramInfos != null) {

View File

@ -91,14 +91,14 @@ EditorFactory.prototype.createMultiField = function(label, name, size, id,
}
EditorFactory.prototype.createFieldLine = function(size, name, value) {
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).val(value);
$(field).attr("maxlength", size);
$(field).attr("value",value);
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
}
@ -115,6 +115,7 @@ EditorFactory.prototype.createFile = function(label, name, size, id,value) {
$(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;

View File

@ -1,36 +1,40 @@
function PluginModel(id, name) {
this.id = "plugin" + id;
this.name = name;
this.nickName = name+"_"+id;
}
function UsePlugin() {
var usePlugin = this;
this.map = new HashMap();//key是id,value是插件的类型http等
this.index = 1;//用来记录plugin的数目
this.usePluginEditorMap = new HashMap();//key是id,value是插件的参数
this.map = new HashMap();
this.index = 1;
this.usePluginEditorMap = new HashMap();
$("#addPlugin").click(function() {
//按钮变化
$("#addPlugin").addClass("clicked");
//显示所有插件
$("#selectUsePlugin").modal('show');
});
$("#deletePlugin").click(function() {
});
//用户点击确认添加插件
$("#selectUsePlugin #ok").click(
function() {
//所选的插件的名字
var pluginName = $(
"#pluginList div input[name='plugins']:checked").val();
if (pluginName == undefined) {
return;
}
//添加到已有的插件列表中
var pluginModel = new PluginModel(usePlugin.index, pluginName);
$("#usePluginList").append(
createRadio(pluginName + "_" + usePlugin.index,
"usePlugin", usePlugin.index));
//在usePlugin类中存储新添加的插件
usePlugin.map.put(usePlugin.index, pluginName);
//记录已改变的插件参数
createRadio(pluginModel.nickName,
"usePlugin", pluginModel.id));
usePlugin.map.put(pluginModel.id, pluginModel);
usePlugin.updateUsePlugin();
//
usePlugin.createEditor(pluginName , usePlugin.index);
usePlugin.createEditor(pluginModel);
usePlugin.index++;
$("#selectUsePlugin").modal('hide');
@ -39,37 +43,35 @@ function UsePlugin() {
$("#selectUsePlugin #cancel").click(function() {
$("#selectUsePlugin").modal('hide');
});
$("#removePlugin")
.click(
function() {
var pluginName = $(
"#usePluginList input[name='usePlugin']:checked")
.val();
if (pluginName == undefined) {
return;
} else {
var index = Number(pluginName.split("_")[1]);
usePlugin.map.remove(index);
usePlugin.usePluginEditorMap.remove(pluginName);
//重新显示插件列表
usePlugin.createUsePlugin(usePlugin.map);
}
$("#usePluginEditor").attr("usePlugin", "");
$("#usePluginEditor").html("");
$("#removePlugin").click(
function() {
var pluginId = $(
"#usePluginList input[name='usePlugin']:checked").attr(
"id");
if (pluginId == undefined) {
return;
} else {
usePlugin.map.remove(pluginId);
usePlugin.usePluginEditorMap.remove(pluginId);
usePlugin.createUsePlugin(usePlugin.map);
}
$("#usePluginEditor").attr("usePlugin", "");
$("#usePluginEditor").html("");
});
});
$("#clearPlugin").click(function() {
$("#usePluginList").html("");
usePlugin.map.clear();
usePlugin.usePluginEditorMap.clear();
});
//重新显示插件列表
this.createUsePlugin = function(map) {
$("#usePluginList").html("");
var keys = map.getKeys();
for ( var i = 0; i < keys.length; i++) {
for (var i = 0; i < keys.length; i++) {
var pluginModel = map.get(keys[i]);
$("#usePluginList").append(
createRadio(map.get(keys[i]) + "_" + keys[i], "usePlugin",keys[i]));
createRadio(pluginModel.nickName, "usePlugin",
pluginModel.id));
}
$("#pluginEditor").html("");
}
@ -84,65 +86,74 @@ function UsePlugin() {
});
}
//获取新选择的插件的参数
this.createEditor = function(pluginName, id) {
this.createEditor = function(pluginModel) {
var containerFactory = new ContainerFactory();
// var pluginName = usePluginName.split("_")[0];
$.post("getPlugin" + "/" + pluginName, {}, function(data) {
if (data.success) {
var pluginData = dataTransfer(data.plugin);
var generator = containerFactory.createEditorContainer(
pluginName, "generator", pluginData);
$(generator).attr("pluginName", pluginName+"_"+id);//昵称初始化为id
$(generator).addClass("generator");
// usePlugin.usePluginEditorMap.put(usePluginName, generator);
usePlugin.usePluginEditorMap.put(id, generator);
} else {
return;
}
$.post("getPlugin" + "/" + pluginModel.name, {},
function(data) {
if (data.success) {
var pluginData = dataTransfer(data.plugin);
//add nickName field to the head of editor
//pluginData.unshift(usePlugin.getNickNameEditor(pluginModel.nickName));
var generator = containerFactory.createEditorContainer(
pluginModel.name, "generator", pluginData);
$(generator).attr("pluginName",
pluginModel.nickName);
$(generator).addClass("generator");
usePlugin.usePluginEditorMap.put(pluginModel.id,
generator);
});
} else {
return;
}
});
}
//将之前更改的plugin的参数存储起来
this.updateUsePlugin = function() {
if ($("#pluginEditor").attr("usePlugin") == undefined
|| $("#pluginEditor").attr("usePlugin") == "") {
return;
}
//插件的参数存储在这里
this.usePluginEditorMap.put($("#pluginEditor").attr("usePlugin"), $(
"#pluginEditor div:first").clone());
$("#pluginEditor").attr("usePlugin", "");
$("#pluginEditor").html("");
}
$("#usePluginList")
.on(
"click",
//"input[name='usePlugin']",
"div[class='line']",
function() {
var usePluginName = $(
"#usePluginList input[name='usePlugin']:checked")
.val();
if (usePluginName == undefined) {
return;
}
usePlugin.updateUsePlugin();
$("#pluginEditor")
.append(
usePlugin.usePluginEditorMap
.get(usePluginName));
$("#pluginEditor").attr("usePlugin", usePluginName);
});
$("#usePluginList").on(
"click",
//"input[name='usePlugin']",
"div[class='line']",
function() {
var usePluginId = $(
"#usePluginList input[name='usePlugin']:checked").attr(
"id");
if (usePluginId == undefined) {
return;
}
usePlugin.updateUsePlugin();
$("#pluginEditor").append(
usePlugin.usePluginEditorMap.get(usePluginId));
$("#pluginEditor").attr("usePlugin", usePluginId);
});
this.getPluginName = function(usePluginName) {
return usePluginName.split("_")[0];
}
this.getUsePluginId = function(usePluginName) {
return usePluginName.split("_")[1];
}
this.getNickNameEditor = function(pluginNickName){
var obj = new Object();
obj.label = "nickName";
obj.name = "nickName";
obj.value = pluginNickName;
var paramTypeModel = new Object();
paramTypeModel.size = 100;
paramTypeModel.text = pluginNickName;
paramTypeModel.type = "field";
obj.paramTypeModel = paramTypeModel;
return obj;
}
}