mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-03 19:44:22 +00:00
People: Add Reject button to Details to revert edits made during edit mode
This commit is contained in:
1 parent
5fdf3ec834
commit
5849ee7f22
4 files changed
+96
-4
No files matched your search
@@ -15,6 +15,10 @@
|
||||
* (the table cells and the detail pane) follows it; the Edit button in the detail pane sets
|
||||
* it. It is not saved: the application starts in view mode.
|
||||
*
|
||||
* When edit mode begins, the library keeps a snapshot of every person. -rejectEdits puts back
|
||||
* the people that changed since then, and ends edit mode. People added or removed during the
|
||||
* edit stay added or removed; removal has its own undo.
|
||||
*
|
||||
* Change notifications:
|
||||
* - structural changes (people added/removed, group membership, folders
|
||||
* added/removed/renamed/reordered/edited) are posted synchronously;
|
||||
@@ -197,6 +201,7 @@ var LibraryDefaultsKey = @"People.Library.v1",
|
||||
BOOL _saveScheduled;
|
||||
|
||||
BOOL _editable;
|
||||
JSObject _editSnapshot;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
@@ -233,7 +238,47 @@ var LibraryDefaultsKey = @"People.Library.v1",
|
||||
|
||||
- (void)setEditable:(BOOL)shouldBeEditable
|
||||
{
|
||||
_editable = !!shouldBeEditable;
|
||||
shouldBeEditable = !!shouldBeEditable;
|
||||
|
||||
if (shouldBeEditable && !_editable)
|
||||
_editSnapshot = [self _snapshotOfPeople];
|
||||
else if (!shouldBeEditable)
|
||||
_editSnapshot = nil;
|
||||
|
||||
_editable = shouldBeEditable;
|
||||
}
|
||||
|
||||
// Maps each person's uid to the JSON of its -dictionaryRepresentation.
|
||||
- (JSObject)_snapshotOfPeople
|
||||
{
|
||||
var snapshot = {};
|
||||
|
||||
for (var i = 0, count = [_people count]; i < count; i++)
|
||||
snapshot[[_people[i] uid]] = [_people[i] dictionaryRepresentation];
|
||||
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
/*
|
||||
Puts back every person that changed since edit mode began, and ends edit mode. The values
|
||||
are set through the setters, so the table, the detail pane and the smart folder counts
|
||||
follow, and the library saves.
|
||||
*/
|
||||
- (void)rejectEdits
|
||||
{
|
||||
if (!_editable || !_editSnapshot)
|
||||
return;
|
||||
|
||||
for (var i = 0, count = [_people count]; i < count; i++)
|
||||
{
|
||||
var person = _people[i],
|
||||
saved = _editSnapshot[[person uid]];
|
||||
|
||||
if (saved && ![[person dictionaryRepresentation] isEqual:saved])
|
||||
[person restoreFromDictionary:saved];
|
||||
}
|
||||
|
||||
[self setEditable:NO];
|
||||
}
|
||||
|
||||
- (CPArray)people
|
||||
|
||||
@@ -124,6 +124,27 @@ var PersonUIDCounter = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
Sets every saved property from aDictionary, a -dictionaryRepresentation, through the setters,
|
||||
so that observers see each change. Reject Edits uses it to put back the values a person had
|
||||
when edit mode began. The uid is not changed.
|
||||
*/
|
||||
- (void)restoreFromDictionary:(CPDictionary)aDictionary
|
||||
{
|
||||
var saved = [[Person alloc] initWithDictionary:aDictionary];
|
||||
|
||||
[self setFirstName:[saved firstName]];
|
||||
[self setLastName:[saved lastName]];
|
||||
[self setEmail:[saved email]];
|
||||
[self setDepartment:[saved department]];
|
||||
[self setCity:[saved city]];
|
||||
[self setBirthDate:[saved birthDate]];
|
||||
[self setSalary:[saved salary]];
|
||||
[self setIsManager:[saved isManager]];
|
||||
[self setNotes:[saved notes]];
|
||||
[self setTags:[saved tags]];
|
||||
}
|
||||
|
||||
// Property-list safe representation used for CPUserDefaults persistence.
|
||||
- (CPDictionary)dictionaryRepresentation
|
||||
{
|
||||
|
||||
@@ -77,9 +77,11 @@ var RowHeight = 30.0,
|
||||
masks in the style of the Aristo3 button bar icons.
|
||||
pencil: <path d="M11.5 1.5l3 3L5 14H2v-3z"/>
|
||||
check: <path d="M3 8.5l3.5 3.5L13 4.5" stroke-width="2" stroke="black" fill="none"/>
|
||||
cross: <path d="M3.5 3.5l9 9M12.5 3.5l-9 9" stroke="black" stroke-width="2" stroke-linecap="round" fill="none"/>
|
||||
*/
|
||||
var EditMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PHBhdGggZD0iTTExLjUgMS41bDMgM0w1IDE0SDJ2LTN6Ii8+PC9zdmc+')",
|
||||
DoneMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PHBhdGggZD0iTTMgOC41bDMuNSAzLjVMMTMgNC41IiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZT0iYmxhY2siIGZpbGw9Im5vbmUiLz48L3N2Zz4=')";
|
||||
DoneMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PHBhdGggZD0iTTMgOC41bDMuNSAzLjVMMTMgNC41IiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZT0iYmxhY2siIGZpbGw9Im5vbmUiLz48L3N2Zz4=')",
|
||||
RejectMask = "url('data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PHBhdGggZD0iTTMuNSAzLjVsOSA5TTEyLjUgMy41bC05IDkiIHN0cm9rZT0iYmxhY2siIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBmaWxsPSJub25lIi8+PC9zdmc+')";
|
||||
|
||||
/*
|
||||
The width the pane takes at first and after a reset, and the narrowest it can become. The
|
||||
@@ -405,7 +407,18 @@ PersonDetailMinimumWidth = PersonDetailPreferredWidth - FieldWidth + ShortFie
|
||||
[_editButton setTarget:self];
|
||||
[_editButton setAction:@selector(toggleEditing:)];
|
||||
|
||||
[buttonBar setButtons:[_editButton]];
|
||||
/*
|
||||
Reject puts back what changed since edit mode began, and ends edit mode. It is enabled
|
||||
only in edit mode.
|
||||
*/
|
||||
var rejectButton = [buttonBar buttonWithImage:MaskImage(RejectMask, iconSize, [CPColor labelColor])
|
||||
alternateImage:MaskImage(RejectMask, iconSize, [CPColor labelColor])];
|
||||
[rejectButton setTarget:self];
|
||||
[rejectButton setAction:@selector(rejectEdits:)];
|
||||
[rejectButton setToolTip:@"Reject edits"];
|
||||
[self _bindEnabledToEditing:rejectButton];
|
||||
|
||||
[buttonBar setButtons:[_editButton, rejectButton]];
|
||||
|
||||
return buttonBar;
|
||||
}
|
||||
@@ -430,6 +443,17 @@ PersonDetailMinimumWidth = PersonDetailPreferredWidth - FieldWidth + ShortFie
|
||||
[_library setEditable:shouldEdit];
|
||||
}
|
||||
|
||||
/*
|
||||
Ends the editing of any field in the window first, so that a value being typed is not sent
|
||||
to the person after the values are put back. Then the library puts back every person that
|
||||
changed since edit mode began, and ends edit mode.
|
||||
*/
|
||||
- (@action)rejectEdits:(id)aSender
|
||||
{
|
||||
[[[self view] window] makeFirstResponder:nil];
|
||||
[_library rejectEdits];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(CPString)aKeyPath ofObject:(id)anObject change:(CPDictionary)aChange context:(id)aContext
|
||||
{
|
||||
[self _updateEditingAppearance];
|
||||
|
||||
@@ -83,7 +83,9 @@ to build with a web component framework.
|
||||
- When an edit is saved, a modal alert asks for an optional description. Accept is the
|
||||
default button. All controls in the alert take part in tab selection.
|
||||
- The detail button bar has a Reject button that discards the edit. A modal alert asks the
|
||||
user to confirm first. Confirm is the default button.
|
||||
user to confirm first. Confirm is the default button. (In place: Reject, enabled in edit
|
||||
mode, puts back every person changed since edit mode began and ends edit mode, with no
|
||||
alert yet.)
|
||||
- The time is stored in UTC and shown in local time, in conversational form.
|
||||
2. When no single row is selected, a covering view over the detail pane says
|
||||
"Please select a single row to edit or display."
|
||||
|
||||
Reference in new issue
Block a user