Qooxdoo – how to use qx.data.store.Json – Stack Overflow coin bitcoin

Qx.Data.Store.Json is read-only store implementation. It just sets its model property, which value is converted from JSON (with qx.Data.Marshal.Json) retrieved from the URL passed to its constructor. In general in qooxdoo data-layer design all connections are bidirectional.

It’s possible to make read-write JSON store through subclassing qx.Data.Store.Json. Its model is normal qooxdoo data object. You can bind to it, you can listen to its changes (the store creates model with bubbling changes) and so on.

Here goes example for list controller, which model is qx.Data.Array. Its change event has type (add, remove and others). So you can make a corresponding request when the model has changed. Backend is cherrypy application for dummy RPC. Note that it is a demo code, which doesn’t dispose request objects, listens for fail events, and other things you should do in a real code.Coin bitcoin

JsonStore.Js qx.Class.Define(‘adhoc.JsonStore’, {

Extend : qx.Data.Store.Json,

Construct : function(baseurl, delegate)

{

This.Base(arguments, baseurl + ‘/list’, delegate);

This. BaseUrl = baseurl;

// can’t refine model property to set apply method because

// it has not init value

This.AddListener(‘changemodel’, this. OnChangeModel, this);

},

Members : {

BaseUrl : null,

Create : function(entry)

{

Var request = new qx.Io.Request.Xhr(this. BaseUrl + ‘/create’);

Request.SetAccept(‘application/json’);

Request.SetParser(‘json’);

Request.SetRequestData(qx.Util.Serializer.ToNativeObject(entry));

Request.AddListener(‘success’, this.Reload, this);

Request.Send();

},

Remove : function(entry)

{

Var request = new qx.Io.Request.Xhr(this. BaseUrl + ‘/remove’);

Request.SetAccept(‘application/json’);

Request.SetParser(‘json’);

Request.SetRequestData({‘id’: entry.GetId()});

coin bitcoin

Request.Send();

},

OnChagneModelDataArray : function(event)

{

Var change = event.GetData();

If(change.Type == ‘add’)

{

This. Create(change.Added[0]);

}

Else if(change.Type == ‘remove’)

{

This. Remove(change.Removed[0]);

}

},

OnChangeModel : function(event)

{

Var model = event.GetData();

Model.AddListener(‘change’, this. OnChagneModelDataArray, this);

}

}

});

Application.Js qx.Class.Define(‘adhoc.Application’, {

Extend : qx.Application.Standalone,

Members : {

Main : function()

{

This.Base(arguments);

If(qx.Core.Environment.Get(‘qx.Debug’))

{

Qx.Log.Appender.Native;

Qx.Log.Appender.Console;

}

Var list = new qx.Ui.Form.List();

List.SetWidth(120);

Var controller = new qx.Data.Controller.List(null, list);

Controller.SetLabelPath(‘name’);

Controller.SetLabelOptions({‘converter’: function(value, model)

{

Return model.GetId() + ‘:’ + value;

coin bitcoin

}});

Var store = new adhoc.JsonStore(‘/document’);

Store.Bind(‘model’, controller, ‘model’);

Var create = new qx.Ui.Form.Button(‘create’);

Create.AddListener(‘execute’, function()

{

Var name = window.Prompt(‘enter document name’);

If(name)

{

Controller.GetModel().Push(qx.Data.Marshal.Json.CreateModel({

‘id’ : null,

‘name’ : name

}));

}

});

Var remove = new qx.Ui.Form.Button(‘remove’);

Controller.Bind(‘selection[0]’, remove, ‘enabled’,{‘converter’:boolean});

Remove.AddListener(‘execute’, function()

{

Var confirmed = window.Confirm(‘remove selected document?’);

If(confirmed)

{

Controller.GetModel().Remove(controller.GetSelection().GetItem(0));

}

});

Var root = this.GetRoot();

Root.Add(create, {‘left’: 10, ‘top’: 10});

Root.Add(remove, {‘left’: 70, ‘top’: 10});

Root.Add(list, {‘left’: 10, ‘top’: 40});

}

}

});

App.Py #!/usr/bin/env python

coin bitcoin

# -*- coding: utf-8 -*-

Import os

Import cherrypy

