Ian Steffy
Ian Steffy

Reputation: 1234

Emberjs Displaying and Creating a subclass to a model

Model: 'Category' Subclass: 'Workflow'

I am trying to display the different 'Workflows' available for each 'Category' but I am receiving this error >>

Uncaught Error: Nothing handled the event 'createWorkflow'. 

Here's some code

VpcYeoman.Category = DS.Model.extend({
    permittype: DS.attr('string'),
    isCompleted: DS.attr('boolean'),
    classNameBindings: ['isAdministrator']
});

VpcYeoman.Workflow = VpcYeoman.Category.extend({
    workflowtype: DS.attr('string')
})

VpcYeoman.Category.FIXTURES = [
  {
    id: 1,
    permittype:'Building'
  },
  {
    id: 2,
    permittype:'Electrical'
  },
  {
    id: 3,
    permittype:'Zoning'
  },
  {
    id: 4,
    permittype:'Fire'
  }
];

I'm also a little stumped on how to make FIXTURES for this subclass. I attempted recreating VpcYeoman.Workflow.FIXTURES = [id & workflowType examples], but it didn't display.

Category.hbs

<div class="department-header">
  <div class="user-header">
    Category: {{permittype}}
  </div>
</div>
<table class="table table-hover table-responsive">
  <thead>
    <tr class="people-list">
      <td><h4>Workflow Type</h4></td>
    </tr>
  </thead>
    <table>
    {{#each workflows}}
      <tr>
        <td>
          {{workflowtype}}
        </td>
      </tr>
    {{/each}}
  </table>

  <div class="input-bar">
      <img src="images/lightning-icon-edited.png" class="input-icon">
      {{input type="text" value=newWorkflowtype placeholder="Create a workflow and press enter" action="createWorkflow"}}
  </div>

&&

VpcYeoman.CategoriesController = Ember.ArrayController.extend({
  actions: {
    createCategory: function () {
      var permittype = this.get('newPermittype');
      if (!permittype.trim()) {return;}

      var category = this.store.createRecord('category', {
        permittype: permittype
      });

      this.set('newPermittype', '');

      category.save();
    },
    createWorkflow: function () {
      var workflowtype = this.get('newWorkflowtype');
      if (!workflowtype.trim()) {return;}

      var workflow = this.store.createRecord('workflow', {
        workflowtype: workflowtype
      });

      this.set('newWorkflowtype', '');

      workflow.save();
    }
  }
});

&&

VpcYeoman.CategoriesRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('category');
  },
  setupController:function(controller, model){
    this._super(controller, model);
    controller.set('workflows', this.store.find('workflow'));
  }
});

VpcYeoman.CategoryRoute = Ember.Route.extend({

});

Upvotes: 0

Views: 167

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

I'm assuming that you have a categories and category routes/templates based on the differently named things up there.

actions go the the particular route's controller Category then the route's route Category then up the routes Categories, Application

It looks like you are setting the workflows on the Categories controller, but trying to use it in the Category template

Upvotes: 1

Related Questions