How to send associated data to server side in ext js4? - extjs

I am new in extjs4 .I am using MVC structure.and I am going to save associated data to server side.I am getting stuck at this point.
I have two tables
1)
Question
========
qid
question
2)
Option
========
oid
option
qid
I am going to displayQuestion answer page. There are 10 questions diplays on the page at a time with their 4 options for each question.
I know how to save single instance of model in to database.
var check = Ext.ModelManager.create(
{
question:que,
}, 'Bal.model.sn.QuestionModel');
check.save();
I am getting all the selected questions with there options.but I dont know how to save associated data to database.And how to create instance of particular models to instantiate model with data..
Here is my other model
'Bal.model.sn.optionModel'
How can i solve this issue...

This functionality is not provided out of box. Please take a look at this thread for some implementations of similar functionality: http://www.sencha.com/forum/showthread.php?141957-Saving-objects-that-are-linked-hasMany-relation-with-a-single-Store/page4

Related

WordPress : make categories automatically match according to external API Value

I'm managing a company website, where we have to display our products. We however do not want to handle the admin edit for this CPT, nor offer the ability to access to the form. But we have to read some product data form the admin edit page. All has to be created or updated via our CRM platform automatically.
For this matter, I already setup a CPT (wprc_pr) and registered 6 custom hierarchical terms: 1 generic for the types (wprc_pr_type) and 5 targeting each types available: wprc_pr_rb, wprc_pr_sp, wprc_pr_pe, wprc_pr_ce and wprc_pr_pr. All those taxonomies are required for filtering purposes (was the old way of working, maybe not the best, opened to suggestions here). We happen to come out with archive pages links looking like site.tld/generic/specific-parent/specific-child/ which is what is desired here.
I have a internal tool, nodeJS based, to batch create products from our CRM. The job is simple: get all products not yet pushed to the website, format a new post, push it to the WP REST API, wait for response, updated CRM data in consequence, and proceed to next product. Handle about 1600 products today on trialn each gone fine
The issue for now is that in order for me to put the correct terms to the new post, I have to compute for each product the generic type and specific type children.
I handled that by creating 6 files, one for each taxonomy. Each file is basically a giant JS object with the id from the CRM as a key, and the term id as a value. My script handles the category assertion like that:
wp_taxonomy = [jsTaxonomyMapper[crm_id1][crm_id2]] // or [] if not found
I have to say it is working pretty well, and that I could stop here. But I will have to take that computing to the wp_after_insert_post hook, in order to reaffect the post to the desired category on updated if something changed on the CRM.
Not quite difficult, but if I happen to add category on the CRM, I'll have to manually edit my mappers to add the new terms, and believe me that's a hassle.
Not waiting for a full solution here, but a way to work the thing. Maybe a way to computed those mappers and store their values in the options table maybe, or have a mapper class, I don't know at all.
Additional information:
Data from the CRM comes as integers (ids corresponding to a label) and the mappers today consist of 6 arrays (nested or not), about 600 total entries.
If you have something for me, or even suggestions to simplify the process, I'll go with it.
Thanks.
EDIT :
Went with another approach, see comment below.

Cakephp 3 - Building an entity over several forms/actions

This is a design question.
I'm trying to build a booking system in cakephp3.
I've never done something like this with cake before.
I thought the best way might be to -- as the post title suggests -- build up an entity over several forms/actions.
Something like choose location -> enter customer details -> enter special requirements -> review full details and pay
So each of those stages becomes an action within my booking controller. The view for each action submits its content to the next action in the chain, and i use patch entity with the request data, and send the result to the new action's view.
I've started to wonder if this is a good way to do it. One significant problem is that the data from each of the previous actions has to be stored in hidden fields so that it can be resubmitted with the new data from the current action.
I want the data from previous actions to be visible in a read only fashion so I've used the entity that i pass to the view to fill an HTML table. That's nice and it works fine but having to also store that same data in hidden fields is not a very nice way to do it.
I hope this is making sense!
Anyway, I thought I'd post on here for some design guidance as i feel like there is probably a better way to do this. I have considered creating temporary records in the database and just passing the id but i was hoping I wouldn't have to.
Any advice here would be very much appreciated.
Cheers.
I would just store the entity in the DB and then proceed with your other views, getting data from the DB. Pseudo:
public function chooseLocation() {
$ent = new Entitiy();
patchEntity($ent,$this->request->data);
if save entity {
redirect to enterCustomerDetails($ent[id]);
}
}
public function enterCustomerDetails($id) {
$ent = $this->Modelname->get($id);
// patch, save, redirect again ...
}

extjs 4 add new record to grid using form and finally to php mysql

