Completed
Pull Request — master (#391)
by Jonas
08:46 queued 05:29
created

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
//{namespace name=backend/connect/view/main}
2
3
/**
4
 * Shopware Controller - Cache backend module
5
 */
6
//{block name="backend/connect/controller/main"}
7
Ext.define('Shopware.apps.Connect.controller.Main', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
8
9
    extend: 'Enlight.app.Controller',
10
11
    stores: [
12
        'main.Navigation',
13
        'export.StreamList', 'export.List', 'import.RemoteCategories', 'import.RemoteProducts', 'import.LocalProducts',
14
        'changed_products.List',
15
        'log.List',
16
		'config.General', 'config.Import', 'config.Export', 'config.CustomerGroup', 'config.PriceGroup',
17
        'config.Units', 'config.ConnectUnits', 'config.MarketplaceAttributes', 'config.LocalProductAttributes'
18
    ],
19
    models: [
20
        'main.Mapping', 'main.Product',
21
        'export.StreamList', 'export.List', 'import.List',
22
        'changed_products.List', 'changed_products.Product', 'log.List',
23
        'config.General', 'config.Import', 'config.Units', 'config.MarketplaceAttributes',
24
        'config.ConnectUnit', 'config.Pages', 'config.LocalProductAttributes', 'config.PriceGroup'
25
    ],
26
27
    refs: [
28
        { ref: 'window', selector: 'connect-window' },
29
        { ref: 'navigation', selector: 'connect-navigation' },
30
        { ref: 'panel', selector: 'connect-panel' },
31
        { ref: 'exportWindow', selector: 'connect-export-window' },
32
        { ref: 'exportList', selector: 'connect-export-list' },
33
        { ref: 'exportStreamList', selector: 'connect-export-stream-list' },
34
        { ref: 'exportFilter', selector: 'connect-export-filter' },
35
        { ref: 'importList', selector: 'connect-import-list' },
36
        { ref: 'changeView', selector: 'connect-changed-products-tabs' },
37
        { ref: 'changedList', selector: 'connect-changed-products-list' },
38
        { ref: 'logList', selector: 'connect-log-list' },
39
        { ref: 'logFilter', selector: 'connect-log-filter' },
40
        { ref: 'logTabs', selector: 'connect-log-tabs' },
41
        { ref: 'marketeplaceMappingPanel', selector: 'connect-config-marketplace-attributes' },
42
        { ref: 'marketeplaceMapping', selector: 'connect-marketplace-attributes-mapping' },
43
        { ref: 'exportConfigForm', selector: 'connect-config-export-form' },
44
        { ref: 'unitsMapping', selector: 'connect-units-mapping-list' }
45
    ],
46
47
    messages: {
48
        login: {
49
            successTitle: '{s name=login/successTitle}Shopware ID{/s}',
50
            successMessage: '{s name=login/successMessage}Login successful{/s}',
51
            waitTitle: '{s name=login/waitTitle}Logging in...{/s}',
52
            waitMessage: '{s name=login/waitMessage}This process might take a few seconds{/s}'
53
        },
54
        growlMessage:'{s name=growlMessage}Shopware Connect{/s}',
55
56
        saveMappingTitle: '{s name=mapping/message/title}Save category mapping{/s}',
57
        saveMappingSuccess: '{s name=mapping/message/success}Category mapping has been saved.{/s}',
58
        saveMappingError: '{s name=mapping/message/error}Category mapping could not be saved.{/s}',
59
60
61
        insertOrUpdateProductTitle: '{s name=export/message/import_product_title}Products export{/s}',
62
        insertOrUpdateProductMessage: '{s name=export/message/import_product_messag}Products were marked for inserting / updating.{/s}',
63
        deleteProductTitle: '{s name=export/message/delete_title}Products export{/s}',
64
        deleteProductMessage: '{s name=export/message/delete_message}Products were marked for deleting.{/s}',
65
66
        exportStreamTitle: '{s name=export/message/export_stream_title}Product streams export{/s}',
67
        exportStreamMessage: '{s name=export/message/export_stream_message}Product streams were marked for export.{/s}',
68
        removeStreamTitle: '{s name=export/message/remove_stream_title}Product streams export{/s}',
69
        removeStreamMessage: '{s name=export/message/remove_stream_message}Products streams were marked for remove.{/s}',
70
        exportDynamicStreamMessage: '{s name=export/message/dynamic_stream_selected}The selected dynamic streams will be exported via cron job{/s}',
71
72
        activateProductTitle: '{s name=import/message/activate_title}Products import{/s}',
73
        activateProductMessage: '{s name=import/message/activate_message}Products have been activated.{/s}',
74
        disableProductTitle: '{s name=import/message/disable_title}Products import{/s}',
75
        disableProductMessage: '{s name=import/message/disable_message}Products have been disabled.{/s}',
76
        unsubscribeProductTitle: '{s name=import/message/unsubscribe_title}Products unsubscribed{/s}',
77
        unsubscribeProductMessage: '{s name=import/message/unsubscribe_message}Products have been unsubscribed.{/s}',
78
79
        priceErrorMessage: '{s name=export/progress/error_price_message}[0] of [1] products weren\'t exported, because there were with empty price fields{/s}',
80
81
        applyMappingToChildCategoriesTitle: '{s name=mapping/applyConfirmTitle}Apply to child categories?{/s}',
82
        applyMappingToChildCategoriesMessage: '{s name=mapping/applyConfirmMessage}Do you want to apply this mapping to all empty child categories? This will immediately save the current mapping, all other unsaved changes will be lost{/s}',
83
84
        updatePartOneMessage: Ext.String.format('{s name=config/message/update_part_one}Update to [0] will take{/s}', marketplaceName),
0 ignored issues
show
Bug introduced by
The variable marketplaceName seems to be never declared. If this is a global, consider adding a /** global: marketplaceName */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
85
        updatePartTwoMessage: '{s name=config/message/update_part_two}to finish{/s}',
86
        doneMessage: '{s name=config/message/done}Done{/s}',
87
88
        hours: '{s name=connect/hours}Hour(s){/s}',
89
        minutes: '{s name=connect/minutes}Minute(s){/s}',
90
        seconds: '{s name=connect/seconds}Second(s){/s}',
91
92
        exportTitle: '{s name=connect/tab_panel/export}Export{/s}',
93
        exportStatusCount:  '{s name=export/message/status_count}Sync-Status: [0] from [1] products{/s}',
94
        priceModeNotSelected: '{s name=config/config/price/price_mode_not_selected}Please select price mode{/s}',
95
        productDescriptionNotSelected: '{s name=config/export/product_description_export_not_selected}Please select product description{/s}',
96
97
        adoptUnitsTitle: '{s name=config/import/adopt_units_confirm_title}Maßeinheiten übernehmen{/s}',
98
        adoptUnitsMessage: '{s name=config/import/adopt_units_confirm_message}Möchten Sie die importieren Maßeinheiten in Ihren Shop übernehmen?{/s}',
99
100
        priceFieldIsNotSupported: '{s name=config/export/priceFieldIsNotSupported}Price field is not maintained. Some of the products have price = 0{/s}',
101
        priceResetSuccess: '{s name=config/price_reset_success}The exported prices were successfully reset. It will take up to 10min for the changes to take effect. When this operation is done, you will get the option to set the price type again when you reopen "Export" in the Connect menu.{/s}',
102
        priceResetError: '{s name=config/price_reset_error}A problem occur in price type reset. Please try again later or contact our support team.{/s}',
103
        priceResetLabel: '{s name=config/price_reset_label}Reset exported prices{/s}',
104
105
        exchangeSettingsResetSuccess: '{s name=config/exchange_settings_success}Successfully reset. It will take up to 10min for the changes to take effect. When this operation is done, you need to login again.{/s}',
106
        exchangeSettingsResetError: '{s name=config/exchange_settings_error}A problem occur in exchange settings reset. Please try again later or contact our support team.{/s}',
107
        exchangeSettingsResetLabel: '{s name=config/exchange_settings_label}Reset exchange settings{/s}',
108
109
        importConnectCategoriesTitle: '{s name=mapping/importConnectCategoriesTitle}Import categories?{/s}',
110
        importConnectCategoriesMessage: '{s name=mapping/importConnectCategoriesMessage}Do you want to import all subcategories of »[0]« to you category »[1]«?{/s}',
111
        importAssignCategoryConfirm: '{s name=import/message/confirm_assign_category}Assign the selected »[0]« products to the category selected below.{/s}',
112
        allProductsMarkedForExportWithCron: '{s name=export/all/marked_for_export_with_cron}All products have been marked for export with CronJob.{/s}',
113
        error: '{s name=connect/error}error{/s}',
114
115
        applyMigrationsTitle: '{s name=connect/import/dataMigrations/title}Apply Datamigrations?{/s}',
116
        applyMigrationsMessage: '{s name=connect/import/dataMigrations/message}Datamigrations have to be done. Would you like to do the migrations now?{/s}',
117
        migrationsMessageTitle:  '{s name=connect/import/migrations/message/title}Datamigration{/s}',
118
        migrationsMessage:  '{s name=connect/import/migrations/message}Datamigration successfully applied{/s}'
119
    },
120
121
122
    /**
123
     * Class property which holds the main application if it is created
124
     *
125
     * @default null
126
     * @object
127
     */
128
    mainWindow: null,
129
130
    exportStatusEl: null,
131
132
    /**
133
     * Init component. Basically will create the app window and register to events
134
     */
135
    init: function () {
136
        var me = this;
137
138
        if (!window.marketplaceName) {
139
            me.sendAjaxRequest(
140
                '{url controller=Connect action=initParams}',
141
                {},
142
                function(response) {
143
144
                    window.marketplaceName = response.data.marketplaceName;
145
                    window.marketplaceNetworkUrl = response.data.marketplaceNetworkUrl;
146
                    window.marketplaceLogo = response.data.marketplaceLogo;
147
                    window.defaultMarketplace = response.data.defaultMarketplace;
148
                    window.isFixedPriceAllowed = response.data.isFixedPriceAllowed;
149
                    window.purchasePriceInDetail = response.data.purchasePriceInDetail;
150
151
                    me.launchAction();
152
                    me.setEventListeners();
153
                }
154
            );
155
        } else {
156
            me.launchAction();
157
            me.setEventListeners();
158
        }
159
160
        me.callParent(arguments);
161
    },
162
163
    launchAction: function () {
164
        var me = this;
165
        switch (me.subApplication.action){
166
            case 'Export':
167
                me.mainWindow = me.getView('export.Window').create({
168
                    'action': me.subApplication.action
169
                }).show();
170
                break;
171
            case 'Settings':
172
                me.customerGroupStore = Ext.create('Shopware.apps.Connect.store.config.CustomerGroup').load({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
173
                    callback: function(){
174
                        me.mainWindow = me.getView('config.Window').create({
175
                            customerGroupStore: me.customerGroupStore
176
                        }).show();
177
                        me.populateLogCommandFilter();
178
                    }
179
                });
180
                break;
181
            default:
182
                var recreateConnectCategories;
183
                me.sendAjaxRequest(
184
                    '{url controller=Connect action=checkForDataMigration}',
185
                    {},
186
                    function(response) {
187
                        recreateConnectCategories = response.data.recreateConnectCategories;
188
                        if (recreateConnectCategories) {
189
                            Ext.Msg.show({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
190
                                    title: me.messages.applyMigrationsTitle,
191
                                    msg: me.messages.applyMigrationsMessage,
192
                                    buttons: Ext.Msg.YESNO,
193
                                    icon: Ext.Msg.QUESTION,
194
                                    fn: me.applyMigrations,
195
                                    scope: me
196
                                }
197
                            );
198
                        } else {
199
                            me.mainWindow = me.getView('main.Window').create({
200
                                'action': me.subApplication.action
201
                            }).show();
202
                        }
203
                    }
204
                );
205
                break;
206
207
        }
208
    },
209
210
    startMigration: function (window, offset) {
211
        offset = parseInt(offset) || 0;
212
        var batchsize = 100;
213
        var limit = offset + batchsize;
214
215
        var me = this,
216
            message = me.messages.migrationsMessage,
217
            title = me.messages.migrationsMessageTitle;
218
219
        window.inProcess = true;
220
221
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
222
            url: '{url action=applyMigrations}',
223
            method: 'POST',
224
            params: {
225
                'offset': offset,
226
                'limit': limit,
227
                'batchsize': batchsize
228
            },
229
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
230
                var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
231
                var doneDetails = limit;
232
                var totalCount = operation.data.totalCount;
233
234
                window.progressField.updateText(Ext.String.format(window.snippets.process, doneDetails, totalCount));
235
                window.progressField.updateProgress(
236
                    limit / totalCount,
237
                    Ext.String.format(window.snippets.process, doneDetails, totalCount),
238
                    true
239
                );
240
241
                if (limit >= totalCount) {
242
                    window.closeWindow();
243
                    me.createGrowlMessage(title, message, false);
244
                    me.mainWindow = me.getView('main.Window').create({
245
                        'action': me.subApplication.action
246
                    }).show();
247
                } else {
248
                    //otherwise we have to call this function recursive with the next offset
249
                    me.startMigration( window, limit);
250
                }
251
            },
252
            failure: function(operation) {
253
                me.createGrowlMessage(title, operation.responseText, true);
254
                window.inProcess = false;
255
            }
256
        });
