refactor the plugin js

This commit is contained in:
fanfuxiaoran 2014-05-07 17:45:10 +08:00
parent 8f55e6fcb1
commit 2b99a987c1
9 changed files with 40 additions and 194 deletions

View File

@ -29,7 +29,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.bench4q.web.newservice.PluginService;
@Controller
@SessionAttributes({ "accessToken" })

View File

@ -91,7 +91,7 @@ public class MonitorController extends BaseController {
if (resultModels == null) {
return fail(map, SERVER_ERROR);
}
success(map);
map = success(map);
map.put("memInfo", resultModels);
return map;
}

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.bench4q" />
<mvc:annotation-driven />
</beans>

View File

@ -3,9 +3,12 @@ label {
margin-right: 30px;
}
input,textarea {
}
button {
margin-right: 5px;
width: 70px;
}
@ -27,9 +30,9 @@ button {
}
table tr td {
table tr td input {
text-align: center;
width:10px;
width: 100%;
}
.editor p {

View File

@ -134,12 +134,12 @@ textarea {
}
body {
margin: 0;
font-family: "Ubuntu", Helvetica, Arial, sans-serif;
font-family: "Helvetica","Ubuntu", Helvetica, Arial, sans-serif;
font-size: 13px;
line-height: 18px;
color: #555555;
background-color: #ffffff;
text-shadow:0 -1px 1px rgba(0, 0, 0, 0.2)
}
a {
color: #369bd7;

View File

@ -2,6 +2,7 @@ $(function() {
$('#test').append(createContainer("test", "test"));
});
function baseCreateEditor(label, id) {
var div = document.createElement("div");
$(div).addClass("editor");
@ -28,7 +29,7 @@ function createFieldLine(size, name) {
$(fieldName).html(name + ":");
var field = document.createElement("input");
$(field).attr("type", "text");
$(field).attr("width", size);
$(field).attr("style", "width:" + size + "px");
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
}
@ -66,7 +67,7 @@ function createFileEditor(label, name, size, id) {
$(fieldName).html(name + ":");
var file = document.createElement("input");
$(file).attr("type", "file");
$(file).attr("width", size);
$(file).attr("style", "width:" + size + "px");
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).append(fileEditor);
return div;
@ -113,11 +114,9 @@ function createTableEditor(label, name, cols, id) {
}
function createTable(cols, name, headers) {
var table = document.createElement("table");
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
$(thead).append(createHeader(headers));
$(tbody).append(createTr(headers, name));
$(table).append(thead);
@ -138,7 +137,7 @@ function createTableEditor(label, name, cols, id) {
function createTr(headers, name) {
var tr = document.createElement("tr");
var td = document.createElement("td");
$(td).html(name+":");
$(td).html(name + ":");
$(tr).append(td);
for ( var i = 1; i < headers.length; i++) {
var input = document.createElement("input");
@ -152,15 +151,35 @@ function createTableEditor(label, name, cols, id) {
}
}
function createSelect(label, name, size, options, id) {
if (size == null) {
size = 150;
}
var div = baseCreateEditor(label, id);
var nameLabel = document.createElement("label");
$(nameLabel).html(name + ":");
$(div).append(nameLabel);
var select = document.createElement("select");
$(select).attr("style", "width:" + size + "px");
for ( var i = 0; i < options.length; i++) {
var option = document.createElement("option");
$(option).attr("value", options[i]);
$(option).html(options[i]);
$(select).append(option);
}
$(div).append(select);
return div;
}
function createContainer(id, name) {
var div = document.createElement("div");
$(div).attr("id", id);
$(div).append(createMultiField("test", "name", 10, "test"));
$(div).append(createFileEditor("file", "file name", 10, "file"));
$(div).append(createField("field", "field name", 10, "field"));
$(div).append(createMultiField("test", "name", 150, "test"));
$(div).append(createFileEditor("file", "file name", 150, "file"));
$(div).append(createField("field", "field name", 150, "field"));
$(div).append(createTableEditor("table", "input", "td1;td1;td3", "id"));
$(div).append(createSelect("select", "select", 150, [ 1, 2, 3 ], "oo"));
return div;
}

View File

@ -1,95 +0,0 @@
function createFile(label, name, size, id) {
var div = baseCreateEditor(label, id);
var fileEditor = document.createElement("div");
var fieldName = document.createElement("label");
$(fieldName).html(name + ":");
var file = document.createElement("input");
$(file).attr("type", "file");
$(file).attr("size", size);
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).append(fileEditor);
return div;
}
function createTable(label,cols,value,id){
}
function createTable(label, name, cols, value, behaviorIndex) {
var table_content = cols.split(";");// table分隔符
var col = table_content.length;
var tableWidth = 300 / col;
var tr = document.createElement("tr");
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 divNode = document.createElement("div");
var p = document.createElement("p");
var labelNode = document.createTextNode(label);
var div = document.createElement("div");
var nameNode = document.createTextNode(name);
var br1 = document.createElement("br");
var br2 = document.createElement("br");
var addColButton = document.createElement("button");
var addColNode = document.createTextNode($.i18n.prop("addCol"));
var removeColButton = document.createElement("button");
var removeColNode = document.createTextNode($.i18n.prop("removeCol"));
var table = document.createElement("table");
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
if (value != null) {
value = value.split("|;");// 一行的信息
var row = value.length - 1;
for (var m = 0; m < row; m++) {
var colValue = value[m].split("|");// 一行中的每列信息
var trNode = document.createElement("tr");
for (var n = 0; n < col; n++) {
var tdNode = document.createElement("td");
var input = document.createElement("input");
input.setAttribute("size", 10);
input.setAttribute("type", "text");
input.setAttribute("style", "width:" + tableWidth + "px;");
input.setAttribute("value", colValue[n]);
tdNode.appendChild(input);
trNode.appendChild(tdNode);
}
tbody.appendChild(trNode);
}
}
$(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("id", tableWidth);
$(removeColButton).attr("type", "submit");
$(removeColButton).attr("class", "btn-large");
$(removeColButton).attr("onClick", "removeCol(this)");
$(table).attr("class", behaviorIndex + "_operateTableCols");
$(table).attr("class", "table-margin");
p.appendChild(labelNode);
addColButton.appendChild(addColNode);
removeColButton.appendChild(removeColNode);
thead.appendChild(tr);
table.appendChild(thead);
table.appendChild(tbody);
div.appendChild(nameNode);
div.appendChild(br1);
div.appendChild(addColButton);
div.appendChild(removeColButton);
div.appendChild(br2);
div.appendChild(table);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;

View File

@ -1,69 +0,0 @@
$(function() {
$('#test').append(createContainer("test", "test"));
});
function baseCreateEditor(label, id) {
var div = document.createElement("div");
$(div).addClass("editor");
$(div).attr("id", id);
var p = document.createElement("p")
$(p).html(label);
$(div).append(p);
return div;
}
function createField(label, name, size, id) {
var div = baseCreateEditor(label, id);
$(div).append(createFieldLine(size, name));
return div;
}
function createFieldLine(size, name) {
if (size <= 0) {
size = 10;
}
var fieldDiv = document.createElement("div");
$(fieldDiv).attr("class", "field");
var fieldName = document.createElement("label");
$(fieldName).html(name + ":");
var field = document.createElement("input");
$(field).attr("type", "text");
$(field).attr("size", size);
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
}
function createMultiField(label, name, size, id) {
var div = createField(label, name, size, id);
var addFieldButton = document.createElement("button");
$(addFieldButton).html("add")
$(addFieldButton).attr("type", "submit");
$(addFieldButton).click(function(event) {
event.preventDefault()
$(createFieldLine(size, name)).insertBefore($(this));
});
var removeFieldButton = document.createElement("button");
$(removeFieldButton).html("remove")
$(removeFieldButton).attr("type", "submit");
$(removeFieldButton).click(function(event) {
event.preventDefault();
$(this).parent().children(".field").last().remove();
});
$(div).append(addFieldButton).append(removeFieldButton);
return div;
}
function createContainer(id, name) {
var div = document.createElement("div");
$(div).attr("id", id);
$(div).append(createMultiField("test", "name", 10, "test"));
$(div).append(createFile("file", "file name", 10, "file"));
$(div).append(createField("field", "field name", 10, "field"));
return div;
}

View File

@ -6,13 +6,14 @@
<link id="bs-css" href="../../lib/chrisma/css/bootstrap-cerulean.css"
rel="stylesheet">
<link href="../../lib/chrisma/css/opa-icons.css" rel="stylesheet">
<link href='../../css/script-editor.css' rel='stylesheet'>
<link
href="http://ajax.aspnetcdn.com/ajax/bootstrap/2.3.2/css/bootstrap-responsive.css"
rel="stylesheet">
<link href="../../lib/chrisma/css/charisma-app.css" rel="stylesheet">
<link href="../../lib/chrisma/css/charisma-app.css" rel="stylesheet">
<link href="../../css/bench4q.css" rel="stylesheet">
<link href='../../css/script-editor.css' rel='stylesheet'>
</head>
<body>
<div id="test"></div>