Completed
Pull Request — master (#399)
by Christian
03:10
created

ller.Mainꞌ).onExportAllAction   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 47
rs 9.0303
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B ion 0 31 6
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=Import action=connectCategoriesNeedRecovery}',
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.startRecoveryOfConnectCategories,
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
    /**
211
     * Recovers ConnectCategories in batch way and updates progress bar
212
     * @param window the progress window
213
     * Qparam totalCount Count of products
214
     * @param offset the actual offset
215
     */
216
    recoverConnectCategories: function (window, totalCount, offset) {
217
        offset = parseInt(offset) || 0;
218
        totalCount = parseInt(totalCount) || 0;
219
        var batchsize = 50;
220
        var articlesProcessed = offset + batchsize;
221
222
        var me = this,
223
            message = me.messages.migrationsMessage,
224
            title = me.messages.migrationsMessageTitle;
225
226
        window.inProcess = true;
227
228
        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...
229
            url: '{url action=applyConnectCategoriesRecovery}',
230
            method: 'POST',
231
            params: {
232
                'offset': offset,
233
                'batchsize': batchsize
234
            },
235
            success: function(response, opts) {
0 ignored issues
show
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...
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...
236
                var doneDetails = articlesProcessed;
237
238
                window.progressField.updateText(Ext.String.format(window.snippets.process, doneDetails, totalCount));
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...
239
                window.progressField.updateProgress(
240
                    articlesProcessed / totalCount,
241
                    Ext.String.format(window.snippets.process, doneDetails, totalCount),
242
                    true
243
                );
244
245
                if (articlesProcessed >= totalCount) {
246
                    me.createGrowlMessage(title, message, false);
247
                    me.mainWindow = me.getView('main.Window').create({
248
                        'action': me.subApplication.action
249
                    }).show();
250
                    window.closeWindow();
251
                } else {
252
                    //otherwise we have to call this function recursive with the next offset
253
                    me.recoverConnectCategories( window, totalCount, articlesProcessed);
254
                }
255
            },
256
            failure: function(operation) {
257
                me.createGrowlMessage(title, operation.responseText, true);
258
                window.inProcess = false;
259
            }
260
        });
261
    },
262
263
    /**
264
     * Callback function from messages box that asks the user wether he wants to start the migration
265
     * if 'yes' is clicked it starts the migration
266
     * @param buttonId
267
     * @param text
268
     * @param opt
269
     */
270
    startRecoveryOfConnectCategories: function(buttonId, text, opt) {
0 ignored issues
show
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...
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...
271
        var me = this;
272
        var totalCount = 0;
273
        if (buttonId === 'yes') {
274
            me.sendAjaxRequest(
275
                '{url controller=Import action=productCountForCategoryRecovery}',
276
                {},
277
                function(response) {
278
                    totalCount = response.data.totalCount;
279
                    me.mainWindow = me.getView('main.Progress').create().show();
280
                    me.mainWindow.progressField.updateText(Ext.String.format(me.mainWindow.snippets.process, 0, totalCount));
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...
281
                    me.recoverConnectCategories(me.mainWindow, totalCount);
282
                }
283
            );
284
        } else {
285
            me.mainWindow = me.getView('main.Window').create({
286
                'action': me.subApplication.action
287
            }).show();
288
        }
289
    },
290
291
    setEventListeners: function () {
292
        var me = this;
293
        me.control({
294
            'connect-navigation': {
295
                select: me.onSelectNavigationEntry
296
            },
297
            'connect-config button[action=save-general-config]': {
298
                click: me.onSaveConfigForm
299
            },
300
            'connect-config-form': {
301
                calculateFinishTime: me.onCalculateFinishTime,
302
                resetPriceType: me.onResetPriceType,
303
                resetExchangeSettings: me.onResetExchangeSettings
304
            },
305
            'connect-config-import-form button[action=save-import-config]': {
306
                click: me.onSaveImportConfigForm
307
            },
308
            'connect-import-unit button[action=save-unit]': {
309
                click: me.onSaveUnitsMapping
310
            },
311
            'connect-import-unit checkbox[name=hideAssignedUnits]': {
312
                change: me.onHideAssignedUnits
313
            },
314
            'connect-import-unit button[action=adoptUnits]': {
315
                click: me.onAdoptUnits
316
            },
317
            'connect-export-price-form': {
318
                saveExportSettings: me.onSaveExportSettingsForm,
319
                collectPriceParams: me.collectPriceParams,
320
                rejectPriceConfigChanges: me.rejectPriceConfigChanges
321
            },
322
            'connect-config-export-form combobox[name=priceGroupForPriceExport]': {
323
                change: me.onChangePriceGroupForPrice
324
            },
325
            'connect-config-export-form combobox[name=priceGroupForPurchasePriceExport]': {
326
                change: me.onChangePriceGroupForPurchasePrice
327
            },
328
            'connect-config-export-form combobox[name=priceFieldForPriceExport]': {
329
                change: me.onChangePriceFieldForPrice
330
            },
331
            'connect-config-export-form combobox[name=priceFieldForPurchasePriceExport]': {
332
                change: me.onChangePriceFieldForPurchasePrice
333
            },
334
            'connect-mapping button[action=save]': {
335
                click: me.onSaveMapping
336
            },
337
            'connect-export button[action=add]': {
338
                click: me.onExportAction
339
            },
340
            'connect-export button[action=delete]': {
341
                click: me.onRemoveArticleAction
342
            },
343
            'connect-export button[action=exportAll]': {
344
                click: me.onExportAllAction
345
            },
346
            'connect-article-export-progress-window': {
347
                startExport: me.startArticleExport,
348
                exportAll: me.exportAll
349
            },
350
            'connect-many-products-dialog': {
351
                cronExportAll: me.cronExportAll
352
            },
353
            'connect-stream-export-progress-window': {
354
                startStreamExport: me.startStreamExport
355
            },
356
            'connect-export-stream button[action=add]': {
357
                click: me.onExportStream
358
            },
359
360
            'connect-export-stream button[action=remove]': {
361
                click: me.onRemoveStreams
362
            },
363
            'connect-config-export-form': {
364
                saveExportSettings: me.onSaveExportSettingsForm,
365
                collectPriceParams: me.collectPriceParams,
366
                rejectPriceConfigChanges: me.rejectPriceConfigChanges
367
368
            },
369
370
            'connect-export-filter button[action=category-clear-filter]': {
371
                click: me.onExportCategoryFilterClearAction
372
            },
373
            'connect-export-filter textfield[name=searchfield]': {
374
                change: function(field, value) {
375
                    var table = me.getExportList(),
376
                        store = table.getStore();
377
                    store.filters.removeAtKey('search');
378
                    if (value.length > 0 ) {
379
                        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...
380
                            property: 'search',
381
                            value: '%' + value + '%'
382
                        }));
383
                    }
384
                    store.load({
385
                        page: 1,
386
                        start: 0
387
                    });
388
                    store.currentPage = 1;
389
                }
390
            },
391
392
            'connect-export-filter [name=supplierId]': {
393
                change: function(field, value) {
394
                    var table = me.getExportList(),
395
                        store = table.getStore();
396
397
                    store.filters.removeAtKey('supplierId');
398
                    if (value) {
399
                        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...
400
                            property: field.name,
401
                            value: value
402
                        }));
403
                    }
404
                    store.load({
405
                        page: 1,
406
                        start: 0
407
                    });
408
                    store.currentPage = 1;
409
                }
410
            },
411
            'connect-export-filter [name=exportStatus]': {
412
                change: function(field, value) {
413
                    var table = me.getExportList(),
414
                        store = table.getStore();
415
                    if(!value) {
416
                        return;
417
                    }
418
                    store.filters.removeAtKey('exportStatus');
419
                    if(field.inputValue != '') {
420
                        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...
421
                            property: field.name,
422
                            value: field.inputValue
423
                        }));
424
                    }
425
                    store.load({
426
                        page: 1,
427
                        start: 0
428
                    });
429
                    store.currentPage = 1;
430
                }
431
            },
432
            'connect-export-filter treepanel': {
433
                select: function(tree, node) {
434
                    var table = me.getExportList(),
435
                        store = table.getStore();
436
437
                    if (!node) {
438
                        store.filters.removeAtKey('exportCategoryFilter');
439
                    } else {
440
                        store.filters.removeAtKey('exportCategoryFilter');
441
                        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...
442
                            property: 'categoryId',
443
                            value:  node.get('id')
444
                        }));
445
                    }
446
                    store.load({
447
                        page: 1,
448
                        start: 0
449
                    });
450
                    store.currentPage = 1;
451
                }
452
            },
453
            'connect-changed-products-list': {
454
                'selectionchange': me.onChangedProductsSelectionChanged
455
            },
456
            'connect-log-filter [filter=commandFilter]': {
457
                change: function(field, value) {
458
                    var table = me.getLogList(),
459
                        store = table.getStore();
460
461
                    store.getProxy().extraParams['commandFilter_' + field.name] = value;
462
                    store.reload();
463
                }
464
            },
465
            'connect-log-filter [name=error]': {
466
                change: function(field, value) {
467
                    var table = me.getLogList(),
468
                        store = table.getStore();
469
470
                    if (!value) {
471
                        return;
472
                    }
473
474
                    store.getProxy().extraParams.errorFilter = field.inputValue;
475
                    store.reload();
476
                }
477
            },
478
            'connect-log-filter textfield[name=searchfield]': {
479
                change: function(field, value) {
480
                    var table = me.getLogList(),
481
                        store = table.getStore();
482
483
                    if (value.length === 0 ) {
484
                        store.clearFilter();
485
                    } else {
486
                        store.filters.clear();
487
                        store.filter(
488
                            'search',
489
                            '%' + value + '%'
490
                        );
491
                    }
492
                }
493
            },
494
            'connect-log-list': {
495
                changeLogging: me.onChangeLogging,
496
                '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...
497
                    var me = this,
498
                        record,
499
                        tabs = me.getLogTabs(),
500
                        request = tabs.down('textarea[name=request]'),
501
                        response = tabs.down('textarea[name=response]');
502
503
                    // make sure that we have a selection
504
                    if (selected && selected.length > 0) {
505
                        record = selected[0];
506
507
                        request.setValue(record.get('request'));
508
                        response.setValue(record.get('response'));
509
                    }
510
511
                }
512
            },
513
            'connect-export-window': {
514
                showPriceWindow: me.onShowPriceWindow
515
            },
516
517
            'connect-export-list': {
518
                getExportStatus: me.onGetExportStatus,
519
                reloadLocalProducts: me.onGetExportStatus
520
            },
521
522
            'connect-log-list button[action=clear]': {
523
                click: function() {
524
                    var table = me.getLogList(),
525
                        store = table.getStore();
526
527
                    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...
528
                        '{s name=log/clear/confirm}Delete log?{/s}',
529
                        '{s name=log/clear/message}You are about to delete all log entries. Continue?{/s}',
530
                        function (response) {
531
                            if ( response !== 'yes' ) {
532
                                return;
533
                            }
534
                            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...
535
                                url: '{url action=clearLog}',
536
                                method: 'POST',
537
                                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...
538
                                    store.reload();
539
                                }
540
                            });
541
542
                        }
543
                    );
544
                }
545
            },
546
            'connect-marketplace-attributes-mapping button[action=save]': {
547
                click: function () {
548
                    me.saveMarketplaceAttributesMapping();
549
                }
550
            }
551
        });
552
553
        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...
554
    },
555
556
    getEventListeners: function() {
557
        var me = this;
558
559
        return {
560
            'connect-login': me.login,
561
            'connect-register': me.register,
562
            scope: me
563
        };
564
    },
565
566
    sendAjaxRequest: function(url, params, callback, errorCallback) {
567
        var me = this;
568
569
        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...
570
            url: url,
571
            method: 'POST',
572
            params: params,
573
            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...
574
                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...
575
576
                if (response.success === false) {
577
                    if (Ext.isFunction(errorCallback)) {
578
                        errorCallback(response);
579
                    } else {
580
                        me.displayErrorMessage(response);
581
                        me.hideLoadingMask();
582
                    }
583
                    return;
584
                }
585
586
                callback(response);
587
            }
588
        });
589
    },
590
591
    login: function(params, callback) {
592
        var me = this;
593
594
        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...
595
            me.messages.login.waitMessage,
596
            me.messages.login.waitTitle
597
        );
598
599
        me.sendAjaxRequest(
600
            '{url controller=Connect action=login}',
601
            params,
602
            function(response) {
603
604
                response.shopwareId = params.shopwareID;
605
                me.splashScreen.close();
606
607
                if (response.success == true) {
608
                    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...
609
610
                    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...
611
                        me.messages.login.successTitle,
612
                        me.messages.login.successMessage,
613
                        me.messages.growlMessage
614
                    );
615
616
                    if (callback && typeof callback === 'function') {
617
                        callback(response);
618
                    }
619
620
                    document.cookie = 'connectLogin=true';
621
                    location.reload();
622
                }
623
            },
624
            function(response) {
625
                me.splashScreen.close();
626
                me.displayErrorMessage(response, callback);
627
            }
628
        );
629
    },
630
631
    register: function(params, callback) {
632
        var me = this;
633
634
        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...
635
            me.messages.login.waitMessage,
636
            me.messages.login.waitTitle
637
        );
638
639
        me.sendAjaxRequest(
640
            '{url controller=Connect action=register}',
641
            params,
642
            function(response) {
643
644
                response.shopwareId = params.shopwareID;
645
                me.splashScreen.close();
646
647
                if (response.success == true) {
648
                    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...
649
650
                    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...
651
                        me.messages.login.successTitle,
652
                        me.messages.login.successMessage,
653
                        me.messages.growlMessage
654
                    );
655
656
                    if (callback && typeof callback === 'function') {
657
                        callback(response);
658
                    }
659
660
                    document.cookie = 'connectLogin=true';
661
                    location.reload();
662
                }
663
            },
664
            function(response) {
665
                me.splashScreen.close();
666
                me.displayErrorMessage(response, callback);
667
            }
668
        );
669
    },
670
671
    displayErrorMessage: function(response, callback) {
672
        var me = this,
673
            message = response.message;
674
675
        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...
676
            title: me.messages.error,
677
            text: message,
678
            width: 350
679
        });
680
681
        callback = typeof callback === 'function' && callback || function() {};
682
683
        if (response.hasOwnProperty('authentication') && response.authentication) {
684
            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...
685
        }
686
687
        this.hideLoadingMask();
688
    },
689
690
    /**
691
     * Dynamically create filter fields for all known command types
692
     */
693
    populateLogCommandFilter: function() {
694
        var me = this,
695
            logList = me.getLogList(),
696
            store = logList.store,
697
            container = me.getLogFilter().down('fieldcontainer');
698
699
        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...
700
            url: '{url action=getLogCommands}',
701
            method: 'POST',
702
            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...
703
                var data;
704
705
                if (!response || !response.responseText) {
706
                    return;
707
                }
708
709
                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...
710
711
                Ext.each(data.data, function(command) {
712
                    store.getProxy().extraParams['commandFilter_' + command] = true;
713
                    container.add({
714
                        boxLabel  : command,
715
                        name      : command,
716
                        inputValue:  true,
717
                        checked   :  true,
718
                        filter    : 'commandFilter'
719
                    });
720
                });
721
722
                store.reload();
723
            },
724
            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...
725
                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...
726
            }
727
728
        });
729
730
    },
731
732
    /**
733
     * Method called when clear category button is clicked.
734
     */
735
    onExportCategoryFilterClearAction: function() {
736
        var me = this;
737
738
        var table = me.getExportList(),
739
            filter = me.getExportFilter(),
0 ignored issues
show
Unused Code introduced by
The variable filter seems to be never used. Consider removing it.
Loading history...
740
            store = table.getStore();
741
        store.filters.removeAtKey('exportCategoryFilter');
742
        store.load();
743
744
        //deselect all nodes
745
        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...
746
    },
747
748
    /**
749
     * Callback method called when the user selects a product in the "changed products" view.
750
     * Will populate the bottom "change view" grid with the correct tabs
751
     *
752
     * @param grid
753
     * @param selected
754
     * @param eOpts
755
     */
756
    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...
757
        var me = this,
758
            record,
759
            remoteChangeSet,
760
            changeRecord,
761
            changeFlag = 0, flags,
762
            changeView = me.getChangeView();
763
764
        // make sure that we have a selection
765
        if (selected && selected.length > 0) {
766
            record = selected[0];
767
768
            // Decode the lastUpdate info
769
            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...
770
771
            // Build a record for the changeset
772
            changeRecord = Ext.create('Shopware.apps.Connect.model.changed_products.Product', {
773
                shortDescriptionLocal: record.get('description'),
774
                shortDescriptionRemote: remoteChangeSet['shortDescription'],
775
776
                longDescriptionLocal: record.get('descriptionLong'),
777
                longDescriptionRemote: remoteChangeSet['longDescription'],
778
779
                additionalDescriptionLocal: record.get('additionalDescription'),
780
                additionalDescriptionRemote: remoteChangeSet['additionalDescription'],
781
782
                nameLocal: record.get('name'),
783
                nameRemote: remoteChangeSet['name'],
784
785
                priceLocal: record.get('price'),
786
                priceRemote: remoteChangeSet['price'],
787
788
                imageLocal: record.get('images'),
789
                imageRemote: remoteChangeSet['image'].join('|')
790
            });
791
792
            // Read updateFlag and build update flag object
793
            changeFlag = record.get('lastUpdateFlag');
794
            flags = {
795
                2: 'shortDescription',
796
                4: 'longDescription',
797
                8: 'name',
798
                16: 'image',
799
                32: 'price',
800
                64: 'imageInitialImport',
801
                128: 'additionalDescription'
802
            };
803
            // Check all flags and show the corresponding tab if it is active
804
            // if not, remove the tab without destroying the component
805
            changeView.removeAll();
806
807
            Ext.each(Object.keys(flags), function(key) {
808
                var fieldName = flags[key];
809
                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...
810
                    var form = changeView.createContainer(fieldName);
811
                    form.loadRecord(changeRecord);
812
                    changeView.add(form);
813
                    form.applyButton.handler = function () {
814
                        me.applyChanges(fieldName, changeRecord.get(fieldName + 'Remote'), record.get('id'), changeView);
815
                    }
816
                }
817
            });
818
819
            changeView.setTitle(record.get('name'));
820
            changeView.setActiveTab(0);
821
        }
822
    },
823
824
    /**
825
     * Callback to apply a given change for a given product
826
     *
827
     * @param type
828
     * @param value
829
     * @param detailId
830
     * @param changeView
831
     */
832
    applyChanges: function(type, value, detailId, changeView) {
833
        var me = this,
834
            changedProductsList = me.getChangedList(),
835
            store = changedProductsList.store;
836
837
        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...
838
            url: '{url controller=LastChanges action=applyChanges}',
839
            method: 'POST',
840
            params: {
841
                type: type,
842
                value: value,
843
                detailId: detailId
844
            },
845
            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...
846
                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...
847
                if (responseObject.success) {
848
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=changed_products/success/notification/message}Successfully applied changes{/s}');
849
                } else {
850
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', responseObject.message);
851
                }
852
853
                store.reload();
854
                changeView.removeAll();
855
            },
856
            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...
857
                me.createGrowlMessage('{s name=connect/error}Error{/s}', response.responseText);
858
            }
859
860
        });
861
862
    },
863
864
    /**
865
     * Callback function that will insert from/for export
866
     *
867
     * @param btn
868
     */
869
    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...
870
        var me = this,
871
            list = me.getExportList(),
872
            records = list.selModel.getSelection(),
873
            ids = [],
874
            title = me.messages.insertOrUpdateProductTitle,
875
            batchSize = 50;
876
877
        if (records.length == 0) {
878
            return;
879
        }
880
881
        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...
882
            ids.push(record.get('id'));
883
        });
884
885
        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...
886
            url: '{url action=getArticleSourceIds}',
