refactor code in plugin-new.js and modify functions in

pluginActionController.java
This commit is contained in:
ZhengYingYing 2014-04-21 20:04:59 +08:00
parent e624626951
commit 856a71c38e
9 changed files with 98 additions and 53 deletions

View File

@ -26,8 +26,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import com.google.gson.Gson;
@Controller
@SessionAttributes({ "accessToken" })
public class PluginActionController {
@ -75,11 +73,11 @@ public class PluginActionController {
if (pluginResponseModel.isSuccess()) {
System.out.println("pluginResponseModel has been used");
List<String> pluginList = pluginResponseModel.getPluginList();
// System.out.println(pluginList.size());
if (pluginList == null) {
pluginList = new ArrayList<String>();
System.out.println("pluginList is empty");
}
System.out.println(pluginList.size());
return new BaseResponseModel(true, pluginList);
} else {
return new BaseResponseModel(false,
@ -106,9 +104,8 @@ public class PluginActionController {
pluginUIModels = new ArrayList<PluginUIModel>();
System.out.println("pluginUIModels is empty");
}
Gson gson = new Gson();
Logger.getLogger(PluginActionController.class).info(
gson.toJson(pluginUIModels));
pluginResponseModel.isSuccess());
return new BaseResponseModel(true, pluginUIModels);
} else {
return new BaseResponseModel(false,
@ -189,14 +186,14 @@ public class PluginActionController {
@RequestParam String pluginName) throws CustomGenericException {
String caller = new String(
"PluginActionController:deletePluginByPluginName");
String url = this.getBaseUrl() + "deletePlugin/" + pluginName;
String url = this.getBaseUrl() + "/deletePlugin/" + pluginName;
Map<String, String> params = BaseService.makeParamsMap("pluginName",
pluginName);
PluginResponseModel pluginResponseModel = (PluginResponseModel) this
.getCommunicateWithMaster().getResponseModel(accessToken, url,
PluginResponseModel.class, params, caller);
if (pluginResponseModel.isSuccess()) {
return new BaseResponseModel(true, "delete success");
return new BaseResponseModel(true);
} else {
return new BaseResponseModel(false,
pluginResponseModel.getFailMessage());

View File

@ -79,6 +79,7 @@ pluginManage_jsp_pluginName=plug-in Name
pluginManage_jsp_createDate=Date created
pluginManage_jsp_action=Actions
pluginManage_jsp_addPlugin=Add Plug-in
pluginManage_jsp_uploadFile=File to upload
homepage=Homepage
changetheme=Change Theme / Skin
classic=Classic

View File

@ -79,6 +79,7 @@ pluginManage_jsp_pluginName=\u63D2\u4EF6\u540D\u79F0
pluginManage_jsp_createDate=\u521B\u5EFA\u65E5\u671F
pluginManage_jsp_action=\u64CD\u4F5C
pluginManage_jsp_addPlugin=\u6DFB\u52A0\u63D2\u4EF6
pluginManage_jsp_uploadFile=\u4E0A\u4F20\u6587\u4EF6
homepage=\u4E3B\u9875
changetheme=\u66F4\u6362\u4E3B\u9898\ / \u76AE\u80A4
classic=\u7ECF\u5178\u6837\u5F0F

View File

@ -26,7 +26,8 @@
<ul class="breadcrumb">
<li><a href="homepage.jsp"><fmt:message key="home" /></a> <span
class="divider">/</span></li>
<li><a href="pluginManage.jsp"><fmt:message key="pluginmanage" /></a></li>
<li><a href="pluginManage.jsp"><fmt:message
key="pluginmanage" /></a></li>
</ul>
</div>
<div class="row-fluid sortable">
@ -36,8 +37,8 @@
<i><fmt:message key="pluginManage_jsp_plugin" /></i>
</h2>
<div class="box-icon">
<a class="btn btn-setting btn-round" onClick="showModel();"><i class="icon-plus"></i></a>
<a class="btn btn-round" id="agentList"><i
<a class="btn btn-setting btn-round" onClick="showModel();"><i
class="icon-plus"></i></a> <a class="btn btn-round" id="agentList"><i
class="icon-list"></i></a> <a class="btn btn-minimize btn-round"><i
class="icon-chevron-up"></i></a> <a
class="btn btn-close btn-round"><i class="icon-remove"></i></a>
@ -76,12 +77,9 @@
<div class="modal-body">
<form method="post" enctype="multipart/form-data"
action="uploadPluginFile">
<!-- <p>
file name:<input class="input-mini" type="text"
name="pluginFileName" id="fileName">
</p> -->
<p>
file to upload:<input type="file" name="pluginFile" />
<fmt:message key="pluginManage_jsp_uploadFile" />
:<input type="file" name="pluginFile" />
</p>
<p>
<input type="submit" />

View File

@ -44,7 +44,7 @@
<div class="userInput">
<div class="registerInput row-fluid">
<img alt="bench4q-username" src="images/username.jpg"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserName:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<input id="username" name="username" tabindex="1" type="text"
<input autofocus id="username" name="username" tabindex="1" type="text"
onchange="form_validation('username')">
</div>
<div class="hide">
@ -53,7 +53,7 @@
</div>
<div class="registerInput row-fluid">
<img alt="bench4q-password" src="images/password.jpg"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<input id="password" name="password" tabindex="1" type="text"
<input id="password" name="password" tabindex="1" type="password"
onchange="form_validation('password')">
</div>
<div class="hide">
@ -62,7 +62,7 @@
</div>
<div class="registerInput row-fluid">
<img alt="bench4q-retype-password" src="images/retype.jpg"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Re-Password:&nbsp;
</span> <input id="retype_pwd" name="retype_pwd" tabindex="1" type="text"
</span> <input id="retype_pwd" name="retype_pwd" tabindex="1" type="password"
onchange="form_validation('retype_pwd')">
</div>
<div class="hide">

View File

@ -3,32 +3,53 @@ $(document).ready(function() {
});
var table = $('#addPluginTable');
var deleteButton = "<a class='btn btn-info' onClick='deleteScript(this)'><i class='icon-trash icon-white'></i>Delete</a>";
var deleteButton = "<a class='btn btn-info' onClick='deletePlugin(this)'><i class='icon-trash icon-white'></i>Delete</a>";
function loadPluginInfo() {
alert("loadPluginInfo");
$.post("loadPluginUIInfo", {}, function(data) {
$.post("loadPluginUIList", {}, function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;// List<PluginUIModel>
alert("data.length="+data.length);
table.dataTable().fnClearTable();
for (var i = 0; i < data.length; i++) {
var time = new Date(data[i].createTimeDate);//时间转换
table.dataTable().fnAddData(
[ data[i].pluginInfoModel.name, data[i].createTimeDate,
deleteButton ]);
[ data[i].pluginInfoModel.name, time, deleteButton ]);
}
});
}
function deletePlugin(selectedNode){
var plugin=selectedNode.parentNode.parentNode.firstChild.firstChild.nodeValue;
var con=confirm("Are you sure you want to delete this plugin?");
if (con==true) {
deleteAPlugin(plugin);
}
}
function deleteAPlugin(plugin){
$.post("deletePluginByPluginName", {
pluginName:plugin
}, function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
alert("delete success!");
location.replace(location) ;
});
}
function showModel() {
$('#myModal_plugin').modal('show');
$('form').ajaxForm({
success : function(data) {
$('#myModal_plugin').modal('hide');
if (data.success) {
alert("upload success!");
loadPluginInfo();
} else {
alert(data.failedMessage);

View File

@ -1,41 +1,52 @@
// data 为List<ParamInfoModel>
// data 为List<ParamInfoModel> paramInfoModels;
function createBehaviorsForm(data, behaviorIndex) {
var paramInfoList = new Array();
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].lable, paramTypeModel);
var type = paramTypeModel.type;
if (type == "Field") {
paramInfoList[j].lable, paramInfoList[j].type, paramTypeModel);
var type = methodParamModel.type;
alert("name=" + methodParamModel.name + ",lable="
+ methodParamModel.lable + ",type=" + methodParamModel.type
+ ",paramTypeModel=" + paramTypeModel);
if (type == "field") {
var size = paramTypeModel.size;
fieldHTML += createField(methodParamModel.lable,
methodParamModel.name, size, behaviorIndex);
} else if (type == "NField") {
} else if (type == "nfield") {
var size = paramTypeModel.size;
fieldHTML += createMultiField(methodParamModel.lable,
methodParamModel.name, size, behaviorIndex);
} else if (type == "Table") {
methodParamModel.name, size, nfieldCount);
nfieldCount++;
} else if (type == "table") {
var cols = paramTypeModel.cols;
alert("cols="+cols);
fieldHTML += createTable(methodParamModel.lable,
methodParamModel.name, cols, behaviorIndex);
} else if (type == "CheckBox") {
} else if (type == "choiceBox") {
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;
} else if (type == "radioButton") {
var rows = paramTypeModel.choiceModels;// List<ChoiceModel>
// choiceModels;
alert("rows.length="+rows.length);
fieldHTML += createRadioButton(methodParamModel.lable,
methodParamModel.name, rows, behaviorIndex);
}
}
alert("fieldHTML=" + fieldHTML);
return fieldHTML;
}
function createField(label, name, size, behaviorIndex) {
alert("createField");
if (size == 0) {
size = 20;
}
@ -62,6 +73,7 @@ function createField(label, name, size, behaviorIndex) {
}
function createMultiField(label, name, size, behaviorIndex) {
alert("createMultField");
if (size == 0) {
size = 20;
}
@ -129,7 +141,8 @@ function removeField(selectedNode) {
}
function createTable(label, name, cols, behaviorIndex) {
var table_content = cols.split("|");// table分隔符
alert("createTable");
var table_content = cols.split(";");// table分隔符
var tr = document.createElement("tr");
for (var i = 0; i < table_content.length; i++) {
var th = document.createElement("th");
@ -212,11 +225,14 @@ function removeCol(selectedNode) {
}
function createCheckBox(label, name, rows, behaviorIndex) {
var valueList = new Array();
for (var i = 0; i < rows.length; i++) {
valueList.push(rows[i].value);
alert("createCheckBox");
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");
@ -229,12 +245,16 @@ function createCheckBox(label, name, rows, behaviorIndex) {
$(div).attr("class", "sample_sub_frame");
$(divInput).attr("class", "sample_sub_frame");
p.appendChild(labelNode);
for (var i = 0; i < valueList.length; i++) {
for (var i = 0; i < rows.length; 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");
}
var checkBoxValue = document.createTextNode(valueList[i]);
divInput.appendChild(checkBoxNode);
divInput.appendChild(checkBoxValue);
@ -250,9 +270,14 @@ function createCheckBox(label, name, rows, behaviorIndex) {
}
function createRadioButton(label, name, rows, behaviorIndex) {
alert("createRadioButton");
var valueList = new Array();
var defaultList = new Array();
for (var i = 0; i < rows.length; i++) {
valueList.push(rows[i].value);
var choiceModel = rows[i];
valueList.push(choiceModel.value);
defaultList.push(choiceModel.defaultValue);
alert("value=" + choiceMode.value + ",defaultValue=" + defauleValue);
}
var divNode = document.createElement("div");
var p = document.createElement("p");
@ -272,6 +297,9 @@ function createRadioButton(label, name, rows, behaviorIndex) {
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);

View File

@ -23,11 +23,9 @@ function setTab(name, m, n) {
$(document).ready(function() {
loadPluginList();
loadPluginParams();
});
function loadPluginList() {
alert("loadPLuginName");
$.post("loadPluginName", {}, function(data) {
if (!data.success) {
alert(data.failedMessage);
@ -42,9 +40,7 @@ function loadPluginList() {
}
// 实现plug-in参数传递
function loadPluginParams() {
alert("loadPluginParams");
$
.post(
"loadPluginUIList",
@ -115,7 +111,6 @@ function createALine(pluginName, index, list) {
function choosePlugin(selectedNode) {
clickPluginChoosedNode = $(selectedNode).attr("id");
alert("clickPluginChoosedNode=" + clickPluginChoosedNode);
var pluginChoosedNode = $('#pluginArea').children();
var length = pluginChoosedNode.length;
// 显示选中
@ -130,7 +125,7 @@ function choosePlugin(selectedNode) {
// 显示文档
var div = document.getElementById("pluginParams").childNodes;
for (var j = 0; j < length; j++) {
if (div[j].getAttribute("id") == clickPluginMethodNode) {
if (div[j].getAttribute("id") == clickPluginChoosedNode) {
$(div[j]).show();
} else {
$(div[j]).hide();
@ -139,7 +134,6 @@ function choosePlugin(selectedNode) {
}
function getParamInfoModelList(plugin) {
alert("pluginParamList.length="+pluginParamList.length);
return pluginParamList[plugin];
}
@ -153,7 +147,6 @@ function pluginFinish() {
pluginName = item + "_" + aPluginIndex;
pluginChoosedList.push(pluginName);
createPluginChoosedLines();
// 生成页面,但不显示
var data = getParamInfoModelList(item);// paramInfoModels
document.getElementById("pluginParams").innerHTML += createAPage(data,
pluginName, pluginChoosedList.length - 1);
@ -347,12 +340,16 @@ function loadMethodParams(behaviorData, behaviorIndex) {
// 生成页面显示
function createAPage(data, name, index) {
alert("createAPage");
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>";
var fieldHTML = createBehaviorsForm(data, index);
if(data!=null){
fieldHTML = createBehaviorsForm(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>"

View File

@ -1,12 +1,14 @@
function BehaviorInfoModel(paramInfoModels,name){
function BehaviorInfoModel(paramInfoModels,behaviorType,name){
this.paramInfoModels=paramInfoModels;
this.behaviorType=behaviorType;
this.name=name;
}
function ParamInfoModel(name,lable,paramTypeModel){
function ParamInfoModel(name,lable,type,paramTypeModel){
this.name=name;
this.lable=lable;
this.type=type;
this.paramTypeModel=paramTypeModel;
}