257
    },
258
259
    applyMigrations: function(buttonId, text, opt) {
0 ignored issues
show
Unused Code introduced by
The parameter text is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter opt is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
260
        var me = this;
261
        console.log(buttonId);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
262
        if (buttonId === 'yes') {
263
            me.mainWindow = me.getView('main.Progress').create().show();
264
            me.startMigration(me.mainWindow);
265
        } else {
266
267
            console.log(me);
268
269
            me.mainWindow = me.getView('main.Window').create({
270
                'action': me.subApplication.action
271
            }).show();
272
        }
273
    },
274
275
    setEventListeners: function () {
276
        var me = this;
277
        me.control({
278
            'connect-navigation': {
279
                select: me.onSelectNavigationEntry
280
            },
281
            'connect-config button[action=save-general-config]': {
282
                click: me.onSaveConfigForm
283
            },
284
            'connect-config-form': {
285
                calculateFinishTime: me.onCalculateFinishTime,
286
                resetPriceType: me.onResetPriceType,
287
                resetExchangeSettings: me.onResetExchangeSettings
288
            },
289
            'connect-config-import-form button[action=save-import-config]': {
290
                click: me.onSaveImportConfigForm
291
            },
292
            'connect-import-unit button[action=save-unit]': {
293
                click: me.onSaveUnitsMapping
294
            },
295
            'connect-import-unit checkbox[name=hideAssignedUnits]': {
296
                change: me.onHideAssignedUnits
297
            },
298
            'connect-import-unit button[action=adoptUnits]': {
299
                click: me.onAdoptUnits
300
            },
301
            'connect-export-price-form': {
302
                saveExportSettings: me.onSaveExportSettingsForm,
303
                collectPriceParams: me.collectPriceParams,
304
                rejectPriceConfigChanges: me.rejectPriceConfigChanges
305
            },
306
            'connect-config-export-form combobox[name=priceGroupForPriceExport]': {
307
                change: me.onChangePriceGroupForPrice
308
            },
309
            'connect-config-export-form combobox[name=priceGroupForPurchasePriceExport]': {
310
                change: me.onChangePriceGroupForPurchasePrice
311
            },
312
            'connect-config-export-form combobox[name=priceFieldForPriceExport]': {
313
                change: me.onChangePriceFieldForPrice
314
            },
315
            'connect-config-export-form combobox[name=priceFieldForPurchasePriceExport]': {
316
                change: me.onChangePriceFieldForPurchasePrice
317
            },
318
            'connect-mapping button[action=save]': {
319
                click: me.onSaveMapping
320
            },
321
            'connect-export button[action=add]': {
322
                click: me.onExportAction
323
            },
324
            'connect-export button[action=delete]': {
325
                click: me.onRemoveArticleAction
326
            },
327
            'connect-export button[action=exportAll]': {
328
                click: me.onExportAllAction
329
            },
330
            'connect-article-export-progress-window': {
331
                startExport: me.startArticleExport
332
            },
333
            'connect-many-products-dialog': {
334
                cronExportAll: me.cronExportAll
335
            },
336
            'connect-stream-export-progress-window': {
337
                startStreamExport: me.startStreamExport
338
            },
339
            'connect-export-stream button[action=add]': {
340
                click: me.onExportStream
341
            },
342
343
            'connect-export-stream button[action=remove]': {
344
                click: me.onRemoveStreams
345
            },
346
            'connect-config-export-form': {
347
                saveExportSettings: me.onSaveExportSettingsForm,
348
                collectPriceParams: me.collectPriceParams,
349
                rejectPriceConfigChanges: me.rejectPriceConfigChanges
350
351
            },
352
353
            'connect-export-filter button[action=category-clear-filter]': {
354
                click: me.onExportCategoryFilterClearAction
355
            },
356
            'connect-export-filter textfield[name=searchfield]': {
357
                change: function(field, value) {
358
                    var table = me.getExportList(),
359
                        store = table.getStore();
360
                    store.filters.removeAtKey('search');
361
                    if (value.length > 0 ) {
362
                        store.filters.add('search', new Ext.util.Filter({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
363
                            property: 'search',
364
                            value: '%' + value + '%'
365
                        }));
366
                    }
367
                    store.load({
368
                        page: 1,
369
                        start: 0
370
                    });
371
                    store.currentPage = 1;
372
                }
373
            },
374
375
            'connect-export-filter [name=supplierId]': {
376
                change: function(field, value) {
377
                    var table = me.getExportList(),
378
                        store = table.getStore();
379
380
                    store.filters.removeAtKey('supplierId');
381
                    if (value) {
382
                        store.filters.add('supplierId', new Ext.util.Filter({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
383
                            property: field.name,
384
                            value: value
385
                        }));
386
                    }
387
                    store.load({
388
                        page: 1,
389
                        start: 0
390
                    });
391
                    store.currentPage = 1;
392
                }
393
            },
394
            'connect-export-filter [name=exportStatus]': {
395
                change: function(field, value) {
396
                    var table = me.getExportList(),
397
                        store = table.getStore();
398
                    if(!value) {
399
                        return;
400
                    }
401
                    store.filters.removeAtKey('exportStatus');
402
                    if(field.inputValue != '') {
403
                        store.filters.add('exportStatus', new Ext.util.Filter({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
404
                            property: field.name,
405
                            value: field.inputValue
406
                        }));
407
                    }
408
                    store.load({
409
                        page: 1,
410
                        start: 0
411
                    });
412
                    store.currentPage = 1;
413
                }
414
            },
415
            'connect-export-filter treepanel': {
416
                select: function(tree, node) {
417
                    var table = me.getExportList(),
418
                        store = table.getStore();
419
420
                    if (!node) {
421
                        store.filters.removeAtKey('exportCategoryFilter');
422
                    } else {
423
                        store.filters.removeAtKey('exportCategoryFilter');
424
                        store.filters.add('exportCategoryFilter', new Ext.util.Filter({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
425
                            property: 'categoryId',
426
                            value:  node.get('id')
427
                        }));
428
                    }
429
                    store.load({
430
                        page: 1,
431
                        start: 0
432
                    });
433
                    store.currentPage = 1;
434
                }
435
            },
436
            'connect-changed-products-list': {
437
                'selectionchange': me.onChangedProductsSelectionChanged
438
            },
439
            'connect-log-filter [filter=commandFilter]': {
440
                change: function(field, value) {
441
                    var table = me.getLogList(),
442
                        store = table.getStore();
443
444
                    store.getProxy().extraParams['commandFilter_' + field.name] = value;
445
                    store.reload();
446
                }
447
            },
448
            'connect-log-filter [name=error]': {
449
                change: function(field, value) {
450
                    var table = me.getLogList(),
451
                        store = table.getStore();
452
453
                    if (!value) {
454
                        return;
455
                    }
456
457
                    store.getProxy().extraParams.errorFilter = field.inputValue;
458
                    store.reload();
459
                }
460
            },
461
            'connect-log-filter textfield[name=searchfield]': {
462
                change: function(field, value) {
463
                    var table = me.getLogList(),
464
                        store = table.getStore();
465
466
                    if (value.length === 0 ) {
467
                        store.clearFilter();
468
                    } else {
469
                        store.filters.clear();
470
                        store.filter(
471
                            'search',
472
                            '%' + value + '%'
473
                        );
474
                    }
475
                }
476
            },
477
            'connect-log-list': {
478
                changeLogging: me.onChangeLogging,
479
                'selectionchange': function(grid, selected, eOpts) {
0 ignored issues
show
Unused Code introduced by
The parameter eOpts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
480
                    var me = this,
481
                        record,
482
                        tabs = me.getLogTabs(),
483
                        request = tabs.down('textarea[name=request]'),
484
                        response = tabs.down('textarea[name=response]');
485
486
                    // make sure that we have a selection
487
                    if (selected && selected.length > 0) {
488
                        record = selected[0];
489
490
                        request.setValue(record.get('request'));
491
                        response.setValue(record.get('response'));
492
                    }
493
494
                }
495
            },
496
            'connect-export-window': {
497
                showPriceWindow: me.onShowPriceWindow
498
            },
499
500
            'connect-export-list': {
501
                getExportStatus: me.onGetExportStatus,
502
                reloadLocalProducts: me.onGetExportStatus
503
            },
504
505
            'connect-log-list button[action=clear]': {
506
                click: function() {
507
                    var table = me.getLogList(),
508
                        store = table.getStore();
509
510
                    Ext.MessageBox.confirm(
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
511
                        '{s name=log/clear/confirm}Delete log?{/s}',
512
                        '{s name=log/clear/message}You are about to delete all log entries. Continue?{/s}',
513
                        function (response) {
514
                            if ( response !== 'yes' ) {
515
                                return;
516
                            }
517
                            Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
518
                                url: '{url action=clearLog}',
519
                                method: 'POST',
520
                                success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter response is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
521
                                    store.reload();
522
                                }
523
                            });
524
525
                        }
526
                    );
527
                }
528
            },
529
            'connect-marketplace-attributes-mapping button[action=save]': {
530
                click: function () {
531
                    me.saveMarketplaceAttributesMapping();
532
                }
533
            }
534
        });
535
536
        Shopware.app.Application.on(me.getEventListeners());
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
537
    },
538
539
    getEventListeners: function() {
540
        var me = this;
541
542
        return {
543
            'connect-login': me.login,
544
            'connect-register': me.register,
545
            scope: me
546
        };
547
    },
548
549
    sendAjaxRequest: function(url, params, callback, errorCallback) {
550
        var me = this;
551
552
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
553
            url: url,
554
            method: 'POST',
555
            params: params,
556
            success: function(operation, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
557
                var response = Ext.decode(operation.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
558
559
                if (response.success === false) {
560
                    if (Ext.isFunction(errorCallback)) {
561
                        errorCallback(response);
562
                    } else {
563
                        me.displayErrorMessage(response);
564
                        me.hideLoadingMask();
565
                    }
566
                    return;
567
                }
568
569
                callback(response);
570
            }
571
        });
572
    },
573
574
    login: function(params, callback) {
575
        var me = this;
576
577
        me.splashScreen = Ext.Msg.wait(
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
578
            me.messages.login.waitMessage,
579
            me.messages.login.waitTitle
580
        );
581
582
        me.sendAjaxRequest(
583
            '{url controller=Connect action=login}',
584
            params,
585
            function(response) {
586
587
                response.shopwareId = params.shopwareID;
588
                me.splashScreen.close();
589
590
                if (response.success == true) {
591
                    Ext.create('Shopware.notification.SubscriptionWarning').checkSecret();
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
592
593
                    Shopware.Notification.createGrowlMessage(
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
594
                        me.messages.login.successTitle,
595
                        me.messages.login.successMessage,
596
                        me.messages.growlMessage
597
                    );
598
599
                    if (callback && typeof callback === 'function') {
600
                        callback(response);
601
                    }
602
603
                    document.cookie = 'connectLogin=true';
604
                    location.reload();
605
                }
606
            },
607
            function(response) {
608
                me.splashScreen.close();
609
                me.displayErrorMessage(response, callback);
610
            }
611
        );
612
    },
613
614
    register: function(params, callback) {
615
        var me = this;
616
617
        me.splashScreen = Ext.Msg.wait(
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
618
            me.messages.login.waitMessage,
619
            me.messages.login.waitTitle
620
        );
621
622
        me.sendAjaxRequest(
623
            '{url controller=Connect action=register}',
624
            params,
625
            function(response) {
626
627
                response.shopwareId = params.shopwareID;
628
                me.splashScreen.close();
629
630
                if (response.success == true) {
631
                    Ext.create('Shopware.notification.SubscriptionWarning').checkSecret();
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
632
633
                    Shopware.Notification.createGrowlMessage(
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
634
                        me.messages.login.successTitle,
635
                        me.messages.login.successMessage,
636
                        me.messages.growlMessage
637
                    );
638
639
                    if (callback && typeof callback === 'function') {
640
                        callback(response);
641
                    }
642
643
                    document.cookie = 'connectLogin=true';
644
                    location.reload();
645
                }
646
            },
647
            function(response) {
648
                me.splashScreen.close();
649
                me.displayErrorMessage(response, callback);
650
            }
651
        );
652
    },
653
654
    displayErrorMessage: function(response, callback) {
655
        var me = this,
656
            message = response.message;
657
658
        Shopware.Notification.createStickyGrowlMessage({
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
659
            title: me.messages.error,
660
            text: message,
661
            width: 350
662
        });
663
664
        callback = typeof callback === 'function' && callback || function() {};
665
666
        if (response.hasOwnProperty('authentication') && response.authentication) {
667
            Shopware.app.Application.fireEvent('open-login', callback);
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
668
        }
669
670
        this.hideLoadingMask();
671
    },
672
673
    /**
674
     * Dynamically create filter fields for all known command types
675
     */
676
    populateLogCommandFilter: function() {
677
        var me = this,
678
            logList = me.getLogList(),
679
            store = logList.store,
680
            container = me.getLogFilter().down('fieldcontainer');
681
682
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
683
            url: '{url action=getLogCommands}',
684
            method: 'POST',
685
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
686
                var data;
687
688
                if (!response || !response.responseText) {
689
                    return;
690
                }
691
692
                data = Ext.JSON.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
693
694
                Ext.each(data.data, function(command) {
695
                    store.getProxy().extraParams['commandFilter_' + command] = true;
696
                    container.add({
697
                        boxLabel  : command,
698
                        name      : command,
699
                        inputValue:  true,
700
                        checked   :  true,
701
                        filter    : 'commandFilter'
702
                    });
703
                });
704
705
                store.reload();
706
            },
707
            failure: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
708
                Shopware.Notification.createGrowlMessage('{s name=connect/error}Error{/s}', response.responseText);
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
709
            }
710
711
        });
712
713
    },
714
715
    /**
716
     * Method called when clear category button is clicked.
717
     */
718
    onExportCategoryFilterClearAction: function() {
719
        var me = this;
720
721
        var table = me.getExportList(),
722
            filter = me.getExportFilter(),
0 ignored issues
show
Unused Code introduced by
The variable filter seems to be never used. Consider removing it.
Loading history...
723
            store = table.getStore();
724
        store.filters.removeAtKey('exportCategoryFilter');
725
        store.load();
726
727
        //deselect all nodes
728
        Ext.getCmp('export-category-filter').getSelectionModel().deselectAll();
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
729
    },
730
731
    /**
732
     * Callback method called when the user selects a product in the "changed products" view.
733
     * Will populate the bottom "change view" grid with the correct tabs
734
     *
735
     * @param grid
736
     * @param selected
737
     * @param eOpts
738
     */
739
    onChangedProductsSelectionChanged: function(grid, selected, eOpts) {
0 ignored issues
show
Unused Code introduced by
The parameter eOpts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
740
        var me = this,
741
            record,
742
            remoteChangeSet,
743
            changeRecord,
744
            changeFlag = 0, flags,
745
            changeView = me.getChangeView();
746
747
        // make sure that we have a selection
748
        if (selected && selected.length > 0) {
749
            record = selected[0];
750
751
            // Decode the lastUpdate info
752
            remoteChangeSet = Ext.JSON.decode(record.get('lastUpdate'));
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
753
754
            // Build a record for the changeset
755
            changeRecord = Ext.create('Shopware.apps.Connect.model.changed_products.Product', {
756
                shortDescriptionLocal: record.get('description'),
757
                shortDescriptionRemote: remoteChangeSet['shortDescription'],
758
759
                longDescriptionLocal: record.get('descriptionLong'),
760
                longDescriptionRemote: remoteChangeSet['longDescription'],
761
762
                additionalDescriptionLocal: record.get('additionalDescription'),
763
                additionalDescriptionRemote: remoteChangeSet['additionalDescription'],
764
765
                nameLocal: record.get('name'),
766
                nameRemote: remoteChangeSet['name'],
767
768
                priceLocal: record.get('price'),
769
                priceRemote: remoteChangeSet['price'],
770
771
                imageLocal: record.get('images'),
772
                imageRemote: remoteChangeSet['image'].join('|')
773
            });
774
775
            // Read updateFlag and build update flag object
776
            changeFlag = record.get('lastUpdateFlag');
777
            flags = {
778
                2: 'shortDescription',
779
                4: 'longDescription',
780
                8: 'name',
781
                16: 'image',
782
                32: 'price',
783
                64: 'imageInitialImport',
784
                128: 'additionalDescription'
785
            };
786
            // Check all flags and show the corresponding tab if it is active
787
            // if not, remove the tab without destroying the component
788
            changeView.removeAll();
789
790
            Ext.each(Object.keys(flags), function(key) {
791
                var fieldName = flags[key];
792
                if (changeFlag & key) {
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
793
                    var form = changeView.createContainer(fieldName);
794
                    form.loadRecord(changeRecord);
795
                    changeView.add(form);
796
                    form.applyButton.handler = function () {
797
                        me.applyChanges(fieldName, changeRecord.get(fieldName + 'Remote'), record.get('id'), changeView);
798
                    }
799
                }
800
            });
801
802
            changeView.setTitle(record.get('name'));
803
            changeView.setActiveTab(0);
804
        }
805
    },
806
807
    /**
808
     * Callback to apply a given change for a given product
809
     *
810
     * @param type
811
     * @param value
812
     * @param detailId
813
     * @param changeView
814
     */
815
    applyChanges: function(type, value, detailId, changeView) {
816
        var me = this,
817
            changedProductsList = me.getChangedList(),
818
            store = changedProductsList.store;
819
820
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
821
            url: '{url controller=LastChanges action=applyChanges}',
822
            method: 'POST',
823
            params: {
824
                type: type,
825
                value: value,
826
                detailId: detailId
827
            },
828
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
829
                var responseObject = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
830
                if (responseObject.success) {
831
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=changed_products/success/notification/message}Successfully applied changes{/s}');
832
                } else {
833
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', responseObject.message);
834
                }
835
836
                store.reload();
837
                changeView.removeAll();
838
            },
839
            failure: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
840
                me.createGrowlMessage('{s name=connect/error}Error{/s}', response.responseText);
841
            }
842
843
        });
844
845
    },
846
847
    /**
848
     * Callback function that will insert from/for export
849
     *
850
     * @param btn
851
     */
852
    onExportAction: function(btn) {
0 ignored issues
show
Unused Code introduced by
The parameter btn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
853
        var me = this,
854
            list = me.getExportList(),
855
            records = list.selModel.getSelection(),
856
            ids = [],
857
            title = me.messages.insertOrUpdateProductTitle;
858
859
        if (records.length == 0) {
860
            return;
861
        }
862
863
        Ext.each(records, function(record) {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
864
            ids.push(record.get('id'));
865
        });
866
867
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
868
            url: '{url action=getArticleSourceIds}',
869
            method: 'POST',
870
            params: {
871
                'ids[]': ids
872
            },
873
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
874
                if (response.responseText) {
875
                    var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
876
                    if (operation) {
877
                        if (!operation.success) {
878
                            me.createGrowlMessage(title, operation.message, true);
879
                        } else {
880
                            Ext.create('Shopware.apps.Connect.view.export.product.Progress', {
881
                                sourceIds: operation.sourceIds
882
                            }).show();
883
                        }
884
                    }
885
                }
886
            }
887
        });
888
    },
889
890
    /**
891
     * Callback function that will insert from/for export
892
     *
893
     * @param sourceIds
894
     * @param batchSize
895
     * @param window
896
     * @param offset
897
     */
898
    startArticleExport: function(sourceIds, batchSize, window, offset) {
899
        offset = parseInt(offset) || 0;
900
        var limit = offset + batchSize;
901
902
        if (limit > sourceIds.length) {
903
            limit = sourceIds.length;
904
        }
905
906
        var me = this,
907
        message = me.messages.insertOrUpdateProductMessage,
908
        title = me.messages.insertOrUpdateProductTitle,
909
        list = me.getExportList();
910
911
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
912
            url: '{url action=insertOrUpdateProduct}',
913
            method: 'POST',
914
            params: {
915
                'sourceIds[]': sourceIds.slice(offset, limit)
916
            },
917
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
918
                var doneDetails = limit;
919
                var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
920
921
                if (!operation.success && operation.messages) {
922
923
                    if(operation.messages.price && operation.messages.price.length > 0){
924
                        var priceMsg = Ext.String.format(
925
                            me.messages.priceErrorMessage, operation.messages.price.length, sourceIds.length
926
                        );
927
                        me.createGrowlMessage(title, priceMsg, true);
928
                    }
929
930
                    if(operation.messages.default && operation.messages.default.length > 0){
931
                        operation.messages.default.forEach( function(message){
932
                            me.createGrowlMessage(title, message, true);
933
                        });
934
                    }
935
                }
936
937
                window.progressField.updateText(Ext.String.format(window.snippets.process, doneDetails, sourceIds.length));
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
938
                window.progressField.updateProgress(
939
                    limit / sourceIds.length,
940
                    Ext.String.format(window.snippets.process, doneDetails, sourceIds.length),
941
                    true
942
                );
943
944
                if (limit >= sourceIds.length) {
945
                    window.closeWindow();
946
                    me.createGrowlMessage(title, message, false);
947
                    list.store.load();
948
                    me.onGetExportStatus();
949
                } else {
950
                    //otherwise we have to call this function recursive with the next offset
951
                    me.startArticleExport(sourceIds, batchSize, window, limit);
952
                }
953
            },
954
            failure: function(operation) {
955
                me.createGrowlMessage(title, operation.responseText, true);
956
                window.inProcess = false;
957
                window.cancelButton.setDisabled(false);
958
            }
959
        });
960
    },
961
962
    cronExportAll: function () {
963
        var me = this;
964
965
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
966
            url: '{url action=exportAllWithCron}',
967
            method: 'POST',
968
969
            success: function (response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
970
                var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
971
                if (operation.success) {
972
                    me.createGrowlMessage("{s name=connect/success}Success{/s}", me.messages.allProductsMarkedForExportWithCron, true);
973
                    me.getExportList().getStore().reload();
974
                } else {
975
                    me.createGrowlMessage("{s name=connect/error}Error{/s}", operation.message, true);
976
                }
977
            }
978
        });
979
    },
980
981
    startStreamExport: function(streamIds, sourceIdCount, batchSize, window, currentStreamIndex, offset) {
982
        offset = parseInt(offset) || 0;
983
        var limit = batchSize;
984
985
        var me = this,
986
            list = me.getExportStreamList();
987
988
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
989
            url: '{url action=exportStream}',
990
            method: 'POST',
991
            params: {
992
                'offset': offset,
993
                'limit': limit,
994
                'streamIds[]': streamIds,
995
                'currentStreamIndex': currentStreamIndex
996
            },
997
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
998
                var sticky = false;
999
                if (response.responseText) {
1000
                    var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1001
                    if (operation) {
1002
                        if (!operation.success && operation.messages) {
1003
                            if(operation.messages.price && operation.messages.price.length > 0){
1004
                                var priceMsg = Ext.String.format(
1005
                                    me.messages.priceErrorMessage, operation.messages.price.length, sourceIdCount
1006
                                );
1007
                                me.createGrowlMessage(me.messages.exportStreamTitle, priceMsg, true);
1008
                            }
1009
1010
                            if(operation.messages.default && operation.messages.default.length > 0){
1011
                                operation.messages.default.forEach( function(message){
1012
                                    me.createGrowlMessage(me.messages.exportStreamTitle, message, true);
1013
                                });
1014
                            }
1015
1016
                            window.inProcess = false;
1017
                            window.cancelButton.setDisabled(false);
1018
                            return;
1019
                        }
1020
1021
                        window.progressFieldStream.updateText(Ext.String.format(window.snippets.processStream, operation.processedStreams, streamIds.length));
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1022
                        window.progressFieldStream.updateProgress(
1023
                            operation.processedStreams / streamIds.length,
1024
                            Ext.String.format(window.snippets.processStream, operation.processedStreams, streamIds.length),
1025
                            false
1026
                        );
1027
1028
                        window.progressField.updateText(Ext.String.format(window.snippets.process, operation.newOffset, sourceIdCount));
1029
                        window.progressField.updateProgress(
1030
                            operation.newOffset / sourceIdCount,
1031
                            Ext.String.format(window.snippets.process, operation.newOffset, sourceIdCount),
1032
                            false
1033
                        );
1034
1035
                        if (operation.hasMoreIterations) {
1036
                            currentStreamIndex = operation.nextStreamIndex;
1037
                            offset = operation.newOffset;
1038
                            me.startStreamExport(streamIds, sourceIdCount, batchSize, window, currentStreamIndex, offset);
1039
                        } else {
1040
                            window.inProcess = false;
1041
                            window.cancelButton.setDisabled(false);
1042
1043
                            me.createGrowlMessage(me.messages.exportStreamTitle, me.messages.exportStreamMessage, sticky);
1044
1045
                            list.setLoading(false);
1046
                            list.store.load();
1047
                        }
1048
                    }
1049
                }
1050
            }
1051
        });
1052
    },
1053
1054
    /**
1055
     * Callback function that will start the export all dialog
1056
     *
1057
     * @param btn
1058
     */
1059
    onExportAllAction: function (btn) {
0 ignored issues
show
Unused Code introduced by
The parameter btn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1060
        var me = this,
1061
            list = me.getExportList(),
1062
            title = me.messages.insertOrUpdateProductTitle;
1063
1064
        list.setLoading(true);
1065
1066
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1067
            url: '{url action=getArticleSourceIds}',
1068
            method: 'POST',
1069
            params: {
1070
                'exportAll': true
1071
            },
1072
            success: function (response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1073
                list.setLoading(false);
1074
1075
                if (!response.responseText) {
1076
                    return;
1077
                }
1078
1079
                var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1080
                if (!operation) {
1081
                    return;
1082
                }
1083
1084
                if (!operation.success) {
1085
                    me.createGrowlMessage(title, operation.message, true);
1086
                } else {
1087
                    if (operation.sourceIds.length > 1000) {
1088
1089
                        Ext.create('Shopware.apps.Connect.view.export.product.manyProductsDialog', {
1090
                            sourceIds: operation.sourceIds
1091
                        }).show();
1092
                        return;
1093
                    }
1094
1095
                    Ext.create('Shopware.apps.Connect.view.export.product.Progress', {
1096
                        sourceIds: operation.sourceIds
1097
                    }).show();
1098
                }
1099
            }
1100
        });
1101
    },
1102
1103
    /**
1104
     * Callback function that will delete a product from/for export
1105
     *
1106
     * @param btn
1107
     */
1108
    onRemoveArticleAction: function(btn) {
0 ignored issues
show
Unused Code introduced by
The parameter btn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1109
        var me = this,
1110
            list = me.getExportList(),
1111
            records = list.selModel.getSelection(),
1112
            ids = [],
1113
            messages = [];
1114
1115
        Ext.each(records, function(record) {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1116
            ids.push(record.get('id'));
1117
        });
1118
1119
        list.setLoading();
1120
1121
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1122
            url: '{url action=deleteProduct}',
1123
            method: 'POST',
1124
            params: {
1125
                'ids[]': ids
1126
            },
1127
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1128
                var sticky = false;
1129
                if (response.responseText) {
1130
                    var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1131
                    if (operation) {
1132
                        if (!operation.success && operation.messages) {
1133
                            messages = operation.messages;
1134
                            sticky = true;
1135
                        }
1136
                    }
1137
                }
1138
                if (messages.length > 0) {
1139
                    messages.forEach( function(message){
1140
                        me.createGrowlMessage(me.messages.deleteProductTitle, message, sticky);
1141
                    });
1142
                } else {
1143
                    me.createGrowlMessage(me.messages.deleteProductTitle, me.messages.deleteProductMessage, sticky);
1144
                }
1145
1146
                list.setLoading(false);
1147
                list.store.load();
1148
            }
1149
        });
1150
    },
1151
1152
    /**
1153
     * Callback function that will export or delete a product stream from/for export
1154
     *
1155
     * @param btn
1156
     */
1157
    onExportStream: function(btn){
0 ignored issues
show
Unused Code introduced by
The parameter btn is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1158
        var me = this,
1159
            list = me.getExportStreamList(),
1160
            records = list.selModel.getSelection(),
1161
            staticStreamIds = [],
1162
            dynamicStreamIds = [];
1163
1164
        if (records.length == 0) {
1165
            return;
1166
        }
1167
1168
        Ext.each(records, function(record) {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1169
            if (record.get('type') == 1) {
1170
                dynamicStreamIds.push(record.get('id'));
1171
            } else {
1172
                staticStreamIds.push(record.get('id'));
1173
            }
1174
        });
1175
        if (dynamicStreamIds.length > 0) {
1176
            me.prepareDynamicStreamExport(dynamicStreamIds);
1177
        }
1178
1179
        if (staticStreamIds.length > 0) {
1180
            me.prepareStaticStreamExport(staticStreamIds);
1181
        }
1182
1183
    },
1184
1185
    prepareDynamicStreamExport: function(ids){
1186
        var me = this,
1187
            list = me.getExportStreamList(),
1188
            store = list.store,
1189
            title = me.messages.exportStreamTitle;
1190
1191
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1192
            url: '{url action=prepareDynamicStreams}',
1193
            method: 'POST',
1194
            params: {
1195
                'streamIds[]': ids
1196
            },
1197
            success: function(response) {
1198
                if (response.responseText) {
1199
                    var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1200
1201
                    if (!operation) {
1202
                        return;
1203
                    }
1204
1205
                    if (!operation.success) {
1206
                        me.createGrowlMessage(title, operation.messages, false);
1207
                        return;
1208
                    }
1209
1210
                    me.createGrowlMessage(title, me.messages.exportDynamicStreamMessage, false);
1211
                    store.reload();
1212
                }
1213
            }
1214
        });
1215
    },
1216
1217
    /**
1218
     * @param ids
1219
     */
1220
    prepareStaticStreamExport: function(ids){
1221
        var me = this;
1222
1223
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1224
            url: '{url action=getStreamProductsCount}',
1225
            method: 'POST',
1226
            params: {
1227
                'ids[]': ids
1228
            },
1229
            success: function(response) {
1230
                if (response.responseText) {
1231
                    var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1232
1233
                    if (!operation) {
1234
                        return;
1235
                    }
1236
1237
                    if (!operation.success) {
1238
                        var title = me.messages.exportStreamTitle,
1239
                            messages = operation.messages;
1240
1241
                        //todo: handle price and default errors
1242
                        if (messages.default.length > 0) {
1243
                            messages.default.forEach(function (message) {
1244
                                me.createGrowlMessage(title, message, false);
1245
                            });
1246
                        }
1247
                    } else {
1248
                        Ext.create('Shopware.apps.Connect.view.export.stream.Progress', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1249
                            streamIds: ids,
1250
                            sourceIdsCount: operation.sourceIdsCount
1251
                        }).show();
1252
                    }
1253
                }
1254
            }
1255
        });
1256
    },
1257
1258
    onRemoveStreams: function(){
1259
        var me = this,
1260
            list = me.getExportStreamList(),
1261
            records = list.selModel.getSelection(),
1262
            ids = [],
1263
            url,
1264
            message,
1265
            messages = [],
1266
            title;
1267
1268
        if (records.length == 0) {
1269
            return;
1270
        }
1271
1272
        Ext.each(records, function(record) {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1273
            ids.push(record.get('id'));
1274
        });
1275
1276
        url = '{url action=removeStreams}';
1277
        title = me.messages.removeStreamTitle;
1278
        message = me.messages.removeStreamMessage;
1279
1280
        list.setLoading();
1281
1282
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1283
            url: url,
1284
            method: 'POST',
1285
            params: {
1286
                'ids[]': ids
1287
            },
1288
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1289
                var sticky = false;
1290
                if (response.responseText) {
1291
                    var operation = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1292
                    if (operation) {
1293
                        if (!operation.success && operation.messages) {
1294
                            messages = operation.messages;
1295
                            sticky = true;
1296
                        }
1297
                    }
1298
                }
1299
1300
                if (messages.length > 0) {
1301
                    messages.forEach( function(message){
1302
                        me.createGrowlMessage(title, message, sticky);
1303
                    });
1304
                } else {
1305
                    me.createGrowlMessage(title, message, sticky);
1306
                }
1307
1308
                list.setLoading(false);
1309
                list.store.load();
1310
            }
1311
        });
1312
    },
1313
1314
    /**
1315
     * Helper to show a growl message
1316
     *
1317
     * @param title
1318
     * @param message
1319
     */
1320
    createGrowlMessage: function(title, message, sticky) {
1321
        var me = this;
1322
1323
        if (!sticky) {
1324
            Shopware.Notification.createGrowlMessage(title, message, me.mainWindow.title);
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1325
        } else {
1326
            Shopware.Notification.createStickyGrowlMessage({
1327
                title: title,
1328
                text: message,
1329
                width: 400
1330
            });
1331
        }
1332
    },
1333
1334
    /**
1335
     * Callback function to set the window title depending on the current navigation entry
1336
     *
1337
     * @param tree
1338
     * @param node
1339
     */
1340
    onSelectNavigationEntry: function(tree, node) {
1341
        var me = this,
1342
            panel = me.getPanel(),
1343
            win = me.getWindow(),
1344
            item = node.get('id'),
1345
            layout = panel.getLayout();
1346
1347
        layout.setActiveItem(item);
1348
        win.loadTitle(node);
1349
    },
1350
1351
    /**
1352
     * Callback function to save the configuration form
1353
     *
1354
     * @param button
0 ignored issues
show
Documentation introduced by
The parameter button does not exist. Did you maybe forget to remove this comment?
Loading history...
1355
     */
1356
    onSaveConfigForm: function(btn) {
1357
        var me = this;
0 ignored issues
show
Unused Code introduced by
The variable me seems to be never used. Consider removing it.
Loading history...
1358
            form = btn.up('form');
0 ignored issues
show
Bug introduced by
The variable form seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.form.
Loading history...
1359
1360
        form.setLoading();
1361
1362
        if (form.getRecord()) {
1363
            var model = form.getRecord();
1364
1365
            form.getForm().updateRecord(model);
1366
            model.save({
1367
                success: function(record) {
0 ignored issues
show
Unused Code introduced by
The parameter record is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1368
                    form.setLoading(false);
1369
                    Shopware.Notification.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1370
                },
1371
                failure: function(record) {
1372
                    form.setLoading(false);
1373
                    var rawData = record.getProxy().getReader().rawData,
1374
                        message = rawData.message;
1375
                    Shopware.Notification.createGrowlMessage('{s name=connect/error}Error{/s}', message);
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1376
                }
1377
            });
1378
        }
1379
    },
1380
1381
    /**
1382
     * Callback function to save the import configuration form
1383
     *
1384
     * @param button
0 ignored issues
show
Documentation introduced by
The parameter button does not exist. Did you maybe forget to remove this comment?
Loading history...
1385
     */
1386
    onSaveImportConfigForm: function(btn) {
1387
        var me = this,
1388
            form = btn.up('form');
1389
1390
        form.setLoading();
1391
        if (form.getRecord()) {
1392
            var model = form.getRecord();
1393
1394
            form.getForm().updateRecord(model);
1395
            model.save({
1396
                success: function(record) {
0 ignored issues
show
Unused Code introduced by
The parameter record is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1397
                    form.setLoading(false);
1398
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1399
                },
1400
                failure: function(record) {
1401
                    form.setLoading(false);
1402
                    var rawData = record.getProxy().getReader().rawData,
1403
                        message = rawData.message;
0 ignored issues
show
Unused Code introduced by
The assignment to variable message seems to be never used. Consider removing it.
Loading history...
1404
                    Shopware.Notification.createGrowlMessage('{s name=connect/error}Error{/s}', response.responseText);
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable response seems to be never declared. If this is a global, consider adding a /** global: response */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1405
                }
1406
            });
1407
        }
1408
    },
1409
1410
    onSaveUnitsMapping: function(btn){
1411
        var me = this,
1412
            unitsStore = me.getUnitsMapping().getStore(),
1413
            form = btn.up('form');
1414
1415
        if (unitsStore.getModifiedRecords().length > 0){
1416
            form.setLoading();
1417
        }
1418
1419
        unitsStore.sync({
1420
            success :function (records, operation) {
0 ignored issues
show
Unused Code introduced by
The parameter records is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter operation is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1421
                form.setLoading(false);
1422
                me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1423
                me.getUnitsMapping().unitsStore.load({
1424
                    scope: this,
1425
                    callback: function(records, operation, success) {
0 ignored issues
show
Unused Code introduced by
The parameter success is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter operation is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter records is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1426
                        me.getUnitsMapping().getStore().reload();
1427
                    }
1428
                });
1429
            },
1430
            failure:function (batch) {
0 ignored issues
show
Unused Code introduced by
The parameter batch is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1431
                me.createGrowlMessage('{s name=connect/error}Error{/s}','{s name=config/units/error_save_message}Mapping der Einheiten konnte nicht gespeichert werden.{/s}');
1432
            }
1433
        });
1434
    },
1435
1436
    /**
1437
     * Reload Shopware Connect units store
1438
     * and show/hide already assigned units
1439
     */
1440
    onHideAssignedUnits: function(checkbox, value)
1441
    {
1442
        var me = this;
1443
        var store = me.getUnitsMapping().getStore();
1444
        var hideAssigned = 0;
1445
1446
        if (value === true) {
1447
            hideAssigned = 1;
1448
        }
1449
1450
        store.load({
1451
            params: {
1452
                'hideAssignedUnits': hideAssigned
1453
            }
1454
        });
1455
    },
1456
1457
    onAdoptUnits: function(btn) {
1458
        var me = this;
1459
        var form = btn.up('form');
1460
1461
        Ext.Msg.show({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1462
            title: me.messages.adoptUnitsTitle,
1463
            msg: me.messages.adoptUnitsMessage,
1464
            buttons: Ext.Msg.YESNO,
1465
            fn: function(response) {
1466
                if(response !== 'yes') {
1467
                    return;
1468
                }
1469
1470
                form.setLoading();
1471
                Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1472
                    url: '{url controller=ConnectConfig action=adoptUnits}',
1473
                    method: 'POST',
1474
                    success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1475
                        var responseObject = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1476
                        form.setLoading(false);
1477
                        if (responseObject.success) {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
1478
                        } else {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
1479
                        }
1480
                    }
1481
                });
1482
            }
1483
        });
1484
    },
1485
1486
    /**
1487
     * Callback function to save the export configuration form
1488
     *
1489
     * @param data
1490
     * @param btn
1491
     */
1492
    onSaveExportSettingsForm: function(data, btn) {
1493
        var me = this,
1494
            form = btn.up('form');
1495
1496
        var model = Ext.create('Shopware.apps.Connect.model.config.Export', data);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1497
1498
        if (data.exportPriceMode.length == 0) {
1499
            return me.createGrowlMessage(me.messages.exportTitle, me.messages.priceModeNotSelected);
1500
        }
1501
1502
        if (!data.hasOwnProperty('descriptionField') || data.descriptionField.length == 0) {
1503
            return me.createGrowlMessage(me.messages.exportTitle, me.messages.productDescriptionNotSelected);
1504
        }
1505
1506
        form.setLoading();
1507
        model.save({
1508
            success: function(record) {
0 ignored issues
show
Unused Code introduced by
The parameter record is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1509
                form.setLoading(false);
1510
                me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1511
1512
                if (me.hasOwnProperty('exportWindow') && me.exportWindow.isWindow) {
1513
                    var domEl = Ext.dom.Query.select('.export-window-wrapper');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1514
                    domEl[0].remove();
1515
                    me.exportWindow.close();
1516
                }
1517
            },
1518
            failure: function(record) {
1519
                form.setLoading(false);
1520
                var rawData = record.getProxy().getReader().rawData,
1521
                    message = rawData.message;
1522
                me.createGrowlMessage('{s name=connect/error}Error{/s}', message);
1523
            }
1524
        });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
1525
    },
1526
1527
    /**
1528
     * Sends marketplace attributes mapping to the PHP
1529
     */
1530
    saveMarketplaceAttributesMapping: function() {
1531
        var me = this,
1532
            panel = me.getMarketeplaceMappingPanel(),
1533
            store = me.getMarketeplaceMapping().localProductAttributesStore;
1534
1535
        if (store.getNewRecords().length > 0 || store.getUpdatedRecords().length > 0 || store.getRemovedRecords().length > 0) {
1536
            panel.setLoading();
1537
            store.sync({
1538
                success :function (records, operation) {
0 ignored issues
show
Unused Code introduced by
The parameter operation is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter records is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1539
                    panel.setLoading(false);
1540
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Änderungen erfolgreich übernommen{/s}');
1541
                },
1542
                failure:function (batch) {
1543
                    panel.setLoading(false);
1544
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', batch.proxy.getReader().jsonData.message);
1545
                }
1546
            });
1547
        }
1548
    },
1549
1550
    /**
1551
     * Calculate needed time to finish synchronization
1552
     *
1553
     * @param progressBar
1554
     */
1555
    onCalculateFinishTime: function(progressBar) {
1556
        var me = this;
1557
        me.time = 0;
1558
        me.resetSpentTime();
1559
1560
        Ext.TaskManager.start({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1561
            interval: 60000,
1562
            run: function() {
1563
                Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1564
                    url: '{url controller=ConnectConfig action=calculateFinishTime}',
1565
                    method: 'POST',
1566
                    success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1567
                        var responseObject = Ext.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1568
1569
                        if (responseObject.time > 0) {
1570
                            if ((responseObject.time - (me.time + me.spentTime)) == 0) {
1571
                                return;
1572
                            }
1573
                            me.time = responseObject.time;
1574
                            me.resetSpentTime();
1575
1576
                            var time = me.secondsToTime(me.time);
1577
                            progressBar.wait({
1578
                                interval: 500,
1579
                                increment: 15,
1580
                                scope: this
1581
                            });
1582
                            progressBar.updateText(me.messages.updatePartOneMessage + ' ' + time.h + ' ' + me.messages.hours + ' ' + time.m + ' ' + me.messages.minutes + ' ' + time.s + ' ' + me.messages.seconds + ' ' + me.messages.updatePartTwoMessage);
1583
                        } else {
1584
                            me.resetSpentTime();
1585
                            me.resetTime();
1586
                            progressBar.reset();
1587
                            progressBar.updateText(me.messages.doneMessage);
1588
                        }
1589
                    }
1590
                });
1591
            }
1592
        });
1593
1594
        Ext.TaskManager.start({
1595
            interval: 5000,
1596
            run: function () {
1597
                if (me.time >= 5) {
1598
                    me.time = me.time - 5;
1599
                    me.spentTime = me.spentTime + 5;
1600
                    var time = me.secondsToTime(me.time);
1601
                    progressBar.updateText(me.messages.updatePartOneMessage + ' ' + time.h + ' ' + me.messages.hours + ' ' + time.m + ' ' + me.messages.minutes + ' ' + time.s + ' ' + me.messages.seconds + ' ' + me.messages.updatePartTwoMessage);
1602
                } else {
1603
                    progressBar.reset();
1604
                    progressBar.updateText(me.messages.doneMessage);
1605
                }
1606
            }
1607
        });
1608
1609
    },
1610
1611
    onResetPriceType: function () {
1612
        var me = this;
1613
1614
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1615
            scope: this,
1616
            url: '{url module=backend controller=ConnectConfig action=resetPriceType}',
1617
            success: function (result) {
1618
                var response = Ext.JSON.decode(result.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1619
                if (response.success) {
1620
                    me.createGrowlMessage(
1621
                        me.messages.priceResetLabel,
1622
                        me.messages.priceResetSuccess
1623
                    );
1624
                } else {
1625
                    me.createGrowlMessage(
1626
                        me.messages.priceResetLabel,
1627
                        me.messages.priceResetError
1628
                    );
1629
                }
1630
            }
1631
        });
1632
    },
1633
1634
    onResetExchangeSettings: function () {
1635
        var me = this;
1636
1637
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1638
            scope: this,
1639
            url: '{url module=backend controller=ConnectConfig action=resetExchangeSettings}',
1640
            success: function (result) {
1641
                var response = Ext.JSON.decode(result.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1642
                if (response.success) {
1643
                    me.createGrowlMessage(
1644
                        me.messages.exchangeSettingsResetLabel,
1645
                        me.messages.exchangeSettingsResetSuccess
1646
                    );
1647
1648
                    //reload after 3 sec
1649
                    setTimeout(function(){
1650
                        location.reload();
1651
                    }, 3000);
1652
                } else {
1653
                    me.createGrowlMessage(
1654
                        me.messages.exchangeSettingsResetLabel,
1655
                        me.messages.exchangeSettingsResetError
1656
                    );
1657
                }
1658
            }
1659
        });
