Ext JS and loading data into a form - extjs

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

Related

Best practice for loading non model data in 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.

How to build sets of entity records using Breeze and local storage

I'm trying to create an off-line data collection app, using AngularJS.
I think, adding Breeze.js should help with saving and querying data to and from the browser local storage:
1) present the user with angular data entry form
2) when the "save" button is clicked - create a new Breeze entity and store it locally
3) the next time this form is used - create a second entity, and add/save it as a part of the same collection
I was wandering if anyone have tried to do something similar and could give me some pointers of how this is done.
I think it's viable and these links should help you to get started:
http://www.breezejs.com/documentation/querying-locally
You also might want to check this Angular sample aswell:
http://www.breezejs.com/samples/todo-angular
One caveat you have to have in mind is that Breeze will need to load the model's metadata from somewhere. Typically you hit a Web API asynchronously and get the metadata from there. However, on your particular scenario you should give a look at trying to load your metadata from a script file. Here's an how-to and discussion about it:
http://www.breezejs.com/documentation/load-metadata-script

Drupal webform submission creating new table

I have created a webform. However I want that whenever I create a new webform and if I input some data and submit it, It must create new table in phpmyadmin for every new form that I create.
By default every submitted data goes to "webform_submitted_data" table. I want every webform that I create must have separate table.
Please give me steps on how to do that.
If you use the webform module as is, it will use its own database table structure exactly as you describe.
If you have particular requirements on how the data of your webforms is stored in the backend, you'll have to create your own custom module that either builds its own forms and does the data storing itself or that hooks into the existing webform functionality and changes just the storing and retrieving part of it.
In either case, it'll be a bit of work on your part to build that custom module.
How the data is stored isn't something you can just configure for the webform module... :-)
However, I'm not sure why you want to change the way the data is stored, but you're aware that you can export the submissions data as csv and other file formats to manipulate later, right?
The webforms mysql view module will give you a pseudo-table for each webform, allowing read access to the data.

How can I use Backbone.Model.save() if my whole app and data is local?

I'm making a totally local Backbone app, no server-side included, and I provide the app with some initial local data. The data is actually the Collection data which is a json file and stored in a folder called data. So I provide the Collection with a url attribute which is data/datalist.json and use this.collection.fetch() to get the inital data. All works well.
But I want any update happens in View would save changes to the corresponding Model data in this Collection json data file. It seems that this.model.save({name: newName}) doesn't work for me. Every time I refresh the whole page, the app will still show the inital data file. So how should I change the data file when a item in View is updated, deleted or created? Do I need to set a url attribute in Model?
Model.save calls the Backbone.sync method, which by default maps CRUD functions to a REST api. If you want to use something other than REST for save/update/delete, then you need to override Backbone.sync.
There is a local storage plugin that overrides sync on Github, which is endorsed by Backbonejs: Backbone.localStorage
This plugin should persist your data while the app is running. You may need to extend it if you want to write changes to your filesystem (not sure, haven't used it myself). Hopefully this gets you started.

Retrieve configurations that are saved in db

I saved all my system wide configurations in db. How do i make the configurations that I have saved in db available everywhere. These need to be available everywhere --in the model, view, controller, component, element etc.
Are you trying to override the Configure::write() function with values that you are storing in the DB? If not, then create a Settings model for your external settings and then pull that data when you need it in the controller. You can then pass those settings to a view (and in turn elements), by following the normal MVC process.
Follow this process:
Create Settings Model
Add model to AppController's $uses array
Perform a find for the settings in your controller -- now the data
is there
Pass the settings data to your view $this->set('settings',
$settings);

Resources