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.

289 lines
9.7 KiB

7 years ago
(function () {
6 years ago
var moduleInjection = {};
BI.module = BI.module || function (xtype, cls) {
6 years ago
if (moduleInjection[xtype] != null) {
_global.console && console.error("module:[" + xtype + "] has been registed");
}
moduleInjection[xtype] = cls;
};
7 years ago
var constantInjection = {};
BI.constant = BI.constant || function (xtype, cls) {
7 years ago
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 = BI.model || function (xtype, cls) {
7 years ago
if (modelInjection[xtype] != null) {
6 years ago
_global.console && console.error("model:[" + xtype + "] has been registed");
7 years ago
}
modelInjection[xtype] = cls;
};
var storeInjection = {};
BI.store = 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 = BI.service || function (xtype, cls) {
7 years ago
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 = BI.provider || function (xtype, cls) {
7 years ago
if (providerInjection[xtype] != null) {
6 years ago
_global.console && console.error("provider:[" + xtype + "] has been registed");
7 years ago
}
providerInjection[xtype] = cls;
};
var configFunctions = {};
BI.config = BI.config || function (type, configFn, opt) {
if (BI.initialized) {
if (constantInjection[type]) {
return (constantInjection[type] = configFn(constantInjection[type]));
}
if (providerInjection[type]) {
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}
// 如果config被重新配置的话,需要删除掉之前的实例
if (providerInstance[type]) {
delete providerInstance[type];
}
return configFn(providers[type]);
}
return BI.Plugin.configWidget(type, configFn, opt);
}
if (!configFunctions[type]) {
configFunctions[type] = [];
BI.prepares.push(function () {
var queue = configFunctions[type];
for (var i = 0; i < queue.length; i++) {
if (constantInjection[type]) {
constantInjection[type] = queue[i](constantInjection[type]);
continue;
}
if (providerInjection[type]) {
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}
if (providerInstance[type]) {
delete providerInstance[type];
}
queue[i](providers[type]);
continue;
}
BI.Plugin.configWidget(type, queue[i]);
}
configFunctions[type] = null;
});
7 years ago
}
4 years ago
configFunctions[type].push(configFn);
7 years ago
};
7 years ago
4 years ago
BI.getReference = BI.getReference || function (type, fn) {
return BI.Plugin.registerObject(type, fn);
};
7 years ago
var actions = {};
6 years ago
var globalAction = [];
BI.action = BI.action || function (type, actionFn) {
6 years ago
if (BI.isFunction(type)) {
6 years ago
globalAction.push(type);
return function () {
BI.remove(globalAction, function (idx) {
return globalAction.indexOf(actionFn) === idx;
});
6 years ago
};
6 years ago
}
7 years ago
if (!actions[type]) {
actions[type] = [];
}
7 years ago
actions[type].push(actionFn);
7 years ago
return function () {
BI.remove(actions[type], function (idx) {
return actions[type].indexOf(actionFn) === idx;
});
7 years ago
if (actions[type].length === 0) {
delete actions[type];
}
7 years ago
};
};
7 years ago
7 years ago
var points = {};
BI.point = BI.point || function (type, action, pointFn, after) {
7 years ago
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
BI.Modules = BI.Modules || {
6 years ago
getModule: function (type) {
6 years ago
if (!moduleInjection[type]) {
6 years ago
_global.console && console.error("module:[" + type + "] does not exists");
return false;
}
return moduleInjection[type];
6 years ago
},
getAllModules: function () {
return moduleInjection;
6 years ago
}
};
BI.Constants = BI.Constants || {
7 years ago
getConstant: function (type) {
return constantInjection[type];
7 years ago
}
};
var callPoint = function (inst, types) {
types = BI.isArray(types) ? types : [types];
BI.each(types, function (idx, type) {
if (points[type]) {
for (var action in points[type]) {
var bfns = points[type][action].before;
if (bfns) {
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) {
_global.console && console.error(e);
}
7 years ago
}
};
}(bfns));
}
var afns = points[type][action].after;
if (afns) {
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) {
_global.console && console.error(e);
}
7 years ago
}
};
}(afns));
}
7 years ago
}
}
});
7 years ago
};
7 years ago
BI.Models = BI.Models || {
7 years ago
getModel: function (type, config) {
7 years ago
var inst = new modelInjection[type](config);
inst._constructor && inst._constructor(config);
inst.mixins && callPoint(inst, inst.mixins);
7 years ago
callPoint(inst, type);
return inst;
7 years ago
}
7 years ago
};
7 years ago
var stores = {};
BI.Stores = BI.Stores || {
7 years ago
getStore: function (type, config) {
if (stores[type]) {
return stores[type];
}
var inst = stores[type] = new storeInjection[type](config);
4 years ago
inst._constructor && inst._constructor(config, function () {
delete stores[type];
});
callPoint(inst, type);
return inst;
7 years ago
}
7 years ago
};
7 years ago
7 years ago
var services = {};
BI.Services = BI.Services || {
7 years ago
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
var providers = {},
providerInstance = {};
7 years ago
BI.Providers = BI.Providers || {
7 years ago
getProvider: function (type, config) {
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}
if (!providerInstance[type]) {
providerInstance[type] = new (providers[type].$get())(config);
7 years ago
}
return providerInstance[type];
}
7 years ago
};
7 years ago
BI.Actions = BI.Actions || {
runAction: function (type, event, config) {
7 years ago
BI.each(actions[type], function (i, act) {
6 years ago
try {
act(event, config);
6 years ago
} catch (e) {
6 years ago
_global.console && console.error(e);
6 years ago
}
7 years ago
});
6 years ago
},
runGlobalAction: function () {
6 years ago
var args = [].slice.call(arguments);
BI.each(globalAction, function (i, act) {
6 years ago
try {
act.apply(null, args);
} catch (e) {
6 years ago
_global.console && console.error(e);
6 years ago
}
6 years ago
});
7 years ago
}
7 years ago
};
5 years ago
4 years ago
BI.getResource = BI.getResource || function (type, config) {
5 years ago
if (constantInjection[type]) {
return BI.Constants.getConstant(type);
}
if (modelInjection[type]) {
return BI.Models.getModel(type, config);
}
if (storeInjection[type]) {
return BI.Stores.getStore(type, config);
}
if (serviceInjection[type]) {
return BI.Services.getService(type, config);
}
if (providerInjection[type]) {
return BI.Providers.getProvider(type, config);
}
};
})();