Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Утилиты. Интерфейс для импорта #883

Merged
merged 20 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
11 changes: 11 additions & 0 deletions _build/data/transport.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@
'value' => '2,3',
'xtype' => 'textfield',
'area' => 'ms2_statuses',
],

'ms2_utility_import_fields' => [
'value' => 'pagetitle,parent,price,article',
'xtype' => 'textfield',
'area' => 'ms2_import',
],
'ms2_utility_import_fields_delimiter' => [
'value' => ';',
'xtype' => 'textfield',
'area' => 'ms2_import',
]
];

Expand Down
214 changes: 214 additions & 0 deletions assets/components/minishop2/js/mgr/utilites/import/panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
miniShop2.panel.UtilitesImport = function (config) {
config = config || {}

Ext.apply(config, {
cls: 'container form-with-labels',
autoHeight: true,
url: miniShop2.config.connector_url,
progress: true,
id: 'ms2-panel-import',
baseParams: {
action: 'mgr/utilites/import/import'
},
items: [{
layout: 'column',
border: false,
anchor: '100%',
cls: 'main-wrapper',
labelAlign: 'top',
buttonAlign: 'left',
style: 'padding: 0 0 0 7px',
items: [{
columnWidth: 0.5,
layout: 'form',
defaults: { msgTarget: 'under' },
border: false,
style: { margin: '0' },
items: [
{
xtype: 'modx-combo-browser',
fieldLabel: _('ms2_utilites_import_label_file'),
emptyText: _('ms2_utilites_import_label_file_empty'),
anchor: '81%',
name: 'importfile',
allowBlank: false,
},
{
layout: 'column',
items: [{
columnWidth: 0.8,
layout: 'form',
border: false,
style: { margin: '0' },
items: [
{
xtype: 'textfield',
name: 'fields',
value: miniShop2.config.utility_import_fields,
width: '99%',
fieldLabel: _('ms2_utilites_import_label_fields'),
allowBlank: false,
},
{
xtype: 'textfield',
name: 'delimiter',
value: miniShop2.config.utility_import_fields_delimiter,
width: '99%',
allowBlank: false,
fieldLabel: _('ms2_utilites_import_label_delimiter'),
}
]
},
{
columnWidth: 0.2,
layout: 'form',
border: false,
style: { margin: '20px 0 0 15px' },
items: [
{
xtype: 'button',
style: 'padding: 4px 10px 7px; margin: 18px 0 0 0',
tooltip: _('ms2_utilites_import_save_fields'),
text: '<i class="icon icon-save"></i>',
handler: function () {
this.saveConfig(this)
}, scope: this
}
]

}]
},
{
xtype: 'xcheckbox',
name: 'update',
value: 1,
id: 'ms-utilites-import-update',
boxLabel: _('ms2_utilites_import_update_products'),
labelAlign: 'right',
listeners: {
check: {
fn: this.onUpdateNeed,
scope: this
},
}
},
{
xtype: 'textfield',
name: 'key',
value: 'article',
width: '99%',
hidden: true,
id: 'ms-utilites-import-key',
fieldLabel: _('ms2_utilites_import_update_key'),
},
{
xtype: 'xcheckbox',
name: 'debug',
value: 1,
hideLabel: true,
id: 'ms-utilites-import-debug',
boxLabel: _('ms2_utilites_import_debug'),
labelAlign: 'right',
},
{
xtype: 'xcheckbox',
name: 'scheduler',
value: 1,
hideLabel: true,
id: 'ms-utilites-import-scheduler',
boxLabel: _('ms2_utilites_import_use_scheduler'),
labelAlign: 'right',
},
{
xtype: 'button',
style: 'margin: 25px 0 0 2px',
text: '<i class="icon icon-download"></i> &nbsp;' + _('ms2_utilites_import_submit'),
handler: function () {
this.submit(this)
}, scope: this
}
]
}/*, {
columnWidth: 0.5,
layout: 'form',
defaults: { msgTarget: 'under' },
border: false,
style: { margin: '0 0 0 20px' },
items: [
{
xtype: 'fieldset',
title: 'Инструкция',
id: 'ms2-utilites-import-instruction',
cls: 'x-fieldset-checkbox-toggle',
style: 'margin: 5px 0 15px; padding: 20px; ',
collapsible: true,
collapsed: true,
stateful: true,
labelAlign: 'top',
stateEvents: ['collapse', 'expand'],
items: [
{
html: ''
},
]
}
]
}*/]
}],
listeners: {
success: {
fn: function (response) {
const data = response.result
const alert = data.success === true ? _('success') : _('error')
MODx.msg.alert(alert, data.message)
}, scope: this
},
failure: {
fn: function (response) {
}, scope: this
}
}
})

miniShop2.panel.UtilitesImport.superclass.constructor.call(this, config)
}

