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.

158 lines
4.3 KiB

8 years ago
/**
* Created by GUY on 2015/6/26.
*/
BI.Navigation = BI.inherit(BI.Widget, {
8 years ago
_defaultConfig: function () {
return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), {
8 years ago
direction: "bottom",//top, bottom, left, right, custom
logic: {
dynamic: false
},
single: false,
8 years ago
defaultShowIndex: false,
tab: false,
8 years ago
cardCreator: function (v) {
8 years ago
return BI.createWidget();
},
afterCardCreated: BI.emptyFn,
afterCardShow: BI.emptyFn
})
},
8 years ago
render: function () {
8 years ago
var self = this, o = this.options;
this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"});
this.cardMap = {};
this.showIndex = 0;
this.layout = BI.createWidget({
type: "bi.card"
});
BI.createWidget(BI.extend({
8 years ago
element: this
8 years ago
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout)
}))));
new BI.ShowListener({
eventObj: this.tab,
cardLayout: this.layout,
8 years ago
cardNameCreator: function (v) {
8 years ago
return self.showIndex + v;
},
8 years ago
cardCreator: function (v) {
8 years ago
var card = o.cardCreator(v);
self.cardMap[v] = card;
return card;
},
afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, this)
8 years ago
});
8 years ago
},
mounted: function () {
var o = this.options;
if (o.defaultShowIndex !== false) {
8 years ago
this.setSelect(o.defaultShowIndex);
}
},
_deleteOtherCards: function (currCardName) {
var self = this, o = this.options;
if (o.single === true) {
BI.each(this.cardMap, function (name, card) {
if (name !== (currCardName + "")) {
self.layout.deleteCardByName(name);
delete self.cardMap[name];
}
});
}
},
8 years ago
afterCardCreated: function (v) {
8 years ago
var self = this;
8 years ago
this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
8 years ago
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
8 years ago
if (type === BI.Events.CLICK) {
8 years ago
self.fireEvent(BI.Navigation.EVENT_CHANGE, obj);
}
});
8 years ago
this.options.afterCardCreated.apply(this, arguments);
},
8 years ago
afterCardShow: function (v) {
8 years ago
this.showIndex = v;
this._deleteOtherCards(v);
8 years ago
this.options.afterCardShow.apply(this, arguments);
},
8 years ago
populate: function () {
8 years ago
var card = this.layout.getShowingCard();
8 years ago
if (card) {
8 years ago
return card.populate.apply(card, arguments);
}
},
8 years ago
_assertCard: function (v) {
8 years ago
if (!this.layout.isCardExisted(v)) {
8 years ago
var card = this.options.cardCreator(v);
this.cardMap[v] = card;
this.layout.addCardByName(v, card);
this.afterCardCreated(v);
}
},
setSelect: function (v) {
this._assertCard();
8 years ago
this.layout.showCardByName(v);
this._deleteOtherCards(v);
if (this.showIndex !== v) {
this.showIndex = v;
BI.nextTick(BI.bind(this.afterCardShow, this, v));
}
8 years ago
},
8 years ago
getSelect: function () {
8 years ago
return this.showIndex;
},
8 years ago
getSelectedCard: function () {
if (BI.isKey(this.showIndex)) {
8 years ago
return this.cardMap[this.showIndex];
}
},
/**
* @override
*/
8 years ago
setValue: function (v) {
8 years ago
var card = this.layout.getShowingCard();
8 years ago
if (card) {
8 years ago
card.setValue(v);
}
},
/**
* @override
*/
8 years ago
getValue: function () {
8 years ago
var card = this.layout.getShowingCard();
8 years ago
if (card) {
8 years ago
return card.getValue();
}
},
8 years ago
empty: function () {
8 years ago
this.layout.deleteAllCard();
this.cardMap = {};
},
8 years ago
destroy: function () {
BI.Navigation.superclass.destroy.apply(this, arguments);
8 years ago
}
});
BI.Navigation.EVENT_CHANGE = "EVENT_CHANGE";
8 years ago
BI.shortcut("bi.navigation", BI.Navigation);