add clearPluginChoosedList removePluginByClicked and

createPluginChoosedLines functions in plugin-new.js
This commit is contained in:
zhengyingying 2014-03-28 17:14:25 +08:00
parent 28ff64a432
commit 32acd6ffa5
2 changed files with 75 additions and 49 deletions

View File

@ -110,14 +110,14 @@ body {
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="removePlugin" onClick="removePlugin();">
id="removePlugin" onClick="removePluginByClicked();">
<fmt:message key="plugin_jsp_remove" />
</button>
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="removeAllPlugin" onClick="">
<fmt:message key="plugin_jsp_removeAll" />
id="removeAllPlugin" onClick="clearPluginChoosedList();">
<fmt:message key="plugin_jsp_clear" />
</button>
</div>
</div>

View File

@ -4,7 +4,8 @@ var pluginList = new Array();
var pluginMethodList = new Array();
var usePluginList = new Array();
var behaviors = new Array();
var clickNode = -1;
var clickPluginMethodNode = -1;
var clickPluginChoosedNode=0;
var place = "";
$(document).ready(function() {
loadPluginList();
@ -72,6 +73,40 @@ function createLineWithRadio(lineText, nameAttr) {
return $(divNode).html() + "<br>";
}
function createALine(pluginName,index,list){
var div = document.createElement("div");
var p = document.createElement("p");
var i = document.createElement("i");
var textNode = document.createTextNode(pluginName);
div.setAttribute("id", index);
i.setAttribute("class", "icon-hand-right");
p.setAttribute("id", index);
p.setAttribute("class", "");
if(list=="pluginMethodList"){
p.setAttribute("onClick", "showMethodDocument(this)");// loadMethodParams
}else if(list=="pluginChoosedList"){
p.setAttribute("onClick", "choosePlugin("+index+");");
}
p.setAttribute("style", "cursor:pointer;width:85%");
p.appendChild(i);
p.appendChild(textNode);
div.appendChild(p);
return div;
}
function choosePlugin(index){
clickPluginChoosedNode=index;
var pluginChoosedNode=$('#pluginArea').children();
var length=pluginChoosedNode.length;
for(var i=0;i<length;i++){
if(i==clickPluginChoosedNode){
$(pluginChoosedNode[i]).find("p").attr("class","visited");
}else{
$(pluginChoosedNode[i]).find("p").attr("class","");
}
}
}
function pluginFinish() {
$('#myModal_Plugin').modal('hide');
var pluginName;
@ -82,26 +117,32 @@ function pluginFinish() {
pluginName = item + "_" + aPluginIndex;
pluginChoosedList.push(pluginName);
document.getElementById("pluginArea").innerHTML += createLine(pluginName);
}
function createLine(pluginName) {
var div = document.createElement("div");
var p = document.createElement("p");
var i = document.createElement("i");
var textNode = document.createTextNode(pluginName);
i.setAttribute("class", "icon-hand-right");
p.appendChild(i);
p.appendChild(textNode);
div.appendChild(p);
return $(div).html();
createPluginChoosedLines();
}
function removePlugin() {
pluginChoosedList.pop();
var last = document.getElementById("pluginArea").lastChild;
document.getElementById("pluginArea").removeChild(last);
function createPluginChoosedLines() {
document.getElementById('pluginArea').innerHTML = "";
for (var j = 0; j < pluginChoosedList.length; j++) {
var div=createALine(pluginChoosedList[j], j,"pluginChoosedList");
document.getElementById('pluginArea').appendChild(div);
}
}
function removePluginByClicked() {
var length=pluginChoosedList.length;
for(var i=parseInt(clickPluginChoosedNode+1);i<length;i++){
pluginChoosedList[i-1]=pluginChoosedList[i];
}
pluginChoosedList.splice(length-1, 1);
createPluginChoosedLines();
}
function clearPluginChoosedList(){
pluginChoosedList.splice(0, pluginChoosedList.length);
for(var i=0;i<pluginList.length;i++){
pluginIndex.put(pluginList[i], 0);
}
document.getElementById('pluginArea').innerHTML = "";
}
function insert() {
@ -178,18 +219,18 @@ function showPluginMethod(plugin, method) {
var length = pluginMethodList.length;
var documentChild = document.getElementById("showPluginMethod").childNodes;
if (place == "before") {
for (var j = length - 1; j >= clickNode; j--) {
for (var j = length - 1; j >= clickPluginMethodNode; j--) {
pluginMethodList[j + 1] = pluginMethodList[j];
$(documentChild[j]).attr("id", parseInt(j + 1));
}
mark = clickNode;
mark = clickPluginMethodNode;
pluginMethodList[mark] = behaviorData;
} else if (place == "after") {
mark = parseInt(clickNode + 1);
if (clickNode == (length - 1) && clickNode != -1) {
mark = parseInt(clickPluginMethodNode + 1);
if (clickPluginMethodNode == (length - 1) && clickPluginMethodNode != -1) {
pluginMethodList.push(behaviorData);
} else {
for (var j = length - 1; j >= clickNode + 1; j--) {
for (var j = length - 1; j >= clickPluginMethodNode + 1; j--) {
pluginMethodList[j + 1] = pluginMethodList[j];
$(documentChild[j]).attr("id", parseInt(j + 1));
}
@ -205,38 +246,26 @@ function createPluginMethodLines() {
document.getElementById("showPluginMethod").innerHTML = "";
document.getElementById('behaviorArea').innerHTML = "";
for (var j = 0; j < pluginMethodList.length; j++) {
var div = document.createElement("div");
var p = document.createElement("p");
var i = document.createElement("i");
var textNode = document.createTextNode(pluginMethodList[j]);
div.setAttribute("id", j);
i.setAttribute("class", "icon-hand-right");
p.setAttribute("id", j);
p.setAttribute("class", "");
p.setAttribute("onClick", "showMethodDocument(this)");// loadMethodParams
p.setAttribute("style", "cursor:pointer;width:85%");
p.appendChild(i);
p.appendChild(textNode);
div.appendChild(p);
var div=createALine(pluginMethodList[j], j,"pluginMethodList");
document.getElementById('behaviorArea').appendChild(div);
loadMethodParams(pluginMethodList[j], j);
}
}
function showMethodDocument(selectedNode) {
clickNode = $(selectedNode).attr("id");
clickPluginMethodNode = $(selectedNode).attr("id");
var length = $("#showPluginMethod").children().length;
var behaviorAreaChild = $('#behaviorArea').children();
var div = $("#showPluginMethod").children();
for (var i = 0; i < length; i++) {
if (behaviorAreaChild[i].getAttribute("id") != clickNode) {
if (behaviorAreaChild[i].getAttribute("id") != clickPluginMethodNode) {
$(behaviorAreaChild[i]).find("p").attr("class", "");
} else {
$(behaviorAreaChild[i]).find("p").attr("class", "visited");
}
}
for (var j = 0; j < length; j++) {
if (div[j].getAttribute("id") == clickNode) {
if (div[j].getAttribute("id") == clickPluginMethodNode) {
$(div[j]).show();
} else {
$(div[j]).hide();
@ -248,13 +277,13 @@ function showMethodDocument(selectedNode) {
function removeInsertPluginByClicked() {
var length=$('#behaviorArea').children().length;
var removeDocumentNode = document.getElementById("showPluginMethod").childNodes;
for(var i=parseInt(clickNode+1);i<length;i++){
for(var i=parseInt(clickPluginMethodNode+1);i<length;i++){
pluginMethodList[i-1]=pluginMethodList[i];
}
pluginMethodList.splice(length-1, 1);//js Array remove element
createPluginMethodLines();
for(var j=0;j<length;j++){
if($(removeDocumentNode[j]).attr("id")==clickNode){
if($(removeDocumentNode[j]).attr("id")==clickPluginMethodNode){
document.getElementById("showPluginMethod").removeChild(removeDocumentNode[j]);
}
}
@ -264,6 +293,7 @@ function clearPluginMethodList(){
pluginMethodList.splice(0, pluginMethodList.length);
document.getElementById('behaviorArea').innerHTML = "";
document.getElementById("showPluginMethod").innerHTML = "";
$('#submitBehaviors').attr("class", "hide");
}
function loadMethodParams(behaviorData, behaviorIndex) {
@ -717,10 +747,6 @@ function cancelBehavior(selectedNode) {
$(divNode).hide();
}
$('#removeAllPlugin').click(function() {
document.getElementById('pluginArea').innerHTML = "";
});
$('#pluginCancel').click(function() {
$('#myModal_Plugin').modal('hide');
});