+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
@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 */
</head>
<body>
+ <#PostForm>
<table border="0" width="100%">
<tr>
<td valign="top" width="30%">
<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>
<#Entities>
<#Entity/><br />
</#Entities>
+ <br />
+ Attr: <#Attr/>
</small>
<hr/>
value = item.name;
}
+Attr: WOString {
+ value = session.defaultManagedObjectContext.persistentStoreCoordinator.managedObjectModel.entitiesByName.Post.propertiesByName.title;
+}
+
+/* real content */
+
PostCount: WOString {
value = postDisplayGroup.allObjects.@count;
}
value = postDisplayGroup.selectedObject.body;
}
-// posts
+Submit: WOSubmitButton {
+ action = context.page; /* just jump back to page */
+ value = "ok";
+}
+
+/* posts */
AddPost: WOHyperlink {
action = postDisplayGroup.insert;
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";
+}