887
            method: 'POST',
888
            params: {
889
                'ids[]': ids
890
            },
891
            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...
892
                if (response.responseText) {
893
                    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...
894
                    if (operation) {
895
                        if (!operation.success) {
896
                            me.createGrowlMessage(title, operation.message, true);
897
                        } else {
898
                            Ext.create('Shopware.apps.Connect.view.export.product.Progress', {
899
                                startButtonHandler: function (caller) {
900
                                    me.startArticleExport(operation.sourceIds, batchSize, caller,0)
901
                                },
902
                                count: operation.sourceIds.length,
903
                                totalTime: operation.sourceIds.length / batchSize * 4 / 60
904
                            }).show();
905
                        }
906
                    }
907
                }
908
            }
909
        });
910
    },
911
912
    exportAll: function(count, batchSize, window, offset) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
913
        var me = this,
914
            message = me.messages.insertOrUpdateProductMessage,
915
            title = me.messages.insertOrUpdateProductTitle,
916
            list = me.getExportList();
917
        offset = parseInt(offset);
918
        batchSize = parseInt(batchSize);
919
        count = parseInt(count);
920
921
        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...
922
            url: '{url action=exportAllProducts}',
923
            method: 'POST',
924
            params: {
925
                'offset': offset,
926
                'batchSize': batchSize
927
            },
928
            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...
929
                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...
930
931
                if (!operation.success && operation.messages) {
932
933
                    if(operation.messages.price && operation.messages.price.length > 0){
934
                        var priceMsg = Ext.String.format(
935
                            me.messages.priceErrorMessage, operation.messages.price.length, count
936
                        );
937
                        me.createGrowlMessage(title, priceMsg, true);
938
                    }
939
940
                    if(operation.messages.default && operation.messages.default.length > 0){
941
                        operation.messages.default.forEach( function(message){
942
                            me.createGrowlMessage(title, message, true);
943
                        });
944
                    }
945
                }
946
947
                window.progressField.updateText(Ext.String.format(window.snippets.process, offset, 0));
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...
948
                window.progressField.updateProgress(
949
                    offset/count,
950
                    Ext.String.format(window.snippets.process, offset, count),
951
                    true
952
                );
953
954
                if (count <= offset) {
955
                    window.closeWindow();
956
                    me.createGrowlMessage(title, message, false);
957
                    list.store.load();
958
                    me.onGetExportStatus();
959
                } else {
960
                    //otherwise we have to call this function recursive with the next offset
961
                    me.exportAll(count,batchSize,window,(offset+batchSize));
962
                }
963
            },
964
            failure: function(operation) {
965
                me.createGrowlMessage(title, operation.responseText, true);
966
                window.inProcess = false;
967
                window.cancelButton.setDisabled(false);
968
            }
969
        });
970
    },
971
972
    /**
973
     * Callback function that will insert from/for export
974
     *
975
     * @param sourceIds
976
     * @param batchSize
977
     * @param window
978
     * @param offset
979
     */
980
    startArticleExport: function(sourceIds, batchSize, window, offset) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
981
        offset = parseInt(offset) || 0;
982
        var limit = offset + batchSize;
983
984
        if (limit > sourceIds.length) {
985
            limit = sourceIds.length;
986
        }
987
988
        var me = this,
989
        message = me.messages.insertOrUpdateProductMessage,
990
        title = me.messages.insertOrUpdateProductTitle,
991
        list = me.getExportList();
992
993
        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...
994
            url: '{url action=insertOrUpdateProduct}',
995
            method: 'POST',
996
            params: {
997
                'sourceIds[]': sourceIds.slice(offset, limit)
998
            },
999
            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...
1000
                var doneDetails = limit;
1001
                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...
1002
1003
                if (!operation.success && operation.messages) {
1004
1005
                    if(operation.messages.price && operation.messages.price.length > 0){
1006
                        var priceMsg = Ext.String.format(
1007
                            me.messages.priceErrorMessage, operation.messages.price.length, sourceIds.length
1008
                        );
1009
                        me.createGrowlMessage(title, priceMsg, true);
1010
                    }
1011
1012
                    if(operation.messages.default && operation.messages.default.length > 0){
1013
                        operation.messages.default.forEach( function(message){
1014
                            me.createGrowlMessage(title, message, true);
1015
                        });
1016
                    }
1017
                }
1018
1019
                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...
1020
                window.progressField.updateProgress(
1021
                    limit / sourceIds.length,
1022
                    Ext.String.format(window.snippets.process, doneDetails, sourceIds.length),
1023
                    true
1024
                );
1025
1026
                if (limit >= sourceIds.length) {
1027
                    window.closeWindow();
1028
                    me.createGrowlMessage(title, message, false);
1029
                    list.store.load();
1030
                    me.onGetExportStatus();
1031
                } else {
1032
                    //otherwise we have to call this function recursive with the next offset
1033
                    me.startArticleExport(sourceIds, batchSize, window, limit);
1034
                }
1035
            },
1036
            failure: function(operation) {
1037
                me.createGrowlMessage(title, operation.responseText, true);
1038
                window.inProcess = false;
1039
                window.cancelButton.setDisabled(false);
1040
            }
1041
        });
1042
    },
1043
1044
    cronExportAll: function () {
1045
        var me = this;
1046
1047
        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...
1048
            url: '{url action=exportAllWithCron}',
1049
            method: 'POST',
1050
1051
            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...
1052
                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...
1053
                if (operation.success) {
1054
                    me.createGrowlMessage("{s name=connect/success}Success{/s}", me.messages.allProductsMarkedForExportWithCron, true);
1055
                    me.getExportList().getStore().reload();
1056
                } else {
1057
                    me.createGrowlMessage("{s name=connect/error}Error{/s}", operation.message, true);
1058
                }
1059
            }
1060
        });
1061
    },
