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.

256 lines
7.6 KiB

8 years ago
/**
7 years ago
* Popover弹出层
* @class BI.Popover
8 years ago
* @extends BI.Widget
*/
7 years ago
BI.Popover = BI.inherit(BI.Widget, {
_constant: {
SIZE: {
SMALL: "small",
NORMAL: "normal",
BIG: "big",
},
MAX_HEIGHT: 600,
BODY_TGAP: 10,
BODY_HGAP: 20,
},
props: {
baseCls: "bi-popover bi-card bi-border-radius",
size: "normal", // small, normal, big
logic: {
dynamic: false,
},
header: null,
5 years ago
headerHeight: 40,
body: null,
footer: null,
5 years ago
footerHeight: 44,
closable: true, // BI-40839 是否显示右上角的关闭按钮
8 years ago
},
7 years ago
render: function () {
var self = this; var o = this.options;
var c = this._constant;
7 years ago
this.startX = 0;
this.startY = 0;
var size = this._calculateSize();
7 years ago
this.tracker = new BI.MouseMoveTracker(function (deltaX, deltaY) {
var W = BI.Widget._renderEngine.createElement("body").width();
var H = BI.Widget._renderEngine.createElement("body").height();
7 years ago
self.startX += deltaX;
self.startY += deltaY;
self.element.css({
left: BI.clamp(self.startX, 0, W - self.element.width()) + "px",
top: BI.clamp(self.startY, 0, H - self.element.height()) + "px",
7 years ago
});
// BI-12134 没有什么特别好的方法
BI.Resizers._resize();
}, function () {
self.tracker.releaseMouseMoves();
7 years ago
}, _global);
var items = [{
el: {
type: "bi.htape",
cls: "bi-message-title bi-header-background",
ref: function (_ref) {
self.dragger = _ref;
8 years ago
},
items: [{
7 years ago
type: "bi.absolute",
items: [{
el: BI.isPlainObject(o.header) ? BI.extend({}, o.header, {
extraCls: "bi-font-bold",
}) : {
type: "bi.label",
cls: "bi-font-bold",
height: o.headerHeight,
text: o.header,
title: o.header,
textAlign: "left",
},
7 years ago
left: 20,
top: 0,
right: 0,
bottom: 0,
}],
}, {
el: o.closable ? {
type: "bi.icon_button",
cls: "bi-message-close close-font",
height: o.headerHeight,
handler: function () {
self.close();
},
} : {
type: "bi.layout",
},
width: 56,
}],
height: o.headerHeight,
},
height: o.headerHeight,
}, o.logic.dynamic ? {
el: {
type: "bi.vertical",
scrolly: true,
cls: "popover-body",
ref: function () {
self.body = this;
},
css: {
"max-height": c.MAX_HEIGHT - o.headerHeight - (o.footer ? o.footerHeight : 0) - c.BODY_TGAP,
"min-height": size.height,
},
items: [{
el: o.body,
}],
},
hgap: c.BODY_HGAP,
tgap: c.BODY_TGAP,
} : {
el: {
type: "bi.absolute",
items: [{
el: o.body,
left: c.BODY_HGAP,
top: c.BODY_TGAP,
right: c.BODY_HGAP,
bottom: 0,
}],
},
}];
7 years ago
if (o.footer) {
items.push({
7 years ago
el: {
type: "bi.absolute",
items: [{
el: o.footer,
7 years ago
left: 20,
top: 0,
right: 20,
bottom: 0,
}],
height: o.footerHeight,
7 years ago
},
height: o.footerHeight,
});
8 years ago
}
7 years ago
return BI.extend({
type: o.logic.dynamic ? "bi.vertical" : "bi.vtape",
items: items,
width: size.width,
}, o.logic.dynamic ? {
type: "bi.vertical",
scrolly: false,
} : {
type: "bi.vtape",
height: size.height,
});
8 years ago
},
7 years ago
mounted: function () {
var self = this; var o = this.options;
7 years ago
this.dragger.element.mousedown(function (e) {
var pos = self.element.offset();
self.startX = pos.left;
self.startY = pos.top;
self.tracker.captureMouseMoves(e);
});
},
_calculateSize: function () {
var o = this.options;
var size = {};
if (BI.isNotNull(o.size)) {
switch (o.size) {
case this._constant.SIZE.SMALL:
size.width = 450;
size.height = 200;
size.type = "small";
break;
case this._constant.SIZE.BIG:
size.width = 900;
size.height = 500;
size.type = "big";
break;
default:
size.width = 550;
size.height = 500;
size.type = "default";
}
}
return {
width: o.width || size.width,
height: o.height || size.height,
type: size.type || "default",
};
8 years ago
},
hide: function () {
7 years ago
8 years ago
},
open: function () {
this.show();
7 years ago
this.fireEvent(BI.Popover.EVENT_OPEN, arguments);
8 years ago
},
close: function () {
this.hide();
7 years ago
this.fireEvent(BI.Popover.EVENT_CLOSE, arguments);
8 years ago
},
setZindex: function (zindex) {
this.element.css({ "z-index": zindex });
8 years ago
},
destroyed: function () {},
8 years ago
});
7 years ago
BI.shortcut("bi.popover", BI.Popover);
8 years ago
7 years ago
BI.BarPopover = BI.inherit(BI.Popover, {
7 years ago
_defaultConfig: function () {
7 years ago
return BI.extend(BI.BarPopover.superclass._defaultConfig.apply(this, arguments), {
btns: [BI.i18nText("BI-Basic_Sure"), BI.i18nText("BI-Basic_Cancel")],
7 years ago
});
},
beforeCreate: function () {
var self = this; var o = this.options;
7 years ago
o.footer || (o.footer = {
type: "bi.right_vertical_adapt",
lgap: 10,
items: [{
type: "bi.button",
text: this.options.btns[1],
value: 1,
level: "ignore",
handler: function (v) {
7 years ago
self.fireEvent(BI.Popover.EVENT_CANCEL, v);
7 years ago
self.close(v);
},
7 years ago
}, {
type: "bi.button",
text: this.options.btns[0],
warningTitle: o.warningTitle,
value: 0,
handler: function (v) {
7 years ago
self.fireEvent(BI.Popover.EVENT_CONFIRM, v);
7 years ago
self.close(v);
},
}],
7 years ago
});
},
7 years ago
});
7 years ago
BI.shortcut("bi.bar_popover", BI.BarPopover);
7 years ago
7 years ago
BI.Popover.EVENT_CLOSE = "EVENT_CLOSE";
BI.Popover.EVENT_OPEN = "EVENT_OPEN";
BI.Popover.EVENT_CANCEL = "EVENT_CANCEL";
BI.Popover.EVENT_CONFIRM = "EVENT_CONFIRM";