edit CsvProvider Plugin

edit CsvProvider Plugin
This commit is contained in:
daisyonly 2014-09-04 15:06:01 +08:00
parent 0f29deb274
commit 9781437652
9 changed files with 74 additions and 33 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> <!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> -->
<ui> <ui>
<plugin name="CsvProvider"> <plugin name="CsvProvider">
<params> <params>

View File

@ -22,7 +22,6 @@ ContainerFactory.prototype.createEditorContainer = function(header, id,
containerInfo[i].name == ""; containerInfo[i].name == "";
} }
if (containerInfo[i].children == null) { if (containerInfo[i].children == null) {
console.log(containerInfo[i]);
this.appendEdtiors(container, containerInfo[i].label, this.appendEdtiors(container, containerInfo[i].label,
containerInfo[i].nameCN, containerInfo[i].required, containerInfo[i].name, containerInfo[i].nameCN, containerInfo[i].required, containerInfo[i].name,
containerInfo[i].paramTypeModel,containerInfo[i].value == null ?"":containerInfo[i].value); containerInfo[i].paramTypeModel,containerInfo[i].value == null ?"":containerInfo[i].value);
@ -59,7 +58,7 @@ ContainerFactory.prototype.appendEdtiors = function(container, label, name, requ
} else if (editorInfo.type.toLowerCase() == "file") { } else if (editorInfo.type.toLowerCase() == "file") {
$(container).append( $(container).append(
editorFactory.createFile(label, name, required, editorInfo.size, id,value)); editorFactory.createFile(label, name, required, editorInfo.size, id,value));
} else if (editorInfo.type.toLowerCase() == "date") { } else if (editorInfo.type.toLowerCase() == "date") {
$(container).append( $(container).append(
editorFactory.createDate(label, name, required, editorInfo.size, id,value)); editorFactory.createDate(label, name, required, editorInfo.size, id,value));

View File

@ -1,13 +1,19 @@
$(function() { $(function() {
$(document).ready(function(){
$("#behaviorEditor").on("focusout",".editor input",function(){ $("#behaviorEditor").on("focusout",".editor input",function(){
var input = $(this); var input = $(this);
if(input.attr("required") == "required" && input.val() == ""){ if(input.attr("required") == "required" && input.val() == ""){
information("Please fill in the parameter"); information("Please fill in the parameter");
input.focus(); input.focus();
} }
}) });
}); $("#pluginEditor").on("focusout",".editor input",function(){
var input = $(this);
if(input.attr("required") == "required" && input.val() == ""){
if (input.attr("type") != "file")
information("Please fill in the parameter");
input.focus();
}
});
}); });
function checkPluginsInput(plugins) { function checkPluginsInput(plugins) {
@ -28,8 +34,7 @@ function checkPagesInput(pages) {
if (pages[i].batches[j].behaviors[k].parameters[q].check == "false"){ if (pages[i].batches[j].behaviors[k].parameters[q].check == "false"){
return false; return false;
} }
} }
} }
} }
} }

View File

@ -4,11 +4,13 @@ $(function() {
// usePlugin.getPluginList(); // usePlugin.getPluginList();
$("#submitScript").click(function() { $("#submitScript").click(function() {
var plugins = usePlugin.getPlugins(); var formData = new FormData();
var plugins = usePlugin.getPlugins( formData );
var pages = usePlugin.getPages(); var pages = usePlugin.getPages();
if(checkPluginsInput(plugins) && checkPagesInput(pages)) if(checkPluginsInput(plugins) && checkPagesInput(pages))
submitScript(pages,plugins); submitScript(pages, plugins, formData);
else else
information("必填的参数没有填写完整,请补充完整后提交"); information("Please complete the required parameters.");
}); });
}); });

View File

