ExtJS synchronize record between clients - extjs

I'm trying to do something fun: I'd like to send the record changes from one client to another and have the second client updated to show these changes. Basically collaborative viewing. The second client is disabled from making changes, he can only watch.
Simple fields like strings, numbers, checkboxes, etc. are easy, that worked right away.
The references are the problem. If I have a combo that uses another model as it's source, I am unable to update it on the second client.
I tried setting just the id, then the entire referenced object, I tried various set options, but simply no dice.
The record does change, I see that the data is updated, I was even able to manually modify the _ reference attributes, but the UI keeps showing the old values for those fields.
Is there a way to send the record from one client to another and have the other client just take over all values and display them in the UI? (it would be better to send just the changes, but I'd be very happy if I could get it to work with the entire record)
EDIT: I'm using SailsJS with socket.io, so the p2p connection is not the issue.
I'm getting the data like this:
var data = record.getData(true);
broadcastRecord(data);
And on the other side I tried:
record.set(data);
A code example for the receiving side would be appreciated, if anyone has an ide how to solve this...

I think your problem is related to associations and comboboxes.
Let's say you have a model User with a field group that references model Group, and that you have a User form with a Group combobox.
In the receiver client, you are probably getting only the group id. record.set(data) updates the bound combobox calling setValue(groupId).
This setValue will try to find the corresponding record inside its store, but it won't ask server-side for that record. Instead, it will create a new record with the passed id (showing an empty combobox).
If possibile, you can set remoteFilter:false to the store and queryMode:'local' on the combobox and preload all the data from that store.
Otherwise, I think you'll have to override the combobox setValue method to get the record remotely.

Related

How to send data to backend when dropdown selected in zapier

Hello I have been trying to implement my app to zapier. I am able to authenticat through oauth2 and calls are going well but I am not able to pass data to back end when I use combobox.
I created two trigger
1) First trigger doesn't have trigger field, just a polling URL which fetch data from server and set variable. It works as expected. It sets data to lets say variable "X"
2) Second trigger is basicly for using "X" I have one trigger field "Y" which is combobox and as documentation I just write X.id.name and I can see combobox with field. I want to implement combobox selected event. I implement polling url like this http://mywebpage.com/myapi/{{Y}} . But whenever I test my zap , lets say I choose id = 5. it always request http://mywebpage.com/myapi/{{Y}} but not http://mywebpage.com/myapi/5 how can I solve it.
Thanks.
Ok I found the fix. I needed to change second trigger type to Unicode, because this way I can get selected one. Now is working.

How to identify a BackboneJS Model serverside

I'm just getting my head around BackboneJS, but one of the (many) things I'm still struggling with is how exactly the Models Sync up and relate to the serverside DB records.
For example, I have a Model "Dvd", now I change an attribute on the "Dvd" Model, the Name for example, and then I call save(), how exactly does the server side know what DB record to update? Does Backbone hold the DB row ID or something else?
Yes, typically you will set up your Backbone models so that they have database row IDs for any objects you're working with. When one of them is brand new on the client side and not yet saved to the server, it will either have a default or no ID, which doesn't matter since the server will be assigning the ID if and when the initial save transaction succeeds.
Upon saving or updating a model item, Backbone expects the server to reply with some JSON that includes any attributes that have changed since the save or update request was made. In the response to the initial save request, the server informs the client of a newly saved item's row ID (and you can also send along any other information you might need to pass to the client at the same time).
By default, the 'id' attribute of a model object is assumed to be its unique identifier, but backbone lets you change this if you're using a different identifier for the primary key. Just give your model an idAttribute parameter (see the docs for Backbone.Model.extend()) to do that.
Meanwhile, either the urlRoot parameter or a url function can be given to your models to characterize the urls that should be used to send the various ajax requests to the server for a given model.

Reloading an Ext.data.Store model?

I'm trying to fix some issue with an ExtJs website but not sure how to proceed. Basically, I have a form that loads an Ext.data.Store model. For new models, the model object initially doesn't have an ID. Once it's saved an ID is assigned to it by the webservice.
The problem is that this Ext.data.Store model is not being reloaded after saving, so it stays without an ID, which causes some problems later on.
So is there any way to force ExtJs to reload the store model after saving? I checked the documentation of Ext.data.Store but cannot see any "reload()" or "refresh()" method. Any suggestion?
You don't need to do anything special. ExtJs has a logic to replace models with phantom flag with the new copies received from the store after update procedure. Chec couple things:
Make sure you have correctly specified idProperty in the model. This is how ExtJs will detect whether record is new or not.
Make sure your store returns properly new/updated records in the response message.
Make sure your data reader properly parses these records in the response message.

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!

How do you make a multiple-choice list from the sqlite database in Android?

I'm new to Android programming, and I wanted to pull list options from a column of the SQLite database for the user to select.
How would I go about doing this?
Like, say the database table to be read is called countries, and the columns were ID, country, and capital.
How would I let the user pick from the list of capitals and have the application return the information in that row?
It sounds like you'd want to present the selections to the user as a Spinner. I would query your database and get a Cursor, wrap that Cursor in a SimpleCursorAdapter, and call setAdapter() on your Spinner instance, passing it the SimpleCursorAdapter instance.
Register to receive onItemSelected events from your Spinner. Then when onItemSelected() is called, you should be able to call getItem(position) on your SimpleCursorAdapter to get the data for the line that was selected. getItem() returns an Object, I'm not entirely sure what you will get back there, but I'm guessing it will actually be a CursorWrapper. I would step into the debugger to verify what that Object actually is that gets returned to you from the getItem() call, and proceed from there.

Resources