2022-10-28 16:11:08 +00:00
|
|
|
import { makeT } from 'app/client/lib/localization';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { ViewSectionRec } from "app/client/models/DocModel";
|
|
|
|
import { KoSaveableObservable, setSaveValue } from "app/client/models/modelUtil";
|
2022-08-08 13:32:50 +00:00
|
|
|
import { cssLabel, cssRow } from "app/client/ui/RightPanelStyles";
|
2020-10-02 15:10:00 +00:00
|
|
|
import { squareCheckbox } from "app/client/ui2018/checkbox";
|
|
|
|
import { testId } from "app/client/ui2018/cssVars";
|
|
|
|
import { Computed, Disposable, dom, IDisposableOwner, styled } from "grainjs";
|
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('GridOptions');
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Builds the grid options.
|
|
|
|
*/
|
|
|
|
export class GridOptions extends Disposable {
|
|
|
|
|
|
|
|
constructor(private _section: ViewSectionRec) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom() {
|
|
|
|
const section = this._section;
|
|
|
|
return [
|
2022-10-28 16:11:08 +00:00
|
|
|
cssLabel(t('GridOptions')),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom('div', [
|
|
|
|
cssRow(
|
|
|
|
checkbox(setSaveValueFromKo(this, section.optionsObj.prop('verticalGridlines'))),
|
2022-10-28 16:11:08 +00:00
|
|
|
t('VerticalGridlines'),
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('v-grid-button')
|
|
|
|
),
|
|
|
|
|
|
|
|
cssRow(
|
|
|
|
checkbox(setSaveValueFromKo(this, section.optionsObj.prop('horizontalGridlines'))),
|
2022-10-28 16:11:08 +00:00
|
|
|
t('HorizontalGridlines'),
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('h-grid-button')
|
|
|
|
),
|
|
|
|
|
|
|
|
cssRow(
|
|
|
|
checkbox(setSaveValueFromKo(this, section.optionsObj.prop('zebraStripes'))),
|
2022-10-28 16:11:08 +00:00
|
|
|
t('ZebraStripes'),
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('zebra-stripe-button')
|
|
|
|
),
|
|
|
|
|
|
|
|
testId('grid-options')
|
|
|
|
]),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a grainjs observable that reflects the value of obs a knockout saveable observable. The
|
|
|
|
// returned observable will set and save obs to the given value when written. If the obs.save() call
|
|
|
|
// fails, then it gets reset to its previous value.
|
|
|
|
function setSaveValueFromKo<T>(owner: IDisposableOwner, obs: KoSaveableObservable<T>) {
|
|
|
|
const ret = Computed.create(null, (use) => use(obs));
|
|
|
|
ret.onWrite(async (val) => {
|
|
|
|
await setSaveValue(obs, val);
|
|
|
|
});
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
const checkbox = styled(squareCheckbox, `
|
|
|
|
margin-right: 8px;
|
|
|
|
`);
|