Best practice for loading non model data in ExtJS - extjs

Let's assume that I have 2 tables in my database, a user table and a folder table. They are matched by two models (beans) in my backend java code and similarly by to models in my extjs client side. Using viewmodel architecture, I want to create a form that shows the username and the amount of folders they have created using viewmodel bindings. Each folder in the database has a CREATE_USER_ID field that contains the id of the user that created the folder. How do I go about loading the required data?

Viewmodels are not designed to load data directly (and not designed to load non model data at all). You've got two options:
Go model (recommended). Two sub-options:
Add folder_amount field to your client side user model. On the server side this does not necessarily need to be added as well as you can adjust your API feeding data to client to add that field dynamically.
If you want to keep your client models exactly matching their server mates, use viewmodel in conjunction with associations (see example here, scroll down to Associations) to load folders themselves, though in the UI only show the amount of them. Mind that you don't need to load all folder fields but just their IDs.
Stick to your own fancy non model approach, but this won't have anything to do with viewmodel bindings. This may be, for example, making an AJAX call to retrieve the number of folders when user data is rendered in the UI.

Related

How can I identify the field data types returned by a RESTful Web API?

I have created a RESTful Web API in ASP.NET. It is returning data from my SQL Server database. How can I identify the data types of the fields that are returned in AngularJS? The reason I want this is because I'm creating a simple interface to load data in an edit form one of many tables that is selected at run time. I don't want to build a custom edit form for each table. It's working, but I want to clean up the interface like displaying boolean values in a checkbox or formatting the appearance of date types. Do I need to return the data in XML to do this or is there some other way?
I solved this by using SqlConnection.GetSchema and SMO objects for the foreign keys.

in backbone.js can a Model be without any url?

I have an app where the menu system is built dynamically using metadata fetched at startup. Based on this data, and menu selections, I need to craft a "filter box" where user can input search criteria. The "main" View consists of a filter box plus a search results panel where result(s) are rendered in accordance with their classes.
Can I model the Filter Box as a Backbone.js Model? It does not have any data fetches from the backend as its composition depends entirely on the menu selections + the metadata? E.g. when user selects "Sales" menu then the filter box might prompt for "Sales Order Number" whereas when user selects "Material" then the filter box might prompt for something else.
I would then use this widget as component of the "main" View, along with a set of results views made up on the fly. As users make their menu selections, this main View will un-render the existing filter box and recompute and re-render a new one. Other components on the screen could query the Filter Box for its settings.
The examples I have seen so far always have a url and a server fetch, save, etc. The only url-free example on the tutorial page says it is a "contrived" example. I was wondering if a backend provider is necessary and programming will be full of gotchas without conforming to this requirement.
Thanks.
You can have models without url property defined. One of the building blocks of Backbone is the Sync object, that will help you when pulling and pushing data, ideally from/to REST endpoints. For this to work you need to tell where the data are served, and to do so you set a value to url on Models or Collections.
If you don't need server comunication but you just want to use the utilities provided by simple Model or Collection (such as event handling, filtering, etc..) you just don't set url and you are good to go (just keep in mind that methods like fetch or save won't work).
Yes you can use Backbone for your DOM logic too. A model doesn't need to represent data from the server. Do whatever you like with the few basic elements of Backbone, simply use them when you feel like it'd do a great job :)

Ext JS and loading data into a form

I have build a simple MVC application where I have a form and I need to load data into it.
I'm wondering if I should load this data using a store or directly using the model class. I have already a store for my grid.
So I see this 3 option.
Load data using Model class
Load data using the existing store (a grid uses this store already)
Create a second store and load my data using it.
If your store uses the same model and the data (record) you edit will defiantly be loaded in that store (for example if you open the form on a double-click of a gridrow) or can be inserted into it I recommend you to go with the store approach.
If you edit a record (model-instance) that will not necessarily loaded into the grid-store the you should load the data using the model.
A second store will only be necessary if both points above are true and you also wan't to batch multiple record (model-instance) edits from that form into one request to the server.
A third option is to bind the form directly to the server, but I recommend you to use the model-approach.
Note that if you need a different proxy for the store and the model
simply set one on the model and one on the store. By default the store
will inherit the proxy of the model but never the model the proxy of
the store

Backbone maintaining state

I am developing a JavaScript heavy single page app with Backbone.js. The goal is as follows;
The user starts with a set of multiselect boxes which are populated with filter elements to query a set of resources. These multiselect boxes are dependent of eachother. Furthermore, the elements in the multiselects are queried from the server and depend on the user that is logged in, in other words they depend on the resources that are associated with the user that is logged in.
The user fills out the multiselect boxes and presses a "filter" button. When this is pressed a collection is fetched, thereby using a set of query parameters (multiple array values) to get the set that reflects the filter elements.
When the collection is fetched the view with the resources appear. This view has multiple subviews, and it must be possible to drill down on specific resources while maintaining state (the collection that is fetched as a result of the query parameters)
How to maintain state in a Backbone app in such a use case? I've looked through many examples but all are to simple to be useful.
I am new to backbone.js and trying to develop a single-page app using Backbone.js. In my limited understanding of backbone.js documentation, I did not come across a better way of maintaining state using backbone.js core. However, in the past, I have worked with jStorage: http://www.jstorage.info/ , a simple wrapper plugin for Prototype, MooTools and jQuery to cache data (string, numbers, objects, even XML nodes) on browser side. It is simple to integrate and get started. In my app, I am going to use this for the time being... I thought this could be shared...hence I mention it here when I came across this question... I hope this would be of some help

MVC design for archived data view

Implementation of a standard archive process in ASP.Net MVC. Backend SQL Server 2005
We've an existing web app built in MVC. We've an Entity "Claim" and it has some child entities like ClaimDetails, Files, etc... A pretty standard setup in DB. Each entity has its own table and are linked via FK. Now, we need to have an "Archive" feature in web app which will allow admin to archive a Claim and its child entities. An archived Claim shud become readonly when visited again.
Here're some points on which I need your valued opinion -
To keep it simple and scalable (for a few million records) for now we plan to simply add a bit field "Archived" to the Claim table in db.
And change the behavior accordingly in the web app.
We've a 'Manage claim' page which renders a bunch of diff views for Claim and its child entities. Now, for a readonly view we can either
use the same views or have a separate set of views. What do you
suggest?
At controller level, we can identify archived claim and select which view to render.
At model level, though it'd be great to be able to use the same model used for Manage Claim - but it might not get us the "text" of
some lookup fields. For example, Claim.BrandId is rendered as a
dropdown in Manage claim (requires only BrandId) but for readonly view
we need 'BrandText'.
Any existing ref or architecture level example would be great.
Here's my prev SO post but its more about db level changes: Design a process to archive data (SQL Server 2005)
Thank you.
I ended up using a duplicate of the existing view with some edits and archive specific changes. I was able to use the same backend model and data fetch structure in a different action.
My entity table has an archived flag which helps identify the status so the rest of the fetch implementation stays the same only a new view (mostly replicated) and a new action (replicated from the existing one) got me the archived view.

Resources