2020-10-02 15:10:00 +00:00
|
|
|
var dispose = require('../lib/dispose');
|
|
|
|
const ko = require('knockout');
|
2021-03-02 12:27:08 +00:00
|
|
|
const {Computed, fromKo} = require('grainjs');
|
2020-10-02 15:10:00 +00:00
|
|
|
const ValueFormatter = require('app/common/ValueFormatter');
|
|
|
|
|
|
|
|
const {cssLabel, cssRow} = require('app/client/ui/RightPanel');
|
2021-03-02 12:27:08 +00:00
|
|
|
const {colorSelect} = require('app/client/ui2018/ColorSelect');
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* AbstractWidget - The base of the inheritance tree for widgets.
|
|
|
|
* @param {Function} field - The RowModel for this view field.
|
2021-03-02 12:27:08 +00:00
|
|
|
* @param {string|undefined} options.defaultTextColor - A hex value to set the default text color
|
|
|
|
* for the widget. Omit defaults to '#000000'.
|
2020-10-02 15:10:00 +00:00
|
|
|
*/
|
2021-03-02 12:27:08 +00:00
|
|
|
function AbstractWidget(field, opts = {}) {
|
2020-10-02 15:10:00 +00:00
|
|
|
this.field = field;
|
|
|
|
this.options = field.widgetOptionsJson;
|
2021-03-02 12:27:08 +00:00
|
|
|
const {defaultTextColor = '#000000'} = opts;
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
this.valueFormatter = this.autoDispose(ko.computed(() => {
|
|
|
|
return ValueFormatter.createFormatter(field.displayColModel().type(), this.options());
|
|
|
|
}));
|
2021-03-02 12:27:08 +00:00
|
|
|
|
|
|
|
this.textColor = Computed.create(this, (use) => use(this.field.textColor) || defaultTextColor)
|
|
|
|
.onWrite((val) => this.field.textColor(val === defaultTextColor ? undefined : val));
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
dispose.makeDisposable(AbstractWidget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the DOM showing configuration buttons and fields in the sidebar.
|
|
|
|
*/
|
|
|
|
AbstractWidget.prototype.buildConfigDom = function() {
|
|
|
|
throw new Error("Not Implemented");
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the transform prompt config DOM in the few cases where it is necessary.
|
|
|
|
* Child classes need not override this function if they do not require transform config options.
|
|
|
|
*/
|
|
|
|
AbstractWidget.prototype.buildTransformConfigDom = function() {
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the data cell DOM.
|
|
|
|
* @param {DataRowModel} row - The rowModel object.
|
|
|
|
*/
|
|
|
|
AbstractWidget.prototype.buildDom = function(row) {
|
|
|
|
throw new Error("Not Implemented");
|
|
|
|
};
|
|
|
|
|
|
|
|
AbstractWidget.prototype.buildColorConfigDom = function() {
|
|
|
|
return [
|
|
|
|
cssLabel('CELL COLOR'),
|
|
|
|
cssRow(
|
2021-03-02 12:27:08 +00:00
|
|
|
colorSelect(
|
|
|
|
this.textColor,
|
|
|
|
fromKo(this.field.fillColor),
|
|
|
|
// Calling `field.widgetOptionsJson.save()` saves both fill and text color settings.
|
|
|
|
() => this.field.widgetOptionsJson.save()
|
2020-10-02 15:10:00 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = AbstractWidget;
|