2022-07-29 01:03:17 +02:00
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
|
|
2022-07-29 20:52:26 +02:00
|
|
|
require('./lang/de.js');
|
2022-07-29 01:03:17 +02:00
|
|
|
|
|
|
|
import { addListToDropdown, createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
|
|
|
|
|
|
|
|
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
|
|
|
|
import Model from '@ckeditor/ckeditor5-ui/src/model';
|
|
|
|
|
|
|
|
export default class PartDBLabelUI extends Plugin {
|
|
|
|
init() {
|
|
|
|
const editor = this.editor;
|
|
|
|
const t = editor.t;
|
|
|
|
|
|
|
|
// The "placeholder" dropdown must be registered among the UI components of the editor
|
|
|
|
// to be displayed in the toolbar.
|
|
|
|
editor.ui.componentFactory.add( 'partdb_label', locale => {
|
|
|
|
const dropdownView = createDropdown( locale );
|
|
|
|
|
|
|
|
// Populate the list in the dropdown with items.
|
|
|
|
addListToDropdown( dropdownView, getDropdownItemsDefinitions(t) );
|
|
|
|
|
|
|
|
dropdownView.buttonView.set( {
|
|
|
|
// The t() function helps localize the editor. All strings enclosed in t() can be
|
|
|
|
// translated and change when the language of the editor changes.
|
2022-07-29 20:52:26 +02:00
|
|
|
label: t( 'Label Placeholder' ),
|
2022-07-29 01:03:17 +02:00
|
|
|
tooltip: true,
|
|
|
|
withText: true
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Disable the placeholder button when the command is disabled.
|
|
|
|
const command = editor.commands.get( 'partdb_label' );
|
|
|
|
dropdownView.bind( 'isEnabled' ).to( command );
|
|
|
|
|
|
|
|
// Execute the command when the dropdown item is clicked (executed).
|
|
|
|
this.listenTo( dropdownView, 'execute', evt => {
|
|
|
|
editor.execute( 'partdb_label', { value: evt.source.commandParam } );
|
|
|
|
editor.editing.view.focus();
|
|
|
|
} );
|
|
|
|
|
|
|
|
return dropdownView;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const PLACEHOLDERS = [
|
|
|
|
{
|
2022-07-29 20:52:26 +02:00
|
|
|
label: 'Part',
|
2022-07-29 01:03:17 +02:00
|
|
|
entries: [
|
2022-07-29 20:52:26 +02:00
|
|
|
['[[ID]]', 'Database ID'],
|
|
|
|
['[[NAME]]', 'Part name'],
|
|
|
|
['[[CATEGORY]]', 'Category'],
|
|
|
|
['[[CATEGORY_FULL]]', 'Category (Full path)'],
|
|
|
|
['[[MANUFACTURER]]', 'Manufacturer'],
|
|
|
|
['[[MANUFACTURER_FULL]]', 'Manufacturer (Full path)'],
|
|
|
|
['[[FOOTPRINT]]', 'Footprint'],
|
|
|
|
['[[FOOTPRINT_FULL]]', 'Footprint (Full path)'],
|
|
|
|
['[[MASS]]', 'Mass'],
|
|
|
|
['[[MPN]]', 'Manufacturer Product Number (MPN)'],
|
|
|
|
['[[TAGS]]', 'Tags'],
|
|
|
|
['[[M_STATUS]]', 'Manufacturing status'],
|
|
|
|
['[[DESCRIPTION]]', 'Description'],
|
|
|
|
['[[DESCRIPTION_T]]', 'Description (plain text)'],
|
|
|
|
['[[COMMENT]]', 'Comment'],
|
|
|
|
['[[COMMENT_T]]', 'Comment (plain text)'],
|
|
|
|
['[[LAST_MODIFIED]]', 'Last modified datetime'],
|
|
|
|
['[[CREATION_DATE]]', 'Creation datetime'],
|
2022-07-29 01:03:17 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2022-07-29 20:52:26 +02:00
|
|
|
label: 'Part lot',
|
2022-07-29 01:03:17 +02:00
|
|
|
entries: [
|
2022-07-29 20:52:26 +02:00
|
|
|
['[[LOT_ID]]', 'Lot ID'],
|
|
|
|
['[[LOT_NAME]]', 'Lot name'],
|
|
|
|
['[[LOT_COMMENT]]', 'Lot comment'],
|
|
|
|
['[[EXPIRATION_DATE]]', 'Lot expiration date'],
|
|
|
|
['[[AMOUNT]]', 'Lot amount'],
|
|
|
|
['[[LOCATION]]', 'Storage location'],
|
|
|
|
['[[LOCATION_FULL]]', 'Storage location (Full path)'],
|
2022-07-29 01:03:17 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2022-07-29 20:52:26 +02:00
|
|
|
label: 'Storage location',
|
2022-07-29 01:03:17 +02:00
|
|
|
entries: [
|
2022-07-29 20:52:26 +02:00
|
|
|
['[[ID]]', 'Location ID'],
|
|
|
|
['[[NAME]]', 'Name'],
|
|
|
|
['[[FULL_PATH]]', 'Full path'],
|
|
|
|
['[[PARENT]]', 'Parent name'],
|
|
|
|
['[[PARENT_FULL_PATH]]', 'Parent full path'],
|
|
|
|
['[[COMMENT]]', 'Comment'],
|
|
|
|
['[[COMMENT_T]]', 'Comment (plain text)'],
|
|
|
|
['[[LAST_MODIFIED]]', 'Last modified datetime'],
|
|
|
|
['[[CREATION_DATE]]', 'Creation datetime'],
|
2022-07-29 01:03:17 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2022-07-29 20:52:26 +02:00
|
|
|
label: 'Globals',
|
2022-07-29 01:03:17 +02:00
|
|
|
entries: [
|
2022-07-29 20:52:26 +02:00
|
|
|
['[[USERNAME]]', 'Username'],
|
|
|
|
['[[USERNAME_FULL]]', 'Username (including name)'],
|
|
|
|
['[[DATETIME]]', 'Current datetime'],
|
|
|
|
['[[DATE]]', 'Current date'],
|
|
|
|
['[[TIME]]', 'Current time'],
|
|
|
|
['[[INSTALL_NAME]]', 'Instance name'],
|
|
|
|
['[[TYPE]]', 'Target type']
|
2022-07-29 01:03:17 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
function getDropdownItemsDefinitions(t) {
|
|
|
|
const itemDefinitions = new Collection();
|
|
|
|
|
|
|
|
for ( const group of PLACEHOLDERS) {
|
|
|
|
//Add group header
|
|
|
|
itemDefinitions.add({
|
|
|
|
'type': 'separator',
|
|
|
|
model: new Model( {
|
|
|
|
withText: true,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
itemDefinitions.add({
|
|
|
|
type: 'button',
|
|
|
|
model: new Model( {
|
|
|
|
label: t(group.label),
|
|
|
|
withText: true,
|
|
|
|
isEnabled: false,
|
|
|
|
} )
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add group entries
|
|
|
|
for ( const entry of group.entries) {
|
|
|
|
const definition = {
|
|
|
|
type: 'button',
|
|
|
|
model: new Model( {
|
|
|
|
commandParam: entry[0],
|
|
|
|
label: t(entry[1]),
|
|
|
|
withText: true
|
|
|
|
} ),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add the item definition to the collection.
|
|
|
|
itemDefinitions.add( definition );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemDefinitions;
|
|
|
|
}
|