1062
1063
    startStreamExport: function(streamIds, sourceIdCount, batchSize, window, currentStreamIndex, offset) {
1064
        offset = parseInt(offset) || 0;
1065
        var limit = batchSize;
1066
1067
        var me = this,
1068
            list = me.getExportStreamList();
1069
1070
        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...
1071
            url: '{url action=exportStream}',
1072
            method: 'POST',
1073
            params: {
1074
                'offset': offset,
1075
                'limit': limit,
1076
                'streamIds[]': streamIds,
1077
                'currentStreamIndex': currentStreamIndex
1078
            },
1079
            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...
1080
                var sticky = false;
1081
                if (response.responseText) {
1082
                    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...
1083
                    if (operation) {
1084
                        if (!operation.success && operation.messages) {
1085
                            if(operation.messages.price && operation.messages.price.length > 0){
1086
                                var priceMsg = Ext.String.format(
1087
                                    me.messages.priceErrorMessage, operation.messages.price.length, sourceIdCount
1088
                                );
1089
                                me.createGrowlMessage(me.messages.exportStreamTitle, priceMsg, true);
1090
                            }
1091
1092
                            if(operation.messages.default && operation.messages.default.length > 0){
1093
                                operation.messages.default.forEach( function(message){
1094
                                    me.createGrowlMessage(me.messages.exportStreamTitle, message, true);
1095
                                });
1096
                            }
1097
1098
                            window.inProcess = false;
1099
                            window.cancelButton.setDisabled(false);
1100
                            return;
1101
                        }
1102
1103
                        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...
1104
                        window.progressFieldStream.updateProgress(
1105
                            operation.processedStreams / streamIds.length,
1106
                            Ext.String.format(window.snippets.processStream, operation.processedStreams, streamIds.length),
1107
                            false
1108
                        );
1109
1110
                        window.progressField.updateText(Ext.String.format(window.snippets.process, operation.newOffset, sourceIdCount));
1111
                        window.progressField.updateProgress(
1112
                            operation.newOffset / sourceIdCount,
1113
                            Ext.String.format(window.snippets.process, operation.newOffset, sourceIdCount),
1114
                            false
1115
                        );
1116
1117
                        if (operation.hasMoreIterations) {
1118
                            currentStreamIndex = operation.nextStreamIndex;
1119
                            offset = operation.newOffset;
1120
                            me.startStreamExport(streamIds, sourceIdCount, batchSize, window, currentStreamIndex, offset);
1121
                        } else {
1122
                            window.inProcess = false;
1123
                            window.cancelButton.setDisabled(false);
1124
1125
                            me.createGrowlMessage(me.messages.exportStreamTitle, me.messages.exportStreamMessage, sticky);
1126
1127
                            list.setLoading(false);
1128
                            list.store.load();
1129
                        }
1130
                    }
1131
                }
1132
            }
1133
        });
1134
    },
1135
1136
    /**
1137
     * Callback function that will start the export all dialog
1138
     *
1139
     * @param btn
1140
     */
1141
    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...
1142
        var me = this,
1143
            list = me.getExportList(),
1144
            title = me.messages.insertOrUpdateProductTitle,
1145
            batchSize = 50;
1146
1147
        list.setLoading(true);
1148
1149
        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...
1150
            url: '{url action=getArticleCount}',
1151
            method: 'POST',
1152
            params: {
1153
                'exportAll': true
1154
            },
1155
            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...
1156
                list.setLoading(false);
1157
1158
                if (!response.responseText) {
1159
                    return;
1160
                }
1161
1162
                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...
1163
                if (!operation) {
1164
                    return;
1165
                }
1166
                if (!operation.success) {
1167
                    me.createGrowlMessage(title, operation.message, true);
1168
                } else {
1169
                    if (operation.count > 1000) {
1170
1171
                        Ext.create('Shopware.apps.Connect.view.export.product.manyProductsDialog', {
1172
                            count: operation.count
1173
                        }).show();
1174
                        return;
1175
                    }
1176
1177
                    Ext.create('Shopware.apps.Connect.view.export.product.Progress', {
1178
                        startButtonHandler: function (caller) {
1179
                            me.exportAll(operation.count, batchSize, caller,0)
1180
                        },
1181
                        count: operation.count,
1182
                        totalTime: operation.count / batchSize * 4 / 60
1183
                    }).show();
1184
                }
1185
            }
1186
        });
1187
    },
1188
1189
    /**
1190
     * Callback function that will delete a product from/for export
1191
     *
1192
     * @param btn
1193
     */
1194
    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...
1195
        var me = this,
1196
            list = me.getExportList(),
1197
            records = list.selModel.getSelection(),
1198
            ids = [],
1199
            messages = [];
1200
1201
        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...
1202
            ids.push(record.get('id'));
1203
        });
1204
1205
        list.setLoading();
1206
1207
        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...
1208
            url: '{url action=deleteProduct}',
1209
            method: 'POST',
1210
            params: {
1211
                'ids[]': ids
1212
            },
1213
            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...
1214
                var sticky = false;
1215
                if (response.responseText) {
1216
                    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...
1217
                    if (operation) {
1218
                        if (!operation.success && operation.messages) {
1219
                            messages = operation.messages;
1220
                            sticky = true;
1221
                        }
1222
                    }
1223
                }
1224
                if (messages.length > 0) {
1225
                    messages.forEach( function(message){
1226
                        me.createGrowlMessage(me.messages.deleteProductTitle, message, sticky);
1227
                    });
1228
                } else {
1229
                    me.createGrowlMessage(me.messages.deleteProductTitle, me.messages.deleteProductMessage, sticky);
1230
                }
1231
1232
                list.setLoading(false);
1233
                list.store.load();
1234
            }
1235
        });
1236
    },
1237
1238
    /**
1239
     * Callback function that will export or delete a product stream from/for export
1240
     *
1241
     * @param btn
1242
     */
1243
    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...
1244
        var me = this,
1245
            list = me.getExportStreamList(),
1246
            records = list.selModel.getSelection(),
1247
            staticStreamIds = [],
1248
            dynamicStreamIds = [];
1249
1250
        if (records.length == 0) {
1251
            return;
1252
        }
1253
1254
        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...
1255
            if (record.get('type') == 1) {
1256
                dynamicStreamIds.push(record.get('id'));
1257
            } else {
1258
                staticStreamIds.push(record.get('id'));
1259
            }
1260
        });
1261
        if (dynamicStreamIds.length > 0) {
1262
            me.prepareDynamicStreamExport(dynamicStreamIds);
1263
        }
1264
1265
        if (staticStreamIds.length > 0) {
1266
            me.prepareStaticStreamExport(staticStreamIds);
1267
        }
1268
1269
    },
1270
1271
    prepareDynamicStreamExport: function(ids){
1272
        var me = this,
1273
            list = me.getExportStreamList(),
1274
            store = list.store,
1275
            title = me.messages.exportStreamTitle;
1276
1277
        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...
1278
            url: '{url action=prepareDynamicStreams}',
1279
            method: 'POST',
1280
            params: {
1281
                'streamIds[]': ids
1282
            },
1283
            success: function(response) {
1284
                if (response.responseText) {
1285
                    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...
1286
1287
                    if (!operation) {
1288
                        return;
1289
                    }
1290
1291
                    if (!operation.success) {
1292
                        me.createGrowlMessage(title, operation.messages, false);
1293
                        return;
1294
                    }
1295
1296
                    me.createGrowlMessage(title, me.messages.exportDynamicStreamMessage, false);
1297
                    store.reload();
1298
                }
1299
            }
1300
        });
1301
    },
1302
1303
    /**
1304
     * @param ids
1305
     */
1306
    prepareStaticStreamExport: function(ids){
1307
        var me = this;
1308
1309
        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...
1310
            url: '{url action=getStreamProductsCount}',
1311
            method: 'POST',
1312
            params: {
1313
                'ids[]': ids
1314
            },
1315
            success: function(response) {
1316
                if (response.responseText) {
1317
                    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...
1318
1319
                    if (!operation) {
1320
                        return;
1321
                    }
1322
1323
                    if (!operation.success) {
1324
                        var title = me.messages.exportStreamTitle,
1325
                            messages = operation.messages;
1326
1327
                        //todo: handle price and default errors
1328
                        if (messages.default.length > 0) {
1329
                            messages.default.forEach(function (message) {
1330
                                me.createGrowlMessage(title, message, false);
1331
                            });
1332
                        }
1333
                    } else {
1334
                        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...
1335
                            streamIds: ids,
1336
                            sourceIdsCount: operation.sourceIdsCount
1337
                        }).show();
1338
                    }
1339
                }
1340
            }
1341
        });
1342
    },
1343
1344
    onRemoveStreams: function(){
1345
        var me = this,
1346
            list = me.getExportStreamList(),
1347
            records = list.selModel.getSelection(),
1348
            ids = [],
1349
            url,
1350
            message,
1351
            messages = [],
1352
            title;
1353
1354
        if (records.length == 0) {
1355
            return;
1356
        }
1357
1358
        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...
1359
            ids.push(record.get('id'));
1360
        });
1361
1362
        url = '{url action=removeStreams}';
1363
        title = me.messages.removeStreamTitle;
1364
        message = me.messages.removeStreamMessage;
1365
1366
        list.setLoading();
1367
1368
        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...
1369
            url: url,
1370
            method: 'POST',
1371
            params: {
1372
                'ids[]': ids
1373
            },
1374
            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...
1375
                var sticky = false;
1376
                if (response.responseText) {
1377
                    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...
1378
                    if (operation) {
1379
                        if (!operation.success && operation.messages) {
1380
                            messages = operation.messages;
1381
                            sticky = true;
1382
                        }
1383
                    }
1384
                }
1385
1386
                if (messages.length > 0) {
1387
                    messages.forEach( function(message){
1388
                        me.createGrowlMessage(title, message, sticky);
1389
                    });
1390
                } else {
1391
                    me.createGrowlMessage(title, message, sticky);
1392
                }
1393
1394
                list.setLoading(false);
1395
                list.store.load();
1396
            }
1397
        });
1398
    },
1399
1400
    /**
1401
     * Helper to show a growl message
1402
     *
1403
     * @param title
1404
     * @param message
1405
     */
1406
    createGrowlMessage: function(title, message, sticky) {
1407
        var me = this;
1408
1409
        if (!sticky) {
1410
            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...
1411
        } else {
1412
            Shopware.Notification.createStickyGrowlMessage({
1413
                title: title,
1414
                text: message,
1415
                width: 400
1416
            });
1417
        }
1418
    },
1419
1420
    /**
1421
     * Callback function to set the window title depending on the current navigation entry
1422
     *
1423
     * @param tree
1424
     * @param node
1425
     */
1426
    onSelectNavigationEntry: function(tree, node) {
1427
        var me = this,
1428
            panel = me.getPanel(),
1429
            win = me.getWindow(),
1430
            item = node.get('id'),
1431
            layout = panel.getLayout();
1432
1433
        layout.setActiveItem(item);
1434
        win.loadTitle(node);
1435
    },
1436
1437
    /**
1438
     * Callback function to save the configuration form
1439
     *
1440
     * @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...
1441
     */
1442
    onSaveConfigForm: function(btn) {
1443
        var me = this;
0 ignored issues
show
Unused Code introduced by
The variable me seems to be never used. Consider removing it.
Loading history...
1444
            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...
1445
1446
        form.setLoading();
1447
1448
        if (form.getRecord()) {
1449
            var model = form.getRecord();
1450
1451
            form.getForm().updateRecord(model);
1452
            model.save({
1453
                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...
1454
                    form.setLoading(false);
1455
                    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...
1456
                },
1457
                failure: function(record) {
1458
                    form.setLoading(false);
1459
                    var rawData = record.getProxy().getReader().rawData,
1460
                        message = rawData.message;
1461
                    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...
1462
                }
1463
            });
1464
        }
1465
    },
1466
1467
    /**
1468
     * Callback function to save the import configuration form
1469
     *
1470
     * @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...
1471
     */
1472
    onSaveImportConfigForm: function(btn) {
1473
        var me = this,
1474
            form = btn.up('form');
1475
1476
        form.setLoading();
1477
        if (form.getRecord()) {
1478
            var model = form.getRecord();
1479
1480
            form.getForm().updateRecord(model);
1481
            model.save({
1482
                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...
1483
                    form.setLoading(false);
1484
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1485
                },
1486
                failure: function(record) {
1487
                    form.setLoading(false);
1488
                    var rawData = record.getProxy().getReader().rawData,
1489
                        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...
1490
                    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...
1491
                }
1492
            });
1493
        }
1494
    },
1495
1496
    onSaveUnitsMapping: function(btn){
1497
        var me = this,
1498
            unitsStore = me.getUnitsMapping().getStore(),
1499
            form = btn.up('form');
1500
1501
        if (unitsStore.getModifiedRecords().length > 0){
1502
            form.setLoading();
1503
        }
1504
1505
        unitsStore.sync({
1506
            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...
1507
                form.setLoading(false);
1508
                me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1509
                me.getUnitsMapping().unitsStore.load({
1510
                    scope: this,
1511
                    callback: function(records, operation, success) {
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...
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...
1512
                        me.getUnitsMapping().getStore().reload();
1513
                    }
1514
                });
1515
            },
1516
            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...
1517
                me.createGrowlMessage('{s name=connect/error}Error{/s}','{s name=config/units/error_save_message}Mapping der Einheiten konnte nicht gespeichert werden.{/s}');
1518
            }
1519
        });
1520
    },
1521
1522
    /**
1523
     * Reload Shopware Connect units store
1524
     * and show/hide already assigned units
1525
     */
1526
    onHideAssignedUnits: function(checkbox, value)
1527
    {
1528
        var me = this;
1529
        var store = me.getUnitsMapping().getStore();
1530
        var hideAssigned = 0;
1531
1532
        if (value === true) {
1533
            hideAssigned = 1;
1534
        }
1535
1536
        store.load({
1537
            params: {
1538
                'hideAssignedUnits': hideAssigned
1539
            }
1540
        });
1541
    },
1542
1543
    onAdoptUnits: function(btn) {
1544
        var me = this;
1545
        var form = btn.up('form');
1546
1547
        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...
1548
            title: me.messages.adoptUnitsTitle,
1549
            msg: me.messages.adoptUnitsMessage,
1550
            buttons: Ext.Msg.YESNO,
1551
            fn: function(response) {
1552
                if(response !== 'yes') {
1553
                    return;
1554
                }
1555
1556
                form.setLoading();
1557
                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...
1558
                    url: '{url controller=ConnectConfig action=adoptUnits}',
1559
                    method: 'POST',
1560
                    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...
1561
                        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...
1562
                        form.setLoading(false);
1563
                        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...
1564
                        } 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...
1565
                        }
1566
                    }
1567
                });
1568
            }
1569
        });
1570
    },
1571
1572
    /**
1573
     * Callback function to save the export configuration form
1574
     *
1575
     * @param data
1576
     * @param btn
1577
     */
1578
    onSaveExportSettingsForm: function(data, btn) {
1579
        var me = this,
1580
            form = btn.up('form');
1581
1582
        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...
1583
1584
        if (data.exportPriceMode.length == 0) {
1585
            return me.createGrowlMessage(me.messages.exportTitle, me.messages.priceModeNotSelected);
1586
        }
1587
1588
        if (!data.hasOwnProperty('descriptionField') || data.descriptionField.length == 0) {
1589
            return me.createGrowlMessage(me.messages.exportTitle, me.messages.productDescriptionNotSelected);
1590
        }
1591
1592
        form.setLoading();
1593
        model.save({
1594
            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...
1595
                form.setLoading(false);
1596
                me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1597
1598
                if (me.hasOwnProperty('exportWindow') && me.exportWindow.isWindow) {
1599
                    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...
1600
                    domEl[0].remove();
1601
                    me.exportWindow.close();
1602
                }
1603
            },
1604
            failure: function(record) {
1605
                form.setLoading(false);
1606
                var rawData = record.getProxy().getReader().rawData,
1607
                    message = rawData.message;
1608
                me.createGrowlMessage('{s name=connect/error}Error{/s}', message);
1609
            }
1610
        });
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...
1611
    },
1612
1613
    /**
1614
     * Sends marketplace attributes mapping to the PHP
1615
     */
1616
    saveMarketplaceAttributesMapping: function() {
1617
        var me = this,
1618
            panel = me.getMarketeplaceMappingPanel(),
1619
            store = me.getMarketeplaceMapping().localProductAttributesStore;
1620
1621
        if (store.getNewRecords().length > 0 || store.getUpdatedRecords().length > 0 || store.getRemovedRecords().length > 0) {
1622
            panel.setLoading();
1623
            store.sync({
1624
                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...
1625
                    panel.setLoading(false);
1626
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Änderungen erfolgreich übernommen{/s}');
1627
                },
1628
                failure:function (batch) {
1629
                    panel.setLoading(false);
1630
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', batch.proxy.getReader().jsonData.message);
1631
                }
1632
            });
1633
        }
1634
    },
1635
1636
    /**
1637
     * Calculate needed time to finish synchronization
1638
     *
1639
     * @param progressBar
1640
     */
1641
    onCalculateFinishTime: function(progressBar) {
1642
        var me = this;
1643
        me.time = 0;
1644
        me.resetSpentTime();
1645
1646
        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...
1647
            interval: 60000,
1648
            run: function() {
1649
                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...
1650
                    url: '{url controller=ConnectConfig action=calculateFinishTime}',
1651
                    method: 'POST',
1652
                    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...
1653
                        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...
1654
1655
                        if (responseObject.time > 0) {
1656
                            if ((responseObject.time - (me.time + me.spentTime)) == 0) {
1657
                                return;
1658
                            }
1659
                            me.time = responseObject.time;
1660
                            me.resetSpentTime();
1661
1662
                            var time = me.secondsToTime(me.time);
1663
                            progressBar.wait({
1664
                                interval: 500,
1665
                                increment: 15,
1666
                                scope: this
1667
                            });
1668
                            progressBar.updateText(me.messages.updatePartOneMessage + ' ' + time.h + ' ' + me.messages.hours + ' ' + time.m + ' ' + me.messages.minutes + ' ' + time.s + ' ' + me.messages.seconds + ' ' + me.messages.updatePartTwoMessage);
1669
                        } else {
1670
                            me.resetSpentTime();
1671
                            me.resetTime();
1672
                            progressBar.reset();
1673
                            progressBar.updateText(me.messages.doneMessage);
1674
                        }
1675
                    }
1676
                });
1677
            }
1678
        });
1679
1680
        Ext.TaskManager.start({
1681
            interval: 5000,
1682
            run: function () {
1683
                if (me.time >= 5) {
1684
                    me.time = me.time - 5;
1685
                    me.spentTime = me.spentTime + 5;
1686
                    var time = me.secondsToTime(me.time);
1687
                    progressBar.updateText(me.messages.updatePartOneMessage + ' ' + time.h + ' ' + me.messages.hours + ' ' + time.m + ' ' + me.messages.minutes + ' ' + time.s + ' ' + me.messages.seconds + ' ' + me.messages.updatePartTwoMessage);
1688
                } else {
1689
                    progressBar.reset();
1690
                    progressBar.updateText(me.messages.doneMessage);
1691
                }
1692
            }
1693
        });
1694
1695
    },
1696
1697
    onResetPriceType: function () {
1698
        var me = this;
1699
1700
        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...
1701
            scope: this,
1702
            url: '{url module=backend controller=ConnectConfig action=resetPriceType}',
1703
            success: function (result) {
1704
                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...
1705
                if (response.success) {
1706
                    me.createGrowlMessage(
1707
                        me.messages.priceResetLabel,
1708
                        me.messages.priceResetSuccess
1709
                    );
1710
                } else {
1711
                    me.createGrowlMessage(
1712
                        me.messages.priceResetLabel,
1713
                        me.messages.priceResetError
1714
                    );
1715
                }
1716
            }
1717
        });
1718
    },
1719
1720
    onResetExchangeSettings: function () {
1721
        var me = this;
1722
1723
        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...
1724
            scope: this,
1725
            url: '{url module=backend controller=ConnectConfig action=resetExchangeSettings}',
1726
            success: function (result) {
1727
                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...
1728
                if (response.success) {
1729
                    me.createGrowlMessage(
1730
                        me.messages.exchangeSettingsResetLabel,
1731
                        me.messages.exchangeSettingsResetSuccess
1732
                    );
1733
1734
                    //reload after 3 sec
1735
                    setTimeout(function(){
1736
                        location.reload();
1737
                    }, 3000);
1738
                } else {
1739
                    me.createGrowlMessage(
1740
                        me.messages.exchangeSettingsResetLabel,
1741
                        me.messages.exchangeSettingsResetError
1742
                    );
1743
                }
1744
            }
1745
        });
1746
    },
1747
1748
    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...
1749
        var me = this;
1750
        var loggingEnabled = 0;
1751
        if (newValue === true) {
1752
            loggingEnabled = 1;
1753
        }
1754
1755
        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...
1756
            url: '{url controller=ConnectConfig action=changeLogging}',
1757
            method: 'POST',
1758
            params: {
1759
                enableLogging: loggingEnabled
1760
            },
1761
            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...
1762
                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...
1763
                if (data.success == false) {
1764
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', '{s name=config/log_label}Logging aktivieren{/s}');
1765
                }
1766
            }
1767
        });
1768
    },
1769
1770
    onGetExportStatus: function() {
1771
        var me = this;
1772
1773
        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...
1774
            scope: me,
1775
            url: '{url controller=Connect action=getExportStatus}',
1776
            success: function (result) {
1777
                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...
1778
                if (response.success === true) {
1779
1780
                    //removes the old export status
1781
                    if (me.exportStatusEl) {
1782
                        Ext.destroy(me.exportStatusEl);
1783
                    }
1784
1785
                    //sets the new export status
1786
                    me.exportStatusEl = me.getExportWindow().getEl().insertHtml(
1787
                        "afterBegin",
1788
                        me.getHtmlStatus(response.data, response.total),
1789
                        true
1790
                    );
1791
                }
1792
            }
1793
        });
1794
    },
1795
1796
    getHtmlStatus: function ($start, $end) {
1797
        var me = this;
1798
1799
        return '<div class="sc-export-status">' +
1800
            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...
1801
            '</div>';
1802
    },
1803
1804
1805
    /**
1806
     * On change customer group for price configuration
1807
     * reload the store with available price fields
1808
     *
1809
     * @param combo
1810
     * @param newValue
1811
     * @param oldValue
1812
     */
1813
    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...
1814
        var me = this;
1815
        var exportConfigForm = me.getExportConfigForm();
1816
        exportConfigForm.setLoading(true);
1817
        exportConfigForm.priceFieldForPrice.store.load({
1818
            params: {
1819
                'customerGroup': newValue
1820
            },
1821
            callback: function() {
1822
                exportConfigForm.setLoading(false);
1823
            }
1824
        });
1825
    },
1826
1827
    /**
1828
     * On change customer group for purchase price configuration
1829
     * reload the store with available price fields
1830
     *
1831
     * @param combo
1832
     * @param newValue
1833
     * @param oldValue
1834
     */
1835
    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...
1836
        var me = this;
1837
        var exportConfigForm = me.getExportConfigForm();
1838
        exportConfigForm.setLoading(true);
1839
        exportConfigForm.priceFieldForPurchasePrice.store.load({
1840
            params: {
1841
                'customerGroup': newValue
1842
            },
1843
            callback: function() {
1844
                exportConfigForm.setLoading(false);
1845
            }
1846
        });
1847
    },
1848
1849
    /**
1850
     * Checks price field selection, if it's not supported
1851
     * shows error message
1852
     *
1853
     * @param combo
1854
     * @param newValue
1855
     * @param oldValue
1856
     */
1857
    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...
1858
        var me = this;
1859
1860
        var newRecord = combo.findRecordByValue(newValue);
1861
        if (newRecord && newRecord.get('available') === false) {
1862
            me.createGrowlMessage('{s name=connect/error}Error{/s}', me.messages.priceFieldIsNotSupported);
1863
        }
1864
    },
1865
1866
    /**
1867
     * Checks price field selection, if it's not supported
1868
     * shows error message
1869
     *
1870
     * @param combo
1871
     * @param newValue
1872
     * @param oldValue
1873
     */
1874
    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...
1875
        var me = this;
1876
1877
        var newRecord = combo.findRecordByValue(newValue);
1878
        if (newRecord && newRecord.get('available') === false) {
1879
            me.createGrowlMessage('{s name=connect/error}Error{/s}', me.messages.priceFieldIsNotSupported);
1880
        }
1881
    },
1882
1883
    onShowPriceWindow: function() {
1884
        var me = this;
1885
1886
        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...
1887
            callback: function(){
1888
                me.exportWindow = me.getView('export.price.Window').create({
1889
                    customerGroupStore: me.customerGroupStore
1890
                }).show();
1891
            }
1892
        });
1893
    },
1894
1895
    /**
1896
     * Resets store
1897
     * @param column
1898
     */
1899
    rejectPriceConfigChanges: function (column) {
1900
        var tabs = column.up('panel').up('panel').items;
1901
1902
        tabs.each(function(tab){
1903
            tab.getStore().rejectChanges();
1904
        });
1905
    },
1906
1907
    /**
1908
     * Collects prices params from given tab panel
1909
     *
1910
     * @param tabPanel
1911
     * @param exportMode
1912
     * @param collection
1913
     */
1914
    collectPriceParams: function(tabPanel, exportMode, collection) {
1915
        var me = this,
0 ignored issues
show
Unused Code introduced by
The variable me seems to be never used. Consider removing it.
Loading history...
1916
            priceTypes = ['price', 'pseudoPrice', 'basePrice'],
1917
            exportPriceType;
1918
1919
        switch (exportMode) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1920
            case 'purchasePrice':
1921
                exportPriceType = 'ForPurchasePriceExport';
1922
                break;
1923
            case 'price':
1924
                exportPriceType = 'ForPriceExport';
1925
                break;
1926
        }
1927
1928
        tabPanel.items.each(function(tab) {
1929
            if (tab.getStore().getUpdatedRecords().length > 0) {
1930
                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...
1931
                collection.exportPriceMode.push(exportMode);
1932
1933
                for (var i = 0; i < priceTypes.length; i++){
1934
                    if (tab.getStore().getAt(0).get(priceTypes[i]) == true) {
1935
                        collection['priceField' + exportPriceType] = priceTypes[i];
1936
                    }
1937
                }
1938
            }
1939
        });
1940
    },
1941
1942
    /**
1943
     * Convert number of seconds into time object
1944
     *
1945
     * @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...
1946
     * @return object
1947
     */
1948
    secondsToTime: function (secs) {
1949
        var hours = parseInt( secs / 3600 ) % 24;
1950
        var minutes = parseInt( secs / 60 ) % 60;
1951
        var seconds = secs % 60;
1952
1953
        var obj = {
1954
            "h": hours,
1955
            "m": minutes,
1956
            "s": seconds
1957
        };
1958
        return obj;
1959
    },
1960
1961
    /**
1962
     * Reset spent time used for synchronization bar
1963
     */
1964
    resetSpentTime: function() {
1965
        var me = this;
1966
        me.spentTime = 0;
1967
    },
1968
1969
    /**
1970
     * Reset time used for synchronization bar
1971
     */
1972
    resetTime: function() {
1973
        var me = this;
1974
        me.time = 0;
1975
    }
1976
});
1977
//{/block}
1978