From 758b6d16bd4ad55ac4618db806d26e74f824286c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E8=BF=9B?= Date: Fri, 10 Jul 2020 06:12:42 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20widgets-form-formula=5Fmin?= =?UTF-8?q?i-schema-model.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets-form-formula_mini-schema-model.js | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/lib/assets/javascripts/builder/editor/widgets/widgets-form/schema/widgets-form-formula_mini-schema-model.js b/lib/assets/javascripts/builder/editor/widgets/widgets-form/schema/widgets-form-formula_mini-schema-model.js index e69de29..8a19faa 100644 --- a/lib/assets/javascripts/builder/editor/widgets/widgets-form/schema/widgets-form-formula_mini-schema-model.js +++ b/lib/assets/javascripts/builder/editor/widgets/widgets-form/schema/widgets-form-formula_mini-schema-model.js @@ -0,0 +1,102 @@ +var _ = require('underscore'); +var WidgetsFormBaseSchema = require('./widgets-form-base-schema-model'); +var DialogConstants = require('builder/components/form-components/_constants/_dialogs'); + +module.exports = WidgetsFormBaseSchema.extend({ + + defaults: { + schema: {}, + aggregate: { + attribute: '', + operator: 'count' + } + }, + + initialize: function (attrs, opts) { + if (!opts.columnOptionsFactory) throw new Error('columnOptionsFactory is required'); + this._columnOptionsFactory = opts.columnOptionsFactory; + + this.listenTo(this, 'change:aggregate', this._updateAggregate); + + this._updateAggregate(); + + WidgetsFormBaseSchema.prototype.initialize.apply(this, arguments); + }, + + parse: function (r) { + r.aggregate = { + attribute: r.column, + operator: r.operation + }; + + return r; + }, + + getFields: function () { + return { + data: 'aggregate,prefix,suffix,description', + style: 'sync_on_bbox_change' + }; + }, + + _updateAggregate: function () { + var aggregate = this.get('aggregate'); + this.set({ + column: aggregate.attribute, + operation: aggregate.operator + }); + + this.updateSchema(); + }, + + updateSchema: function () { + var columnOptions = this._columnOptionsFactory.create(this.get('column'), this._isNumberType); + + this.schema = _.extend(this.schema, { + aggregate: { + type: 'Operators', + title: _t('editor.widgets.widgets-form.data.operation'), + options: columnOptions, + dialogMode: DialogConstants.Mode.FLOAT, + editorAttrs: { + showSearch: false + } + }, + suffix: { + type: 'EnablerEditor', + title: '', + label: _t('editor.widgets.widgets-form.data.suffix'), + editor: { + type: 'Text' + } + }, + prefix: { + type: 'EnablerEditor', + title: '', + label: _t('editor.widgets.widgets-form.data.prefix'), + editor: { + type: 'Text' + } + }, + description: { + type: 'EnablerEditor', + title: '', + label: _t('editor.widgets.widgets-form.style.description'), + editor: { + type: 'TextArea' + } + } + }); + }, + + canSave: function () { + var column = this.get('column'); + var operation = this.get('operation'); + + return operation === 'count' || !!column; + }, + + _isNumberType: function (m) { + return m.get('type') === 'number'; + } +});