diff --git a/ABFactoryCore.js b/ABFactoryCore.js index 8e358eb..cb986e9 100644 --- a/ABFactoryCore.js +++ b/ABFactoryCore.js @@ -8,6 +8,8 @@ // const _ = require("lodash"); // const uuidv4 = require("uuid"); +const ABClassManager = require("../platform/ABClassManager"); + const ABApplication = require("../platform/ABApplication"); const ABApplicationMobile = require("../platform/ABApplicationMobile"); const ABDefinition = require("../platform/ABDefinition"); @@ -97,6 +99,9 @@ class ABFactory extends EventEmitter { this._allDatacollections = []; // {array} of all the ABDataCollection(s) in our site. + this.ClassManager = ABClassManager; + // {ClassManager} the single source for our Class Libraries. + // // Class References // @@ -275,6 +280,10 @@ class ABFactory extends EventEmitter { } init() { + // BEFORE Definitions are loaded, + // make sure any local Plugins are loaded. + this.ClassManager.registerLocalPlugins(this.pluginAPI()); + let allDefinitions = Object.keys(this._definitions).map( (k) => this._definitions[k] ); @@ -679,13 +688,20 @@ class ABFactory extends EventEmitter { objectNew(values) { var newObj = null; - if (values.isExternal == true) + if (values.plugin_key) { + // If this is from a plugin, create it from ClassManager + newObj = this.ClassManager.createObject( + values.plugin_key, + values, + this + ); + } else if (values.isExternal == true) newObj = new ABObjectExternal(values, this); else if (values.isImported == true) newObj = new ABObjectImport(values, this); - else if (values.isNetsuite == true) + else if (values.isNetsuite == true) { newObj = new ABObjectApiNetsuite(values, this); - else if (values.isAPI == true) newObj = new ABObjectApi(values, this); + } else if (values.isAPI == true) newObj = new ABObjectApi(values, this); else newObj = new ABObject(values, this); /* @@ -707,6 +723,14 @@ class ABFactory extends EventEmitter { return this.objectByID("d84cd351-d96c-490f-9afb-2a0b880ca0ec"); } + objectPlugin() { + return this.objectByID("8a20528a-e472-4e80-911a-b14285425caf"); + } + + objectPluginLinks() { + return this.objectByID("7ff322ff-3434-4611-9fd1-4d2996414c1a"); + } + objectProcessDefinition() { return this.objectByID("af91fc75-fb73-4d71-af14-e22832eb5915"); } @@ -743,6 +767,27 @@ class ABFactory extends EventEmitter { return this.objectByID("db5b3b26-5300-4c92-bc73-8ce4f4696992"); } + // + // Plugin + // + pluginAPI() { + let api = this.ClassManager.getPluginAPI(); + api.AB = this; + api.platform = this.platform ?? "service"; + return api; + } + + pluginRegister(plugin) { + let pluginClass = plugin(this.pluginAPI()); + if (Array.isArray(pluginClass)) { + pluginClass.forEach((p) => { + this.ClassManager.pluginRegister(p); + }); + } else { + this.ClassManager.pluginRegister(pluginClass); + } + } + // // Hints // diff --git a/ABViewManagerCore.js b/ABViewManagerCore.js index d8b357f..f2f324b 100644 --- a/ABViewManagerCore.js +++ b/ABViewManagerCore.js @@ -71,6 +71,7 @@ var AllViews = [ require("../platform/views/ABViewFormSelectSingle"), require("../platform/views/ABViewFormTextbox"), require("../platform/views/ABViewFormTree"), + require("../platform/views/ABViewFormURL"), ]; /* @@ -120,8 +121,8 @@ module.exports = class ABViewManagerCore { if (!isPlugin(values.key)) { console.error( "!! View[" + - values.key + - "] not yet defined. Have an ABView instead:" + values.key + + "] not yet defined. Have an ABView instead:" ); } return new Views["view"](values, application, parent); diff --git a/views/ABViewCore.js b/views/ABViewCore.js index 5c4bd86..f6e082c 100644 --- a/views/ABViewCore.js +++ b/views/ABViewCore.js @@ -352,11 +352,11 @@ module.exports = class ABViewCore extends ABMLClass { var form = null; var curr = this; - while (curr.key != "form" && !curr.isRoot() && curr.parent) { + while (!curr.isForm && !curr.isRoot() && curr.parent) { curr = curr.parent; } - if (curr.key == "form") { + if (curr.isForm) { form = curr; } diff --git a/views/ABViewFormCore.js b/views/ABViewFormCore.js index 73afd9d..be6dfd8 100644 --- a/views/ABViewFormCore.js +++ b/views/ABViewFormCore.js @@ -56,6 +56,7 @@ const ABViewFormPropertyComponentDefaults = { module.exports = class ABViewFormCore extends ABViewContainer { constructor(values, application, parent, defaultValues) { super(values, application, parent, defaultValues || ABViewFormDefaults); + this.isForm = true; } static common() {