I have a button in shell.html, on click of that button I need to post the current view model.
I can determine the current view model's Module Id, but how can I get a reference to it so that I can invoke its methods from Shell.js
For eg, if my current view model has a method called "SubmitApplication"
I would like to call or trigger this method from Shell.js on click of the button in Shell.html
Please help.
Thanks
Consider using Durandal's event system for cross module communication.
http://durandaljs.com/documentation/Leveraging-Publish-Subscribe.html
By default app has event capabilities included, which would allow you to do something along the following line:
shell.js
submitOnClick: function(){
app.trigger('application:submit', payload);
}
viewmodel
app.on('application:submit').then(function(payload){
//do something with payload
});
Related
I want to include a view like so: #include(user.myview), but within this view I need UserController logic. So I thought about calling a route: #include( route('user.route') ) which calls a Controllerfunction and returns the view but that isn't working. Any Ideas how to deal with this problem?
You need to create view composer and use it to get the data.
View composers are callbacks or class methods that are called when a view is rendered. If you have data that you want to be bound to a view each time that view is rendered, a view composer can help you organize that logic into a single location.
Simply add a link in you view and include it in your desired location.
Link will have a route.
On clicking the link, controller method can be called. e.g. show_link.blade.php
In your show_link.blade.php view:
<a href= {{route('route-name')}} > Click here</a>.
This route will call a method via .
Route::get('/call/method', 'controller#your_method_name')->name('route-name');
In controller, method your_method_name that will look like this:
public function your_method_name()
{
return "show what you want to";
}
have 1st view = index.js
2nd view = another.js
global file alloy.js
I have called the global class (alloy.js) method from index.js and now i want to move to another.js view but after httpRequest method finishes (which is declared and implemented in alloy.js).
---alloy.js---
Alloy.Global.httpMethod=function(){
//xml response is achieved, now from here i want to navigate to another.js view
}
---index.js---
Alloy.Global.httpMethod();
---another.js---
//some UI objects.
The first thing you want to do is create a controller, your another.js must be a Controller, it can be created by doing Right click on app and creating a new controller from there.
Once your controller is created, you can easily do what Phil said in the comment. i.e
Alloy.createController('another').getView().open();
This has to be placed in your onload function of HttpClient.
Hope it Helps.
attempting to call $(this).fineUploader("getButton", id); in the submit event handler and getting undefined as a result.
I assume the buttons are being tracked since access to the button is available within the validate and upload events. However, I really would like to know which button was clicked during the submit event so I can set parameters for the specific file upload. The validate event has no file id present to associate specific parameters
In Response to Comments, additional information:
Fineuploader Version 4.1.1
I have tried the scenario in many configurations and getButton method call never works in the submit handler
myfineuploader.on('submit', function(event, id, name) {
var button = $(this).fineUploader('getButton', id);
console.log(button); // Button always shows undefined here
}
The buttons are defined as spans outside of the template, setup like this in the config:
button: $("#button1"),
extraButtons: [
{
element: $("#button2")
}
]
The button is not associated with the file until after the submit event callback has completed. This was done to ensure that mappings were created only for files that passed all possible validation steps, since it is possible to reject a file in your "submit" handler as well. After some thought, it may be best to create this button to file mapping as soon as we have created an ID for this file internally. I've created an item in our issue tracker to deal with this.
If you move your logic into a "submitted" event handler instead, you should be good to go.
Referring to this post on Backbone.EventBinder, I am lost on how to use EventBinder with Backbone views (which is the most popular use case). Is it still recommend to add a close() method to the Backbone.View prototype and a onClose() method to the view as suggested in this post? Also where does one store the binder object, so that binder.unbindAll() can be called on close? What is the recommended way to close child views (e.g. a parent view on a collection which has child views on the associated models). A working example would be a great addition to the Backbone.EventBinder project.
Yes, you should still add a close method to your views. The EventBinder does not negate any of what that Zombies post says. Rather, it helps to automate a lot of the process by making it easier to unbind all of your events within the view.
Take a look at the Marionette.View source code for an example of how it's used:
https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L9
https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L16
https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L97
If you're using Marionette, you don't need to add the close method yourself, or add the event binder yourself. That's handled for you.
If you want to add this to your own views, it's easy:
MyView = Backbone.View.extend({
initialize: function(){
// add the event binder
this.eventBinder = new Backbone.EventBinder();
// bind some stuff
this.eventBinder.bindTo(this.model, "change:foo", this.doStuff, this);
},
close: function(){
// ... other stuff
this.eventBinder.unbindAll();
}
});
I have a requirement in my application where in I need to show the UI components(like text field, combo box) based on the values i get from the server side. To be precise, I have a combobox on the page, when the user changes the values i need to send the selected value to server to get information on what needs to be displayed. Without using MVC i implemented it as below
When the user changes the value in the combobox, i refresh(using load method) another store
When i get the data back from the server('datachanged' event) i read the data and create the UI components
Now I am trying to use ExtJS MVC, so i have two questions
How do I access a store which is associated to a controller but not necessarily to any UI components from the view
How can I setup the events of a store in the controller(in the control function) just like we setup events from view
Code i want to setup events from Store like 'datachanged' in controller like below -
this.control({
'viewport > #content-panel' : {
render : this.createMainTabs
}
});
In addition to sha's reply I can say that you may setup your store eventhandlers in your controller. For example you have a combobox with a store, so you could write like this:
this.control({
'#myCombo' : {
afterrender : this.setupStoreListeners
}
});
....
setupStoreListeners: function(combo){
var store = combo.store;
store.on('datachanged', //.....);
}
And one more thing, as sha wrote you could always get store by name, but I use this only when I need to share a store instance between multiple controllers. If I need this store only in one controller, I just save it inside this controller:
setupController: function(){
this.myStore = this.getCombo().store; // now you could use this.myStore anywhere you need
}
To get store object in the controller just use this.getStore('StoreName'), each store by default has its own instance and it doesn't really matter whether it's binded to any UI component you have.
After you get store object you can subscribe to any store events using any method you prefer. I usually like
store.on('load', {...})
Also I would not change anything in UI from the view code. I would put all this customization into controller code.