Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js - Render modal view with URL and parent view still displaying

In my Ember.js application I have an index view with a list of various posts. I'm trying to implement a 'show' action that happens when a post is clicked on. What it should do is display a modal a more detailed version of the post. Each modal view for a post should also have its own URL. Also the index view that lists the posts should still be shown behind the post modal. Finally when the post modal is closed the URL should change back to the index URL

So far my routes are something like this:

App.Router.reopen 
  location: 'history'
  rootURL: '/'

App.Router.map ->
  @resource 'posts', ->
    @route 'show', path: '/:post_id'

App.PostsShowRoute = Ember.Route.extend
  model: (params) ->
    App.Post.find(params.post_id)

This is my modal view (using Zurb Foundation reveal modal)

App.PostsShowView = Ember.View.extend
  templateName: 'postModal'
  classNames: ['reveal-modal']

  didInsertElement: ->
    @$().foundation('reveal', 'open')

I'm rendering into an outlet into my index template, but with the current set it navigates away from my index template and renders the modal only. Once again I'd like to have the modal render within the index page with its own URL, and upon being closed go back to the index URL.

like image 967
Bryan Cosgrove Avatar asked Sep 04 '13 16:09

Bryan Cosgrove


People also ask

What is the use of a view in Ember JS?

A view in an Ember.js is used for to handle user events and also creates the re-usable component. The UI will be developed by using the views. The below figure shows how event handling occurs −

How to use Handlebars templates in Ember JS?

Handlebars templates in Ember.js are powerful and can be rendered by using Ember.View and inserted into DOM. You can set templateName property of a view to indicate which template to use.

What is event handling in Emberjs?

When user clicks on the event the view turns a primitive event (a click) into a semantic event ( Event Handling) and transferred to the Ember.Route for to get the event action. Handlebars templates in Ember.js are powerful and can be rendered by using Ember.View and inserted into DOM.

What happens when you rerender a view in HTML?

If the view is in the DOM, the rendering process will be deferred to give bindings a chance to synchronize. If children were added during the rendering process using appendChild , rerender will remove them, because they will be added again if needed by the next render.


1 Answers

You can add an additional outlet to your application template for modals, and then render your modals into that outlet.

<script type="text/x-handlebars">
  {{outlet}}
  {{outlet modal}}
</script>

App.PostShow = Ember.Route.extend({
  renderTemplate: function() {
    this.render('postModal',{outlet:'modal',into:'application'});
  }
});
like image 132
Jeremy Green Avatar answered Oct 06 '22 16:10

Jeremy Green