Skip to content

Commit

Permalink
Update export_contextmenu.js for Pimcore 11
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarlovi authored Sep 28, 2023
1 parent 4fe7a56 commit 32933d6
Showing 1 changed file with 69 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,92 +1,77 @@
pimcore.registerNS("pimcore.plugin.datadefinitions.export.context_menu");

pimcore.plugin.datadefinitions.export.context_menu = Class.create(pimcore.plugin.admin, {
getClassName: function () {
return "pimcore.plugin.datadefinitions.export.context_menu";
},

initialize: function () {
pimcore.plugin.broker.registerPlugin(this);
},
document.addEventListener(pimcore.events.prepareObjectTreeContextMenu, function (event) {
if (!Ext.ClassManager.get('Executable')) {
Ext.define('Executable', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
]
});
}

prepareObjectTreeContextMenu: function (tree, treeClass, menuItem) {
if (!Ext.ClassManager.get('Executable')) {
Ext.define('Executable', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
]
});
}
const tree = event.detail.menu;

var $this = this;
Ext.create('Ext.data.Store', {
model: 'Executable',
proxy: {
type: 'ajax',
url: '/admin/process_manager/executables/list-by-type',
extraParams: {
type: 'exportdefinition'
},
reader: {
type: 'json',
rootProperty: 'data'
}
Ext.create('Ext.data.Store', {
model: 'Executable',
proxy: {
type: 'ajax',
url: '/admin/process_manager/executables/list-by-type',
extraParams: {
type: 'exportdefinition'
},
sorters: [{
property: 'name',
direction: 'ASC'
}],
sortRoot: 'data',
autoLoad: true,
listeners: {
refresh: function (store) {
var exportMenu = [];
store.each(function (executable) {
exportMenu.push({
text: executable.get('name'),
iconCls: "pimcore_icon_object pimcore_icon_overlay_add",
handler: $this.exportObjects.bind($this, executable, menuItem)
});
});

if (exportMenu) {
tree.add([
{xtype: 'menuseparator'},
{
text: t("data_definitions_processmanager_export_from_here"),
iconCls: "pimcore_icon_object pimcore_icon_overlay_download",
menu: exportMenu
}
]);
}
}
reader: {
type: 'json',
rootProperty: 'data'
}
});
},
},
sorters: [{
property: 'name',
direction: 'ASC'
}],
sortRoot: 'data',
autoLoad: true,
listeners: {
refresh: function (store) {
var exportMenu = [];
store.each(function (executable) {
exportMenu.push({
text: executable.get('name'),
iconCls: "pimcore_icon_object pimcore_icon_overlay_add",
handler: function (menuItem) {
Ext.Ajax.request({
url: '/admin/process_manager/executables/run',
params: {
id: executable.id,
startupConfig: Ext.encode({
root: menuItem.$iid,
}),
csrfToken: pimcore.settings['csrfToken']
},
method: 'POST',
success: function (result) {
result = Ext.decode(result.responseText);

exportObjects: function (executable, menuItem) {
Ext.Ajax.request({
url: '/admin/process_manager/executables/run',
params: {
id: executable.id,
startupConfig: Ext.encode({
root: menuItem.get('id'),
}),
csrfToken: pimcore.settings['csrfToken']
},
method: 'POST',
success: function (result) {
result = Ext.decode(result.responseText);
if (result.success) {
Ext.Msg.alert(t('success'), t('processmanager_executable_started'));
} else {
Ext.Msg.alert(t('error'), result.message);
}
}.bind(this)
});
}
});
});

if (result.success) {
Ext.Msg.alert(t('success'), t('processmanager_executable_started'));
} else {
Ext.Msg.alert(t('error'), result.message);
if (exportMenu) {
tree.add([
{xtype: 'menuseparator'},
{
text: t("data_definitions_processmanager_export_from_here"),
iconCls: "pimcore_icon_object pimcore_icon_overlay_download",
menu: exportMenu
}
]);
}
}.bind(this)
});
}
}
}
});
});

new pimcore.plugin.datadefinitions.export.context_menu();

0 comments on commit 32933d6

Please sign in to comment.