0
votes

In my app I'm creating a reusable UI component that will let the user request an appointment with 3 possible times. Since this is a reusable UI component, this would be a view (in my understanding).

Where things get tricky is in the implementation. For this we'll be using a couple models (one appointment with many times). As I go down the path of adding times and saving the appointment to the server I keep thinking, managing models is usually a controllers job, not the view.

So what is right?

Do I want to create a controller during the view's initialization and do all model manipulation with that? Or is it okay to create the model in the view and manipulate and save it there?

Ultimately I want to just include the view in the template, and everything else should just work:

{{#view App.ScheduleAppointment}}
1

1 Answers

1
votes

Reusable UI components should be Components. THIS is another awesome resource.

And I think you're right, managing models is a controller's job. Not views, or components given they're just pieces of UI. Reusable across contexts in the case of components.

To handle models I think you should send actions to the controller: here

this.sendAction('action', param1, param2);

I'd look something like this, from templates:

{{my-component value1=value1 ....  action="actionFromComponent" }}

And in the controller:

App.MyController = Ember.Controller.extend({
    actions: {
        actionFromComponent: function(param1, param2) {
            .....
        }
    }
})

I hope this helps you!