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.

222 lines
6.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"
},
HEADER_HEIGHT: 40
},
8 years ago
_defaultConfig: function () {
7 years ago
return BI.extend(BI.Popover.superclass._defaultConfig.apply(this, arguments), {
7 years ago
baseCls: "bi-popover bi-card",
// width: 600,
// height: 500,
size: "normal", // small, normal, big
7 years ago
header: null,
body: null,
footer: null
7 years ago
});
8 years ago
},
7 years ago
render: function () {
8 years ago
var self = this, o = this.options;
7 years ago
this.startX = 0;
this.startY = 0;
this.tracker = new BI.MouseMoveTracker(function (deltaX, deltaY) {
var size = self._calculateSize();
var W = $("body").width(), H = $("body").height();
self.startX += deltaX;
self.startY += deltaY;
self.element.css({
left: BI.clamp(self.startX, 0, W - size.width) + "px",
top: BI.clamp(self.startY, 0, H - size.height) + "px"
});
// BI-12134 没有什么特别好的方法
BI.Resizers._resize();
}, function () {
self.tracker.releaseMouseMoves();
}, window);
7 years ago
var items = {
north: {
el: {
type: "bi.htape",
7 years ago
cls: "bi-message-title bi-header-background",
7 years ago
ref: function (_ref) {
self.dragger = _ref;
},
items: [{
type: "bi.absolute",
items: [{
el: BI.isPlainObject(o.header) ? BI.createWidget(o.header, {
extraCls: "bi-font-bold"
}) : {
type: "bi.label",
cls: "bi-font-bold",
height: this._constant.HEADER_HEIGHT,
text: o.header,
textAlign: "left"
8 years ago
},
left: 20,
top: 0,
right: 0,
bottom: 0
}]
}, {
el: {
type: "bi.icon_button",
cls: "bi-message-close close-font",
height: this._constant.HEADER_HEIGHT,
handler: function () {
self.close();
}
},
width: 56
}]
8 years ago
},
height: this._constant.HEADER_HEIGHT
7 years ago
},
center: {
el: {
type: "bi.absolute",
items: [{
el: BI.createWidget(o.body),
left: 20,
7 years ago
top: 10,
7 years ago
right: 20,
bottom: 0
}]
8 years ago
}
}
7 years ago
};
if (o.footer) {
items.south = {
el: {
type: "bi.absolute",
items: [{
el: BI.createWidget(o.footer),
left: 20,
top: 0,
right: 20,
bottom: 0
}]
},
height: 44
};
8 years ago
}
7 years ago
var size = this._calculateSize();
return {
7 years ago
type: "bi.border",
items: items,
width: size.width,
height: size.height
};
8 years ago
},
7 years ago
mounted: function () {
var self = this;
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 = 220;
break;
case this._constant.SIZE.BIG:
size.width = 900;
size.height = 500;
break;
default:
size.width = 550;
size.height = 500;
}
}
return {
width: o.width || size.width,
height: o.height || size.height
};
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), {
7 years ago
btns: [BI.i18nText(BI.i18nText("BI-Basic_Sure")), BI.i18nText(BI.i18nText("BI-Basic_Cancel"))]
});
},
beforeCreate: function () {
var self = this, o = this.options;
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);
}
}, {
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
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";