lib/rid/generators/update/templates/update.js in rid-0.4.1 vs lib/rid/generators/update/templates/update.js in rid-0.5.0

- old
+ new

@@ -1,29 +1,48 @@ function(doc, req) { // !code path.js // !code mustache.js // !json templates/layout.mustache // !json templates/<%= pluralized_model_name %>/show.mustache + // !json templates/<%= pluralized_model_name %>/deleted.mustache - if (!doc) { - var doc = { - _id: req.form.id, - type: '<%= model_name %>', + var doc = { + type: '<%= model_name %>', <% attributes.each do |attribute| -%> - '<%= attribute %>': req.form['<%= attribute %>'], + '<%= attribute %>': req.form['<%= attribute %>'], <% end -%> - }; - var view = { + _id: req.form.id, + _rev: req.form.rev + }; + + if (req.form['delete'] == 'true') { + doc._deleted = true; + }; + + var view = { + path: path(), + body: { path: path(), - title: "Created Post", - body: { - path: path(), <% attributes.each do |attribute| -%> - '<%= attribute %>': doc['<%= attribute %>'], + '<%= attribute %>': doc['<%= attribute %>'], <% end -%> - id: doc._id - } - }; + id: doc._id + } + }; + var partial; - return [doc, Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.show })]; + if (doc._deleted) { + view.title = "Deleted <%= model_name.humanize %>"; + view.notice = "<%= model_name.humanize %> has been deleted."; + partial = 'deleted'; + } else { + view.title = "Showing <%= model_name.humanize %>"; + if (doc._rev) { + view.notice = "<%= model_name.humanize %> has been updated."; + } else { + view.notice = "<%= model_name.humanize %> has been created."; + }; + partial = 'show'; } + + return [doc, Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>[partial] })]; }