fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
8.8 KiB

import { Editor, TextButton } from "@/base";
import {
AbsoluteLayout,
VerticalLayout,
shortcut,
Widget,
extend,
emptyFn,
i18nText,
Controller,
createWidget,
nextTick,
isNotNull,
isKey,
isFunction,
isArray,
isNumber,
isEmpty
} from "@/core";
8 years ago
/**
* 无限制-已选择状态输入框
* Created by GUY on 2016/5/18.
* @class SimpleStateEditor
* @extends Single
8 years ago
*/
@shortcut()
export class SimpleStateEditor extends Widget {
static xtype = "bi.simple_state_editor";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_CLICK = "EVENT_CLICK";
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
static EVENT_CLICK_LABEL = "EVENT_CLICK_LABEL";
static EVENT_START = "EVENT_START";
static EVENT_PAUSE = "EVENT_PAUSE";
static EVENT_STOP = "EVENT_STOP";
static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM";
static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR";
static EVENT_ENTER = "EVENT_ENTER";
static EVENT_RESTRICT = "EVENT_RESTRICT";
static EVENT_SPACE = "EVENT_SPACE";
static EVENT_EMPTY = "EVENT_EMPTY";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls: `${conf.baseCls || ""} bi-simple-state-editor`,
8 years ago
hgap: 4,
vgap: 2,
lgap: 0,
rgap: 0,
tgap: 0,
bgap: 0,
validationChecker: emptyFn,
quitChecker: emptyFn,
8 years ago
mouseOut: false,
allowBlank: true,
watermark: "",
errorText: "",
height: 24,
text: "",
defaultText: i18nText("BI-Basic_Unrestricted"),
7 years ago
});
}
8 years ago
_init() {
super._init(...arguments);
const o = this.options;
this.editor = createWidget({
type: Editor.xtype,
simple: o.simple,
8 years ago
height: o.height,
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
value: o.value,
validationChecker: o.validationChecker,
quitChecker: o.quitChecker,
allowBlank: o.allowBlank,
watermark: o.watermark,
errorText: o.errorText,
autoTrim: o.autoTrim,
8 years ago
});
this.text = createWidget({
type: TextButton.xtype,
cls: "bi-water-mark",
8 years ago
textAlign: "left",
text: o.text,
8 years ago
height: o.height,
hgap: o.hgap + 2,
handler: () => {
this._showInput();
this.editor.focus();
this.editor.setValue("");
},
8 years ago
});
this.text.on(TextButton.EVENT_CHANGE, () => {
nextTick(() => {
this.fireEvent(SimpleStateEditor.EVENT_CLICK_LABEL);
8 years ago
});
});
createWidget({
type: AbsoluteLayout.xtype,
8 years ago
element: this,
items: [
{
el: this.text,
left: 0,
right: 0,
top: 0,
bottom: 0,
}
],
8 years ago
});
this.editor.on(Controller.EVENT_CHANGE, (...args) => {
this.fireEvent(Controller.EVENT_CHANGE, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_FOCUS, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_FOCUS, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_BLUR, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_BLUR, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_CLICK, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_CLICK, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_CHANGE, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_CHANGE, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_KEY_DOWN, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_KEY_DOWN, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_VALID, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_VALID, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_CONFIRM, (...args) => {
this._showHint();
this.fireEvent(SimpleStateEditor.EVENT_CONFIRM, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_CHANGE_CONFIRM, (...args) => {
this._showHint();
this.fireEvent(SimpleStateEditor.EVENT_CHANGE_CONFIRM, ...args);
});
this.editor.on(Editor.EVENT_START, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_START, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_PAUSE, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_PAUSE, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_STOP, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_STOP, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_SPACE, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_SPACE, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_ERROR, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_ERROR, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_ENTER, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_ENTER, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_RESTRICT, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_RESTRICT, ...args);
8 years ago
});
this.editor.on(Editor.EVENT_EMPTY, (...args) => {
this.fireEvent(SimpleStateEditor.EVENT_EMPTY, ...args);
8 years ago
});
createWidget({
type: VerticalLayout.xtype,
8 years ago
scrolly: false,
8 years ago
element: this,
items: [this.editor],
8 years ago
});
this._showHint();
if (isNotNull(o.text)) {
this.setState(o.text);
}
}
8 years ago
setWaterMark(v) {
this.options.watermark = v;
this.editor.setWaterMark(v);
}
doRedMark() {
if (this.editor.getValue() === "" && isKey(this.options.watermark)) {
8 years ago
return;
}
this.text.doRedMark(...arguments);
}
8 years ago
unRedMark() {
this.text.unRedMark(...arguments);
}
8 years ago
doHighLight() {
if (this.editor.getValue() === "" && isKey(this.options.watermark)) {
8 years ago
return;
}
this.text.doHighLight(...arguments);
}
8 years ago
unHighLight() {
this.text.unHighLight(...arguments);
}
8 years ago
focus() {
8 years ago
this._showInput();
this.editor.focus();
}
8 years ago
blur() {
8 years ago
this.editor.blur();
this._showHint();
}
8 years ago
_showInput() {
8 years ago
this.editor.visible();
this.text.invisible();
}
8 years ago
_showHint() {
8 years ago
this.editor.invisible();
this.text.visible();
}
8 years ago
_setText(v) {
this.text.setText(v);
this.text.setTitle(v);
}
isValid() {
8 years ago
return this.editor.isValid();
}
8 years ago
setErrorText(text) {
8 years ago
this.editor.setErrorText(text);
}
8 years ago
getErrorText() {
8 years ago
return this.editor.getErrorText();
}
8 years ago
isEditing() {
8 years ago
return this.editor.isEditing();
}
8 years ago
getLastValidValue() {
8 years ago
return this.editor.getLastValidValue();
}
8 years ago
getLastChangedValue() {
return this.editor.getLastChangedValue();
}
setValue(k) {
8 years ago
this.editor.setValue(k);
}
8 years ago
getValue() {
8 years ago
return this.editor.getValue();
}
8 years ago
getState() {
8 years ago
return this.editor.getValue().match(/[^\s]+/g);
}
8 years ago
setState(v) {
const o = this.options;
super.setValue(...arguments);
const defaultText = isFunction(o.defaultText) ? o.defaultText() : o.defaultText;
if (isNumber(v)) {
if (v === Selection.All) {
this._setText(i18nText("BI-Already_Selected"));
this.text.element.removeClass("bi-water-mark");
} else if (v === Selection.Multi) {
this._setText(i18nText("BI-Already_Selected"));
this.text.element.removeClass("bi-water-mark");
8 years ago
} else {
this._setText(isKey(defaultText) ? defaultText : o.text);
this.text.element.addClass("bi-water-mark");
8 years ago
}
8 years ago
return;
}
if (!isArray(v) || v.length === 1) {
this._setText(v);
this.text.element.removeClass("bi-water-mark");
} else if (isEmpty(v)) {
this._setText(o.text);
this.text.element.addClass("bi-water-mark");
8 years ago
} else {
this._setText(i18nText("BI-Already_Selected"));
this.text.element.removeClass("bi-water-mark");
8 years ago
}
}
getText() {
return this.text.getText();
8 years ago
}
}