lib/rid/generators/show/templates/show.js in rid-0.4.1 vs lib/rid/generators/show/templates/show.js in rid-0.5.0
- old
+ new
@@ -2,38 +2,47 @@
// !code path.js
// !code mustache.js
// !json templates/layout.mustache
// !json templates/<%= pluralized_model_name %>/show.mustache
// !json templates/<%= pluralized_model_name %>/form.mustache
+ // !json templates/<%= pluralized_model_name %>/delete.mustache
- if(doc) {
- provides("html", function() {
- var view = {
- path: path(),
- title: "Showing <%= model_name.humanize %>",
- body: {
- path: path(),
-<% attributes.each do |attribute| -%>
- '<%= attribute %>': doc['<%= attribute %>'],
-<% end -%>
- id: doc._id
- }
- };
-
- return Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.show });
- });
- } else {
+ provides("html", function() {
var view = {
path: path(),
- title: "New <%= model_name.humanize %>",
body: {
- path: path(),
+ path: path()
+ }
+ };
+ var partial;
+
+ if(doc) {
<% attributes.each do |attribute| -%>
- '<%= attribute %>': '',
+ view.body['<%= attribute %>'] = doc['<%= attribute %>'];
<% end -%>
- id: ''
+ view.body.id = doc._id;
+
+ if (req.query.edit != undefined) {
+ // edit
+ view.title = "Editing <%= model_name.humanize %>";
+ partial = "form";
+ } else {
+ view.body.rev = doc._rev;
+ if (req.query['delete'] != undefined) {
+ // delete
+ view.title = "Deleting <%= model_name.humanize %>";
+ partial = "delete";
+ } else {
+ // show
+ view.title = "Showing <%= model_name.humanize %>";
+ partial = "show";
+ }
}
- };
+ } else {
+ // new
+ view.title = "New <%= model_name.humanize %>";
+ partial = "form";
+ }
- return Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.form });
- }
+ return Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>[partial] });
+ });
}