Backbone view, routes - permalink - backbone.js

I have a question on Backbone routes and views.
Assuming that there is a page with 3 views, View-1,2,3. Each view nested inside the other (view 3 inside view 2 which is inside view 1) and that view 3 is result of navigating from view 1 to view 2 to view 3.
For example, view-1 shows all customers, and view-2 shows the selected customer and view-3 shows active order(s) of the selected customer.
Now, if I want to give a permalink to this entire view (which shows the active order(s) of a particular customer selected from a list of customers) to another user then how to design it.
Are there any good practices in this scenario.

Related

Load several views in one page

I would like to print the content of several views of my couchDB database inside a page.
I have several listContainers in my page and each listContainers must print the content of one view.
To do that I added an "onDidLoad" event to my page which triggers several QueryViews (one QueryView per view).
I correctly binded the content of each ListContainer with its corresponding view.
My problem is that all the lists print the same content which is the content of the last loaded view. All the views seem to be loaded but only the last view loaded is taken into account.
Is it possible to have several QueryViews for one page and how can I load the content of different views inside one page ?
Yes, it is possible to have multiple Query view components in one Page. Use the Marker property to set a different value for each component. In the MobileComponent Source you will find all your views marked as myView#myMarker. Select corresponding view markers for your listContainers.

AngularJS: Preserving the state of a view when the user goes to a sub-view

Within AngularJS, is there a way of preserving the state of a model & view between invocations?
Say, you have a master view that displays a tables or tables of information; the user has manipulated the view and applied filters and sort orders, etc to the information on display in this master view. The user then selects an item on this master view and is taken to another, child view, that displays information about the item they have selected; if the user then decides to return to the previous view I want that view to be in the same state as it was before, with its filters etc intact.
I'm currently using the technique described here: Maintain model of scope when changing between views in AngularJS where I preserve the model state using a service and that service is then injected back into the controller when its recreated. Is this the AngularJS way, or is there a better way of preserving model/view state between invocations?

Decoupling Backbone views where one triggers change in other view

I have a page which contains two Backbone Views. A view for list of contacts ContactsListView and a view for navigating NavView.
ContactsListView has collection of Contact models. My list of contacts collections is quite bigger so I don’t want to display all of them on page load.
So I have implemented contacts collection to fetch only a range (initially 0 to 50) of contacts from server and ContactsListView displays it. And use NavView to display the range of contacts ContactsListView is displaying currently. It also has next and previous buttons on click of which ContactsListView should display next or previous range of contacts.
Here my NavView is actually controlling what range of contacts ContactsListView should be displaying. But I want to decouple ContactsListView from NavView.
I realized I can do this with creating a Range model (with from and to attributes with default set to 0 and 50) and passing it to ContactsListView and NavView. While ContactsListView adds a listener, ContactsListView.show(from, to), to change event on Range model and NavView is updating the Range model when clicked on next or previous button. As the Range model changes ContactsListView listener would fetch contacts to update it's view.
Or
I can create a Range model and pass it to NavView. NavView then updates the range on click of prev or next button and triggers an event rangeUpdated with range values on (NavView) itself. I add listener on NavView in some additional code piece (probably my own controller object) and invoke ContactsListView.show(from, to) explicitly.
Which one is better way to decouple ContactsListView and NavView? Or is there other way to decouple them?
As long as your question is tagged with backbone.marionette, I assume you are using it, or thinking about using it.
One option could be using the marionette.compositeview, that lets you define both a model and a collection in the same view, so you wouldn't need to share models between views.
But maybe, that could not the best approach if you really want to decouple both views. For decoupling them, your second option using your own controller (or marionette.controller) is the one I like more, as you don't need the range number as explicit data contained in a model within the ContactListView (you already have that information in NavView).
Lastly, I like to do the fetching/saving data from the Controller, and not from within the view. The View in MVC patterns just show things, getting information from the model. Retrieving data from server that will be stored in the model seems more a Controller operation. I don't know how are you binding the data with the view, but maybe the ideal will be fetching the data from the Controller, and let the view render itself when the change of model is detected.
Initialize both views with Range model.
In Contact List view listen to Range model change event to request new data from Contacts collection and show them.
When click on Nav view just set the Range model with new values (it will trigger change event and your Contact List view will be updated).

Backbone View Architecture

I have 2 parts in my application:
A grid of players each with a thumbnail to click which activates a detail view on the left side of the page.
Detail view - activated when player is clicked on grid.
The model is very straightforward and will be read only. (Player model and Players collection)
The way I am thinking of organizing views is as follows:
AppView - main view that fetches collection (to create grid) and populates the grid. (JSONP is done in model) and manages events for the grid such as pagination.
PlayerThumb View - The view that contains a thumbnail of player that can be clicked from inside the grid.
CardView - This view contains the players large picture as well as stats about the player.
My confusion is how do I communicate information to the card view when a player thumb view is clicked?
What is the responsibility of the AppView? Is it doing too much? Should I create a PlayerGridView? If this is the case, what would app view be used for?

Drupal 7 view custom templates

I have created 1 views which include the 5 types of content types nodes.
What i want to do is customize the view template.
The first 2 stories display in other format like complete title, summary and image
and last 3 stories only title.
How this possible using views.
Or i have to use $view=views_get_view_result() method
You can create the first 2 stories as a regular View (either a page or a block, whichever you want to use) and create the remaining 3 stories as an attachment to the first view.
In the View, you should be able to create an attachment which you can then attach at the end of the first View.
This way, you can have slightly different configurations for each view but still have them in the same View page or block like:
I've posted a lengthier, illustrated step-by-step on my blog at http://nmc-codes.blogspot.ca/2012/10/views-attachment-in-drupal-7.html

Resources