Path = os.Path.Abspath(os.Path.Dirname( file ))

Config = {

‘global’ : {

‘server.Socket host’ : ‘127.0.0.1’,

‘server.Socket port’ : 8080,

‘server.Thread pool’ : 8

},

‘/static’ : {

‘tools.Staticdir.On’ : true,

‘tools.Staticdir.Dir’ : os.Path.Join(path, ‘qxjsonstore’)

}

}

Class document:

Store = none

Def init (self):

Self. Store = {

1 : {‘id’: 1, ‘name’: ‘foo’},

2 : {‘id’: 2, ‘name’: ‘bar’},

3 : {‘id’: 3, ‘name’: ‘baz’},

4 : {‘id’: 4, ‘name’: ‘qux’},

}

@cherrypy.Expose

@cherrypy.Tools.Json out()

Def list(self):

Return self. Store.Values()

@cherrypy.Expose

@cherrypy.Tools.Json out()

Def create(self, **kwargs):

Id = max(self. Store.Keys()) + 1

Self. Store[id] = {‘id’: id, ‘name’: kwargs[‘name’]}

Return id

@cherrypy.Expose

@cherrypy.Tools.Json out()

Def remove(self, id):

Del self.Coin bitcoin store[int(id)]

Class app:

Document = none

Def init (self):

Self.Document = document()

@cherrypy.Expose

Def index(self):

Return ”’

Var qx = {};

Qx.$$environment = {qx.Application: adhoc.Application};

”’

If name == ‘ main ‘:

Cherrypy.Quickstart(app(), ‘/’, config)

Here’s runnable snippet for the demo. Also in case of advanced binding to qx.Data.Array beware of bug#8127 which the team doesn’t hurry to fix. User-code fix is possible though.

Qx.Data.Store.Json only gets data from the server. I don’t see how you can implement adduser or deleteuser using qx.Data.Store.Json – there’s no way to set request data on the xhr the store uses internally. From the qooxdoo manual: the main purpose of the store components is to load data from a source and convert that data into a model. Nothing about writing back to the server there – in fact, the only explicitly read+write store is the offline store – which makes use of local storage.Coin bitcoin

If I understand your problem correctly, you need to use qx.Io.Rest.Resource to fetch, add and delete (and probably also update) users and documents on the server. With this, you can map combinations of urls and http verbs to server-side operations on users and documents. This also lets you set data to send along for operations like add and update. You can get the data returned by the async actions called on the resource by listening for the success event on the resource itself – whatever data there is in the response it will be in the event’s data property.

You can then automatically convert the JSON contained in the event to qooxdoo objects via qx.Data.Marshal.Json, then set the resulting model into a controller’s model property. It will create the same type of classes as the stores in qx.Data.Store.Coin bitcoin

Stack exchange

Network

• technology

• life / arts

• culture / recreation

• science

• other

• stack overflow

• server fault

• super user

• web applications

• ask ubuntu

• webmasters

• game development

• tex – latex

• software engineering

• unix linux

• ask different (apple)

• wordpress development

• geographic information systems

• electrical engineering

• android enthusiasts

• information security

• database administrators

• drupal answers

• sharepoint

• user experience

• mathematica

• salesforce

• expressionengine® answers

• stack overflow em português

• blender

• network engineering

• cryptography

• code review

• magento

• software recommendations

• signal processing

• emacs

• raspberry pi

• stack overflow на русском

• programming puzzles code golf

• stack overflow en español

• ethereum

• data science

• arduino

• bitcoin

More (28)

coin bitcoin

• photography

• science fiction fantasy

• graphic design

• movies TV

• music: practice theory

• worldbuilding

• seasoned advice (cooking)

• home improvement

• personal finance money

• academia

• law

More (16)

• english language usage

• skeptics

• mi yodeya (judaism)

• travel

• christianity

• english language learners

• japanese language

• arqade (gaming)

• bicycles

• role-playing games

• anime manga

• puzzling

• motor vehicle maintenance repair

More (32)

• mathoverflow

• mathematics

• cross validated (stats)

• theoretical computer science

• physics

• chemistry

• biology

• computer science

• philosophy

More (10)

• meta stack exchange

• stack apps

• API

• data

• area 51