Skip to content

Instantly share code, notes, and snippets.

@pulkitsinghal
Created February 3, 2013 14:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pulkitsinghal/4702055 to your computer and use it in GitHub Desktop.
Save pulkitsinghal/4702055 to your computer and use it in GitHub Desktop.
Out-of-box document-level do not delete support for table rows
diff --git a/UI/iOS/CouchUITableSource.h b/UI/iOS/CouchUITableSource.h
index c335c99..3f08d1e 100644
--- a/UI/iOS/CouchUITableSource.h
+++ b/UI/iOS/CouchUITableSource.h
@@ -45,6 +45,13 @@
#pragma mark Editing The Table:
+/**
+ * If non-nil, specifies the property name of the query row's value that will be used
+ * to determine if a doc explicitly forbids its own deletion as a row by UI gestures?
+ * If this is not set then deletionAllowed property is put to use.
+ */
+@property (copy) NSString* doNotDeleteProperty;
+
/** Is the user allowed to delete rows by UI gestures? (Defaults to YES.) */
@property (nonatomic) BOOL deletionAllowed;
diff --git a/UI/iOS/CouchUITableSource.m b/UI/iOS/CouchUITableSource.m
index 7b9546a..10d3e6d 100644
--- a/UI/iOS/CouchUITableSource.m
+++ b/UI/iOS/CouchUITableSource.m
@@ -17,6 +17,7 @@
CouchLiveQuery* _query;
NSMutableArray* _rows;
NSString* _labelProperty;
+ NSString* _doNotDeleteProperty;
BOOL _deletionAllowed;
}
@end
@@ -136,6 +137,7 @@
@synthesize labelProperty=_labelProperty;
+@synthesize doNotDeleteProperty=_doNotDeleteProperty;
- (NSString*) labelForRow: (CouchQueryRow*)row {
@@ -191,7 +193,17 @@
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- return _deletionAllowed;
+ if (_doNotDeleteProperty != nil) { // per document setting
+ CouchQueryRow* row = [self rowAtIndex: indexPath.row];
+ id value = [row.document propertyForKey: _doNotDeleteProperty];
+ if (value != [NSNull null] && value) {
+ return false; // if the document must not not be deleted, return false here
+ } else {
+ return true; // if the document may be deleted, return true here
+ }
+ } else { // global setting
+ return _deletionAllowed;
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment