complicated sliver logic implemented
diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
index 1141dcb..65ccdbd 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
@@ -594,35 +594,66 @@
inputType: this.model.inputType,
model: this.model,
}},
+});
- applyConstraints: function() {
- for (constraint in this.model.constraints) {
- // constraint syntax: "operator,destField.destSubField,srcField.srcSubField"
- // i.e. equal,node.deployment,deploymentNetwork.id
- parts = constraints.split(",");
- operator = parts[0];
- parts1 = parts[1].split(".");
- destField = parts1[0];
- destSubField = parts1[1];
- parts2 = parts[2].split(".");
- srcField = parts2[0];
- srcID = this.$el.find(srcModel).val();
- if (operator == "equal"):
- filterMaker = function makeFilter(destSubField,srcID) { return function(linkedObj) { return (linkedObj.attributes[destSubField] == srcID); } };
- filterFunc = filterMaker(destSubField, srcID);
- else:
- continue;
+XOSDetailView_sliver = XOSDetailView.extend( {
+ events: $.extend(XOSDetailView.events,
+ {"change #field_deploymentNetwork": "onDeploymentNetworkChange"}
+ ),
- newSelect = idToSelect(destField,
- model.attributes[destField],
- model.foreignFields[destField],
- "humanReadableName",
- false,
- filterFunc);
+ onShow: function() {
+ // Note that this causes the selects to be updated a second time. The
+ // first time was when the template was originally invoked, and the
+ // selects will all have the full unfiltered set of candidates. Then
+ // onShow will fire, and we'll update them with the filtered values.
+ this.onDeploymentNetworkChange();
+ },
- this.$el.find(destFieldName).html(newSelect);
- },
+ onDeploymentNetworkChange: function(e) {
+ var deploymentID = this.$el.find("#field_deploymentNetwork").val();
+ console.log("onDeploymentNetworkChange");
+ console.log(deploymentID);
+
+ filterFunc = function(model) { return (model.attributes.deployment==deploymentID); }
+ newSelect = idToSelect("node",
+ this.model.attributes.node,
+ this.model.foreignFields["node"],
+ "humanReadableName",
+ false,
+ filterFunc);
+ this.$el.find("#field_node").html(newSelect);
+
+ filterFunc = function(model) { for (index in model.attributes.deployments) {
+ item=model.attributes.deployments[index];
+ if (item.toString()==deploymentID.toString()) return true;
+ };
+ return false;
+ }
+ newSelect = idToSelect("flavor",
+ this.model.attributes.flavor,
+ this.model.foreignFields["flavor"],
+ "humanReadableName",
+ false,
+ filterFunc);
+ this.$el.find("#field_flavor").html(newSelect);
+
+ filterFunc = function(model) { for (index in xos.imageDeployments.models) {
+ imageDeployment = xos.imageDeployments.models[index];
+ if ((imageDeployment.attributes.deployment == deploymentID) && (imageDeployment.attributes.image == model.id)) {
+ return true;
+ }
+ }
+ return false;
+ };
+ newSelect = idToSelect("image",
+ this.model.attributes.image,
+ this.model.foreignFields["image"],
+ "humanReadableName",
+ false,
+ filterFunc);
+ this.$el.find("#field_image").html(newSelect);
+ },
});
/* XOSItemView
@@ -959,7 +990,7 @@
} else {
selected = "";
}
- if ((filterFunc) && (!filterFunc(linkedObject)) {
+ if ((filterFunc) && (!filterFunc(linkedObject))) {
continue;
}
result = result + '<option value="' + linkedId + '"' + selected + '>' + linkedName + '</option>';
@@ -975,13 +1006,13 @@
fieldName = name of field within models of collection that will be displayed
*/
-idToSelect = function(variable, selectedId, collectionName, fieldName, readOnly. filterFunc) {
+idToSelect = function(variable, selectedId, collectionName, fieldName, readOnly, filterFunc) {
if (readOnly) {
readOnly = " readonly";
} else {
readOnly = "";
}
- result = '<select name="' + variable + '"' + readOnly + '>' +
+ result = '<select name="' + variable + '" id="field_' + variable + '"' + readOnly + '>' +
idToOptions(selectedId, collectionName, fieldName, filterFunc) +
'</select>';
return result;