addChild link working for things other than slivers
diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
index 8e45267..b0e2dee 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
@@ -474,7 +474,8 @@
relatedListViewClassName = relatedName + "ListView";
assert(this.app[relatedListViewClassName] != undefined, relatedListViewClassName + " not found");
- relatedListViewClass = this.app[relatedListViewClassName].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id)});
+ relatedListViewClass = this.app[relatedListViewClassName].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id),
+ parentModel: this.model});
this.app[regionName].show(new relatedListViewClass());
if (this.app.hideTabsByDefault) {
this.app[regionName].$el.hide();
@@ -511,6 +512,7 @@
detailFields: this.model.detailFields,
foreignFields: this.model.foreignFields,
inputType: this.model.inputType,
+ model: this.model,
}},
});
@@ -533,6 +535,7 @@
detailFields: this.model.detailFields,
foreignFields: this.model.foreignFields,
inputType: this.model.inputType,
+ model: this.model,
}},
});
@@ -547,6 +550,7 @@
XOSListView = Marionette.CompositeView.extend({
childViewContainer: 'tbody',
+ parentModel: null,
events: {"click button.btn-xos-add": "addClicked",
"click button.btn-xos-refresh": "refreshClicked",
@@ -587,8 +591,27 @@
}
},
+ getAddChildHash: function() {
+ if (this.parentModel) {
+ // Find the field name in the model that should point to
+ // the parent object. For example, when adding a sliver, the
+ // fieldName that should point to 'users' is 'creator'.
+ parentFieldName = "unknown";
+ for (fieldName in this.collection.foreignFields) {
+ cname = this.collection.foreignFields[fieldName];
+ if (cname = this.collection.collectionName) {
+ parentFieldName = fieldName;
+ }
+ }
+ return "#addChild" + firstCharUpper(this.collection.modelName) + "/" + this.parentModel.modelName + "/" + parentFieldName + "/" + this.parentModel.id; // modelName, fieldName, id
+ } else {
+ return null;
+ }
+ },
+
templateHelpers: function() {
- return { title: this.title };
+ return { title: this.title,
+ addChildHash: this.getAddChildHash() };
},
});
diff --git a/planetstack/core/xoslib/templates/xosAdmin.html b/planetstack/core/xoslib/templates/xosAdmin.html
index 8957e03..8ca18db 100644
--- a/planetstack/core/xoslib/templates/xosAdmin.html
+++ b/planetstack/core/xoslib/templates/xosAdmin.html
@@ -89,7 +89,8 @@
</script>
<script type="text/template" id="xos-list-footer-template">
- <a href="#addChildSliver/slice/slice/23">Add another...</a>
+ <% console.log(model); %>
+ <a href="<%= addChildHash %>">Add...</a>
</script>
<script type="text/template" id="xos-delete-button-template">
@@ -156,7 +157,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
@@ -185,7 +186,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-image-listitem-template">
@@ -215,7 +216,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
@@ -247,7 +248,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-network-listitem-template">
@@ -276,7 +277,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-networkSliver-listitem-template">
@@ -303,7 +304,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-networkDeployment-listitem-template">
@@ -329,7 +330,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
@@ -354,7 +355,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-sliceRole-listitem-template">
@@ -380,7 +381,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
@@ -412,7 +413,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-site-listitem-template">
@@ -477,7 +478,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-sliceDeployment-listitem-template">
@@ -503,7 +504,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-slicePrivilege-listitem-template">
@@ -537,7 +538,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
@@ -574,7 +575,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
@@ -604,7 +605,7 @@
</tr></thead>
<tbody></tbody>
</table>
- <%= xosListFooterTemplate() %>
+ <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
</script>
<script type="text/template" id="xosAdmin-userDeployment-listitem-template">