From b2e87786af028071f6412e827c72c6f31c781010 Mon Sep 17 00:00:00 2001 From: chuckh Date: Fri, 10 Dec 2010 07:51:59 +0800 Subject: [PATCH 1/8] Fixed RxAutoComplete.as so framework will compile in Flex 4 --- framework/.actionScriptProperties | 1 + framework/.project | 36 +++++++++---------- .../com.adobe.flexbuilder.project.prefs | 3 ++ .../restfulx/components/rx/RxAutoComplete.as | 32 ++++++++++++----- 4 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 framework/.settings/com.adobe.flexbuilder.project.prefs diff --git a/framework/.actionScriptProperties b/framework/.actionScriptProperties index d75926b..1c64242 100644 --- a/framework/.actionScriptProperties +++ b/framework/.actionScriptProperties @@ -12,3 +12,4 @@ + diff --git a/framework/.project b/framework/.project index 4c45fb0..94a82a1 100644 --- a/framework/.project +++ b/framework/.project @@ -1,18 +1,18 @@ - - - restfulx - - - - - - com.adobe.flexbuilder.project.flexbuilder - - - - - - com.adobe.flexbuilder.project.flexlibnature - com.adobe.flexbuilder.project.actionscriptnature - - + + + restflex-flex4 + + + + + + com.adobe.flexbuilder.project.flexbuilder + + + + + + com.adobe.flexbuilder.project.flexlibnature + com.adobe.flexbuilder.project.actionscriptnature + + diff --git a/framework/.settings/com.adobe.flexbuilder.project.prefs b/framework/.settings/com.adobe.flexbuilder.project.prefs new file mode 100644 index 0000000..b1c90c3 --- /dev/null +++ b/framework/.settings/com.adobe.flexbuilder.project.prefs @@ -0,0 +1,3 @@ +#Thu Dec 09 14:01:08 PST 2010 +eclipse.preferences.version=1 +upgradeSDK/fb4=Flex 4.1 Air 2.5 diff --git a/framework/src/org/restfulx/components/rx/RxAutoComplete.as b/framework/src/org/restfulx/components/rx/RxAutoComplete.as index 311fc50..b0b1d76 100644 --- a/framework/src/org/restfulx/components/rx/RxAutoComplete.as +++ b/framework/src/org/restfulx/components/rx/RxAutoComplete.as @@ -21,6 +21,15 @@ * * Redistributions of files must retain the above copyright notice. ******************************************************************************/ + +/**FLEX 4 Changes*************************************************************** + * + * Changed selectionBeginIndex to selectionAnchorPosition + * + * Changed setSelection to selectRange + * + ******************************************************************************/ + package org.restfulx.components.rx { import flash.events.Event; import flash.events.KeyboardEvent; @@ -392,8 +401,9 @@ package org.restfulx.components.rx { showDropdown = true; } else if (dropdown) { if (typedTextChanged) { - cursorPosition = textInput.selectionBeginIndex; - + //cursorPosition = textInput.selectionBeginIndex; + cursorPosition = textInput.selectionAnchorPosition; // Flex 4 + if (ArrayCollection(dataProvider).length) { if (!itemPreselected && !itemShown) { showDropdown = true; @@ -427,18 +437,21 @@ package org.restfulx.components.rx { showDropdown = false; showingDropdown = true; if (dropdownClosed) dropdownClosed = false; - textInput.setSelection(0, textInput.text.length); + //textInput.setSelection(0, textInput.text.length); + textInput.selectRange(0, textInput.text.length); // Flex 4 } else if (dropdown) { if (typedTextChanged) { //This is needed because a call to super.updateDisplayList() iset the text // in the textInput to "" and the value typed by the user gets losts textInput.text = _typedText; - textInput.setSelection(cursorPosition, cursorPosition); + // textInput.setSelection(cursorPosition, cursorPosition); + textInput.selectRange(cursorPosition, cursorPosition); //Flex 4 typedTextChanged = false; } else if (typedText) { //Sets the selection when user navigates the suggestion list through //arrows keys. - textInput.setSelection(0, textInput.text.length); + //textInput.setSelection(0, textInput.text.length); + textInput.selectRange(0, textInput.text.length); //Flex4 } if (clearingText) clearingText = false; @@ -514,11 +527,13 @@ package org.restfulx.components.rx { // field to original text if (event.keyCode == Keyboard.UP && prevIndex == 0) { textInput.text = _typedText; - textInput.setSelection(textInput.text.length, textInput.text.length); + //textInput.setSelection(textInput.text.length, textInput.text.length); + textInput.selectRange(textInput.text.length, textInput.text.length); // Flex 4 selectedIndex = -1; } else if (event.keyCode == Keyboard.ESCAPE && showingDropdown) { textInput.text = _typedText; - textInput.setSelection(textInput.text.length, textInput.text.length); + //textInput.setSelection(textInput.text.length, textInput.text.length); + textInput.selectRange(textInput.text.length, textInput.text.length); //Flex 4 showingDropdown = false; dropdownClosed = true; } else if (event.keyCode == Keyboard.ENTER || event.keyCode == Keyboard.TAB) { @@ -561,7 +576,8 @@ package org.restfulx.components.rx { super.close(event); if (selectedIndex == 0) { textInput.text = selectedLabel; - textInput.setSelection(cursorPosition, textInput.text.length); + //textInput.setSelection(cursorPosition, textInput.text.length); // Flex 4 + textInput.selectRange(cursorPosition, textInput.text.length); } } } From e48111d832f13a0660c4e83062ab2831eff748c1 Mon Sep 17 00:00:00 2001 From: scho Date: Mon, 24 Jan 2011 03:29:50 -0800 Subject: [PATCH 2/8] If a null value is serialized and the corresponding ActionScript Class is Number, the value will be set to NaN and not to 0. --- framework/src/org/restfulx/serializers/GenericSerializer.as | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/org/restfulx/serializers/GenericSerializer.as b/framework/src/org/restfulx/serializers/GenericSerializer.as index b439189..3f59563 100644 --- a/framework/src/org/restfulx/serializers/GenericSerializer.as +++ b/framework/src/org/restfulx/serializers/GenericSerializer.as @@ -221,7 +221,11 @@ package org.restfulx.serializers { } else { if (defaultValue == null) { try { - object[targetName] = ""; + if(object[targetName] is Number){ + object[targetName] = NaN; + }else{ + object[targetName] = ""; + } } catch (e:Error) { object[targetName] = null; } From 3f79bfd0505f6de4a8bd1ea2a6e6fa59825752ea Mon Sep 17 00:00:00 2001 From: scho Date: Mon, 24 Jan 2011 05:08:02 -0800 Subject: [PATCH 3/8] If you catch the CacheUpdateEvent after a destroy, you have access to the destroyed object via event.data --- framework/src/org/restfulx/controllers/CacheController.as | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/org/restfulx/controllers/CacheController.as b/framework/src/org/restfulx/controllers/CacheController.as index 74008aa..657cead 100644 --- a/framework/src/org/restfulx/controllers/CacheController.as +++ b/framework/src/org/restfulx/controllers/CacheController.as @@ -158,7 +158,7 @@ package org.restfulx.controllers { } RxUtils.cleanupModelReferences(model, fqn); ModelsCollection(data[fqn]).removeItem(model); - Rx.models.dispatchEvent(new CacheUpdateEvent(fqn, CacheUpdateEvent.DESTROY, serviceProvider)); + Rx.models.dispatchEvent(new CacheUpdateEvent(fqn, CacheUpdateEvent.DESTROY, serviceProvider, model)); model.dispatchEvent(new AfterDestroyEvent); } } From 83effe44968ed0c995aebc8f9f002fa27e7124a8 Mon Sep 17 00:00:00 2001 From: scho Date: Tue, 25 Jan 2011 05:00:47 -0800 Subject: [PATCH 4/8] --- tests/src/restfulx/test/responses/books.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/src/restfulx/test/responses/books.xml b/tests/src/restfulx/test/responses/books.xml index 5e0afad..e2d8f74 100644 --- a/tests/src/restfulx/test/responses/books.xml +++ b/tests/src/restfulx/test/responses/books.xml @@ -7,6 +7,13 @@ 458237344 2008/12/09 00:02:40 + + 2008/12/09 00:02:40 + 1023124238 + Book5NameString + 458237344 + 2008/12/09 00:02:40 + 2008/12/09 00:02:40 968145068 From 3a324f2414af257d565126e7b2023ff075e3a94c Mon Sep 17 00:00:00 2001 From: scho Date: Tue, 25 Jan 2011 05:03:26 -0800 Subject: [PATCH 5/8] Added several authors to expand test cases for HasManyTrough test --- tests/src/restfulx/test/responses/authors.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/src/restfulx/test/responses/authors.xml b/tests/src/restfulx/test/responses/authors.xml index d2fc11e..d1b3e80 100644 --- a/tests/src/restfulx/test/responses/authors.xml +++ b/tests/src/restfulx/test/responses/authors.xml @@ -28,4 +28,18 @@ Author3NameString 2008/12/09 00:02:40 + + 1023124238 + 2008/12/09 00:02:40 + 790999880 + Author5NameString + 2008/12/09 00:02:40 + + + 1023124238 + 2008/12/09 00:02:40 + 790999881 + Author6NameString + 2008/12/09 00:02:40 + \ No newline at end of file From 6b17cbf754c1fdf7d6cfcedd312a75b5fa1fc2d8 Mon Sep 17 00:00:00 2001 From: scho Date: Tue, 25 Jan 2011 05:06:19 -0800 Subject: [PATCH 6/8] Adjusted tests to the more complex data (one additional book in first store, 2 authors for the first book) --- .../models/HasManyThroughRelationshipsTest.as | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/src/restfulx/test/cases/models/HasManyThroughRelationshipsTest.as b/tests/src/restfulx/test/cases/models/HasManyThroughRelationshipsTest.as index fa638cb..40ffeeb 100644 --- a/tests/src/restfulx/test/cases/models/HasManyThroughRelationshipsTest.as +++ b/tests/src/restfulx/test/cases/models/HasManyThroughRelationshipsTest.as @@ -22,6 +22,8 @@ * Redistributions of files must retain the above copyright notice. ******************************************************************************/ package restfulx.test.cases.models { + import mx.controls.Alert; + import org.restfulx.Rx; import org.restfulx.collections.ModelsCollection; import org.restfulx.events.CacheUpdateEvent; @@ -90,17 +92,17 @@ package restfulx.test.cases.models { var firstStore:Store = stores.withId("458237344") as Store; var firstBook:Book = books.withId("404163108") as Book; var firstAuthor:Author = authors.withId("404163108") as Author; - + assertEquals(4, stores.length); - assertEquals(4, books.length); - assertEquals(4, authors.length); - + assertEquals(5, books.length); + assertEquals(6, authors.length); + assertEquals("Store4NameString", firstStore.name); - assertEquals(1, firstStore.authors.length); - assertEquals(1, firstStore.books.length); + assertEquals(3, firstStore.authors.length); + assertEquals(2, firstStore.books.length); assertEquals("Author4NameString", Author(firstStore.authors.getItemAt(0)).name); assertEquals("Book4NameString", Book(firstStore.books.getItemAt(0)).name); - assertEquals(1, firstStore.randomAuthors.length); + assertEquals(3, firstStore.randomAuthors.length); assertEquals("Author4NameString", Author(firstStore.randomAuthors.getItemAt(0)).name); Rx.models.removeEventListener(CacheUpdateEvent.ID, onCacheUpdateForm2); } From 60b329f7448d9808140d0eeebfbf867504710cff Mon Sep 17 00:00:00 2001 From: scho Date: Tue, 25 Jan 2011 05:07:21 -0800 Subject: [PATCH 7/8] Fixing some imports --- .../test/cases/models/HasManyThroughRelationshipsTest.as | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/src/restfulx/test/cases/models/HasManyThroughRelationshipsTest.as b/tests/src/restfulx/test/cases/models/HasManyThroughRelationshipsTest.as index 40ffeeb..d8b70c6 100644 --- a/tests/src/restfulx/test/cases/models/HasManyThroughRelationshipsTest.as +++ b/tests/src/restfulx/test/cases/models/HasManyThroughRelationshipsTest.as @@ -22,8 +22,6 @@ * Redistributions of files must retain the above copyright notice. ******************************************************************************/ package restfulx.test.cases.models { - import mx.controls.Alert; - import org.restfulx.Rx; import org.restfulx.collections.ModelsCollection; import org.restfulx.events.CacheUpdateEvent; From 5f7c53f6c68847929c4b18b0bf2a8e2809e14c65 Mon Sep 17 00:00:00 2001 From: scho Date: Tue, 25 Jan 2011 05:11:12 -0800 Subject: [PATCH 8/8] Fixing HasManyThrough bug. Form 2 wasn't working correctly. Extended tests showed the wrong behavior, which are fixed with this commit. --- .../restfulx/serializers/GenericSerializer.as | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/framework/src/org/restfulx/serializers/GenericSerializer.as b/framework/src/org/restfulx/serializers/GenericSerializer.as index 3f59563..a0f73fc 100644 --- a/framework/src/org/restfulx/serializers/GenericSerializer.as +++ b/framework/src/org/restfulx/serializers/GenericSerializer.as @@ -210,6 +210,7 @@ package org.restfulx.serializers { } object[targetName] = ref; + processHasManyThroughRelationships(ref,targetType); } else if (isNestedArray) { object[targetName] = processNestedArray(attribute, targetType, disconnected); } else if (isNestedObject && !disconnected) { @@ -337,10 +338,18 @@ package org.restfulx.serializers { // form 2 e.g. object[authors] } else if (object.hasOwnProperty(localSingleName) && object.hasOwnProperty(refNamePlural)) { - if (object[refNamePlural] == null) { - object[refNamePlural] = new ModelsCollection; - } - object[localSingleName][relationship["attribute"]] = object[refNamePlural]; + for each(var item:Object in ModelsCollection(object[refNamePlural])){ + if (checkConditions(item, conditions)) { + if (items.hasItem(item)) { + items.setItem(item); + } else { + items.addItem(item); + } + }else if (items.hasItem(item)) { + items.removeItem(item); + } + } + object[localSingleName][relationship["attribute"]] = items; } } catch (e:Error) { // do something