1660
    },
1661
1662
    onChangeLogging: function(checkbox, newValue, oldValue) {
0 ignored issues
show
Unused Code introduced by
The parameter oldValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1663
        var me = this;
1664
        var loggingEnabled = 0;
1665
        if (newValue === true) {
1666
            loggingEnabled = 1;
1667
        }
1668
1669
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1670
            url: '{url controller=ConnectConfig action=changeLogging}',
1671
            method: 'POST',
1672
            params: {
1673
                enableLogging: loggingEnabled
1674
            },
1675
            success: function(response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1676
                var data = Ext.JSON.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1677
                if (data.success == false) {
1678
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', '{s name=config/log_label}Logging aktivieren{/s}');
1679
                }
1680
            }
1681
        });
1682
    },
1683
1684
    onGetExportStatus: function() {
1685
        var me = this;
1686
1687
        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1688
            scope: me,
1689
            url: '{url controller=Connect action=getExportStatus}',
1690
            success: function (result) {
1691
                var response = Ext.JSON.decode(result.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1692
                if (response.success === true) {
1693
1694
                    //removes the old export status
1695
                    if (me.exportStatusEl) {
1696
                        Ext.destroy(me.exportStatusEl);
1697
                    }
1698
1699
                    //sets the new export status
1700
                    me.exportStatusEl = me.getExportWindow().getEl().insertHtml(
1701
                        "afterBegin",
1702
                        me.getHtmlStatus(response.data, response.total),
1703
                        true
1704
                    );
1705
                }
1706
            }
1707
        });
1708
    },
1709
1710
    getHtmlStatus: function ($start, $end) {
1711
        var me = this;
1712
1713
        return '<div class="sc-export-status">' +
1714
            Ext.String.format(me.messages.exportStatusCount, $start, $end) +
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1715
            '</div>';
1716
    },
1717
1718
1719
    /**
1720
     * On change customer group for price configuration
1721
     * reload the store with available price fields
1722
     *
1723
     * @param combo
1724
     * @param newValue
1725
     * @param oldValue
1726
     */
1727
    onChangePriceGroupForPrice: function(combo, newValue, oldValue) {
0 ignored issues
show
Unused Code introduced by
The parameter oldValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1728
        var me = this;
1729
        var exportConfigForm = me.getExportConfigForm();
1730
        exportConfigForm.setLoading(true);
1731
        exportConfigForm.priceFieldForPrice.store.load({
1732
            params: {
1733
                'customerGroup': newValue
1734
            },
1735
            callback: function() {
1736
                exportConfigForm.setLoading(false);
1737
            }
1738
        });
1739
    },
1740
1741
    /**
1742
     * On change customer group for purchase price configuration
1743
     * reload the store with available price fields
1744
     *
1745
     * @param combo
1746
     * @param newValue
1747
     * @param oldValue
1748
     */
1749
    onChangePriceGroupForPurchasePrice: function(combo, newValue, oldValue) {
0 ignored issues
show
Unused Code introduced by
The parameter oldValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1750
        var me = this;
1751
        var exportConfigForm = me.getExportConfigForm();
1752
        exportConfigForm.setLoading(true);
1753
        exportConfigForm.priceFieldForPurchasePrice.store.load({
1754
            params: {
1755
                'customerGroup': newValue
1756
            },
1757
            callback: function() {
1758
                exportConfigForm.setLoading(false);
1759
            }
1760
        });
1761
    },
1762
1763
    /**
1764
     * Checks price field selection, if it's not supported
1765
     * shows error message
1766
     *
1767
     * @param combo
1768
     * @param newValue
1769
     * @param oldValue
1770
     */
1771
    onChangePriceFieldForPurchasePrice: function(combo, newValue, oldValue) {
0 ignored issues
show
Unused Code introduced by
The parameter oldValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1772
        var me = this;
1773
1774
        var newRecord = combo.findRecordByValue(newValue);
1775
        if (newRecord && newRecord.get('available') === false) {
1776
            me.createGrowlMessage('{s name=connect/error}Error{/s}', me.messages.priceFieldIsNotSupported);
1777
        }
1778
    },
1779
1780
    /**
1781
     * Checks price field selection, if it's not supported
1782
     * shows error message
1783
     *
1784
     * @param combo
1785
     * @param newValue
1786
     * @param oldValue
1787
     */
1788
    onChangePriceFieldForPrice: function(combo, newValue, oldValue) {
0 ignored issues
show
Unused Code introduced by
The parameter oldValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1789
        var me = this;
1790
1791
        var newRecord = combo.findRecordByValue(newValue);
1792
        if (newRecord && newRecord.get('available') === false) {
1793
            me.createGrowlMessage('{s name=connect/error}Error{/s}', me.messages.priceFieldIsNotSupported);
1794
        }
1795
    },
1796
1797
    onShowPriceWindow: function() {
1798
        var me = this;
1799
1800
        me.customerGroupStore = Ext.create('Shopware.apps.Connect.store.config.CustomerGroup').load({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1801
            callback: function(){
1802
                me.exportWindow = me.getView('export.price.Window').create({
1803
                    customerGroupStore: me.customerGroupStore
1804
                }).show();
1805
            }
1806
        });
1807
    },
1808
1809
    /**
1810
     * Resets store
1811
     * @param column
1812
     */
1813
    rejectPriceConfigChanges: function (column) {
1814
        var tabs = column.up('panel').up('panel').items;
1815
1816
        tabs.each(function(tab){
1817
            tab.getStore().rejectChanges();
1818
        });
1819
    },
1820
1821
    /**
1822
     * Collects prices params from given tab panel
1823
     *
1824
     * @param tabPanel
1825
     * @param exportMode
1826
     * @param collection
1827
     */
1828
    collectPriceParams: function(tabPanel, exportMode, collection) {
1829
        var me = this,
0 ignored issues
show
Unused Code introduced by
The variable me seems to be never used. Consider removing it.
Loading history...
1830
            priceTypes = ['price', 'pseudoPrice', 'basePrice'],
1831
            exportPriceType;
1832
1833
        switch (exportMode) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1834
            case 'purchasePrice':
1835
                exportPriceType = 'ForPurchasePriceExport';
1836
                break;
1837
            case 'price':
1838
                exportPriceType = 'ForPriceExport';
1839
                break;
1840
        }
1841
1842
        tabPanel.items.each(function(tab) {
1843
            if (tab.getStore().getUpdatedRecords().length > 0) {
1844
                collection['priceGroup' + exportPriceType] = tab.customerGroup.get('key');
0 ignored issues
show
Bug introduced by
The variable exportPriceType seems to not be initialized for all possible execution paths.
Loading history...
1845
                collection.exportPriceMode.push(exportMode);
1846
1847
                for (var i = 0; i < priceTypes.length; i++){
1848
                    if (tab.getStore().getAt(0).get(priceTypes[i]) == true) {
1849
                        collection['priceField' + exportPriceType] = priceTypes[i];
1850
                    }
1851
                }
1852
            }
1853
        });
1854
    },
1855
1856
    /**
1857
     * Convert number of seconds into time object
1858
     *
1859
     * @param integer secs Number of seconds to convert
0 ignored issues
show
Documentation introduced by
The parameter integer does not exist. Did you maybe forget to remove this comment?
Loading history...
1860
     * @return object
1861
     */
1862
    secondsToTime: function (secs) {
1863
        var hours = parseInt( secs / 3600 ) % 24;
1864
        var minutes = parseInt( secs / 60 ) % 60;
1865
        var seconds = secs % 60;
1866
1867
        var obj = {
1868
            "h": hours,
1869
            "m": minutes,
1870
            "s": seconds
1871
        };
1872
        return obj;
1873
    },
1874
1875
    /**
1876
     * Reset spent time used for synchronization bar
1877
     */
1878
    resetSpentTime: function() {
1879
        var me = this;
1880
        me.spentTime = 0;
1881
    },
1882
1883
    /**
1884
     * Reset time used for synchronization bar
1885
     */
1886
    resetTime: function() {
1887
        var me = this;
1888
        me.time = 0;
1889
    }
1890
});
1891
//{/block}
1892