Skip to content

Instantly share code, notes, and snippets.

@oskarrough
Last active December 26, 2016 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oskarrough/234f4c28eb056a65b98fa18d83249e9d to your computer and use it in GitHub Desktop.
Save oskarrough/234f4c28eb056a65b98fa18d83249e9d to your computer and use it in GitHub Desktop.
modal-routing
import Ember from 'ember';
export default Ember.Controller.extend({
/*openModal: function(modal, opts) {
this.controllerFor(modal).set('model', opts);
return this.render(modal, {
into: 'application',
outlet: 'modal'
});
},
closeModal: function() {
return this.disconnectOutlet({
outlet: 'modal',
parentView: 'application'
});
}*/
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
openPost(post) {
this.set('post', post);
}
}
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('posts', {path: 'posts'});
this.route('post', {path: 'posts/:post_id'});
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
beforeModel() {
this.transitionTo('posts');
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
const models = new Array(6).fill(0).map((v,k) => {
return Ember.Object.create({
id: k+1
});
});
return Ember.RSVP.Promise.resolve(Ember.A(models));
}
});
<p>This is an example with two pages.We have two routes: "{{link-to "posts" "posts"}}" and "{{link-to "post" "post" 1}}. They are not nested.</p>
<p>When you visit a post from a link or action it should open in a modal with the posts behind.</p>
<p>If you visit the post directly either from an external URL or by refreshing, it will show the post by itself. And not as a modal.</p>
<p>Currently, we have a link-to helper with an action nested inside. This ensures we have links for fallback but the action takes priority and sets a <code>post</code> model on the posts controller to show it in a modal. Perhaps the action could set the URL as well?</p>
{{outlet}}
<h2>Post</h2>
{{model}}
{{post-item post=model}}
<h2>Posts</h2>
{{#each model as |post|}}
<ul class="Post">
{{#link-to "post" post.id}}
<li {{action "openPost" post bubbles=false}}>
{{post-item post=post}}
</li>
{{/link-to}}
</ul>
{{/each}}
<h3>Posts modal</h3>
{{#if post}}
<div style="border: 1px solid">
{{post-item post=post}}
</div>
{{/if}}
{
"version": "0.10.6",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment