在函数form
中,使用 Javascript-jointJS 我尝试制作一个在我按下按钮时显示的表单。
我想在我的表单中写下我的数据后保留我的数据,并且当我第二次尝试显示我的表单以便能够在表单的字段中查看它们时。
我该怎么做?到目前为止,我可以第一次成功查看它们,但不能第二次查看它们。
form: function(){
var selectedObjectDataText = JSON.stringify(this.selection.invoke('toJSON'));
var selectedObjectDataJSON = JSON.parse(selectedObjectDataText);
if(selectedObjectDataJSON.length > 0){
if(selectedObjectDataJSON[0].attrs["text"]["text"] == "Activity"){
$("#detailsDialog").dialog({
autoOpen: false,
width: 500, height: 600,
close: function() {
$("#detailsForm").validate().resetForm();
$("#detailsForm").find(".error").removeClass("error");
}
});
$("#detailsForm").validate({
rules: {
name: { required: true},
displayed_name: { required: true},
mode: "required",
process_group: "required",
process_admin: "required",
process_in_force_from: { required: true},
process_in_force_to: { required: true},
created: { required: true},
website: { required: true},
version: { required: true},
},
submitHandler: function() {
formSubmitHandler(selectedObjectDataJSON, dataJSON);
}
});
var formSubmitHandler = $.noop;
var showDetailsDialog = function(client, selectedObjectDataJSON, dataJSON) {
if(client.length > 0){
alert("BRHKA DATA");
$("#name").val(client[0].name);
$("#displayed_name").val(client[0].displayed_name);
$("#mode").val(client[0].mode);
$("#process_group").val(client[0].process_group);
$("#process_admin").val(client[0].process_admin);
$("#process_in_force_from").val(client[0].process_in_force_from);
$("#process_in_force_to").val(client[0].process_in_force_to);
$("#website").val(client[0].website);
$("#created").val(client[0].created);
$("#version").val(client[0].version);
}
else{
$("#name").val('');
$("#displayed_name").val('');
$("#mode").val('');
$("#process_group").val('');
$("#process_admin").val('');
$("#process_in_force_from").val('');
$("#process_in_force_to").val('');
$("#website").val('');
$("#created").val('');
$("#version").val('');
}
formSubmitHandler = function(selectedObjectDataJSON, dataJSON) {
saveClient(client, selectedObjectDataJSON, dataJSON);
};
$("#detailsDialog").dialog("option", "title", "Διαδικασία")
.dialog("open");
};
var saveClient = function(client, selectedObjectDataJSON, dataJSON) {
$.extend(client, {
Name: $("#name").val(),
Displayed_Name: $("#displayed_name").val(),
Mode: parseInt($("#mode").val(), 10),
Process_Group: parseInt($("#process_group").val(), 10),
Process_Admin: parseInt($("#process_admin").val(), 10),
Process_In_Force_From: $("#process_in_force_from").val(),
Process_In_Force_To: $("#process_in_force_to").val(),
Website: $("#website").val(),
Created: $("#created").val(),
Version: $("#version").val(),
});
var position = -1;
if(dataJSON.length > 0){
for(var i=0;i<dataJSON.length && position < 0;i++){
var var1 = JSON.stringify(dataJSON[i].ActivityID);
var var2 = JSON.stringify(selectedObjectDataJSON[0].id);
alert(var1 + " - " + var2);
if(var1 == var2){
alert("BRIKA IDIO");
position = i;
}
}
}
if(position >= 0){
dataJSON[position].name = $("#name").val();
dataJSON[position].displayed_name = $("#displayed_name").val();
dataJSON[position].mode = $("#mode").val();
dataJSON[position].process_group = $("#process_group").val();
dataJSON[position].process_admin = $("#process_admin").val();
dataJSON[position].process_in_force_from = $("#process_in_force_from").val();
dataJSON[position].process_in_force_to = $("#process_in_force_to").val();
dataJSON[position].created = $("#created").val();
dataJSON[position].website = $("#website").val();
dataJSON[position].version = $("#version").val();
}
else{
var myhtml = { "ActivityID": selectedObjectDataJSON[0].id,
"name": $("#name").val(),
"displayed_name": $("#displayed_name").val(),
"mode": $("#mode").val(),
"process_group": $("#process_group").val(),
"process_admin": $("#process_admin").val(),
"process_in_force_from": $("#process_in_force_from").val(),
"process_in_force_to": $("#process_in_force_to").val(),
"created": $("#created").val(),
"website": $("#website").val(),
"version": $("#version").val() };
dataJSON.push(myhtml);
}
$("#formData").html(JSON.stringify(dataJSON));
$("#detailsDialog").dialog("close");
};
var activityData = JSON.parse("[]");
var objData = $("#formData").html();
var dataJSON = JSON.parse(objData);
var position = -1;
var selectedObjectDataText = JSON.stringify(this.selection.invoke('toJSON'));
var selectedObjectDataJSON = JSON.parse(selectedObjectDataText);
alert(JSON.stringify(selectedObjectDataJSON[0].id));
if(dataJSON.length > 0){
for(var i=0;i<dataJSON.length && position < 0;i++){
var var1 = JSON.stringify(dataJSON[i].ActivityID);
var var2 = JSON.stringify(selectedObjectDataJSON[0].id);
if(var1 == var2){
position = i;
}
}
}
if(position >= 0){
activityData.push(dataJSON[position]);
}
showDetailsDialog(activityData, selectedObjectDataJSON, dataJSON);
}
}
},