Improved method of wrapping.
#FA-8, #FA-10
This commit is contained in:
@ -8,52 +8,51 @@
|
||||
<description/>
|
||||
<name>ProcessorUtils</name>
|
||||
<script><![CDATA[var _source;
|
||||
var _appScope;
|
||||
|
||||
var ProcessorUtils = Class.create();
|
||||
ProcessorUtils.prototype = {
|
||||
initialize: function(options) {
|
||||
var { table, scope, name } = options;
|
||||
if(table) this.setSource(options.table, {scope, name});
|
||||
initialize: function(appScope) {
|
||||
if(!appScope)
|
||||
new LogUtils().write("Application scope is not received.", {type: "error", funcName: "initialize"});
|
||||
|
||||
_appScope = appScope;
|
||||
},
|
||||
|
||||
setSource: function(table, options){
|
||||
var { scope, name } = options;
|
||||
wrapScriptInclude: function(scriptPrototype, options = {}){
|
||||
var {
|
||||
table = "sys_script_include",
|
||||
name = scriptPrototype.type,
|
||||
sys_id = false
|
||||
} = options;
|
||||
|
||||
var sourceGr = new GlideRecord(table);
|
||||
sourceGr.addQuery("name", name);
|
||||
sourceGr.addQuery("sys_scope.scope", scope);
|
||||
sourceGr.query();
|
||||
if(sourceGr.next()){
|
||||
_source = sourceGr;
|
||||
}
|
||||
},
|
||||
|
||||
wrapper: function(scopedClass){
|
||||
Object.getOwnPropertyNames(scopedClass).forEach(function(f) {
|
||||
if(Object.getOwnPropertyDescriptor(scopedClass,f).writable){
|
||||
if (typeof scopedClass[f] === 'function') {
|
||||
var old = scopedClass[f];
|
||||
var sourceRecord = this.getSourceRecord(table, { name, sys_id });
|
||||
|
||||
Object.getOwnPropertyNames(scriptPrototype).forEach(function(f) {
|
||||
if(Object.getOwnPropertyDescriptor(scriptPrototype,f).writable){
|
||||
if (typeof scriptPrototype[f] === 'function') {
|
||||
var old = scriptPrototype[f];
|
||||
var funcName = f.toString();
|
||||
if(_source){
|
||||
var sourceTable = _source.getTableName();
|
||||
var sourceID = _source.getValue("sys_id");
|
||||
}
|
||||
scopedClass[f] = function() {
|
||||
scriptPrototype[f] = function() {
|
||||
functionName = Symbol(funcName);
|
||||
var returnValue = false;
|
||||
try{
|
||||
if(old == undefined) throw new Error("Function: " + funcName + " does not exist");
|
||||
returnValue = old.apply(this, arguments);
|
||||
}catch(err){
|
||||
var func = funcName ? "Function: " + funcName : undefined;
|
||||
var message = err.message ? "Message: " +err.message : undefined;
|
||||
var line = err.lineNumber ? "Line: " + err.lineNumber : undefined;
|
||||
|
||||
|
||||
var options = {
|
||||
type: "error",
|
||||
funcName: funcName
|
||||
funcName: funcName,
|
||||
lineNumber: line
|
||||
};
|
||||
new LogUtils().write("message", options);
|
||||
new LogUtils().write(message, options);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
@ -62,6 +61,19 @@ ProcessorUtils.prototype = {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getSourceRecord: function(table, options){
|
||||
var { sys_id, name } = options;
|
||||
|
||||
var sourceGr = new GlideRecord(table);
|
||||
if(name) sourceGr.addQuery("name", name);
|
||||
if(sys_id) sourceGr.addQuery("sys_id", sys_id);
|
||||
sourceGr.addQuery("sys_scope.scope", _appScope);
|
||||
sourceGr.query();
|
||||
if(sourceGr.next()){
|
||||
_source = sourceGr;
|
||||
}
|
||||
},
|
||||
|
||||
type: 'ProcessorUtils'
|
||||
};]]></script>
|
||||
|
||||
Reference in New Issue
Block a user