Skip to content

Instantly share code, notes, and snippets.

@SinisterMinister
Created November 13, 2013 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SinisterMinister/7441031 to your computer and use it in GitHub Desktop.
Save SinisterMinister/7441031 to your computer and use it in GitHub Desktop.
Kumo.AppsNewController = Ember.ObjectController.extend(Ember.PromiseProxyMixin, {
projects: null,
selectedProject: null,
repositories: null,
repositoriesGetter: function () {
var self = this;
return ORM.factory('repository').where('projectId').isEqual(this.get('selectedProject.id')).findAll().then(function (data) {
self.set('repositories', data);
});
}.observes('selectedProject')
});
@bartsqueezy
Copy link

Why not do something like this??

Kumo.AppsNewController = Em.ObjectController.extend({
    _reposLoadSuccess: function (data) {
        this.set('repositories', data);
    },
    _reposLoadFail: function (error) {
        // do something now that this has faild
    },

    actions: {
        projectSelectionChanged: function (projectId) {
            // update your model
            this.set('model.selectedProject', projectId);

            // get new repos
            this.send('getRepositories', projectId);
        },
        getRepositories: function (id) {
            ORM.factory('repository').where('projectId').isEqual(id).findAll().then(
                this._reposLoadSuccess,
                this._reposLoadFail
            );
        }
    }
});

Kumo.AppsNewView = Em.View.extend({
    tagName: 'form',
    templateName: 'apps/new/view'

    projectsSelect: Em.View.extend({
        tagName: 'select',
        changed: function (e) {
            this.controller.send('projectSelectionChanged', this.get('value'));
        }
    })
});

and in your AppsNewView template

<label for="select">Project</label>
{{view view.projectsSelect}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment