Skip to content
This repository
tree: 4d0fee7bac
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 50 lines (40 sloc) 1.935 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<div class="hero-unit">
  <h3>Params</h3>
  {{#params}}
  <p>{{action}} action on {{controller}} controller.</p>
  {{/params}}
</div>

<script type="text/javascript">
$(function () {
  geddy.io.addListenersForModels(['<%= names.constructor.singular %>']);

  var renderTemplate = function (<%= names.property.singular %>) {
    var template = [ ''
      , '<div class="row list-item" id="<%= names.property.singular %>-' + <%= names.property.singular %>.id + '">'
      , ' <div class="span8">'
      , ' <h3><a href="/<%= names.property.plural %>/' + <%= names.property.singular %>.id + '">' + <%= names.property.singular %>.<%= properties['default'].name || "id" %> + '</a></h3>'
      , ' </div>'
      , ' <div class="span4">'
      , ' <h3><i class="icon-list-alt"></i>' + <%= names.property.singular %>.id + '</h3>'
      , ' </div>'
      , '</div>'
    ].join('');

    return $(template);
  }

  var <%= names.constructor.plural %>Controller = function (opts) {
    this.options = opts || {};

    this.create = function (<%= names.property.singular %>) {
      $('#<%= names.property.plural %>-list').append(renderTemplate(<%= names.property.singular %>));
    };

    this.update = function (<%= names.property.singular %>) {
      $('#<%= names.property.singular %>-' + <%= names.property.singular %>.id).replaceWith(renderTemplate(<%= names.property.singular %>));
    };

    this.remove = function (id) {
      $('#<%= names.property.singular %>-' + id).remove();
    };

  };
  geddy.<%= names.constructor.plural %> = new <%= names.constructor.plural %>Controller();

  geddy.model.<%= names.constructor.singular %>.on('save' , geddy.<%= names.constructor.plural %>.create);
  geddy.model.<%= names.constructor.singular %>.on('update' , geddy.<%= names.constructor.plural %>.update);
  geddy.model.<%= names.constructor.singular %>.on('remove' , geddy.<%= names.constructor.plural %>.remove);
});
</script>
Something went wrong with that request. Please try again.