Commit c5c40a40 authored by Sebastien Robin's avatar Sebastien Robin

gui prototype: store property values

parent 4c0010e8
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
priv.prepareDialogForElement = function(title, element_id) { priv.prepareDialogForElement = function(title, element_id) {
// code to allow changing values on connections. For now we assume // code to allow changing values on connections. For now we assume
// that it is throughput. But we will need more generic code // that it is throughput. But we will need more generic code
var throughput = $( "#throughput" ), //var throughput = $( "#throughput" ),
allFields = $( [] ).add( throughput ); // allFields = $( [] ).add( throughput );
$(function() { $(function() {
$( "input[type=submit]" ) $( "input[type=submit]" )
.button() .button()
...@@ -65,25 +65,42 @@ ...@@ -65,25 +65,42 @@
// Render fields for that particular element // Render fields for that particular element
var fieldset = $("#dialog-fieldset"); var fieldset = $("#dialog-fieldset");
$("#dialog-fieldset").children().remove() $("#dialog-fieldset").children().remove()
var render_field = function(property_list, prefix) { var element_id_prefix = element_id.split("_")[0];
var property_list = configuration[element_id_prefix].property_list || [];
console.log("getData on element_id", element_id);
var previous_data = priv.plumb.getData()["element"];
previous_data = previous_data[element_id] || {};
previous_data = previous_data.data || {};
console.log("previous_data", previous_data);
var previous_value;
var renderField = function(property_list, previous_data, prefix) {
if (prefix === undefined) { if (prefix === undefined) {
prefix = ""; prefix = "";
} }
_.each(property_list, function(property, key, list) { _.each(property_list, function(property, key, list) {
if (property._class === "Dream.Property") { if (property._class === "Dream.Property") {
console.log("property.id, previous_data", property.id, previous_data);
previous_value = previous_data[property.id] || "";
if (previous_value.length > 0) {
previous_value = ' value="' + previous_value + '"';
}
//previous_value = ' value="bar"';
console.log("previous_value");
fieldset.append("<label>" + prefix + property.id + "</label>" + fieldset.append("<label>" + prefix + property.id + "</label>" +
'<input type="text" name="' + property.id + '" id="' + property.id + '<input type="text" name="' + prefix + property.id + '"' +
'" class="text ui-widget-content ui-corner-all"/>') previous_value +
' id="' + prefix + property.id + '"' +
' class="text ui-widget-content ui-corner-all"/>')
} else if (property._class === "Dream.PropertyList") { } else if (property._class === "Dream.PropertyList") {
var next_prefix = prefix + property.id + "."; var next_prefix = prefix + property.id + "-";
render_field(property.property_list, next_prefix); var next_previous_data = previous_data[property.id] || {};
console.log("next_previous_data", next_previous_data);
renderField(property.property_list, next_previous_data, next_prefix);
} }
}); });
}; };
var element_id_prefix = element_id.split("_")[0];
var property_list = configuration[element_id_prefix].property_list || [];
console.log("property_list to be rendered", property_list); console.log("property_list to be rendered", property_list);
render_field(property_list); renderField(property_list, previous_data);
$( "#dialog-form" ).dialog({ $( "#dialog-form" ).dialog({
autoOpen: false, autoOpen: false,
...@@ -100,28 +117,33 @@ ...@@ -100,28 +117,33 @@
priv.removeElement(element_id); priv.removeElement(element_id);
$( this ).dialog( "close" ); $( this ).dialog( "close" );
}, },
"Validate": function() { Validate: function() {
var bValid = true, i, i_length, box; var data = {}, prefixed_property_id, property_element;
allFields.removeClass( "ui-state-error" ); var updateDataPropertyList = function(property_list, data, prefix) {
console.log("updateDataPropertyList, property_list", property_list);
bValid = bValid && checkRegexp( throughput, /^([0-9])+$/, "Througput must be integer." ); if (prefix === undefined) {
prefix = "";
if ( bValid ) {
// Update the model with new value
i_length = model.box_list.length;
for (i = 0; i < i_length; i++) {
box = model.box_list[i];
if (box.id === priv.box_id) {
box.throughput = parseInt(throughput.val(), 10);
}
} }
priv.updateModel(); _.each(property_list, function(property, key, list) {
$( this ).dialog( "close" ); if (property._class === "Dream.Property") {
} prefixed_property_id = prefix + property.id;
console.log("prefixed_property_id", prefixed_property_id);
property_element = $("#" + prefixed_property_id);
data[property.id] = property_element.val();
} else if (property._class === "Dream.PropertyList") {
var next_prefix = prefix + property.id + "-";
data[property.id] = {};
updateDataPropertyList(property.property_list, data[property.id], next_prefix);
}
});
};
updateDataPropertyList(property_list, data);
priv.plumb.updateElementData(element_id, {data: data});
$( this ).dialog( "close" );
}, },
}, },
close: function() { close: function() {
allFields.val( "" ).removeClass( "ui-state-error" ); //allFields.val( "" ).removeClass( "ui-state-error" );
} }
}); });
}; };
...@@ -135,7 +157,6 @@ ...@@ -135,7 +157,6 @@
priv.plumb.newElement(element, configuration[element_id]); priv.plumb.newElement(element, configuration[element_id]);
$("#" + element.id).bind('click', function() { $("#" + element.id).bind('click', function() {
console.log("bind click on window", $(this)); console.log("bind click on window", $(this));
//$("#dialog-form").attr("title", "bar");
$( "#dialog-form" ).dialog( "destroy" ) ; $( "#dialog-form" ).dialog( "destroy" ) ;
priv.prepareDialogForElement(element.id, element.id); priv.prepareDialogForElement(element.id, element.id);
$( "#dialog-form" ).dialog( "open" ); $( "#dialog-form" ).dialog( "open" );
...@@ -164,6 +185,15 @@ ...@@ -164,6 +185,15 @@
} }
}); });
Object.defineProperty(that, "updateElementData", {
configurable: false,
enumerable: false,
writable: false,
value: function (element_id, data) {
priv.plumb.updateElementData(element_id, data);
}
});
return that; return that;
}; };
var DreamNamespace = (function () { var DreamNamespace = (function () {
......
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
}); });
console.log("going to add newElement", value); console.log("going to add newElement", value);
dream_instance.newElement(value); dream_instance.newElement(value);
dream_instance.updateElementData(element_id, {data: value.data || {}});
}); });
// Now link elements between them and update id_container // Now link elements between them and update id_container
_.each(response.data.element, function(value, key, list) { _.each(response.data.element, function(value, key, list) {
......
...@@ -133,6 +133,16 @@ ...@@ -133,6 +133,16 @@
priv.onDataChange(); priv.onDataChange();
}; };
Object.defineProperty(that, "updateElementData", {
configurable: false,
enumerable: false,
writable: false,
value: function (element_id, data) {
_.extend(priv.element_container[element_id], data);
priv.onDataChange();
}
});
Object.defineProperty(that, "start", { Object.defineProperty(that, "start", {
configurable: false, configurable: false,
enumerable: false, enumerable: false,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment