diff --git a/src/PimcoreDataHubBundle.php b/src/PimcoreDataHubBundle.php index 73d70343..6a7021a3 100644 --- a/src/PimcoreDataHubBundle.php +++ b/src/PimcoreDataHubBundle.php @@ -82,6 +82,7 @@ public function getJsPaths(): array return [ '/bundles/pimcoredatahub/js/datahub.js', '/bundles/pimcoredatahub/js/config.js', + '/bundles/pimcoredatahub/js/adapter/abstract.js', '/bundles/pimcoredatahub/js/adapter/graphql.js', '/bundles/pimcoredatahub/js/configuration/graphql/configItem.js', '/bundles/pimcoredatahub/js/fieldConfigDialog.js', diff --git a/src/Resources/public/js/adapter/abstract.js b/src/Resources/public/js/adapter/abstract.js new file mode 100644 index 00000000..2d1c5693 --- /dev/null +++ b/src/Resources/public/js/adapter/abstract.js @@ -0,0 +1,119 @@ +/** + * Pimcore + * + * This source file is available under two different licenses: + * - GNU General Public License version 3 (GPLv3) + * - Pimcore Commercial License (PCL) + * Full copyright and license information is available in + * LICENSE.md which is distributed with this source code. + * + * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) + * @license http://www.pimcore.org/license GPLv3 and PCL + */ + +pimcore.registerNS("pimcore.plugin.datahub.adapter.abstract"); +pimcore.plugin.datahub.adapter.abstract = Class.create({ + initialize: function (configPanel) { + this.configPanel = configPanel; + }, + + addConfiguration: function (type) { + Ext.MessageBox.prompt(t('plugin_pimcore_datahub_configpanel_enterkey_title'), t('plugin_pimcore_datahub_configpanel_enterkey_prompt'), this.addConfigurationComplete.bind(this, type), null, null, ""); + }, + + addConfigurationComplete: function (type, button, value, object) { + var regresult = value.match(/[a-zA-Z0-9_\-]+/); + if (button == "ok" && value.length > 2 && value.length <= 80 && regresult == value) { + Ext.Ajax.request({ + url: "/admin/pimcoredatahub/config/add", + params: { + name: value, + type: type + }, + success: function (response) { + var data = Ext.decode(response.responseText); + this.configPanel.refreshTree(); + + if (!data || !data.success) { + pimcore.helpers.showNotification(t("error"), t("plugin_pimcore_datahub_configpanel_error_adding_config") + ':
' + data.message, "error"); + } else { + this.openConfiguration(data.name); + } + + }.bind(this) + }); + } + else if (button == "cancel") { + return; + } + else { + Ext.Msg.alert(t("plugin_pimcore_datahub_configpanel"), value.length <= 80 ? t("plugin_pimcore_datahub_configpanel_invalid_name") : t("plugin_pimcore_datahub_configpanel_invalid_length")); + } + }, + + openConfiguration: function (id) { + this.checkIfPanelExists(id); + }, + + cloneConfiguration: function (tree, record) { + Ext.MessageBox.prompt(t('plugin_pimcore_datahub_configpanel_enterclonekey_title'), t('plugin_pimcore_datahub_configpanel_enterclonekey_enterclonekey_prompt'), + this.cloneConfigurationComplete.bind(this, tree, record), null, null, ""); + }, + + cloneConfigurationComplete: function (tree, record, button, value, object) { + + var regresult = value.match(/[a-zA-Z0-9_\-]+/); + if (button == "ok" && value.length > 2 && value.length <= 80 && regresult == value) { + Ext.Ajax.request({ + url: "/admin/pimcoredatahub/config/clone", + params: { + name: value, + originalName: record.data.id + }, + success: function (response) { + var data = Ext.decode(response.responseText); + + this.configPanel.refreshTree(); + + if (!data || !data.success) { + pimcore.helpers.showNotification(t("error"), t("plugin_pimcore_datahub_configpanel_error_cloning_config") + ':
' + data.message, "error"); + } else { + this.openConfiguration(data.name, tree, record); + } + + }.bind(this) + }); + } + else if (button == "cancel") { + return; + } + else { + Ext.Msg.alert(t("plugin_pimcore_datahub_configpanel"), value.length <= 80 ? t("plugin_pimcore_datahub_configpanel_invalid_name") : t("plugin_pimcore_datahub_configpanel_invalid_length")); + } + }, + + deleteConfiguration: function (tree, record) { + Ext.Msg.confirm(t('delete'), t('delete_message'), function (btn) { + if (btn == 'yes') { + Ext.Ajax.request({ + url: "/admin/pimcoredatahub/config/delete", + params: { + name: record.data.id + } + }); + + this.configPanel.getEditPanel().removeAll(); + record.remove(); + } + }.bind(this)); + }, + + checkIfPanelExists: function(id) { + let existingPanel = Ext.getCmp("plugin_pimcore_datahub_configpanel_panel_" + id); + if(existingPanel) { + this.configPanel.editPanel.setActiveTab(existingPanel); + return true; + } + return false; + } +}); diff --git a/src/Resources/public/js/adapter/graphql.js b/src/Resources/public/js/adapter/graphql.js index 1fb4af8c..92c92e88 100644 --- a/src/Resources/public/js/adapter/graphql.js +++ b/src/Resources/public/js/adapter/graphql.js @@ -12,50 +12,9 @@ */ pimcore.registerNS("pimcore.plugin.datahub.adapter.graphql"); -pimcore.plugin.datahub.adapter.graphql = Class.create({ - - initialize: function (configPanel) { - this.configPanel = configPanel; - }, - - addConfiguration: function (type) { - Ext.MessageBox.prompt(t('plugin_pimcore_datahub_configpanel_enterkey_title'), t('plugin_pimcore_datahub_configpanel_enterkey_prompt'), this.addConfigurationComplete.bind(this, type), null, null, ""); - }, - - addConfigurationComplete: function (type, button, value, object) { - var regresult = value.match(/[a-zA-Z0-9_\-]+/); - if (button == "ok" && value.length > 2 && value.length <= 80 && regresult == value) { - Ext.Ajax.request({ - url: "/admin/pimcoredatahub/config/add", - params: { - name: value, - type: type - }, - success: function (response) { - var data = Ext.decode(response.responseText); - this.configPanel.refreshTree(); - - if (!data || !data.success) { - pimcore.helpers.showNotification(t("error"), t("plugin_pimcore_datahub_configpanel_error_adding_config") + ':
' + data.message, "error"); - } else { - this.openConfiguration(data.name); - } - - }.bind(this) - }); - } - else if (button == "cancel") { - return; - } - else { - Ext.Msg.alert(t("plugin_pimcore_datahub_configpanel"), value.length <= 80 ? t("plugin_pimcore_datahub_configpanel_invalid_name") : t("plugin_pimcore_datahub_configpanel_invalid_length")); - } - }, - +pimcore.plugin.datahub.adapter.graphql = Class.create(pimcore.plugin.datahub.adapter.abstract, { openConfiguration: function (id) { - var existingPanel = Ext.getCmp("plugin_pimcore_datahub_configpanel_panel_" + id); - if(existingPanel) { - this.configPanel.editPanel.setActiveTab(existingPanel); + if(this.checkIfPanelExists(id)) { return; } @@ -65,7 +24,12 @@ pimcore.plugin.datahub.adapter.graphql = Class.create({ name: id }, success: function (response) { - var data = Ext.decode(response.responseText); + // check again here to prevent double click problem + if(this.checkIfPanelExists(id)) { + return; + } + + let data = Ext.decode(response.responseText); pimcore.plugin.datahub.graphql = pimcore.plugin.datahub.graphql || {}; pimcore.plugin.datahub.graphql.supportedQueryDataTypes = data.supportedGraphQLQueryDataTypes; @@ -75,59 +39,5 @@ pimcore.plugin.datahub.adapter.graphql = Class.create({ pimcore.layout.refresh(); }.bind(this) }); - }, - - cloneConfiguration: function (tree, record) { - Ext.MessageBox.prompt(t('plugin_pimcore_datahub_configpanel_enterclonekey_title'), t('plugin_pimcore_datahub_configpanel_enterclonekey_enterclonekey_prompt'), - this.cloneConfigurationComplete.bind(this, tree, record), null, null, ""); - }, - - cloneConfigurationComplete: function (tree, record, button, value, object) { - - var regresult = value.match(/[a-zA-Z0-9_\-]+/); - if (button == "ok" && value.length > 2 && value.length <= 80 && regresult == value) { - Ext.Ajax.request({ - url: "/admin/pimcoredatahub/config/clone", - params: { - name: value, - originalName: record.data.id - }, - success: function (response) { - var data = Ext.decode(response.responseText); - - this.configPanel.refreshTree(); - - if (!data || !data.success) { - pimcore.helpers.showNotification(t("error"), t("plugin_pimcore_datahub_configpanel_error_cloning_config") + ':
' + data.message, "error"); - } else { - this.openConfiguration(data.name, tree, record); - } - - }.bind(this) - }); - } - else if (button == "cancel") { - return; - } - else { - Ext.Msg.alert(t("plugin_pimcore_datahub_configpanel"), value.length <= 80 ? t("plugin_pimcore_datahub_configpanel_invalid_name") : t("plugin_pimcore_datahub_configpanel_invalid_length")); - } - }, - - deleteConfiguration: function (tree, record) { - Ext.Msg.confirm(t('delete'), t('delete_message'), function (btn) { - if (btn == 'yes') { - Ext.Ajax.request({ - url: "/admin/pimcoredatahub/config/delete", - params: { - name: record.data.id - } - }); - - this.configPanel.getEditPanel().removeAll(); - record.remove(); - } - }.bind(this)); - }, - + } }); diff --git a/src/Resources/public/js/config.js b/src/Resources/public/js/config.js index be9cc52e..ee531d2d 100644 --- a/src/Resources/public/js/config.js +++ b/src/Resources/public/js/config.js @@ -83,7 +83,7 @@ pimcore.plugin.datahub.config = Class.create({ let firstHandler; for (let key in pimcore.plugin.datahub.adapter) { - if( pimcore.plugin.datahub.adapter.hasOwnProperty( key ) && this.userIsAllowedToCreate(key)) { + if( key !== 'abstract' && pimcore.plugin.datahub.adapter.hasOwnProperty( key ) && this.userIsAllowedToCreate(key)) { let adapter = new pimcore.plugin.datahub.adapter[key](this); if (!firstHandler) {