From: Scott Baker Date: Tue, 16 Dec 2014 00:49:24 +0000 (-0800) Subject: complicated sliver logic implemented X-Git-Url: http://git.onelab.eu/?p=plstackapi.git;a=commitdiff_plain;h=fd4a8af58f3976ce0ed2cd1b0b7b9c4cb7b721a6 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 @@ XOSDetailView = Marionette.ItemView.extend({ 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; - - newSelect = idToSelect(destField, - model.attributes[destField], - model.foreignFields[destField], - "humanReadableName", - false, - filterFunc); - - this.$el.find(destFieldName).html(newSelect); - }, +XOSDetailView_sliver = XOSDetailView.extend( { + events: $.extend(XOSDetailView.events, + {"change #field_deploymentNetwork": "onDeploymentNetworkChange"} + ), + + 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(); + }, + 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 @@ idToOptions = function(selectedId, collectionName, fieldName, filterFunc) { } else { selected = ""; } - if ((filterFunc) && (!filterFunc(linkedObject)) { + if ((filterFunc) && (!filterFunc(linkedObject))) { continue; } result = result + ''; @@ -975,13 +1006,13 @@ idToOptions = function(selectedId, collectionName, fieldName, filterFunc) { 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 = '' + idToOptions(selectedId, collectionName, fieldName, filterFunc) + ''; return result;