git://git.onelab.eu
/
plstackapi.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
0e4e3b0
)
readonly fields, wip
author
Scott Baker
<smbaker@gmail.com>
Tue, 9 Dec 2014 07:54:18 +0000
(23:54 -0800)
committer
Scott Baker
<smbaker@gmail.com>
Tue, 9 Dec 2014 07:54:18 +0000
(23:54 -0800)
planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
patch
|
blob
|
history
planetstack/core/xoslib/static/js/xoslib/xosHelper.js
patch
|
blob
|
history
planetstack/core/xoslib/templates/xosAdmin.html
patch
|
blob
|
history
diff --git
a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
index
f24bcbc
..
f02aed8
100644
(file)
--- a/
planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
+++ b/
planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
@@
-320,13
+320,9
@@
if (! window.XOSLIB_LOADED ) {
attrs.addFields = attrs.detailFields;
}
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";
if (!attrs.collectionName) {
attrs.collectionName = modelName + "s";
@@
-342,7
+338,7
@@
if (! window.XOSLIB_LOADED ) {
modelAttrs[key] = value;
collectionAttrs[key] = value;
}
modelAttrs[key] = value;
collectionAttrs[key] = value;
}
- if ($.inArray(key, ["validate", "preSave"])) {
+ if ($.inArray(key, ["validate", "preSave"
, "readOnlyFields"
])) {
modelAttrs[key] = value;
}
}
modelAttrs[key] = value;
}
}
diff --git
a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
index
3205598
..
9e69aa7
100644
(file)
--- a/
planetstack/core/xoslib/static/js/xoslib/xosHelper.js
+++ b/
planetstack/core/xoslib/static/js/xoslib/xosHelper.js
@@
-142,6
+142,7
@@
XOSApplication = Marionette.Application.extend({
console.log(parent_id);
model = new xos[collection_name].model();
model.attributes[parent_fieldName] = parent_id;
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]});
console.log(model);
detailViewClass = app[addChildName];
var detailView = new detailViewClass({model: model, collection:xos[collection_name]});
@@
-672,10
+673,16
@@
idToOptions = function(selectedId, collectionName, fieldName) {
fieldName = name of field within models of collection that will be displayed
*/
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>';
idToOptions(selectedId, collectionName, fieldName) +
'</select>';
+ console.log(result);
return result;
}
return result;
}
diff --git
a/planetstack/core/xoslib/templates/xosAdmin.html
b/planetstack/core/xoslib/templates/xosAdmin.html
index
a222889
..
3848fc0
100644
(file)
--- a/
planetstack/core/xoslib/templates/xosAdmin.html
+++ b/
planetstack/core/xoslib/templates/xosAdmin.html
@@
-89,7
+89,9
@@
</script>
<script type="text/template" id="xos-list-footer-template">
</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">
</script>
<script type="text/template" id="xos-delete-button-template">
@@
-106,12
+108,13
@@
<table>
\r
<% _.each(addFields, function(fieldName) { %>
\r
<tr><td><%= fieldNameToHumanReadable(fieldName) %>:</td>
\r
<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
<% 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
<% } 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
<% } 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
<% } %>
\r
</tr>
\r
<% }); %>
\r
@@
-121,7
+124,7
@@
</script>
<script type="text/template" id="xos-detail-template">
</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
<form>
<table>
\r
<% console.log(model); _.each(detailFields, function(fieldName) { %>
\r
@@
-622,3
+625,4
@@
xosListFooterTemplate = _.template($("#xos-list-footer-template").html());
xosDeleteButtonTemplate = _.template($("#xos-delete-button-template").html());
xosDetailLinkTemplate = _.template($("#xos-detail-link-template").html());
</script>
xosDeleteButtonTemplate = _.template($("#xos-delete-button-template").html());
xosDetailLinkTemplate = _.template($("#xos-detail-link-template").html());
</script>
+