@ -36,13 +36,36 @@ DataCollector.prototype.fieldData = function(editor) {
// if (!this.validate(value)) { // if (!this.validate(value)) {
// return false; // return false;
// } // }
var required = editor.children("input").attr("required"); var required = editor.children("input").attr("required");
var check = "true"; var check = "true";
if (required == "required" && value == "") if (required == "required" && value == "")
check = "false"; check = "false";
return new Parameter(name, value, check); return new Parameter(name, value, check);
}; };
DataCollector.prototype.fileData = function(editor, formData) {
var check = "true";
var value = null;
var inputs = editor.find("input");
if ($(inputs[0]).attr("checkFile") != undefined){
value = $(inputs[0]).attr("checkFile");
}
else{
if (inputs[0].files.length == 0){
check = "false";
}
else{
var file = inputs[0].files[0];
formData.append("paramFiles", file);
value = file.name;
}
}
var name = editor.attr("id");
return new Parameter(name, value, check);
}
DataCollector.prototype.dateData = function(editor) { DataCollector.prototype.dateData = function(editor) {
var name = editor.attr("id"); var name = editor.attr("id");
var value = editor.children("input").val(); var value = editor.children("input").val();
@ -126,7 +149,7 @@ DataCollector.prototype.selectData = function(editor) {
return new Parameter(name, value); return new Parameter(name, value);
}; };
DataCollector.prototype.getUnitParams = function(paramEditors) { DataCollector.prototype.getUnitParams = function(paramEditors, fromData) {
var params = new Array(); var params = new Array();
for ( var i = 0; i < paramEditors.length; i++) { for ( var i = 0; i < paramEditors.length; i++) {
var editor = $(paramEditors[i]); var editor = $(paramEditors[i]);
@ -171,7 +194,10 @@ DataCollector.prototype.getUnitParams = function(paramEditors) {
return; return;
} }
params.push(data); params.push(data);
} else { }else if (editorType == "file"){
data = this.fileData(editor, fromData);
params.push(data);
}else {
information($.i18n.prop('dataCollect-errorType')); information($.i18n.prop('dataCollect-errorType'));
} }

View File

@ -115,7 +115,6 @@ EditorFactory.prototype.createFile = function(label, name, required, size, id, v
if (size == null || size <= 0) { if (size == null || size <= 0) {
size = 150; size = 150;
} }
var div = this.createBaseEditor(label, id, required); var div = this.createBaseEditor(label, id, required);
$(div).children(".editor").attr("editorType", "file"); $(div).children(".editor").attr("editorType", "file");
var fileEditor = document.createElement("div"); var fileEditor = document.createElement("div");
@ -124,12 +123,18 @@ EditorFactory.prototype.createFile = function(label, name, required, size, id, v
$(fieldName).html(name); $(fieldName).html(name);
var file = document.createElement("input"); var file = document.createElement("input");
$(file).attr("type", "file"); $(file).attr("type", "file");
if(value != ""){
$(file).attr("checkFile", value);
}
if(required == "true"){ if(required == "true"){
$(file).attr("required", "required"); $(file).attr("required", "required");
} }
// $(field).attr("maxlength", size);
$(fileEditor).append(fieldName.outerHTML + file.outerHTML); $(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).children(".editor").append(fileEditor); $(div).children(".editor").append(fileEditor);
var label = document.createElement("label");
$(label).html(value);
$(div).append(label);
return div; return div;
} }

View File

@ -29,15 +29,14 @@ $(function() {
var usePlugin = new UsePlugin("useBehaviorList"); var usePlugin = new UsePlugin("useBehaviorList");
getScriptObject(scriptId,usePlugin); getScriptObject(scriptId,usePlugin);
$("#scriptName").val(getvars()['name']); $("#scriptName").val(getvars()['name']);
$("#tabs").tabs(); $("#tabs").tabs();
$("#submitScript").click(function() { $("#submitScript").click(function() {
var plugins = usePlugin.getPlugins(); var formData = new FormData();
var plugins = usePlugin.getPlugins(formData);
var pages = usePlugin.getPages(); var pages = usePlugin.getPages();
if(checkPluginsInput(plugins) && checkPagesInput(pages)) if(checkPluginsInput(plugins) && checkPagesInput(pages))
updateScript(scriptId,pages,plugins); updateScript(scriptId,pages,plugins,formData);
else else
information("必填的参数没有填写完整,请补充完整后提交"); information("必填的参数没有填写完整,请补充完整后提交");

View File

@ -28,7 +28,7 @@ function CollectScriptData(behavior) {
// this.behaviors = behaviors; // this.behaviors = behaviors;
//} //}
function submitScript(pages,usePlugins) { function submitScript(pages,usePlugins, formData) {
var scriptName = $("#scriptName").val(); var scriptName = $("#scriptName").val();
@ -37,42 +37,47 @@ function submitScript(pages,usePlugins) {
return; return;
} }
var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages); var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages);
formData.append("runScenarioModelStr", JSON.stringify(runScenarioModel));
$.ajax({ $.ajax({
type : "POST", type : "POST",
url : "submitScriptCreated" + "/" + scriptName, url : "submitScriptCreated" + "/" + scriptName,
data :{runScenarioModelStr: JSON.stringify(runScenarioModel)},//JSON.stringify(runScenarioModel), data :formData,
// dataType : "json", processData: false,
// contentType : "application/json", contentType: false,
success : function(data) { success : function(data) {
if (!data.success) { if (!data.success) {
return; return;
} else { } else {
information("success"); information("success");
formData = new FormData();
} }
} }
}); });
} }
function updateScript(scriptId, pages, usePlugins){ function updateScript(scriptId, pages, usePlugins ,formData){
var scriptName = $("#scriptName").val(); var scriptName = $("#scriptName").val();
if (scriptName == undefined || scriptName == "") { if (scriptName == undefined || scriptName == "") {
information("need a script name!"); information("need a script name!");
return; return;
} }
var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages); var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages);
formData.append("runScenarioModelStr", JSON.stringify(runScenarioModel));
formData.append("scriptId",scriptId);
formData.append("scriptName",scriptName);
console.log(formData);
$.ajax({ $.ajax({
type : "POST", type : "POST",
url : "updateScript", url : "updateScript",
data :{scriptId:scriptId,scriptName:scriptName, runScenarioModelStr: JSON.stringify(runScenarioModel)},//JSON.stringify(runScenarioModel), data :formData,
// dataType : "json", processData: false,
// contentType : "application/json", contentType: false,
success : function(data) { success : function(data) {
if (!data.success) { if (!data.success) {
return; return;
} else { } else {
information("success"); information("success");
formData = new FormData();
} }
} }
}); });

View File

@ -125,7 +125,7 @@ function UsePlugin(behaviorListContainerId) {
return; return;
} }
usePluginEditorMap.put($("#pluginEditor").attr("usePlugin"), $( usePluginEditorMap.put($("#pluginEditor").attr("usePlugin"), $(
"#pluginEditor div:first").clone()); "#pluginEditor div:first").clone(true));
$("#pluginEditor").attr("usePlugin", ""); $("#pluginEditor").attr("usePlugin", "");
$("#pluginEditor").html(""); $("#pluginEditor").html("");
@ -175,7 +175,7 @@ function UsePlugin(behaviorListContainerId) {
return containerId; return containerId;
} }
//this is for submit //this is for submit
this.getPlugins = function() { this.getPlugins = function(formData) {
updateUsePlugin(); updateUsePlugin();
var keys = map.getKeys(); var keys = map.getKeys();
var usePlugins = new Array(); var usePlugins = new Array();
@ -184,7 +184,7 @@ function UsePlugin(behaviorListContainerId) {
var usePluginViewModel = map.get(id); var usePluginViewModel = map.get(id);
var usePluginContainer = usePluginEditorMap.get(id); var usePluginContainer = usePluginEditorMap.get(id);
var params = paramDataCollector.getUnitParams($( var params = paramDataCollector.getUnitParams($(
usePluginContainer).find(".editor")); usePluginContainer).find(".editor"), formData);
usePlugins.push(new UsePluginModel(usePluginViewModel.id, usePluginViewModel.name,usePluginViewModel.nickName, params)); usePlugins.push(new UsePluginModel(usePluginViewModel.id, usePluginViewModel.name,usePluginViewModel.nickName, params));
} }
return usePlugins; return usePlugins;