I have researched lot of exampls for last 4 days but just couldnt come up with right approach.I am preparing extjs 4 app using sencha architect. There is a grid with lot of entries coming from store which is populated from php mysql backend.
I am tryng to add new record using a button "Add Announcement" and the data should be entered using a form.
grid store has three fields (Extra ID which needs to be passed on to new record in database) but the form has 2 fields.
Request your help in knowing the right approach. Possible options with me:
create new record in store, send it to mysql. Select new record, edit the new record in form, again send it to mysql
get a blank form, enter data, submit using url, create entry in mysql. send data back to store.
use gridediting plugin to create new record. know how to use it for editing. Dont know how o create new record
In any case how should i pass class ID to the new record
If the record has only a few fields then #3 approach would do. I have written an example of grid with all CRUD operation, however, not in Architect. Anyway, the same or similar buttons handlers can be used for coding it in Architect.
You can find the example here: http://extjs.eu/ext-examples/#writable-grid

MVC ExtJS 4, update a store record using record from other store

I have two stores:
FAQs - contains a lot of models of my items
FAQ - contains one model.
In view mode I work with FAQs (to see all items) and in edit mode I work with FAQ just to work with one item and not to load all of them.
After finishing editing and saving FAQ I need to find that item in FAQs and make changes there as I've made in FAQ. I don't use network for it.
I know two ways:
1) find needed record in FAQs and replace it there
_updateFaqsStore: function() {
var faqsStore = Ext.data.StoreManager.lookup("faqs.FAQs");
var activeRec = this.activeRecord;
var index = faqsStore.indexOf( faqsStore.findRecord('id',activeRec.get('id')) ); // index in faqsStore of activeRec
faqsStore.remove(faqsStore.findRecord('id',activeRec.get('id'))); // remove old rec
faqsStore.insert(index, activeRec); // insert new - activeRec
but the object structure is not the same (though I use the same model)
2) find needed record in FAQs and set there every field
var faqsItem = faqsStore.findRecord('id', activeRec.get('id')); // find same item in FAQs store
faqsItem.set("myField", activeRec.get('myField')); // make changes in FAQs as in FAQ
but I need to enumerate all fields.
Maybe, there is some other way out? Please, help me!
You should not use two stores in this case. Why aren't you just using one store FAQs ? You then select the record, and you edit it directly.
For your use case there is no need at all to use two stores.
Also, you say you need to minimize the number of requests to the server. There is no problem for this. Just edit all the records you need to, and the at the end, you save all to the server at once.
Look at this example : it shows how to edit a record in a separate form, how to configure your requests (autoSync and batch buttons). You will deactivate autoSync and use batches to minimize roundtrips to the server.
Look also at rowediting example. This allows you to edit the data even easier.

Flex 4 data management - how do I approach this?

quite an explanation here, hope someone has the patience to read it through
I'm building an application in Flex 4 that handles an ordering system. I have a small mySql database and I've written a few services in php to handle the database.
Basically the logic goes like this:
I have tables for customers, products, productGroups, orders, and orderContent
I have no problem with the CRUD management of the products, orders and customers, it is the order submission that the customer will fill in that is giving me headaches:
What I want is to display the products in dataGrids, ordered by group, which will be populated with Flex datamanagement via the php-services, and that per se is no problem. But I also want an extra column in the datagrid that the user can fill in with the amount he wishes to order of that product. This column would in theory then bind to the db table "orderContent" via the php services.
The problem is that you would need to create a new order in the database first that the data could bind to (orderContent is linked to an order in the db).
I do not want to create a new order every time a user enters the page to look at the products, rather I would like to create the order when a button is pressed and then take everything from the datagrids on the page and submit it into the database.
My idea has been to create a separate one-column datagrid, line it up next to the datagrid that contains the products and in that datagrid the user would be able to enter the amount of that product he'd like to order.
I've created a valueObject that contains the data I would need for an order:
Code:
package valueObjects
{
public class OrderAmount
{
public var productId:int;
public var productAmount:int;
public var productPrice:Number;
public function orderAmount()
{
}
}
}
My idea was to use a service to get all products from a certain group, populate an ArrayCollection with the data, then transfer each object in that ArrayCollection to an instance of the Value Object above, add the value object to another ArrayCollection that would the be used as a dataProvider for the one-column datagrid (I would only display amount which would be set to zero at first, but use the other data upon transfering it to the db)
I've tried to use the results from the automatically generated serviceResults that retrieve the products for the datagrid and put in a resultHandler that transfers the valueobjects, however this does not seem to work.
Basically my question is this: Am I approaching this thing completely wrong, or is there a way I can get it to work the way I planned?
Would I need to create a completely new service request to get the product id:s, and price to populate the one-column datagrid.
I'll post some code if that would help.
Thank you if you read this far.
Solved it by creating a Value Object class to hold all the info needed for each row in the grid and from the php service that returned all products in a group, I looped through the result and transfered the data needed into my Value Object.
I then added each Value Object into an ArrayCollection and made that the dataProvider for the dataGrid.
No need to use two grids. I forgot how logic things get when you think of datagrid data just as an ArrayCollection and forget the visual presentation of it on screen.
Put in a few itemRenderers and the whole thing is beautiful!

Resources