|
|
|
@ -4,6 +4,8 @@ import RaisedButton from 'material-ui/RaisedButton';
|
|
|
|
|
import IconEdit from 'material-ui/svg-icons/editor/mode-edit';
|
|
|
|
|
import IconChangeHistory from 'material-ui/svg-icons/action/change-history';
|
|
|
|
|
|
|
|
|
|
import { withRouter } from 'react-router';
|
|
|
|
|
|
|
|
|
|
import * as EteSync from '../api/EteSync';
|
|
|
|
|
|
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
@ -90,107 +92,63 @@ const ItemChangeLog = pure((props: any) => {
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
class Pim extends React.PureComponent {
|
|
|
|
|
const CollectionRoutes = withRouter(
|
|
|
|
|
class CollectionRoutesInner extends React.PureComponent {
|
|
|
|
|
props: {
|
|
|
|
|
etesync: CredentialsData;
|
|
|
|
|
syncInfo: SyncInfo;
|
|
|
|
|
history: History;
|
|
|
|
|
syncInfo: SyncInfo,
|
|
|
|
|
routePrefix: string,
|
|
|
|
|
collections: Array<EteSync.CollectionInfo>,
|
|
|
|
|
componentEdit: any,
|
|
|
|
|
componentView: any,
|
|
|
|
|
items: {[key: string]: any},
|
|
|
|
|
onItemSave: (item: Object, journalUid: string, originalContact?: Object) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constructor(props: any) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.onEventSave = this.onEventSave.bind(this);
|
|
|
|
|
this.onContactSave = this.onContactSave.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onEventSave(event: EventType, journalUid: string, originalEvent?: EventType) {
|
|
|
|
|
const syncJournal = this.props.syncInfo.get(journalUid);
|
|
|
|
|
|
|
|
|
|
if (syncJournal === undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const journal = syncJournal.journal;
|
|
|
|
|
|
|
|
|
|
let action = (originalEvent === undefined) ? EteSync.SyncEntryAction.Add : EteSync.SyncEntryAction.Change;
|
|
|
|
|
let saveEvent = store.dispatch(
|
|
|
|
|
createJournalEntry(this.props.etesync, journal, syncJournal.journalEntries, action, event.toIcal()));
|
|
|
|
|
(saveEvent as any).then(() => {
|
|
|
|
|
this.props.history.goBack();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onContactSave(contact: ContactType, journalUid: string, originalContact?: ContactType) {
|
|
|
|
|
const syncJournal = this.props.syncInfo.get(journalUid);
|
|
|
|
|
|
|
|
|
|
if (syncJournal === undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const journal = syncJournal.journal;
|
|
|
|
|
|
|
|
|
|
let action = (originalContact === undefined) ? EteSync.SyncEntryAction.Add : EteSync.SyncEntryAction.Change;
|
|
|
|
|
let saveContact = store.dispatch(
|
|
|
|
|
createJournalEntry(this.props.etesync, journal, syncJournal.journalEntries, action, contact.toIcal()));
|
|
|
|
|
(saveContact as any).then(() => {
|
|
|
|
|
this.props.history.goBack();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { collectionsAddressBook, collectionsCalendar, addressBookItems, calendarItems } = itemsSelector(this.props);
|
|
|
|
|
const props = this.props;
|
|
|
|
|
const ComponentEdit = props.componentEdit;
|
|
|
|
|
const ComponentView = props.componentView;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Switch>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({history}) => (
|
|
|
|
|
<PimMain
|
|
|
|
|
contacts={objValues(addressBookItems)}
|
|
|
|
|
events={objValues(calendarItems)}
|
|
|
|
|
history={history}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim.contacts.new')}
|
|
|
|
|
path={routeResolver.getRoute(props.routePrefix + '.new')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({match}) => (
|
|
|
|
|
<Container style={{maxWidth: 400}}>
|
|
|
|
|
<ContactEdit collections={collectionsAddressBook} onSave={this.onContactSave} />
|
|
|
|
|
<ComponentEdit collections={props.collections} onSave={props.onItemSave} />
|
|
|
|
|
</Container>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim.contacts._id.edit')}
|
|
|
|
|
path={routeResolver.getRoute(props.routePrefix + '._id.edit')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({match}) => (
|
|
|
|
|
<Container style={{maxWidth: 400}}>
|
|
|
|
|
<ContactEdit
|
|
|
|
|
initialCollection={(addressBookItems[match.params.itemUid] as any).journalUid}
|
|
|
|
|
item={addressBookItems[match.params.itemUid]}
|
|
|
|
|
collections={collectionsAddressBook}
|
|
|
|
|
onSave={this.onContactSave}
|
|
|
|
|
<ComponentEdit
|
|
|
|
|
initialCollection={(props.items[match.params.itemUid] as any).journalUid}
|
|
|
|
|
item={props.items[match.params.itemUid]}
|
|
|
|
|
collections={props.collections}
|
|
|
|
|
onSave={props.onItemSave}
|
|
|
|
|
/>
|
|
|
|
|
</Container>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim.contacts._id.log')}
|
|
|
|
|
path={routeResolver.getRoute(props.routePrefix + '._id.log')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({match}) => (
|
|
|
|
|
<Container>
|
|
|
|
|
<ItemChangeLog
|
|
|
|
|
syncInfo={this.props.syncInfo}
|
|
|
|
|
items={addressBookItems}
|
|
|
|
|
syncInfo={props.syncInfo}
|
|
|
|
|
items={props.items}
|
|
|
|
|
uid={match.params.itemUid}
|
|
|
|
|
/>
|
|
|
|
|
</Container>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim.contacts._id')}
|
|
|
|
|
path={routeResolver.getRoute(props.routePrefix + '._id')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({match, history}) => (
|
|
|
|
|
<Container>
|
|
|
|
@ -201,7 +159,7 @@ class Pim extends React.PureComponent {
|
|
|
|
|
icon={<IconChangeHistory />}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
history.push(routeResolver.getRoute(
|
|
|
|
|
'pim.contacts._id.log',
|
|
|
|
|
props.routePrefix + '._id.log',
|
|
|
|
|
{itemUid: match.params.itemUid}))
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
@ -213,82 +171,110 @@ class Pim extends React.PureComponent {
|
|
|
|
|
icon={<IconEdit />}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
history.push(routeResolver.getRoute(
|
|
|
|
|
'pim.contacts._id.edit',
|
|
|
|
|
props.routePrefix + '._id.edit',
|
|
|
|
|
{itemUid: match.params.itemUid}))
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<Contact item={addressBookItems[match.params.itemUid]} />
|
|
|
|
|
</Container>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim.events.new')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({match}) => (
|
|
|
|
|
<Container style={{maxWidth: 400}}>
|
|
|
|
|
<EventEdit collections={collectionsCalendar} onSave={this.onEventSave} />
|
|
|
|
|
<ComponentView item={props.items[match.params.itemUid]} />
|
|
|
|
|
</Container>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Switch>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
class Pim extends React.PureComponent {
|
|
|
|
|
props: {
|
|
|
|
|
etesync: CredentialsData;
|
|
|
|
|
syncInfo: SyncInfo;
|
|
|
|
|
history: History;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constructor(props: any) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.onEventSave = this.onEventSave.bind(this);
|
|
|
|
|
this.onContactSave = this.onContactSave.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onEventSave(event: EventType, journalUid: string, originalEvent?: EventType) {
|
|
|
|
|
const syncJournal = this.props.syncInfo.get(journalUid);
|
|
|
|
|
|
|
|
|
|
if (syncJournal === undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const journal = syncJournal.journal;
|
|
|
|
|
|
|
|
|
|
let action = (originalEvent === undefined) ? EteSync.SyncEntryAction.Add : EteSync.SyncEntryAction.Change;
|
|
|
|
|
let saveEvent = store.dispatch(
|
|
|
|
|
createJournalEntry(this.props.etesync, journal, syncJournal.journalEntries, action, event.toIcal()));
|
|
|
|
|
(saveEvent as any).then(() => {
|
|
|
|
|
this.props.history.goBack();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onContactSave(contact: ContactType, journalUid: string, originalContact?: ContactType) {
|
|
|
|
|
const syncJournal = this.props.syncInfo.get(journalUid);
|
|
|
|
|
|
|
|
|
|
if (syncJournal === undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const journal = syncJournal.journal;
|
|
|
|
|
|
|
|
|
|
let action = (originalContact === undefined) ? EteSync.SyncEntryAction.Add : EteSync.SyncEntryAction.Change;
|
|
|
|
|
let saveContact = store.dispatch(
|
|
|
|
|
createJournalEntry(this.props.etesync, journal, syncJournal.journalEntries, action, contact.toIcal()));
|
|
|
|
|
(saveContact as any).then(() => {
|
|
|
|
|
this.props.history.goBack();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { collectionsAddressBook, collectionsCalendar, addressBookItems, calendarItems } = itemsSelector(this.props);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Switch>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim.events._id.edit')}
|
|
|
|
|
path={routeResolver.getRoute('pim')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({match}) => (
|
|
|
|
|
<Container style={{maxWidth: 400}}>
|
|
|
|
|
<EventEdit
|
|
|
|
|
initialCollection={(calendarItems[match.params.itemUid] as any).journalUid}
|
|
|
|
|
item={calendarItems[match.params.itemUid]}
|
|
|
|
|
collections={collectionsCalendar}
|
|
|
|
|
onSave={this.onEventSave}
|
|
|
|
|
render={({history}) => (
|
|
|
|
|
<PimMain
|
|
|
|
|
contacts={objValues(addressBookItems)}
|
|
|
|
|
events={objValues(calendarItems)}
|
|
|
|
|
history={history}
|
|
|
|
|
/>
|
|
|
|
|
</Container>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim.events._id.log')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({match}) => (
|
|
|
|
|
<Container>
|
|
|
|
|
<ItemChangeLog
|
|
|
|
|
path={routeResolver.getRoute('pim.contacts')}
|
|
|
|
|
render={() => (
|
|
|
|
|
<CollectionRoutes
|
|
|
|
|
syncInfo={this.props.syncInfo}
|
|
|
|
|
items={calendarItems}
|
|
|
|
|
uid={match.params.itemUid}
|
|
|
|
|
routePrefix="pim.contacts"
|
|
|
|
|
collections={collectionsAddressBook}
|
|
|
|
|
items={addressBookItems}
|
|
|
|
|
componentEdit={ContactEdit}
|
|
|
|
|
componentView={Contact}
|
|
|
|
|
onItemSave={this.onContactSave}
|
|
|
|
|
/>
|
|
|
|
|
</Container>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Route
|
|
|
|
|
path={routeResolver.getRoute('pim.events._id')}
|
|
|
|
|
exact={true}
|
|
|
|
|
render={({match, history}) => (
|
|
|
|
|
<Container>
|
|
|
|
|
<div style={{textAlign: 'right', marginBottom: 15}}>
|
|
|
|
|
<RaisedButton
|
|
|
|
|
label="Change History"
|
|
|
|
|
style={{marginLeft: 15}}
|
|
|
|
|
icon={<IconChangeHistory />}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
history.push(routeResolver.getRoute(
|
|
|
|
|
'pim.events._id.log',
|
|
|
|
|
{itemUid: match.params.itemUid}))
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<RaisedButton
|
|
|
|
|
label="Edit"
|
|
|
|
|
secondary={true}
|
|
|
|
|
style={{marginLeft: 15}}
|
|
|
|
|
icon={<IconEdit />}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
history.push(routeResolver.getRoute(
|
|
|
|
|
'pim.events._id.edit',
|
|
|
|
|
{itemUid: match.params.itemUid}))
|
|
|
|
|
}
|
|
|
|
|
path={routeResolver.getRoute('pim.events')}
|
|
|
|
|
render={() => (
|
|
|
|
|
<CollectionRoutes
|
|
|
|
|
syncInfo={this.props.syncInfo}
|
|
|
|
|
routePrefix="pim.events"
|
|
|
|
|
collections={collectionsCalendar}
|
|
|
|
|
items={calendarItems}
|
|
|
|
|
componentEdit={EventEdit}
|
|
|
|
|
componentView={Event}
|
|
|
|
|
onItemSave={this.onEventSave}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<Event item={calendarItems[match.params.itemUid]} />
|
|
|
|
|
</Container>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Switch>
|
|
|
|
|