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.

201 lines
6.2 KiB

7 years ago
(function () {
7 years ago
var constantInjection = {};
BI.constant = function (xtype, cls) {
if (constantInjection[xtype] != null) {
6 years ago
_global.console && console.error("constant:[" + xtype + "] has been registed");
7 years ago
}
constantInjection[xtype] = cls;
};
var modelInjection = {};
BI.model = function (xtype, cls) {
if (modelInjection[xtype] != null) {
6 years ago
_global.console && console.error("model:[" + xtype + "] has been registed");
7 years ago
}
modelInjection[xtype] = cls;
};
var storeInjection = {};
7 years ago
BI.store = function (xtype, cls) {
7 years ago
if (storeInjection[xtype] != null) {
6 years ago
_global.console && console.error("store:[" + xtype + "] has been registed");
7 years ago
}
storeInjection[xtype] = cls;
};
7 years ago
var serviceInjection = {};
BI.service = function (xtype, cls) {
if (serviceInjection[xtype] != null) {
6 years ago
_global.console && console.error("service:[" + xtype + "] has been registed");
7 years ago
}
serviceInjection[xtype] = cls;
};
7 years ago
var providerInjection = {};
BI.provider = function (xtype, cls) {
if (providerInjection[xtype] != null) {
6 years ago
_global.console && console.error("provider:[" + xtype + "] has been registed");
7 years ago
}
providerInjection[xtype] = cls;
};
BI.config = function (type, configFn) {
if (constantInjection[type]) {
return constantInjection[type] = configFn(constantInjection[type]);
}
if (providerInjection[type]) {
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}
7 years ago
return configFn(providers[type]);
7 years ago
}
7 years ago
BI.Plugin.configWidget(type, configFn);
7 years ago
};
7 years ago
7 years ago
var actions = {};
7 years ago
var globalAction = [];
7 years ago
BI.action = function (type, actionFn) {
7 years ago
if (BI.isFunction(type)) {
7 years ago
globalAction.push(type);
return function () {
BI.remove(globalAction, actionFn);
};
7 years ago
}
7 years ago
if (!actions[type]) {
actions[type] = [];
}
7 years ago
actions[type].push(actionFn);
7 years ago
return function () {
actions[type].remove(actionFn);
if (actions[type].length === 0) {
delete actions[type];
}
7 years ago
};
};
7 years ago
7 years ago
var points = {};
BI.point = function (type, action, pointFn, after) {
if (!points[type]) {
points[type] = {};
7 years ago
}
7 years ago
if (!points[type][action]) {
points[type][action] = {};
}
if (!points[type][action][after ? "after" : "before"]) {
7 years ago
points[type][action][after ? "after" : "before"] = [];
}
points[type][action][after ? "after" : "before"].push(pointFn);
7 years ago
};
7 years ago
7 years ago
BI.Constants = {
getConstant: function (type) {
return constantInjection[type];
}
};
7 years ago
var callPoint = function (inst, type) {
if (points[type]) {
for (var action in points[type]) {
7 years ago
var bfns = points[type][action].before;
if (bfns) {
7 years ago
BI.aspect.before(inst, action, function (bfns) {
return function () {
for (var i = 0, len = bfns.length; i < len; i++) {
try {
bfns[i].apply(inst, arguments);
} catch (e) {
6 years ago
_global.console && console.error(e);
7 years ago
}
7 years ago
}
7 years ago
};
}(bfns));
7 years ago
}
7 years ago
var afns = points[type][action].after;
if (afns) {
7 years ago
BI.aspect.after(inst, action, function (afns) {
return function () {
for (var i = 0, len = afns.length; i < len; i++) {
try {
afns[i].apply(inst, arguments);
} catch (e) {
6 years ago
_global.console && console.error(e);
7 years ago
}
7 years ago
}
7 years ago
};
7 years ago
}(afns));
7 years ago
}
}
}
};
7 years ago
7 years ago
BI.Models = {
getModel: function (type, config) {
7 years ago
var inst = new modelInjection[type](config);
callPoint(inst, type);
return inst;
7 years ago
}
7 years ago
};
7 years ago
var stores = {};
BI.Stores = {
getStore: function (type, config) {
if (stores[type]) {
return stores[type];
}
7 years ago
stores[type] = new storeInjection[type](config);
callPoint(stores[type], type);
return stores[type];
7 years ago
}
7 years ago
};
7 years ago
7 years ago
var services = {};
BI.Services = {
getService: function (type, config) {
if (services[type]) {
return services[type];
}
7 years ago
services[type] = new serviceInjection[type](config);
callPoint(services[type], type);
return services[type];
7 years ago
}
7 years ago
};
7 years ago
7 years ago
var providers = {}, providerInstance = {};
7 years ago
BI.Providers = {
getProvider: function (type, config) {
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}
if (!providerInstance[type]) {
providerInstance[type] = new providers[type].$get()(config);
}
return providerInstance[type];
}
7 years ago
};
7 years ago
BI.Actions = {
runAction: function (type, event, config) {
7 years ago
BI.each(actions[type], function (i, act) {
7 years ago
try {
act(event, config);
7 years ago
} catch (e) {
6 years ago
_global.console && console.error(e);
7 years ago
}
7 years ago
});
7 years ago
},
runGlobalAction: function () {
7 years ago
var args = [].slice.call(arguments);
BI.each(globalAction, function (i, act) {
7 years ago
try {
act.apply(null, args);
} catch (e) {
6 years ago
_global.console && console.error(e);
7 years ago
}
7 years ago
});
7 years ago
}
7 years ago
};
7 years ago
})();