¿How to use routes inside a Modal in Emberjs? - ember.js

sorry for my English. I will try to explain better I can.
I have an application in EmberJS, this application have its routes. Also, when I click in a button, I should show a Modal Window and change the route. That problem was resolved. The problem is. This modal window must to be a kindly of wizard, so when the user click on next, I should to change the route and show inside the modal the correct content, when the user click in next again, the route must to change again but the new content should be showed into the modal too.
The problem seems to be, ember takes my application outlet and show the new content inside that outlet, not inside of the outlet defined into the modal.
How I achieve this?

Related

How to create generic popup for across the app?

I am trying to create a popup which is available and controlled by across application.
so I keep the html assets in app template. and the I would like to show and hide the popup any page from the app.
I understand that, It can achivable by service. but I don't have much idea to implement this. any one suggest me the right way?
Required is : show popup from any page, close pupup on click of close button in the popup.
here is my Twiddle
In case of angular it can be achieved from factory object.
I would probably do this:
create a component for the popup
create a service for the popup that that exposes methods for setting a property called "isOpen" to true/false. Other parts of the app can use the methods for opening and closing the popup.
Inject the popup service into the application controller
Add it to the application template in an {{if popupService.isOpen}} block
Good luck, remember to write lots of tests, make sure each part is working before you go to the next step, and remember to consult the guides often ;-)

How to Disable `back` and `forward` button of the browser window

In my applicaiton, I requried couple of things to be added.
No forward/Back Browser button should work for reach a hash.
Instead of brower back forward, there should be a back and forward button has to added in the applicaiton itself.
how to achive this both?
I am looking for a component to use globally for both 2 requriements.
Thanks in advance.
Disabling the native back/forward buttons of the browser in Ember.js is quite unusual but could possibly be achieved by using the NoneLocation class. To enable that open the config/environment.js file of your app and change the locationType property to none.
If you want to display back/forward buttons in your app you can use the History API and specifically window.history.back() and window.history.forward()

Ember route and navigation in modal, keeping parent route visible

Is it possible to have a route, say images/ show a list of images, and on click have an image open in a modal/viewer, say images/viewer/10, that has navigation (previous links to images/viewer/9, next links to images/viewer/11), updating the viewer modal while keeping the background images/ behind the modal as is, so that you can cancel the modal and go back to images/ without reloading the route?
see https://ember-twiddle.com/1da304530ea1367389361213fcf839c6?openFiles=templates.images.hbs%2C
You can define your routes like this:
Router.map(function() {
this.route('images', function() {
this.route('viewer', {path: "/viewer/:id"});
});
});
Pay attention in file structure in twiddle (images parent route for outlet and viewer nested route for modal, not images index route).
And then, you can show the modal viewer template in an outlet defined in images template.
Well, when you navigate to /images, you will see images template, without the modal. And the route's hooks will have executed.
From images, if you navigate to /images/viwer/x, the viewer route hooks will execute, but not images, because have already been executed.
When you navigate from images/viewer/x to /images will do the same (images route hooks will not execute one more time).
Hope this helps.
regards

where to put template button click event

I have button on my template(not in component) and need to add click event for it.what is the correct js file to place my click event ?
I search from ember site where it state that component action should put in respective component js action or it will bubbule up to route js . Either It have not mansion or I couldn't find where to put template(not in component) action since there are no place to add the action other than respective route js file.
so is it ok to put my template action in respective route js file ?
I am novice to ember and sorry for poor English.
Yes, you can put action handler(s) inside your route.
You can handle template event from either corresponding controller or router.
Just put the handling function inside actions property inside either place.
The order template look for action is controller first ,router and upper router untile application router.

Transition to a route mantaining the previous content in ember

I've a generic route /login that displays the login form inside a modal. Now I want the content behind to remain the same of the previous url.
How do you go about this?
Thank you
Trying to implement login modal form as a generic /login route is probably not the best option, as it does not go well with the way Ember routes work, which can be summarised as follows:
Given url is matched to (possibly multiple nested) routes.
Each matched route resolves it's model and then renders corresponding templates to appropriate outlets. Templates for previous route are wiped out.
Navigating to generic /login would wipe out the templates rendered by previous route - namely there would be no content in the modal background (see also related question).
I would suggest either:
Not rendering /login route in modal dialog, but instead in the main app outlet, and only then redirecting user to the previous route. UI experience is probably not much worse as user probably does not need any information from the modal background anyway.
Instead of having generic /login route, you could use query parameter, e.g. ?should_login=true on ApplicationController which would render login modal in appropriate outlet. This way primary application state would still be encapsulated in the route url, thus templates for the previous would be properly rendered in the modal background. Suggested approach on how to handle modal dialog can be found here.