I have a search box on admin page admin.hbs
like this:
{{input value=search class="wide input" placeholder="Inquiry ID or User Email"}}
<div class="medium info btn" {{action 'search' search}}><button {{bind-attr class="isLoading:loading"}} >Search</button></div>
In the admin_controller.js
, the search action looks like this:
search: function(search){
if (!this.get('isLoading')){
this.set('isLoading', true);
if(search.indexOf('@') == -1){
this.transitionToRoute('inquiry', search);
} else {
this.transitionToRoute('user', search);
}
this.set('isLoading', false);
}
}
This function check whether the input is inquiry id or user email, and then transition to different route in order to get the right data. My issue is with the user search so I'll just show codes relates to user search. Here is the router.js
:
App.Router.map(function(){
this.resource("inquiry", {path: "inquiry/:inquiry_id"});
this.route("user", {path: "user/:email"});
});
This is the user_route.js
:
App.UserRoute = Ember.Route.extend({
queryParams: {
email: {
refresh: true,
}
},
model: function(params){
return this.store.find('user', {email: params.email}).then(function(users{
if (users){
return users.get('firstObject');
}
});
},
setupController: function(controller, model){
this._super(controller, model);
controller.set('isLoading', false);
}
});
Currently the url is always like: ../admin/user/test1@gmail.com
I want it to be like: ../admin/user/1
I mean instead of showing the email I put in the search box, I want the url to show the user id, which is also a property in user model. I have a solution now: grab the user model in admin_controller.js
depend on the user email. Then get the user id and pass the model to user_route.js
. But I don't know how to get the user model in admin_controller.js
. Could someone give me a clue?
Aucun commentaire:
Enregistrer un commentaire