-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor graphql adapter to abstract and adding panel exists check
- Loading branch information
Showing
4 changed files
with
130 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") + ': <br/>' + 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") + ': <br/>' + 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; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters