attrs.addFields = attrs.detailFields;
}
- if (!attrs.inputType) {
- attrs.inputType = {};
- }
-
- if (!attrs.foreignFields) {
- attrs.foreignFields = {};
- }
+ attrs.inputType = attrs.inputType || {};
+ attrs.foreignFields = attrs.foreignFields || {};
+ attrs.readOnlyFields = attrs.readOnlyFields || [];
if (!attrs.collectionName) {
attrs.collectionName = modelName + "s";
modelAttrs[key] = value;
collectionAttrs[key] = value;
}
- if ($.inArray(key, ["validate", "preSave"])) {
+ if ($.inArray(key, ["validate", "preSave", "readOnlyFields"])) {
modelAttrs[key] = value;
}
}
console.log(parent_id);
model = new xos[collection_name].model();
model.attributes[parent_fieldName] = parent_id;
+ model.readOnlyFields.push(parent_fieldName);
console.log(model);
detailViewClass = app[addChildName];
var detailView = new detailViewClass({model: model, collection:xos[collection_name]});
fieldName = name of field within models of collection that will be displayed
*/
-idToSelect = function(variable, selectedId, collectionName, fieldName) {
- result = '<select name="' + variable + '">' +
+idToSelect = function(variable, selectedId, collectionName, fieldName, readOnly) {
+ if (readOnly) {
+ readOnly = " readonly";
+ } else {
+ readOnly = "";
+ }
+ result = '<select name="' + variable + '"' + readOnly + '>' +
idToOptions(selectedId, collectionName, fieldName) +
'</select>';
+ console.log(result);
return result;
}
</script>
<script type="text/template" id="xos-list-footer-template">
- <a href="<%= addChildHash %>">Add...</a>
+ <% if (addChildHash) { %>
+ <a href="<%= addChildHash %>">Add...</a>
+ <% } %>
</script>
<script type="text/template" id="xos-delete-button-template">
<table>\r
<% _.each(addFields, function(fieldName) { %>\r
<tr><td><%= fieldNameToHumanReadable(fieldName) %>:</td>\r
+ <% readOnly = $.inArray(fieldName, model.readOnlyFields)>=0 ? " readonly" : ""; console.log(fieldName + " " + readOnly); console.log(model.readOnlyFields); %>\r
<% if (fieldName in foreignFields) { %>\r
- <td><%= idToSelect(fieldName, model.attributes[fieldName], foreignFields[fieldName], "humanReadableName") %></td>\r
+ <td><%= idToSelect(fieldName, model.attributes[fieldName], foreignFields[fieldName], "humanReadableName", readOnly) %></td>\r
<% } else if (inputType[fieldName] == "checkbox") { %>\r
- <td><input type="checkbox" name="<%= fieldName %>" <% if (model.attributes[fieldName]) print("checked"); %>></td>\r
+ <td><input type="checkbox" name="<%= fieldName %>" <% if (model.attributes[fieldName]) print("checked"); %><%= readOnly %>></td>\r
<% } else { %>\r
- <td><input type="text" name="<%= fieldName %>" value="<%= model.attributes[fieldName] %>"></td>\r
+ <td><input type="text" name="<%= fieldName %>" value="<%= model.attributes[fieldName] %>"<%= readOnly %>></td>\r
<% } %>\r
</tr>\r
<% }); %>\r
</script>
<script type="text/template" id="xos-detail-template">
- <h3 class="xos-detail-title">Add Object: <%= modelName %></h3>
+ <h3 class="xos-detail-title">Edit Object: <%= modelName %></h3>
<form>
<table>\r
<% console.log(model); _.each(detailFields, function(fieldName) { %>\r
xosDeleteButtonTemplate = _.template($("#xos-delete-button-template").html());
xosDetailLinkTemplate = _.template($("#xos-detail-link-template").html());
</script>
+