Ext.extend(miniShop2.panel.UtilitesImport, MODx.FormPanel, {

onUpdateNeed: function (cb) {
var updateKey = Ext.getCmp('ms-utilites-import-key')
if (cb.getValue()) {
updateKey.show()
} else {
updateKey.hide()
}
},

saveConfig: function () {
var form = this.getForm()
var values = form.getValues()

MODx.Ajax.request({
url: miniShop2.config['connector_url'],
params: {
action: 'mgr/utilites/import/saveconfig',
fields: values.fields,
delimiter: values.delimiter
},
listeners: {
success: {
fn: function (r) {
MODx.msg.status({
title: _('ms2_utilites_import_save_fields_title'),
message: _('ms2_utilites_import_save_fields_message'),
delay: 7
})
}, scope: this
}
}
})

}

})
Ext.reg('minishop2-utilites-import', miniShop2.panel.UtilitesImport)
4 changes: 1 addition & 3 deletions assets/components/minishop2/js/mgr/utilites/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ miniShop2.panel.Utilites = function (config) {
cls: 'main-wrapper',
}]
},
/*
// todo
{
title: _('ms2_utilites_import'),
layout: 'anchor',
Expand All @@ -40,7 +38,7 @@ miniShop2.panel.Utilites = function (config) {
xtype: 'minishop2-utilites-import',
cls: 'main-wrapper',
}]
}*/
}
]
}]

Expand Down
10 changes: 6 additions & 4 deletions core/components/minishop2/controllers/mgr/utilites.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ public function getLanguageTopics()
*/
public function loadCustomCssJs()
{

$this->addCss($this->miniShop2->config['cssUrl'] . 'mgr/utilites/gallery.css');

$this->addJavascript($this->miniShop2->config['jsUrl'] . 'mgr/minishop2.js');
$this->addJavascript($this->miniShop2->config['jsUrl'] . 'mgr/utilites/panel.js');
$this->addJavascript($this->miniShop2->config['jsUrl'] . 'mgr/utilites/gallery/panel.js');
$this->addJavascript($this->miniShop2->config['jsUrl'] . 'mgr/utilites/import/panel.js');

$config = $this->miniShop2->config;

Expand All @@ -42,7 +41,7 @@ public function loadCustomCssJs()
$config['utility_gallery_source_id'] = $productSource;
$config['utility_gallery_source_name'] = $source->get('name');

$properties = $source->get('properties');
$properties = $source->get('properties');
$propertiesString = '';
foreach (json_decode($properties['thumbnails']['value'], true) as $key => $value) {
$propertiesString .= "<strong>$key: </strong>" . json_encode($value) . "<br>";
Expand All @@ -54,10 +53,13 @@ public function loadCustomCssJs()
$config['utility_gallery_total_products'] = $this->modx->getCount('msProduct', ['class_key' => 'msProduct']);
$config['utility_gallery_total_products_files'] = $this->modx->getCount('msProductFile', ['parent' => 0]);

// get params for import
$config['utility_import_fields'] = $this->getOption('ms2_utility_import_fields', null, 'pagetitle,parent,price,article', true);
$config['utility_import_fields_delimiter'] = $this->getOption('ms2_utility_import_fields_delimiter', null, ';', true);

$this->addHtml(
'<script>
miniShop2.config = ' . json_encode($config) . ';

Ext.onReady(function() {
MODx.add({xtype: "minishop2-utilites"});
});
Expand Down
Loading