From: helge Date: Sat, 6 Aug 2005 17:58:31 +0000 (+0000) Subject: added save/rollback changes X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94495ef6a74c6ccf0b8a5244aba8177b36ddc99e;p=sope added save/rollback changes git-svn-id: http://svn.opengroupware.org/SOPE/trunk@981 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements index 7b9099d4..2c2d4079 100644 Binary files a/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements and b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements differ diff --git a/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout index 3a70bb84..b2d62124 100644 Binary files a/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout and b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout differ diff --git a/sope-appserver/samples/CoreDataBlog/ChangeLog b/sope-appserver/samples/CoreDataBlog/ChangeLog index 2a7d436c..c6b44c77 100644 --- a/sope-appserver/samples/CoreDataBlog/ChangeLog +++ b/sope-appserver/samples/CoreDataBlog/ChangeLog @@ -1,3 +1,7 @@ +2005-08-06 Helge Hess + + * added ability to save/rollback changes in managed object context + 2005-08-05 Helge Hess * changed to use WODisplayGroup and .woo to access database diff --git a/sope-appserver/samples/CoreDataBlog/Main.m b/sope-appserver/samples/CoreDataBlog/Main.m index 3e3026c3..6e741dda 100644 --- a/sope-appserver/samples/CoreDataBlog/Main.m +++ b/sope-appserver/samples/CoreDataBlog/Main.m @@ -29,6 +29,7 @@ @end +#include "WOSession+CoreData.h" #include "common.h" @implementation Main @@ -58,4 +59,19 @@ return nil; } +- (id)saveChanges { + NSError *error; + + if (![[[self session] defaultManagedObjectContext] save:&error]) { + // TODO: improve error handling + [self errorWithFormat:@"Failed to save: %@", error]; + } + return nil /* stay on page */; +} + +- (id)rollback { + [[[self session] defaultManagedObjectContext] rollback]; + return nil /* stay on page */; +} + @end /* Main */ diff --git a/sope-appserver/samples/CoreDataBlog/Main.wo/Main.html b/sope-appserver/samples/CoreDataBlog/Main.wo/Main.html index 37f198fd..e380c7fd 100644 --- a/sope-appserver/samples/CoreDataBlog/Main.wo/Main.html +++ b/sope-appserver/samples/CoreDataBlog/Main.wo/Main.html @@ -5,6 +5,7 @@ + <#PostForm>
@@ -26,7 +27,6 @@
Post: <#SelectedPostTitle/> - <#PostForm> @@ -55,13 +55,30 @@ <#BodyEditField/> + + +
Title
+ <#Submit/> +
-
+ <#HasChanges> +
+ <#SaveChanges/> + <#Rollback/> + + + (<#InsertedCount/> inserted, + <#UpdatedCount/> updated, + <#DeletedCount/> deleted) + + + +
@@ -69,6 +86,8 @@ <#Entities> <#Entity/>
+
+ Attr: <#Attr/>

diff --git a/sope-appserver/samples/CoreDataBlog/Main.wo/Main.wod b/sope-appserver/samples/CoreDataBlog/Main.wo/Main.wod index 41aafcba..bbcdd7b9 100644 --- a/sope-appserver/samples/CoreDataBlog/Main.wo/Main.wod +++ b/sope-appserver/samples/CoreDataBlog/Main.wo/Main.wod @@ -13,6 +13,12 @@ Entity: WOString { value = item.name; } +Attr: WOString { + value = session.defaultManagedObjectContext.persistentStoreCoordinator.managedObjectModel.entitiesByName.Post.propertiesByName.title; +} + +/* real content */ + PostCount: WOString { value = postDisplayGroup.allObjects.@count; } @@ -76,7 +82,12 @@ BodyEditField: WOText { value = postDisplayGroup.selectedObject.body; } -// posts +Submit: WOSubmitButton { + action = context.page; /* just jump back to page */ + value = "ok"; +} + +/* posts */ AddPost: WOHyperlink { action = postDisplayGroup.insert; @@ -87,3 +98,28 @@ DeletePost: WOHyperlink { RefetchPosts: WOHyperlink { action = postDisplayGroup.fetch; } + +/* saving */ + +HasChanges: WOConditional { + condition = session.defaultManagedObjectContext.hasChanges; +} + +InsertedCount: WOString { + value = session.defaultManagedObjectContext.insertedObjects.@count; +} +UpdatedCount: WOString { + value = session.defaultManagedObjectContext.updatedObjects.@count; +} +DeletedCount: WOString { + value = session.defaultManagedObjectContext.deletedObjects.@count; +} + +SaveChanges: WOSubmitButton { + action = saveChanges; + value = "save"; +} +Rollback: WOSubmitButton { + action = rollback; + value = "rollback"; +}