[qooxdoo-commit] SF.net SVN: qooxdoo:[21662] branches/branch_1_0_x/qooxdoo/framework/source/ class/
Brought to you by:
ecker,
martinwittemann
From: <mar...@us...> - 2010-03-01 07:43:50
|
Revision: 21662 http://qooxdoo.svn.sourceforge.net/qooxdoo/?rev=21662&view=rev Author: martinwittemann Date: 2010-03-01 07:43:44 +0000 (Mon, 01 Mar 2010) Log Message: ----------- [BUG #3486] The bindings need to be removed befor the new model is set in the controller to avoid not expected data manipulation. Modified Paths: -------------- branches/branch_1_0_x/qooxdoo/framework/source/class/qx/data/controller/Form.js branches/branch_1_0_x/qooxdoo/framework/source/class/qx/test/data/controller/Form.js Modified: branches/branch_1_0_x/qooxdoo/framework/source/class/qx/data/controller/Form.js =================================================================== --- branches/branch_1_0_x/qooxdoo/framework/source/class/qx/data/controller/Form.js 2010-03-01 07:42:05 UTC (rev 21661) +++ branches/branch_1_0_x/qooxdoo/framework/source/class/qx/data/controller/Form.js 2010-03-01 07:43:44 UTC (rev 21662) @@ -208,6 +208,17 @@ // apply method _applyModel : function(value, old) { + // first, get rid off all bindings (avoids whong data population) + if (this.__objectController != null) { + var items = this.getTarget().getItems(); + for (var name in items) { + var item = items[name]; + var targetProperty = + this.__isModelSelectable(item) ? "modelSelection[0]" : "value"; + this.__objectController.removeTarget(item, targetProperty, name); + } + } + // set the model of the object controller if available if (this.__objectController != null) { this.__objectController.setModel(value); Modified: branches/branch_1_0_x/qooxdoo/framework/source/class/qx/test/data/controller/Form.js =================================================================== --- branches/branch_1_0_x/qooxdoo/framework/source/class/qx/test/data/controller/Form.js 2010-03-01 07:42:05 UTC (rev 21661) +++ branches/branch_1_0_x/qooxdoo/framework/source/class/qx/test/data/controller/Form.js 2010-03-01 07:43:44 UTC (rev 21662) @@ -533,7 +533,62 @@ // distroy the objects c.dispose(); + }, + + + testConnectionWithListControllerSelection : function() { + // generate fake data + var data = [{name: "a", age: 1}, {name: "b", age: 2}, {name: "c", age: 3}]; + var model = qx.data.marshal.Json.createModel(data); + + // list + var list = new qx.ui.form.List(); + var listController = new qx.data.controller.List(model, list, "name"); + + // form + var form = new qx.ui.form.Form(); + form.add(new qx.ui.form.TextField(), "Name", null, "name"); + form.add(new qx.ui.form.Spinner(), "Age", null, "age"); + var formController = new qx.data.controller.Form(null, form); + + // connection + listController.bind("selection[0]", formController, "model"); + + // select the first item + var listItems = list.getSelectables(); + list.setSelection([listItems[0]]); + + // check if the model is still the same + this.assertEquals("a", model.getItem(0).getName()); + this.assertEquals("b", model.getItem(1).getName()); + this.assertEquals("c", model.getItem(2).getName()); + this.assertEquals(1, model.getItem(0).getAge()); + this.assertEquals(2, model.getItem(1).getAge()); + this.assertEquals(3, model.getItem(2).getAge()); + + // select the second item + var listItems = list.getSelectables(); + list.setSelection([listItems[1]]); + + // check if the model is still the same + this.assertEquals("a", model.getItem(0).getName()); + this.assertEquals("b", model.getItem(1).getName()); + this.assertEquals("c", model.getItem(2).getName()); + this.assertEquals(1, model.getItem(0).getAge()); + this.assertEquals(2, model.getItem(1).getAge()); + this.assertEquals(3, model.getItem(2).getAge()); + + // select the first item again + var listItems = list.getSelectables(); + list.setSelection([listItems[0]]); + + // check if the model is still the same + this.assertEquals("a", model.getItem(0).getName()); + this.assertEquals("b", model.getItem(1).getName()); + this.assertEquals("c", model.getItem(2).getName()); + this.assertEquals(1, model.getItem(0).getAge()); + this.assertEquals(2, model.getItem(1).getAge()); + this.assertEquals(3, model.getItem(2).getAge()); } - } }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |