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"?>
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
<!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> -->
<ui>
<plugin name="CsvProvider">
<params>

View File

@ -22,7 +22,6 @@ ContainerFactory.prototype.createEditorContainer = function(header, id,
containerInfo[i].name == "";
}
if (containerInfo[i].children == null) {
console.log(containerInfo[i]);
this.appendEdtiors(container, containerInfo[i].label,
containerInfo[i].nameCN, containerInfo[i].required, containerInfo[i].name,
containerInfo[i].paramTypeModel,containerInfo[i].value == null ?"":containerInfo[i].value);

View File

@ -1,12 +1,18 @@
$(function() {
$(document).ready(function(){
$("#behaviorEditor").on("focusout",".editor input",function(){
var input = $(this);
if(input.attr("required") == "required" && input.val() == ""){
information("Please fill in the parameter");
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();
}
});
});
@ -29,7 +35,6 @@ function checkPagesInput(pages) {
return false;
}
}
}
}
}

View File

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

View File

@ -36,13 +36,36 @@ DataCollector.prototype.fieldData = function(editor) {
// if (!this.validate(value)) {
// return false;
// }
var required = editor.children("input").attr("required");
var check = "true";
if (required == "required" && value == "")
check = "false";
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) {
var name = editor.attr("id");
var value = editor.children("input").val();
@ -126,7 +149,7 @@ DataCollector.prototype.selectData = function(editor) {
return new Parameter(name, value);
};
DataCollector.prototype.getUnitParams = function(paramEditors) {
DataCollector.prototype.getUnitParams = function(paramEditors, fromData) {
var params = new Array();
for ( var i = 0; i < paramEditors.length; i++) {
var editor = $(paramEditors[i]);
@ -171,7 +194,10 @@ DataCollector.prototype.getUnitParams = function(paramEditors) {
return;
}
params.push(data);
} else {
}else if (editorType == "file"){
data = this.fileData(editor, fromData);
params.push(data);
}else {
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) {
size = 150;
}
var div = this.createBaseEditor(label, id, required);
$(div).children(".editor").attr("editorType", "file");
var fileEditor = document.createElement("div");
@ -124,12 +123,18 @@ EditorFactory.prototype.createFile = function(label, name, required, size, id, v
$(fieldName).html(name);
var file = document.createElement("input");
$(file).attr("type", "file");
if(value != ""){
$(file).attr("checkFile", value);
}
if(required == "true"){
$(file).attr("required", "required");
}
// $(field).attr("maxlength", size);
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).children(".editor").append(fileEditor);
var label = document.createElement("label");
$(label).html(value);
$(div).append(label);
return div;
}

View File

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

View File

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

View File

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