edit create page

This commit is contained in:
hmm 2014-08-19 10:10:48 +08:00
parent 1688254000
commit 7eefaae62d
6 changed files with 79 additions and 51 deletions

View File

@ -108,20 +108,16 @@ body {
</div>
<div class="span3 buttonsControl">
<button type="submit" class="btn btn-primary btn-width"
id="addBehavior">
<fmt:message key="plugin_jsp_add" />
</button>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="insertBehaviorBefore">
<fmt:message key="plugin_jsp_insertBefore" />
id="insertChildNode">
<fmt:message key="plugin_jsp_insertChild" />
</button>
</div>
<div>
<button type="submit" class="btn btn-primary btn-width"
id="insertBehaviorAfter">
<fmt:message key="plugin_jsp_insertAfter" />
id="addBehavior">
<fmt:message key="plugin_jsp_add" />
</button>
</div>
<div>

View File

@ -19,7 +19,7 @@ function getScriptObject(scriptId) {
} else {
// alert(data.script);
var scriptObj = eval("(" + data.script + ")");
createRadioGroupByAttribute(scriptObj.usePlugins, "name", "plugins",
createRadioGroupByAttribute(scriptObj.usePlugins, "nickName", "name","id","plugins",
"usePluginList");

View File

@ -1,35 +1,46 @@
/**
*
*/
function Behavior() {
function BehaviorModel(pluginModel, method, id){
this.pluginModel = pluginModel;
this.method = method;
this.id = id;
this.behaviorName = pluginModel.nickName+"_"+method+"_"+id;
}
function Behavior(usePlugin) {
this.usePlugin = usePlugin;
this.behaviorList = new Array();
this.behaviorEditorMap = new HashMap();
this.index = 1;
var behavior = this;
//init tree node container
jstreeCreate("useBehaviorList");
$("#addBehavior").click(function() {
$("#usePlugins").html($("#usePluginList").html());
behavior.showPluginList();
// $("#usePlugins").html($("#usePluginList").html());
$("#selectBehavior").modal('show');
$("#addBehavior").addClass("clicked");
});
$("#insertBehaviorBefore").click(function() {
$("#usePlugins").html($("#usePluginList").html());
behavior.showPluginList();
// $("#usePlugins").html($("#usePluginList").html());
$("#selectBehavior").modal('show');
$("#insertBehaviorBefore").addClass("clicked");
});
$("#insertBehaviorAfter").click(function() {
$("#usePlugins").html($("#usePluginList").html());
behavior.showPluginList();
// $("#usePlugins").html($("#usePluginList").html());
$("#selectBehavior").modal('show');
$("#insertBehaviorAfter").addClass("clicked");
});
$("#selectBehavior").on(
"click",
"input[name='usePlugin']",
"div[name='behavior_usePlugin']",
function() {
var usePluginName = $(
"#selectBehavior input[name='usePlugin']:checked")
var pluginName = $(
"#selectBehavior input[name='behavior_usePlugin']:checked")
.val();
var pluginName = usePluginName.split("_")[0];
// var pluginName = usePluginName.split("_")[0];
$.post("loadBehaviorList", {
pluginName : pluginName
}, function(data) {
@ -37,51 +48,51 @@ function Behavior() {
alert("fail");
return;
}
var methods = new Array();
for ( var i = 0; i < data.behaviors.length; i++) {
methods.push(data.behaviors[i].name);
}
// var methods = new Array();
// for ( var i = 0; i < data.behaviors.length; i++) {
// methods.push(data.behaviors[i].name);
// }
$("#pluginMethod").html("");
createRadioGroup(methods, "method", "pluginMethod");
createRadioGroupByAttribute(data.behaviors, "name", "name", "name", "method", "pluginMethod")
});
});
$("#selectBehavior #ok").click(
function() {
var usePluginName = $(
"#usePlugins input[name='usePlugin']:checked").val();
var usePluginId = $(
"#usePlugins input[name='behavior_usePlugin']:checked").attr("id");
var method = $("#pluginMethod input[name='method']:checked")
.val();
if (usePluginName == undefined || method == undefined) {
var pluginId = usePluginId.split("_")[2];
if (pluginId == undefined || method == undefined) {
return;
}
var behaviorName = usePluginName + "_" + method + "_"
+ behavior.index;
behavior.index++;
jstreeCreate("useBehaviorList");
var behaviorModel = new BehaviorModel(behavior.usePlugin.map.get(pluginId),method,behavior.index);
if ($("#addBehavior").hasClass("clicked")) {
var pos = "last";
behavior.appendBehavior(behaviorName);
jstreeCreateNode("useBehaviorList",behaviorName,behavior.index,pos);
behavior.appendBehavior( behaviorModel);
jstreeCreateNode("useBehaviorList", behaviorModel.behaviorName,behaviorModel.id,pos);
$("#addBehavior").removeClass("clicked");
} else if ($("#insertBehaviorBefore").hasClass("clicked")) {
var pos = "before";
behavior.insertBehavior(behaviorName);//前插入和后插入一样??
jstreeCreateNode("useBehaviorList",behaviorName,behavior.index,pos);
jstreeCreateNode("useBehaviorList", behaviorModel.behaviorName,behaviorModel.id,pos);
$("#insertBehaviorBefore").removeClass("clicked");
} else {
var pos = "after";
behavior.insertBehavior(behaviorName);//前插入和后插入一样??
jstreeCreateNode("useBehaviorList",behaviorName,behavior.index,pos);
jstreeCreateNode("useBehaviorList", behaviorModel.behaviorName,behaviorModel.id,pos);
$("#insertBehaviorAfter").removeClass("clicked");
}
behavior.updateBehaviorEditors();
behavior.createBehaviorEditor(behaviorName);
$("#selectBehavior").modal('hide');
$("#usePlugins").html("");
$("#pluginMethod").html("");
behavior.index++;
});
$("#selectBehavior #cancel").click(function() {
$("#selectBehavior").modal('hide');
@ -210,4 +221,14 @@ function Behavior() {
}
}
this.showPluginList = function(){
$("#usePlugins").html("");
var keys = usePlugin.map.getKeys();
for (var i = 0; i < keys.length; i++) {
var pluginModel = usePlugin.map.get(keys[i]);
$("#usePlugins").append(
createRadio("behavior_plugin_"+pluginModel.id,pluginModel.nickName, "behavior_usePlugin",pluginModel.name));
}
}
}

View File

@ -2,7 +2,7 @@ $(function() {
$("#tabs").tabs();
var usePlugin = new UsePlugin();
usePlugin.getPluginList();
var behavior = new Behavior();
var behavior = new Behavior(usePlugin);
var collectScriptData = new CollectScriptData(usePlugin, behavior);
$("#submitScript").click(function() {
submitScript(collectScriptData);

View File

@ -1,37 +1,48 @@
function createRadioGroup(items,name,containerId){
for ( var i = 0; i < items.length; i++) {
var radio = createRadio(items[i],name,items[i]);
var radio = createRadio(items[i],items[i],name,items[i]);
$("#" + containerId).append(radio);
}
}
/**
* @param item 显示文本
* @param name 统一radio
* @param id 方便label标签和div选择
* @returns
* @param id synchronize the radio, label and div
* @param text show in the web
* @param name this is same in a radio group
* @param value
* @returns
*/
function createRadio (item,name,id) {
var line = $("<div style='cursor:pointer;'>");
function createRadio (id,text,name,value) {
var line = $("<div style='cursor:pointer;' name='"+name+"'>");
line.click(function(){
document.getElementById(id).checked = true;
})
var input = $("<input type='radio' name="+name+" id="+id+">");
input.attr("value",item);
input.attr("value",value);
input.attr("text",text);
var span = $("<label for="+id+" style='cursor:pointer;'>");
span.html(item);
span.html(text);
line.append(input);
line.append(span);
line.addClass("line");
return line;
}
function createRadioGroupByAttribute(items,attr,name,containerId){
/**
* @param items
* @param textAttr the key of text which is show in the web
* @param valueAttr the key of value which is store in the web
* @param idAttr
* @param name
* @param containerId
*/
function createRadioGroupByAttribute(items,textAttr,valueAttr,idAttr, name,containerId){
for ( var i = 0; i < items.length; i++) {
var radio = createRadio(items[i][attr],name,items[i]["id"]);
var radio = createRadio(items[i][idAttr],items[i][textAttr],name,items[i][valueAttr]);
$("#" + containerId).append(radio);
}
}
function jstreeCreateNode(containerId,name,id,pos){
var ref = $("#"+containerId).jstree(true);
var sel = ref.get_selected();

View File

@ -1,6 +1,6 @@
function PluginModel(id, name) {
this.id = "plugin" + id;
this.id = id;
this.name = name;
this.nickName = name+"_"+id;
@ -27,8 +27,8 @@ function UsePlugin() {
var pluginModel = new PluginModel(usePlugin.index, pluginName);
$("#usePluginList").append(
createRadio(pluginModel.nickName,
"usePlugin", pluginModel.id));
createRadio( pluginModel.id, pluginModel.nickName,
"usePlugin",pluginModel.name));
usePlugin.map.put(pluginModel.id, pluginModel);
@ -125,7 +125,7 @@ function UsePlugin() {
$("#usePluginList").on(
"click",
//"input[name='usePlugin']",
"div[class='line']",
"div[name='usePlugin']",
function() {
var usePluginId = $(
"#usePluginList input[name='usePlugin']:checked").attr(