2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* This module export a component for editing some document settings consisting of the timezone,
|
|
|
|
* (new settings to be added here ...).
|
|
|
|
*/
|
2021-07-22 22:17:55 +00:00
|
|
|
import { dom, styled } from 'grainjs';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { Computed, Observable } from 'grainjs';
|
|
|
|
|
2021-07-22 22:17:55 +00:00
|
|
|
import { loadMomentTimezone } from 'app/client/lib/imports';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { DocInfoRec } from 'app/client/models/DocModel';
|
|
|
|
import { DocPageModel } from 'app/client/models/DocPageModel';
|
2021-07-22 22:17:55 +00:00
|
|
|
import { vars } from 'app/client/ui2018/cssVars';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { saveModal } from 'app/client/ui2018/modals';
|
2021-07-22 22:17:55 +00:00
|
|
|
import { buildTZAutocomplete } from 'app/client/widgets/TZAutocomplete';
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a simple saveModal for saving settings.
|
|
|
|
*/
|
|
|
|
export async function showDocSettingsModal(docInfo: DocInfoRec, docPageModel: DocPageModel): Promise<void> {
|
|
|
|
const moment = await loadMomentTimezone();
|
|
|
|
return saveModal((ctl, owner) => {
|
|
|
|
const timezone = Observable.create(owner, docInfo.timezone.peek());
|
|
|
|
return {
|
|
|
|
title: 'Document Settings',
|
|
|
|
body: [
|
|
|
|
cssDataRow("This document's ID (for API use):"),
|
|
|
|
cssDataRow(dom('tt', docPageModel.currentDocId.get())),
|
|
|
|
cssDataRow('Time Zone:'),
|
2021-07-22 22:17:55 +00:00
|
|
|
cssDataRow(dom.create(buildTZAutocomplete, moment, timezone, (val) => timezone.set(val))),
|
2020-10-02 15:10:00 +00:00
|
|
|
],
|
|
|
|
// At this point, we only need to worry about saving this one setting.
|
|
|
|
saveFunc: () => docInfo.timezone.saveOnly(timezone.get()),
|
|
|
|
// If timezone hasn't changed, there is nothing to save, so disable the Save button.
|
|
|
|
saveDisabled: Computed.create(owner, (use) => use(timezone) === docInfo.timezone.peek()),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// This matches the style used in showProfileModal in app/client/ui/AccountWidget.
|
|
|
|
const cssDataRow = styled('div', `
|
|
|
|
margin: 16px 0px;
|
|
|
|
font-size: ${vars.largeFontSize};
|
|
|
|
`);
|