Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AppBuilder/ABFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ABValidator {
constructor(AB) {
this.AB = AB;
this.errors = [];
this.platform = "web";
}

addError(name, message) {
Expand Down
2 changes: 1 addition & 1 deletion AppBuilder/core
Submodule core updated from 4f8fa7 to d93e5d
18 changes: 18 additions & 0 deletions AppBuilder/platform/ABApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,24 @@ module.exports = class ABClassApplication extends ABApplicationCore {
return super.save();
}

viewAll(fn = () => true) {
let vmViews = super.viewAll(fn);
let pluginViews = this.AB.ClassManager.viewAll(fn);
let allViews = [...vmViews, ...pluginViews];
let L = this.AB.Label();

// Sort by label from common() if available, otherwise by key
return allViews.sort((a, b) => {
const aCommon = a.common ? a.common() : {};
const bCommon = b.common ? b.common() : {};
const aLabel =
aCommon.label || L(aCommon.labelKey || aCommon.key) || "";
const bLabel =
bCommon.label || L(bCommon.labelKey || bCommon.key) || "";
return aLabel.localeCompare(bLabel);
});
}

warningsEval() {
super.warningsEval();

Expand Down
161 changes: 161 additions & 0 deletions AppBuilder/platform/ABClassManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import ABUIPlugin from "./plugins/ABUIPlugin.js";
import ABPropertiesObjectPlugin from "./plugins/ABPropertiesObjectPlugin";
import ABObjectPlugin from "./plugins/ABObjectPlugin.js";
import ABModelPlugin from "./plugins/ABModelPlugin.js";
import ABViewPlugin from "./plugins/ABViewPlugin.js";
import ABViewComponentPlugin from "./plugins/ABViewComponentPlugin.js";
import ABViewPropertiesPlugin from "./plugins/ABViewPropertiesPlugin.js";
import ABViewEditorPlugin from "./plugins/ABViewEditorPlugin.js";

const classRegistry = {
ObjectTypes: new Map(),
ObjectPropertiesTypes: new Map(),
FieldTypes: new Map(),
ViewTypes: new Map(),
ViewPropertiesTypes: new Map(),
ViewEditorTypes: new Map(),
};

function registerViewPropertiesTypes(name, ctor) {
classRegistry.ViewPropertiesTypes.set(name, ctor);
}

function registerViewEditorTypes(name, ctor) {
classRegistry.ViewEditorTypes.set(name, ctor);
}

function registerObjectPropertiesTypes(name, ctor) {
classRegistry.ObjectPropertiesTypes.set(name, ctor);
}

function registerObjectTypes(name, ctor) {
classRegistry.ObjectTypes.set(name, ctor);
}

function registerViewTypes(name, ctor) {
classRegistry.ViewTypes.set(name, ctor);
}

/**
* @method getPluginAPI()
* This is the data structure we provide to each of our plugins so they
* can register their custom classes.
* We provide base objects from which they can extend.
* @returns {Object}
*/
export function getPluginAPI() {
return {
ABUIPlugin,
ABPropertiesObjectPlugin,
ABObjectPlugin,
ABModelPlugin,
ABViewPlugin,
ABViewComponentPlugin,
ABViewPropertiesPlugin,
ABViewEditorPlugin,
// ABFieldPlugin,
// ABViewPlugin,
};
}

// export function createField(type, config) {
// const FieldClass = classRegistry.FieldTypes.get(type);
// if (!FieldClass) throw new Error(`Unknown object type: ${type}`);
// return new FieldClass(config);
// }
export function createObject(key, config, AB) {
const ObjectClass = classRegistry.ObjectTypes.get(key);
if (!ObjectClass) throw new Error(`Unknown object type: ${key}`);
return new ObjectClass(config, AB);
}

export function createPropertiesObject(key, config, AB) {
const ObjectClass = classRegistry.ObjectPropertiesTypes.get(key);
if (!ObjectClass) throw new Error(`Unknown object type: ${key}`);
return new ObjectClass(config, AB);
}

export function allObjectProperties() {
return Array.from(classRegistry.ObjectPropertiesTypes.values());
}

// export function createObjectProperty(key, config) {
// const ObjectClass = classRegistry.ObjectPropertiesTypes.get(key);
// if (!ObjectClass) throw new Error(`Unknown object type: ${key}`);
// return new ObjectClass(config);
// }

export function viewCreate(type, config, application, parent) {
const ViewClass = classRegistry.ViewTypes.get(type);
if (!ViewClass) throw new Error(`Unknown View type: ${type}`);
return new ViewClass(config, application, parent);
}

export function viewAll(fn = () => true) {
return Array.from(classRegistry.ViewTypes.values()).filter(fn);
}

export function viewPropertiesAll(fn = () => true) {
return Array.from(classRegistry.ViewPropertiesTypes.values()).filter(fn);
}

export function viewEditorCreate(key, view, base, ids) {
const EditorClass = classRegistry.ViewEditorTypes.get(key);
if (!EditorClass) throw new Error(`Unknown View Editor type: ${key}`);
return new EditorClass(view, base, ids);
}

export function viewEditorAll(fn = () => true) {
return Array.from(classRegistry.ViewEditorTypes.values()).filter(fn);
}

export function pluginRegister(pluginClass) {
let type = pluginClass.getPluginType();
switch (type) {
case "object":
registerObjectTypes(pluginClass.getPluginKey(), pluginClass);
break;
case "properties-object":
registerObjectPropertiesTypes(pluginClass.getPluginKey(), pluginClass);
break;
// case "field":
// break;
case "view":
registerViewTypes(pluginClass.getPluginKey(), pluginClass);
break;
case "properties-view":
registerViewPropertiesTypes(pluginClass.getPluginKey(), pluginClass);
break;
case "editor-view":
registerViewEditorTypes(pluginClass.getPluginKey(), pluginClass);
break;
default:
throw new Error(
`ABClassManager.pluginRegister():: Unknown plugin type: ${type}`
);
}
}

///
/// For development
///
// import propertyNSAPI from "../../../plugins/ab_plugin_object_netsuite_api/properties/ABPropertiesObjectNetsuiteAPI.js";
// import objectNSAPI from "./plugins/developer/ABObjectNetsuiteAPI.js";

export function registerLocalPlugins(API) {
// let { registerObjectTypes, registerObjectPropertiesTypes } = API;
// let cPropertyNSAPI = propertyNSAPI(API);
// registerObjectPropertiesTypes(cPropertyNSAPI.getPluginKey(), cPropertyNSAPI);
// let cObjectNSAPI = objectNSAPI(API);
// registerObjectTypes(cObjectNSAPI.getPluginKey(), cObjectNSAPI);
}

// module.exports = {
// getPluginAPI,
// createPropertiesObject,
// // createField,
// // createObjectProperty,
// // createView,
// // classRegistry, // Expose the registry for testing or introspection
// registerLocalPlugins,
// };
26 changes: 0 additions & 26 deletions AppBuilder/platform/ABModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,6 @@ module.exports = class ABModel extends ABModelCore {
/// Instance Methods
///

// Prepare multilingual fields to be untranslated
// Before untranslating we need to ensure that values.translations is set.
prepareMultilingualData(values) {
// if this object has some multilingual fields, translate the data:
var mlFields = this.object.multilingualFields();
// if mlFields are inside of the values saved we want to translate otherwise do not because it will reset the translation field and you may loose unchanged translations
var shouldTranslate = false;
if (mlFields.length) {
mlFields.forEach(function (field) {
if (values[field] != null) {
shouldTranslate = true;
}
});
}
if (shouldTranslate) {
if (
values.translations == null ||
typeof values.translations == "undefined" ||
values.translations == ""
) {
values.translations = [];
}
this.object.unTranslate(values, values, mlFields);
}
}

request(method, params) {
return this.AB.Network[method](params);
}
Expand Down
25 changes: 24 additions & 1 deletion AppBuilder/platform/ABViewManager.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
const ABViewManagerCore = require("../core/ABViewManagerCore");
const ClassManager = require("./ABClassManager");

module.exports = class ABViewManager extends ABViewManagerCore {};
module.exports = class ABViewManager extends ABViewManagerCore {
/**
* @function newView
* return an instance of an ABView based upon the values.key value.
* @return {ABView}
*/
static newView(values, application, parent) {
parent = parent || null;

// check to see if this is a plugin view
if (values.plugin_key) {
// If this is from a plugin, create it from ClassManager
return ClassManager.viewCreate(
values.plugin_key,
values,
application,
parent
);
}

return super.newView(values, application, parent);
}
};
Loading
Loading