]> err.no Git - sope/commitdiff
added save/rollback changes
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Sat, 6 Aug 2005 17:58:31 +0000 (17:58 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Sat, 6 Aug 2005 17:58:31 +0000 (17:58 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@981 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements
sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout
sope-appserver/samples/CoreDataBlog/ChangeLog
sope-appserver/samples/CoreDataBlog/Main.m
sope-appserver/samples/CoreDataBlog/Main.wo/Main.html
sope-appserver/samples/CoreDataBlog/Main.wo/Main.wod

index 7b9099d496bac5fa510902e68191d206efd7218d..2c2d407964b7126c3157935ae46f23dab9119c58 100644 (file)
Binary files a/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements and b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements differ
index 3a70bb84258ea1fdb0944ca61c70da4d3756b086..b2d621243556e747f6e5f6285c370ca907f343f4 100644 (file)
Binary files a/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout and b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout differ
index 2a7d436c9b5e6970baf58e9f3914d4b9cc74303f..c6b44c77dc22ba587ae1a418bed4e0116813d56e 100644 (file)
@@ -1,3 +1,7 @@
+2005-08-06  Helge Hess  <helge.hess@opengroupware.org>
+
+       * added ability to save/rollback changes in managed object context
+
 2005-08-05  Helge Hess  <helge.hess@opengroupware.org>
 
        * changed to use WODisplayGroup and .woo to access database
index 3e3026c33adfd987f5e72f86907cf538e872f514..6e741ddafe74964c21cba479e41878fb5a504d84 100644 (file)
@@ -29,6 +29,7 @@
 
 @end
 
+#include "WOSession+CoreData.h"
 #include "common.h"
 
 @implementation Main
   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 */
index 37f198fd2d61910579479eb4a67c136e2e201737..e380c7fd654f636f88d54aedb23477904bddd2a6 100644 (file)
@@ -5,6 +5,7 @@
   </head>
 
   <body>
+   <#PostForm>
     <table border="0" width="100%">
       <tr>
         <td valign="top" width="30%">
@@ -26,7 +27,6 @@
         <td valign="top">
           <fieldset style="height: 400px;">
             <legend>Post: <#SelectedPostTitle/></legend>
-            <#PostForm>
               <table border="0" width="100%" cellspacing="4">
                 <tr>
                   <td width="25%" valign="top">Title</td>
                     <#BodyEditField/>
                   </td>
                 </tr>
+                <tr>
+                  <td valign="top" colspan="2">
+                    <#Submit/>
+                  </td>
+                </tr>
               </table>
-            </#PostForm>
           </fieldset>
         </td>
       </tr>
     </table>
 
+    <#HasChanges>
+      <hr />
+      <#SaveChanges/>
+      <#Rollback/>
+      
+      <i>
+        (<#InsertedCount/> inserted,
+         <#UpdatedCount/> updated,
+         <#DeletedCount/> deleted)
+      </i>
+    </#HasChanges>
+   </#PostForm>
+
 
     <hr />
     <small>
@@ -69,6 +86,8 @@
       <#Entities>
         <#Entity/><br />
       </#Entities>
+      <br />
+      Attr: <#Attr/>
     </small>
 
     <hr/>
index 41aafcba93468af517e7d98187ab07c61e747c66..bbcdd7b94cd15cae1fabcb7159df9a2c9c7cc214 100644 (file)
@@ -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";
+}