Completed
Push — master ( b26934...7f62ea )
by Jonas
15s
created

ller.Mainꞌ).doMigration   A

Complexity

Conditions 4
Paths 24

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 24
nop 4
dl 0
loc 55
rs 9.078
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ion 0 21 2
A ion 0 4 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
                var addShopIdToConnectCategories;
206
                me.sendAjaxRequest(
207
                    '{url controller=Import action=connectCategoriesNeedAdditionalShopId}',
208
                    {},
209
                    function(response) {
210
                        addShopIdToConnectCategories = response.data.addShopIdToConnectCategories;
211
                        if (addShopIdToConnectCategories) {
212
                            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...
213
                                    title: me.messages.applyMigrationsTitle,
214
                                    msg: me.messages.applyMigrationsMessage,
215
                                    buttons: Ext.Msg.YESNO,
216
                                    icon: Ext.Msg.QUESTION,
217
                                    fn: me.startAdditionOfShopIdToConnectCategories,
218
                                    scope: me
219
                                }
220
                            );
221
                        } else {
222
                            me.mainWindow = me.getView('main.Window').create({
223
                                'action': me.subApplication.action
224
                            }).show();
225
                        }
226
                    }
227
                );
228
                break;
229
230
        }
231
    },
232
233
    /**
234
     * Recovers ConnectCategories in batch way and updates progress bar
235
     * @param window the progress window
236
     * @param action the action that has to be performend
237
     * @param totalCount Count of products
238
     * @param offset the actual offset
239
     */
240
    doMigration: function (window, action, totalCount, offset) {
241
        offset = parseInt(offset) || 0;
242
        totalCount = parseInt(totalCount) || 0;
243
        var batchsize = 50;
244
        var articlesProcessed = offset + batchsize;
245
246
        var me = this,
247
            message = me.messages.migrationsMessage,
248
            title = me.messages.migrationsMessageTitle;
249
250
        window.inProcess = true;
251
252
        var url;
253
        if (action === 'applyConnectCategoriesRecovery') {
254
            url = '{url action=applyConnectCategoriesRecovery}'
255
        } else if (action === 'addShopIdToConnectCategories') {
256
            url = '{url action=addShopIdToConnectCategories}'
257
        }
258
259
        if (url) {
260
            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...
261
                url: url,
262
                method: 'POST',
263
                params: {
264
                    'offset': offset,
265
                    'batchsize': batchsize
266
                },
267
                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...
268
                    var doneDetails = articlesProcessed;
269
270
                    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...
271
                    window.progressField.updateProgress(
272
                        articlesProcessed / totalCount,
273
                        Ext.String.format(window.snippets.process, doneDetails, totalCount),
274
                        true
275
                    );
276
277
                    if (articlesProcessed >= totalCount) {
278
                        me.createGrowlMessage(title, message, false);
279
                        me.mainWindow = me.getView('main.Window').create({
280
                            'action': me.subApplication.action
281
                        }).show();
282
                        window.closeWindow();
283
                    } else {
284
                        //otherwise we have to call this function recursive with the next offset
285
                        me.doMigration( window, action, totalCount, articlesProcessed);
286
                    }
287
                },
288
                failure: function(operation) {
289
                    me.createGrowlMessage(title, operation.responseText, true);
290
                    window.inProcess = false;
291
                }
292
            });
293
        }
294
    },
295
296
    /**
297
     * Callback function from messages box that asks the user wether he wants to start the migration
298
     * if 'yes' is clicked it starts the migration
299
     * @param buttonId
300
     * @param text
301
     * @param opt
302
     */
303
    startRecoveryOfConnectCategories: function(buttonId, text, opt) {
0 ignored issues
show
Unused Code introduced by
The parameter text is not used and could be removed.

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

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

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

Loading history...
304
        var me = this;
305
        var totalCount = 0;
306
        if (buttonId === 'yes') {
307
            me.sendAjaxRequest(
308
                '{url controller=Import action=productCountForCategoryRecovery}',
309
                {},
310
                function(response) {
311
                    totalCount = response.data.totalCount;
312
                    me.mainWindow = me.getView('main.Progress').create().show();
313
                    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...
314
                    me.doMigration(me.mainWindow, 'applyConnectCategoriesRecovery', totalCount);
315
                }
316
            );
317
        } else {
318
            me.mainWindow = me.getView('main.Window').create({
319
                'action': me.subApplication.action
320
            }).show();
321
        }
322
    },
323
324
    /**
325
     * Callback function from messages box that asks the user wether he wants to start the migration
326
     * if 'yes' is clicked it starts the migration
327
     * @param buttonId
328
     * @param text
329
     * @param opt
330
     */
331
    startAdditionOfShopIdToConnectCategories: 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...
332
        var me = this;
333
        var totalCount = 0;
334
        if (buttonId === 'yes') {
335
            me.sendAjaxRequest(
336
                '{url controller=Import action=productCountForCategoryRecovery}',
337
                {},
338
                function(response) {
339
                    totalCount = response.data.totalCount;
340
                    me.mainWindow = me.getView('main.Progress').create().show();
341
                    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...
342
                    me.doMigration(me.mainWindow, 'addShopIdToConnectCategories', totalCount);
343
                }
344
            );
345
        } else {
346
            me.mainWindow = me.getView('main.Window').create({
347
                'action': me.subApplication.action
348
            }).show();
349
        }
350
    },
351
352
    setEventListeners: function () {
353
        var me = this;
354
        me.control({
355
            'connect-navigation': {
356
                select: me.onSelectNavigationEntry
357
            },
358
            'connect-config button[action=save-general-config]': {
359
                click: me.onSaveConfigForm
360
            },
361
            'connect-config-form': {
362
                calculateFinishTime: me.onCalculateFinishTime,
363
                resetPriceType: me.onResetPriceType,
364
                resetExchangeSettings: me.onResetExchangeSettings
365
            },
366
            'connect-config-import-form button[action=save-import-config]': {
367
                click: me.onSaveImportConfigForm
368
            },
369
            'connect-import-unit button[action=save-unit]': {
370
                click: me.onSaveUnitsMapping
371
            },
372
            'connect-import-unit checkbox[name=hideAssignedUnits]': {
373
                change: me.onHideAssignedUnits
374
            },
375
            'connect-import-unit button[action=adoptUnits]': {
376
                click: me.onAdoptUnits
377
            },
378
            'connect-export-price-form': {
379
                saveExportSettings: me.onSaveExportSettingsForm,
380
                collectPriceParams: me.collectPriceParams,
381
                rejectPriceConfigChanges: me.rejectPriceConfigChanges
382
            },
383
            'connect-config-export-form combobox[name=priceGroupForPriceExport]': {
384
                change: me.onChangePriceGroupForPrice
385
            },
386
            'connect-config-export-form combobox[name=priceGroupForPurchasePriceExport]': {
387
                change: me.onChangePriceGroupForPurchasePrice
388
            },
389
            'connect-config-export-form combobox[name=priceFieldForPriceExport]': {
390
                change: me.onChangePriceFieldForPrice
391
            },
392
            'connect-config-export-form combobox[name=priceFieldForPurchasePriceExport]': {
393
                change: me.onChangePriceFieldForPurchasePrice
394
            },
395
            'connect-mapping button[action=save]': {
396
                click: me.onSaveMapping
397
            },
398
            'connect-export button[action=add]': {
399
                click: me.onExportAction
400
            },
401
            'connect-export button[action=delete]': {
402
                click: me.onRemoveArticleAction
403
            },
404
            'connect-export button[action=exportAll]': {
405
                click: me.onExportAllAction
406
            },
407
            'connect-article-export-progress-window': {
408
                startExport: me.startArticleExport,
409
                exportAll: me.exportAll
410
            },
411
            'connect-many-products-dialog': {
412
                cronExportAll: me.cronExportAll
413
            },
414
            'connect-stream-export-progress-window': {
415
                startStreamExport: me.startStreamExport
416
            },
417
            'connect-export-stream button[action=add]': {
418
                click: me.onExportStream
419
            },
420
421
            'connect-export-stream button[action=remove]': {
422
                click: me.onRemoveStreams
423
            },
424
            'connect-config-export-form': {
425
                saveExportSettings: me.onSaveExportSettingsForm,
426
                collectPriceParams: me.collectPriceParams,
427
                rejectPriceConfigChanges: me.rejectPriceConfigChanges
428
429
            },
430
431
            'connect-export-filter button[action=category-clear-filter]': {
432
                click: me.onExportCategoryFilterClearAction
433
            },
434
            'connect-export-filter textfield[name=searchfield]': {
435
                change: function(field, value) {
436
                    var table = me.getExportList(),
437
                        store = table.getStore();
438
                    store.filters.removeAtKey('search');
439
                    if (value.length > 0 ) {
440
                        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...
441
                            property: 'search',
442
                            value: '%' + value + '%'
443
                        }));
444
                    }
445
                    store.load({
446
                        page: 1,
447
                        start: 0
448
                    });
449
                    store.currentPage = 1;
450
                }
451
            },
452
453
            'connect-export-filter [name=supplierId]': {
454
                change: function(field, value) {
455
                    var table = me.getExportList(),
456
                        store = table.getStore();
457
458
                    store.filters.removeAtKey('supplierId');
459
                    if (value) {
460
                        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...
461
                            property: field.name,
462
                            value: value
463
                        }));
464
                    }
465
                    store.load({
466
                        page: 1,
467
                        start: 0
468
                    });
469
                    store.currentPage = 1;
470
                }
471
            },
472
            'connect-export-filter [name=exportStatus]': {
473
                change: function(field, value) {
474
                    var table = me.getExportList(),
475
                        store = table.getStore();
476
                    if(!value) {
477
                        return;
478
                    }
479
                    store.filters.removeAtKey('exportStatus');
480
                    if(field.inputValue != '') {
481
                        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...
482
                            property: field.name,
483
                            value: field.inputValue
484
                        }));
485
                    }
486
                    store.load({
487
                        page: 1,
488
                        start: 0
489
                    });
490
                    store.currentPage = 1;
491
                }
492
            },
493
            'connect-export-filter treepanel': {
494
                select: function(tree, node) {
495
                    var table = me.getExportList(),
496
                        store = table.getStore();
497
498
                    if (!node) {
499
                        store.filters.removeAtKey('exportCategoryFilter');
500
                    } else {
501
                        store.filters.removeAtKey('exportCategoryFilter');
502
                        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...
503
                            property: 'categoryId',
504
                            value:  node.get('id')
505
                        }));
506
                    }
507
                    store.load({
508
                        page: 1,
509
                        start: 0
510
                    });
511
                    store.currentPage = 1;
512
                }
513
            },
514
            'connect-changed-products-list': {
515
                'selectionchange': me.onChangedProductsSelectionChanged
516
            },
517
            'connect-log-filter [filter=commandFilter]': {
518
                change: function(field, value) {
519
                    var table = me.getLogList(),
520
                        store = table.getStore();
521
522
                    store.getProxy().extraParams['commandFilter_' + field.name] = value;
523
                    store.reload();
524
                }
525
            },
526
            'connect-log-filter [name=error]': {
527
                change: function(field, value) {
528
                    var table = me.getLogList(),
529
                        store = table.getStore();
530
531
                    if (!value) {
532
                        return;
533
                    }
534
535
                    store.getProxy().extraParams.errorFilter = field.inputValue;
536
                    store.reload();
537
                }
538
            },
539
            'connect-log-filter textfield[name=searchfield]': {
540
                change: function(field, value) {
541
                    var table = me.getLogList(),
542
                        store = table.getStore();
543
544
                    if (value.length === 0 ) {
545
                        store.clearFilter();
546
                    } else {
547
                        store.filters.clear();
548
                        store.filter(
549
                            'search',
550
                            '%' + value + '%'
551
                        );
552
                    }
553
                }
554
            },
555
            'connect-log-list': {
556
                changeLogging: me.onChangeLogging,
557
                '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...
558
                    var me = this,
559
                        record,
560
                        tabs = me.getLogTabs(),
561
                        request = tabs.down('textarea[name=request]'),
562
                        response = tabs.down('textarea[name=response]');
563
564
                    // make sure that we have a selection
565
                    if (selected && selected.length > 0) {
566
                        record = selected[0];
567
568
                        request.setValue(record.get('request'));
569
                        response.setValue(record.get('response'));
570
                    }
571
572
                }
573
            },
574
            'connect-export-window': {
575
                showPriceWindow: me.onShowPriceWindow
576
            },
577
578
            'connect-export-list': {
579
                getExportStatus: me.onGetExportStatus,
580
                reloadLocalProducts: me.onGetExportStatus
581
            },
582
583
            'connect-log-list button[action=clear]': {
584
                click: function() {
585
                    var table = me.getLogList(),
586
                        store = table.getStore();
587
588
                    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...
589
                        '{s name=log/clear/confirm}Delete log?{/s}',
590
                        '{s name=log/clear/message}You are about to delete all log entries. Continue?{/s}',
591
                        function (response) {
592
                            if ( response !== 'yes' ) {
593
                                return;
594
                            }
595
                            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...
596
                                url: '{url action=clearLog}',
597
                                method: 'POST',
598
                                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...
599
                                    store.reload();
600
                                }
601
                            });
602
603
                        }
604
                    );
605
                }
606
            },
607
            'connect-marketplace-attributes-mapping button[action=save]': {
608
                click: function () {
609
                    me.saveMarketplaceAttributesMapping();
610
                }
611
            }
612
        });
613
614
        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...
615
    },
616
617
    getEventListeners: function() {
618
        var me = this;
619
620
        return {
621
            'connect-login': me.login,
622
            'connect-register': me.register,
623
            scope: me
624
        };
625
    },
626
627
    sendAjaxRequest: function(url, params, callback, errorCallback) {
628
        var me = this;
629
630
        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...
631
            url: url,
632
            method: 'POST',
633
            params: params,
634
            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...
635
                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...
636
637
                if (response.success === false) {
638
                    if (Ext.isFunction(errorCallback)) {
639
                        errorCallback(response);
640
                    } else {
641
                        me.displayErrorMessage(response);
642
                        me.hideLoadingMask();
643
                    }
644
                    return;
645
                }
646
647
                callback(response);
648
            }
649
        });
650
    },
651
652
    login: function(params, callback) {
653
        var me = this;
654
655
        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...
656
            me.messages.login.waitMessage,
657
            me.messages.login.waitTitle
658
        );
659
660
        me.sendAjaxRequest(
661
            '{url controller=Connect action=login}',
662
            params,
663
            function(response) {
664
665
                response.shopwareId = params.shopwareID;
666
                me.splashScreen.close();
667
668
                if (response.success == true) {
669
                    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...
670
671
                    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...
672
                        me.messages.login.successTitle,
673
                        me.messages.login.successMessage,
674
                        me.messages.growlMessage
675
                    );
676
677
                    if (callback && typeof callback === 'function') {
678
                        callback(response);
679
                    }
680
681
                    document.cookie = 'connectLogin=true';
682
                    location.reload();
683
                }
684
            },
685
            function(response) {
686
                me.splashScreen.close();
687
                me.displayErrorMessage(response, callback);
688
            }
689
        );
690
    },
691
692
    register: function(params, callback) {
693
        var me = this;
694
695
        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...
696
            me.messages.login.waitMessage,
697
            me.messages.login.waitTitle
698
        );
699
700
        me.sendAjaxRequest(
701
            '{url controller=Connect action=register}',
702
            params,
703
            function(response) {
704
705
                response.shopwareId = params.shopwareID;
706
                me.splashScreen.close();
707
708
                if (response.success == true) {
709
                    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...
710
711
                    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...
712
                        me.messages.login.successTitle,
713
                        me.messages.login.successMessage,
714
                        me.messages.growlMessage
715
                    );
716
717
                    if (callback && typeof callback === 'function') {
718
                        callback(response);
719
                    }
720
721
                    document.cookie = 'connectLogin=true';
722
                    location.reload();
723
                }
724
            },
725
            function(response) {
726
                me.splashScreen.close();
727
                me.displayErrorMessage(response, callback);
728
            }
729
        );
730
    },
731
732
    displayErrorMessage: function(response, callback) {
733
        var me = this,
734
            message = response.message;
735
736
        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...
737
            title: me.messages.error,
738
            text: message,
739
            width: 350
740
        });
741
742
        callback = typeof callback === 'function' && callback || function() {};
743
744
        if (response.hasOwnProperty('authentication') && response.authentication) {
745
            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...
746
        }
747
748
        this.hideLoadingMask();
749
    },
750
751
    /**
752
     * Dynamically create filter fields for all known command types
753
     */
754
    populateLogCommandFilter: function() {
755
        var me = this,
756
            logList = me.getLogList(),
757
            store = logList.store,
758
            container = me.getLogFilter().down('fieldcontainer');
759
760
        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...
761
            url: '{url action=getLogCommands}',
762
            method: 'POST',
763
            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...
764
                var data;
765
766
                if (!response || !response.responseText) {
767
                    return;
768
                }
769
770
                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...
771
772
                Ext.each(data.data, function(command) {
773
                    store.getProxy().extraParams['commandFilter_' + command] = true;
774
                    container.add({
775
                        boxLabel  : command,
776
                        name      : command,
777
                        inputValue:  true,
778
                        checked   :  true,
779
                        filter    : 'commandFilter'
780
                    });
781
                });
782
783
                store.reload();
784
            },
785
            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...
786
                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...
787
            }
788
789
        });
790
791
    },
792
793
    /**
794
     * Method called when clear category button is clicked.
795
     */
796
    onExportCategoryFilterClearAction: function() {
797
        var me = this;
798
799
        var table = me.getExportList(),
800
            filter = me.getExportFilter(),
0 ignored issues
show
Unused Code introduced by
The variable filter seems to be never used. Consider removing it.
Loading history...
801
            store = table.getStore();
802
        store.filters.removeAtKey('exportCategoryFilter');
803
        store.load();
804
805
        //deselect all nodes
806
        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...
807
    },
808
809
    /**
810
     * Callback method called when the user selects a product in the "changed products" view.
811
     * Will populate the bottom "change view" grid with the correct tabs
812
     *
813
     * @param grid
814
     * @param selected
815
     * @param eOpts
816
     */
817
    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...
818
        var me = this,
819
            record,
820
            remoteChangeSet,
821
            changeRecord,
822
            changeFlag = 0, flags,
823
            changeView = me.getChangeView();
824
825
        // make sure that we have a selection
826
        if (selected && selected.length > 0) {
827
            record = selected[0];
828
829
            // Decode the lastUpdate info
830
            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...
831
832
            // Build a record for the changeset
833
            changeRecord = Ext.create('Shopware.apps.Connect.model.changed_products.Product', {
834
                shortDescriptionLocal: record.get('description'),
835
                shortDescriptionRemote: remoteChangeSet['shortDescription'],
836
837
                longDescriptionLocal: record.get('descriptionLong'),
838
                longDescriptionRemote: remoteChangeSet['longDescription'],
839
840
                additionalDescriptionLocal: record.get('additionalDescription'),
841
                additionalDescriptionRemote: remoteChangeSet['additionalDescription'],
842
843
                nameLocal: record.get('name'),
844
                nameRemote: remoteChangeSet['name'],
845
846
                priceLocal: record.get('price'),
847
                priceRemote: remoteChangeSet['price'],
848
849
                imageLocal: record.get('images'),
850
                imageRemote: remoteChangeSet['image'].join('|')
851
            });
852
853
            // Read updateFlag and build update flag object
854
            changeFlag = record.get('lastUpdateFlag');
855
            flags = {
856
                2: 'shortDescription',
857
                4: 'longDescription',
858
                8: 'name',
859
                16: 'image',
860
                32: 'price',
861
                64: 'imageInitialImport',
862
                128: 'additionalDescription'
863
            };
864
            // Check all flags and show the corresponding tab if it is active
865
            // if not, remove the tab without destroying the component
866
            changeView.removeAll();
867
868
            Ext.each(Object.keys(flags), function(key) {
869
                var fieldName = flags[key];
870
                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...
871
                    var form = changeView.createContainer(fieldName);
872
                    form.loadRecord(changeRecord);
873
                    changeView.add(form);
874
                    form.applyButton.handler = function () {
875
                        me.applyChanges(fieldName, changeRecord.get(fieldName + 'Remote'), record.get('id'), changeView);
876
                    }
877
                }
878
            });
879
880
            changeView.setTitle(record.get('name'));
881
            changeView.setActiveTab(0);
882
        }
883
    },
884
885
    /**
886
     * Callback to apply a given change for a given product
887
     *
888
     * @param type
889
     * @param value
890
     * @param detailId
891
     * @param changeView
892
     */
893
    applyChanges: function(type, value, detailId, changeView) {
894
        var me = this,
895
            changedProductsList = me.getChangedList(),
896
            store = changedProductsList.store;
897
898
        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...
899
            url: '{url controller=LastChanges action=applyChanges}',
900
            method: 'POST',
901
            params: {
902
                type: type,
903
                value: value,
904
                detailId: detailId
905
            },
906
            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...
907
                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...
908
                if (responseObject.success) {
909
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=changed_products/success/notification/message}Successfully applied changes{/s}');
910
                } else {
911
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', responseObject.message);
912
                }
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
913
914
                store.reload();
915
                changeView.removeAll();
916
            },
917
            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...
918
                me.createGrowlMessage('{s name=connect/error}Error{/s}', response.responseText);
919
            }
920
921
        });
922
923
    },
924
925
    /**
926
     * Callback function that will insert from/for export
927
     *
928
     * @param btn
929
     */
930
    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...
931
        var me = this,
932
            list = me.getExportList(),
933
            records = list.selModel.getSelection(),
934
            ids = [],
935
            title = me.messages.insertOrUpdateProductTitle,
936
            batchSize = 50;
937
938
        if (records.length == 0) {
939
            return;
940
        }
941
942
        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...
943
            ids.push(record.get('id'));
944
        });
945
946
        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...
947
            url: '{url action=getArticleSourceIds}',
948
            method: 'POST',
949
            params: {
950
                'ids[]': ids
951
            },
952
            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...
953
                if (response.responseText) {
954
                    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...
955
                    if (operation) {
956
                        if (!operation.success) {
957
                            me.createGrowlMessage(title, operation.message, true);
958
                        } else {
959
                            Ext.create('Shopware.apps.Connect.view.export.product.Progress', {
960
                                startButtonHandler: function (caller) {
961
                                    me.startArticleExport(operation.sourceIds, batchSize, caller,0)
962
                                },
963
                                count: operation.sourceIds.length,
964
                                totalTime: operation.sourceIds.length / batchSize * 4 / 60
965
                            }).show();
966
                        }
967
                    }
968
                }
969
            }
970
        });
971
    },
972
973
    exportAll: function(count, batchSize, window, offset) {
974
        var me = this,
975
            message = me.messages.insertOrUpdateProductMessage,
976
            title = me.messages.insertOrUpdateProductTitle,
977
            list = me.getExportList();
978
        offset = parseInt(offset);
979
        batchSize = parseInt(batchSize);
980
        count = parseInt(count);
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
981
982
        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...
983
            url: '{url action=exportAllProducts}',
984
            method: 'POST',
985
            params: {
986
                'offset': offset,
987
                'batchSize': batchSize
988
            },
989
            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...
990
                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...
991
992
                if (!operation.success && operation.messages) {
993
994
                    if(operation.messages.price && operation.messages.price.length > 0){
995
                        var priceMsg = Ext.String.format(
996
                            me.messages.priceErrorMessage, operation.messages.price.length, count
997
                        );
998
                        me.createGrowlMessage(title, priceMsg, true);
999
                    }
1000
1001
                    if(operation.messages.default && operation.messages.default.length > 0){
1002
                        operation.messages.default.forEach( function(message){
1003
                            me.createGrowlMessage(title, message, true);
1004
                        });
1005
                    }
1006
                }
1007
1008
                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...
1009
                window.progressField.updateProgress(
1010
                    offset/count,
1011
                    Ext.String.format(window.snippets.process, offset, count),
1012
                    true
1013
                );
1014
1015
                if (count <= offset) {
1016
                    window.closeWindow();
1017
                    me.createGrowlMessage(title, message, false);
1018
                    list.store.load();
1019
                    me.onGetExportStatus();
1020
                } else {
1021
                    //otherwise we have to call this function recursive with the next offset
1022
                    me.exportAll(count,batchSize,window,(offset+batchSize));
1023
                }
1024
            },
1025
            failure: function(operation) {
1026
                me.createGrowlMessage(title, operation.responseText, true);
1027
                window.inProcess = false;
1028
                window.cancelButton.setDisabled(false);
1029
            }
1030
        });
1031
    },
1032
1033
    /**
1034
     * Callback function that will insert from/for export
1035
     *
1036
     * @param sourceIds
1037
     * @param batchSize
1038
     * @param window
1039
     * @param offset
1040
     */
1041
    startArticleExport: function(sourceIds, batchSize, window, offset) {
1042
        offset = parseInt(offset) || 0;
1043
        var limit = offset + batchSize;
1044
1045
        if (limit > sourceIds.length) {
1046
            limit = sourceIds.length;
1047
        }
1048
1049
        var me = this,
1050
        message = me.messages.insertOrUpdateProductMessage,
1051
        title = me.messages.insertOrUpdateProductTitle,
1052
        list = me.getExportList();
1053
1054
        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...
1055
            url: '{url action=insertOrUpdateProduct}',
1056
            method: 'POST',
1057
            params: {
1058
                'sourceIds[]': sourceIds.slice(offset, limit)
1059
            },
1060
            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...
1061
                var doneDetails = limit;
1062
                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...
1063
1064
                if (!operation.success && operation.messages) {
1065
1066
                    if(operation.messages.price && operation.messages.price.length > 0){
1067
                        var priceMsg = Ext.String.format(
1068
                            me.messages.priceErrorMessage, operation.messages.price.length, sourceIds.length
1069
                        );
1070
                        me.createGrowlMessage(title, priceMsg, true);
1071
                    }
1072
1073
                    if(operation.messages.default && operation.messages.default.length > 0){
1074
                        operation.messages.default.forEach( function(message){
1075
                            me.createGrowlMessage(title, message, true);
1076
                        });
1077
                    }
1078
                }
1079
1080
                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...
1081
                window.progressField.updateProgress(
1082
                    limit / sourceIds.length,
1083
                    Ext.String.format(window.snippets.process, doneDetails, sourceIds.length),
1084
                    true
1085
                );
1086
1087
                if (limit >= sourceIds.length) {
1088
                    window.closeWindow();
1089
                    me.createGrowlMessage(title, message, false);
1090
                    list.store.load();
1091
                    me.onGetExportStatus();
1092
                } else {
1093
                    //otherwise we have to call this function recursive with the next offset
1094
                    me.startArticleExport(sourceIds, batchSize, window, limit);
1095
                }
1096
            },
1097
            failure: function(operation) {
1098
                me.createGrowlMessage(title, operation.responseText, true);
1099
                window.inProcess = false;
1100
                window.cancelButton.setDisabled(false);
1101
            }
1102
        });
1103
    },
1104
1105
    cronExportAll: function () {
1106
        var me = this;
1107
1108
        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...
1109
            url: '{url action=exportAllWithCron}',
1110
            method: 'POST',
1111
1112
            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...
1113
                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...
1114
                if (operation.success) {
1115
                    me.createGrowlMessage("{s name=connect/success}Success{/s}", me.messages.allProductsMarkedForExportWithCron, true);
1116
                    me.getExportList().getStore().reload();
1117
                } else {
1118
                    me.createGrowlMessage("{s name=connect/error}Error{/s}", operation.message, true);
1119
                }
1120
            }
1121
        });
1122
    },
1123
1124
    startStreamExport: function(streamIds, sourceIdCount, batchSize, window, currentStreamIndex, offset) {
1125
        offset = parseInt(offset) || 0;
1126
        var limit = batchSize;
1127
1128
        var me = this,
1129
            list = me.getExportStreamList();
1130
1131
        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...
1132
            url: '{url action=exportStream}',
1133
            method: 'POST',
1134
            params: {
1135
                'offset': offset,
1136
                'limit': limit,
1137
                'streamIds[]': streamIds,
1138
                'currentStreamIndex': currentStreamIndex
1139
            },
1140
            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...
1141
                var sticky = false;
1142
                if (response.responseText) {
1143
                    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...
1144
                    if (operation) {
1145
                        if (!operation.success && operation.messages) {
1146
                            if(operation.messages.price && operation.messages.price.length > 0){
1147
                                var priceMsg = Ext.String.format(
1148
                                    me.messages.priceErrorMessage, operation.messages.price.length, sourceIdCount
1149
                                );
1150
                                me.createGrowlMessage(me.messages.exportStreamTitle, priceMsg, true);
1151
                            }
1152
1153
                            if(operation.messages.default && operation.messages.default.length > 0){
1154
                                operation.messages.default.forEach( function(message){
1155
                                    me.createGrowlMessage(me.messages.exportStreamTitle, message, true);
1156
                                });
1157
                            }
1158
1159
                            window.inProcess = false;
1160
                            window.cancelButton.setDisabled(false);
1161
                            return;
1162
                        }
1163
1164
                        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...
1165
                        window.progressFieldStream.updateProgress(
1166
                            operation.processedStreams / streamIds.length,
1167
                            Ext.String.format(window.snippets.processStream, operation.processedStreams, streamIds.length),
1168
                            false
1169
                        );
1170
1171
                        window.progressField.updateText(Ext.String.format(window.snippets.process, operation.newOffset, sourceIdCount));
1172
                        window.progressField.updateProgress(
1173
                            operation.newOffset / sourceIdCount,
1174
                            Ext.String.format(window.snippets.process, operation.newOffset, sourceIdCount),
1175
                            false
1176
                        );
1177
1178
                        if (operation.hasMoreIterations) {
1179
                            currentStreamIndex = operation.nextStreamIndex;
1180
                            offset = operation.newOffset;
1181
                            me.startStreamExport(streamIds, sourceIdCount, batchSize, window, currentStreamIndex, offset);
1182
                        } else {
1183
                            window.inProcess = false;
1184
                            window.cancelButton.setDisabled(false);
1185
1186
                            me.createGrowlMessage(me.messages.exportStreamTitle, me.messages.exportStreamMessage, sticky);
1187
1188
                            list.setLoading(false);
1189
                            list.store.load();
1190
                        }
1191
                    }
1192
                }
1193
            }
1194
        });
1195
    },
1196
1197
    /**
1198
     * Callback function that will start the export all dialog
1199
     *
1200
     * @param btn
1201
     */
1202
    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...
1203
        var me = this,
1204
            list = me.getExportList(),
1205
            title = me.messages.insertOrUpdateProductTitle,
1206
            batchSize = 50;
1207
1208
        list.setLoading(true);
1209
1210
        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...
1211
            url: '{url action=getArticleCount}',
1212
            method: 'POST',
1213
            params: {
1214
                'exportAll': true
1215
            },
1216
            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...
1217
                list.setLoading(false);
1218
1219
                if (!response.responseText) {
1220
                    return;
1221
                }
1222
1223
                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...
1224
                if (!operation) {
1225
                    return;
1226
                }
1227
                if (!operation.success) {
1228
                    me.createGrowlMessage(title, operation.message, true);
1229
                } else {
1230
                    if (operation.count > 1000) {
1231
1232
                        Ext.create('Shopware.apps.Connect.view.export.product.manyProductsDialog', {
1233
                            count: operation.count
1234
                        }).show();
1235
                        return;
1236
                    }
1237
1238
                    Ext.create('Shopware.apps.Connect.view.export.product.Progress', {
1239
                        startButtonHandler: function (caller) {
1240
                            me.exportAll(operation.count, batchSize, caller,0)
1241
                        },
1242
                        count: operation.count,
1243
                        totalTime: operation.count / batchSize * 4 / 60
1244
                    }).show();
1245
                }
1246
            }
1247
        });
1248
    },
1249
1250
    /**
1251
     * Callback function that will delete a product from/for export
1252
     *
1253
     * @param btn
1254
     */
1255
    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...
1256
        var me = this,
1257
            list = me.getExportList(),
1258
            records = list.selModel.getSelection(),
1259
            ids = [],
1260
            messages = [];
1261
1262
        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...
1263
            ids.push(record.get('id'));
1264
        });
1265
1266
        list.setLoading();
1267
1268
        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...
1269
            url: '{url action=deleteProduct}',
1270
            method: 'POST',
1271
            params: {
1272
                'ids[]': ids
1273
            },
1274
            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...
1275
                var sticky = false;
1276
                if (response.responseText) {
1277
                    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...
1278
                    if (operation) {
1279
                        if (!operation.success && operation.messages) {
1280
                            messages = operation.messages;
1281
                            sticky = true;
1282
                        }
1283
                    }
1284
                }
1285
                if (messages.length > 0) {
1286
                    messages.forEach( function(message){
1287
                        me.createGrowlMessage(me.messages.deleteProductTitle, message, sticky);
1288
                    });
1289
                } else {
1290
                    me.createGrowlMessage(me.messages.deleteProductTitle, me.messages.deleteProductMessage, sticky);
1291
                }
1292
1293
                list.setLoading(false);
1294
                list.store.load();
1295
            }
1296
        });
1297
    },
1298
1299
    /**
1300
     * Callback function that will export or delete a product stream from/for export
1301
     *
1302
     * @param btn
1303
     */
1304
    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...
1305
        var me = this,
1306
            list = me.getExportStreamList(),
1307
            records = list.selModel.getSelection(),
1308
            staticStreamIds = [],
1309
            dynamicStreamIds = [];
1310
1311
        if (records.length == 0) {
1312
            return;
1313
        }
1314
1315
        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...
1316
            if (record.get('type') == 1) {
1317
                dynamicStreamIds.push(record.get('id'));
1318
            } else {
1319
                staticStreamIds.push(record.get('id'));
1320
            }
1321
        });
1322
        if (dynamicStreamIds.length > 0) {
1323
            me.prepareDynamicStreamExport(dynamicStreamIds);
1324
        }
1325
1326
        if (staticStreamIds.length > 0) {
1327
            me.prepareStaticStreamExport(staticStreamIds);
1328
        }
1329
1330
    },
1331
1332
    prepareDynamicStreamExport: function(ids){
1333
        var me = this,
1334
            list = me.getExportStreamList(),
1335
            store = list.store,
1336
            title = me.messages.exportStreamTitle;
1337
1338
        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...
1339
            url: '{url action=prepareDynamicStreams}',
1340
            method: 'POST',
1341
            params: {
1342
                'streamIds[]': ids
1343
            },
1344
            success: function(response) {
1345
                if (response.responseText) {
1346
                    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...
1347
1348
                    if (!operation) {
1349
                        return;
1350
                    }
1351
1352
                    if (!operation.success) {
1353
                        me.createGrowlMessage(title, operation.messages, false);
1354
                        return;
1355
                    }
1356
1357
                    me.createGrowlMessage(title, me.messages.exportDynamicStreamMessage, false);
1358
                    store.reload();
1359
                }
1360
            }
1361
        });
1362
    },
1363
1364
    /**
1365
     * @param ids
1366
     */
1367
    prepareStaticStreamExport: function(ids){
1368
        var me = this;
1369
1370
        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...
1371
            url: '{url action=getStreamProductsCount}',
1372
            method: 'POST',
1373
            params: {
1374
                'ids[]': ids
1375
            },
1376
            success: function(response) {
1377
                if (response.responseText) {
1378
                    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...
1379
1380
                    if (!operation) {
1381
                        return;
1382
                    }
1383
1384
                    if (!operation.success) {
1385
                        var title = me.messages.exportStreamTitle,
1386
                            messages = operation.messages;
1387
1388
                        //todo: handle price and default errors
1389
                        if (messages.default.length > 0) {
1390
                            messages.default.forEach(function (message) {
1391
                                me.createGrowlMessage(title, message, false);
1392
                            });
1393
                        }
1394
                    } else {
1395
                        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...
1396
                            streamIds: ids,
1397
                            sourceIdsCount: operation.sourceIdsCount
1398
                        }).show();
1399
                    }
1400
                }
1401
            }
1402
        });
1403
    },
1404
1405
    onRemoveStreams: function(){
1406
        var me = this,
1407
            list = me.getExportStreamList(),
1408
            records = list.selModel.getSelection(),
1409
            ids = [],
1410
            url,
1411
            message,
1412
            messages = [],
1413
            title;
1414
1415
        if (records.length == 0) {
1416
            return;
1417
        }
1418
1419
        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...
1420
            ids.push(record.get('id'));
1421
        });
1422
1423
        url = '{url action=removeStreams}';
1424
        title = me.messages.removeStreamTitle;
1425
        message = me.messages.removeStreamMessage;
1426
1427
        list.setLoading();
1428
1429
        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...
1430
            url: url,
1431
            method: 'POST',
1432
            params: {
1433
                'ids[]': ids
1434
            },
1435
            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...
1436
                var sticky = false;
1437
                if (response.responseText) {
1438
                    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...
1439
                    if (operation) {
1440
                        if (!operation.success && operation.messages) {
1441
                            messages = operation.messages;
1442
                            sticky = true;
1443
                        }
1444
                    }
1445
                }
1446
1447
                if (messages.length > 0) {
1448
                    messages.forEach( function(message){
1449
                        me.createGrowlMessage(title, message, sticky);
1450
                    });
1451
                } else {
1452
                    me.createGrowlMessage(title, message, sticky);
1453
                }
1454
1455
                list.setLoading(false);
1456
                list.store.load();
1457
            }
1458
        });
1459
    },
1460
1461
    /**
1462
     * Helper to show a growl message
1463
     *
1464
     * @param title
1465
     * @param message
1466
     */
1467
    createGrowlMessage: function(title, message, sticky) {
1468
        var me = this;
1469
1470
        if (!sticky) {
1471
            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...
1472
        } else {
1473
            Shopware.Notification.createStickyGrowlMessage({
1474
                title: title,
1475
                text: message,
1476
                width: 400
1477
            });
1478
        }
1479
    },
1480
1481
    /**
1482
     * Callback function to set the window title depending on the current navigation entry
1483
     *
1484
     * @param tree
1485
     * @param node
1486
     */
1487
    onSelectNavigationEntry: function(tree, node) {
1488
        var me = this,
1489
            panel = me.getPanel(),
1490
            win = me.getWindow(),
1491
            item = node.get('id'),
1492
            layout = panel.getLayout();
1493
1494
        layout.setActiveItem(item);
1495
        win.loadTitle(node);
1496
    },
1497
1498
    /**
1499
     * Callback function to save the configuration form
1500
     *
1501
     * @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...
1502
     */
1503
    onSaveConfigForm: function(btn) {
1504
        var me = this;
0 ignored issues
show
Unused Code introduced by
The variable me seems to be never used. Consider removing it.
Loading history...
1505
            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...
1506
1507
        form.setLoading();
1508
1509
        if (form.getRecord()) {
1510
            var model = form.getRecord();
1511
1512
            form.getForm().updateRecord(model);
1513
            model.save({
1514
                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...
1515
                    form.setLoading(false);
1516
                    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...
1517
                },
1518
                failure: function(record) {
1519
                    form.setLoading(false);
1520
                    var rawData = record.getProxy().getReader().rawData,
1521
                        message = rawData.message;
1522
                    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...
1523
                }
1524
            });
1525
        }
1526
    },
1527
1528
    /**
1529
     * Callback function to save the import configuration form
1530
     *
1531
     * @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...
1532
     */
1533
    onSaveImportConfigForm: function(btn) {
1534
        var me = this,
1535
            form = btn.up('form');
1536
1537
        form.setLoading();
1538
        if (form.getRecord()) {
1539
            var model = form.getRecord();
1540
1541
            form.getForm().updateRecord(model);
1542
            model.save({
1543
                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...
1544
                    form.setLoading(false);
1545
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1546
                },
1547
                failure: function(record) {
1548
                    form.setLoading(false);
1549
                    var rawData = record.getProxy().getReader().rawData,
1550
                        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...
1551
                    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...
1552
                }
1553
            });
1554
        }
1555
    },
1556
1557
    onSaveUnitsMapping: function(btn){
1558
        var me = this,
1559
            unitsStore = me.getUnitsMapping().getStore(),
1560
            form = btn.up('form');
1561
1562
        if (unitsStore.getModifiedRecords().length > 0){
1563
            form.setLoading();
1564
        }
1565
1566
        unitsStore.sync({
1567
            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...
1568
                form.setLoading(false);
1569
                me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1570
                me.getUnitsMapping().unitsStore.load({
1571
                    scope: this,
1572
                    callback: function(records, operation, success) {
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 success is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter 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...
1573
                        me.getUnitsMapping().getStore().reload();
1574
                    }
1575
                });
1576
            },
1577
            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...
1578
                me.createGrowlMessage('{s name=connect/error}Error{/s}','{s name=config/units/error_save_message}Mapping der Einheiten konnte nicht gespeichert werden.{/s}');
1579
            }
1580
        });
1581
    },
1582
1583
    /**
1584
     * Reload Shopware Connect units store
1585
     * and show/hide already assigned units
1586
     */
1587
    onHideAssignedUnits: function(checkbox, value)
1588
    {
1589
        var me = this;
1590
        var store = me.getUnitsMapping().getStore();
1591
        var hideAssigned = 0;
1592
1593
        if (value === true) {
1594
            hideAssigned = 1;
1595
        }
1596
1597
        store.load({
1598
            params: {
1599
                'hideAssignedUnits': hideAssigned
1600
            }
1601
        });
1602
    },
1603
1604
    onAdoptUnits: function(btn) {
1605
        var me = this;
1606
        var form = btn.up('form');
1607
1608
        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...
1609
            title: me.messages.adoptUnitsTitle,
1610
            msg: me.messages.adoptUnitsMessage,
1611
            buttons: Ext.Msg.YESNO,
1612
            fn: function(response) {
1613
                if(response !== 'yes') {
1614
                    return;
1615
                }
1616
1617
                form.setLoading();
1618
                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...
1619
                    url: '{url controller=ConnectConfig action=adoptUnits}',
1620
                    method: 'POST',
1621
                    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...
1622
                        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...
1623
                        form.setLoading(false);
1624
                        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...
1625
                        } 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...
1626
                        }
1627
                    }
1628
                });
1629
            }
1630
        });
1631
    },
1632
1633
    /**
1634
     * Callback function to save the export configuration form
1635
     *
1636
     * @param data
1637
     * @param btn
1638
     */
1639
    onSaveExportSettingsForm: function(data, btn) {
1640
        var me = this,
1641
            form = btn.up('form');
1642
1643
        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...
1644
1645
        if (data.exportPriceMode.length == 0) {
1646
            return me.createGrowlMessage(me.messages.exportTitle, me.messages.priceModeNotSelected);
1647
        }
1648
1649
        if (!data.hasOwnProperty('descriptionField') || data.descriptionField.length == 0) {
1650
            return me.createGrowlMessage(me.messages.exportTitle, me.messages.productDescriptionNotSelected);
1651
        }
1652
1653
        form.setLoading();
1654
        model.save({
1655
            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...
1656
                form.setLoading(false);
1657
                me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Successfully applied changes{/s}');
1658
1659
                if (me.hasOwnProperty('exportWindow') && me.exportWindow.isWindow) {
1660
                    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...
1661
                    domEl[0].remove();
1662
                    me.exportWindow.close();
1663
                }
1664
            },
1665
            failure: function(record) {
1666
                form.setLoading(false);
1667
                var rawData = record.getProxy().getReader().rawData,
1668
                    message = rawData.message;
1669
                me.createGrowlMessage('{s name=connect/error}Error{/s}', message);
1670
            }
1671
        });
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...
1672
    },
1673
1674
    /**
1675
     * Sends marketplace attributes mapping to the PHP
1676
     */
1677
    saveMarketplaceAttributesMapping: function() {
1678
        var me = this,
1679
            panel = me.getMarketeplaceMappingPanel(),
1680
            store = me.getMarketeplaceMapping().localProductAttributesStore;
1681
1682
        if (store.getNewRecords().length > 0 || store.getUpdatedRecords().length > 0 || store.getRemovedRecords().length > 0) {
1683
            panel.setLoading();
1684
            store.sync({
1685
                success :function (records, operation) {
0 ignored issues
show
Unused Code introduced by
The parameter records is not used and could be removed.

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

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

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

Loading history...
1686
                    panel.setLoading(false);
1687
                    me.createGrowlMessage('{s name=connect/success}Success{/s}', '{s name=config/success/message}Änderungen erfolgreich übernommen{/s}');
1688
                },
1689
                failure:function (batch) {
1690
                    panel.setLoading(false);
1691
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', batch.proxy.getReader().jsonData.message);
1692
                }
1693
            });
1694
        }
1695
    },
1696
1697
    /**
1698
     * Calculate needed time to finish synchronization
1699
     *
1700
     * @param progressBar
1701
     */
1702
    onCalculateFinishTime: function(progressBar) {
1703
        var me = this;
1704
        me.time = 0;
1705
        me.resetSpentTime();
1706
1707
        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...
1708
            interval: 60000,
1709
            run: function() {
1710
                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...
1711
                    url: '{url controller=ConnectConfig action=calculateFinishTime}',
1712
                    method: 'POST',
1713
                    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...
1714
                        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...
1715
1716
                        if (responseObject.time > 0) {
1717
                            if ((responseObject.time - (me.time + me.spentTime)) == 0) {
1718
                                return;
1719
                            }
1720
                            me.time = responseObject.time;
1721
                            me.resetSpentTime();
1722
1723
                            var time = me.secondsToTime(me.time);
1724
                            progressBar.wait({
1725
                                interval: 500,
1726
                                increment: 15,
1727
                                scope: this
1728
                            });
1729
                            progressBar.updateText(me.messages.updatePartOneMessage + ' ' + time.h + ' ' + me.messages.hours + ' ' + time.m + ' ' + me.messages.minutes + ' ' + time.s + ' ' + me.messages.seconds + ' ' + me.messages.updatePartTwoMessage);
1730
                        } else {
1731
                            me.resetSpentTime();
1732
                            me.resetTime();
1733
                            progressBar.reset();
1734
                            progressBar.updateText(me.messages.doneMessage);
1735
                        }
1736
                    }
1737
                });
1738
            }
1739
        });
1740
1741
        Ext.TaskManager.start({
1742
            interval: 5000,
1743
            run: function () {
1744
                if (me.time >= 5) {
1745
                    me.time = me.time - 5;
1746
                    me.spentTime = me.spentTime + 5;
1747
                    var time = me.secondsToTime(me.time);
1748
                    progressBar.updateText(me.messages.updatePartOneMessage + ' ' + time.h + ' ' + me.messages.hours + ' ' + time.m + ' ' + me.messages.minutes + ' ' + time.s + ' ' + me.messages.seconds + ' ' + me.messages.updatePartTwoMessage);
1749
                } else {
1750
                    progressBar.reset();
1751
                    progressBar.updateText(me.messages.doneMessage);
1752
                }
1753
            }
1754
        });
1755
1756
    },
1757
1758
    onResetPriceType: function () {
1759
        var me = this;
1760
1761
        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...
1762
            scope: this,
1763
            url: '{url module=backend controller=ConnectConfig action=resetPriceType}',
1764
            success: function (result) {
1765
                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...
1766
                if (response.success) {
1767
                    me.createGrowlMessage(
1768
                        me.messages.priceResetLabel,
1769
                        me.messages.priceResetSuccess
1770
                    );
1771
                } else {
1772
                    me.createGrowlMessage(
1773
                        me.messages.priceResetLabel,
1774
                        me.messages.priceResetError
1775
                    );
1776
                }
1777
            }
1778
        });
1779
    },
1780
1781
    onResetExchangeSettings: function () {
1782
        var me = this;
1783
1784
        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...
1785
            scope: this,
1786
            url: '{url module=backend controller=ConnectConfig action=resetExchangeSettings}',
1787
            success: function (result) {
1788
                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...
1789
                if (response.success) {
1790
                    me.createGrowlMessage(
1791
                        me.messages.exchangeSettingsResetLabel,
1792
                        me.messages.exchangeSettingsResetSuccess
1793
                    );
1794
1795
                    //reload after 3 sec
1796
                    setTimeout(function(){
1797
                        location.reload();
1798
                    }, 3000);
1799
                } else {
1800
                    me.createGrowlMessage(
1801
                        me.messages.exchangeSettingsResetLabel,
1802
                        me.messages.exchangeSettingsResetError
1803
                    );
1804
                }
1805
            }
1806
        });
1807
    },
1808
1809
    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...
1810
        var me = this;
1811
        var loggingEnabled = 0;
1812
        if (newValue === true) {
1813
            loggingEnabled = 1;
1814
        }
1815
1816
        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...
1817
            url: '{url controller=ConnectConfig action=changeLogging}',
1818
            method: 'POST',
1819
            params: {
1820
                enableLogging: loggingEnabled
1821
            },
1822
            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...
1823
                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...
1824
                if (data.success == false) {
1825
                    me.createGrowlMessage('{s name=connect/error}Error{/s}', '{s name=config/log_label}Logging aktivieren{/s}');
1826
                }
1827
            }
1828
        });
1829
    },
1830
1831
    onGetExportStatus: function() {
1832
        var me = this;
1833
1834
        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...
1835
            scope: me,
1836
            url: '{url controller=Connect action=getExportStatus}',
1837
            success: function (result) {
1838
                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...
1839
                if (response.success === true) {
1840
1841
                    //removes the old export status
1842
                    if (me.exportStatusEl) {
1843
                        Ext.destroy(me.exportStatusEl);
1844
                    }
1845
1846
                    //sets the new export status
1847
                    me.exportStatusEl = me.getExportWindow().getEl().insertHtml(
1848
                        "afterBegin",
1849
                        me.getHtmlStatus(response.data, response.total),
1850
                        true
1851
                    );
1852
                }
1853
            }
1854
        });
1855
    },
1856
1857
    getHtmlStatus: function ($start, $end) {
1858
        var me = this;
1859
1860
        return '<div class="sc-export-status">' +
1861
            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...
1862
            '</div>';
1863
    },
1864
1865
1866
    /**
1867
     * On change customer group for price configuration
1868
     * reload the store with available price fields
1869
     *
1870
     * @param combo
1871
     * @param newValue
1872
     * @param oldValue
1873
     */
1874
    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...
1875
        var me = this;
1876
        var exportConfigForm = me.getExportConfigForm();
1877
        exportConfigForm.setLoading(true);
1878
        exportConfigForm.priceFieldForPrice.store.load({
1879
            params: {
1880
                'customerGroup': newValue
1881
            },
1882
            callback: function() {
1883
                exportConfigForm.setLoading(false);
1884
            }
1885
        });
1886
    },
1887
1888
    /**
1889
     * On change customer group for purchase price configuration
1890
     * reload the store with available price fields
1891
     *
1892
     * @param combo
1893
     * @param newValue
1894
     * @param oldValue
1895
     */
1896
    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...
1897
        var me = this;
1898
        var exportConfigForm = me.getExportConfigForm();
1899
        exportConfigForm.setLoading(true);
1900
        exportConfigForm.priceFieldForPurchasePrice.store.load({
1901
            params: {
1902
                'customerGroup': newValue
1903
            },
1904
            callback: function() {
1905
                exportConfigForm.setLoading(false);
1906
            }
1907
        });
1908
    },
1909
1910
    /**
1911
     * Checks price field selection, if it's not supported
1912
     * shows error message
1913
     *
1914
     * @param combo
1915
     * @param newValue
1916
     * @param oldValue
1917
     */
1918
    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...
1919
        var me = this;
1920
1921
        var newRecord = combo.findRecordByValue(newValue);
1922
        if (newRecord && newRecord.get('available') === false) {
1923
            me.createGrowlMessage('{s name=connect/error}Error{/s}', me.messages.priceFieldIsNotSupported);
1924
        }
1925
    },
1926
1927
    /**
1928
     * Checks price field selection, if it's not supported
1929
     * shows error message
1930
     *
1931
     * @param combo
1932
     * @param newValue
1933
     * @param oldValue
1934
     */
1935
    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...
1936
        var me = this;
1937
1938
        var newRecord = combo.findRecordByValue(newValue);
1939
        if (newRecord && newRecord.get('available') === false) {
1940
            me.createGrowlMessage('{s name=connect/error}Error{/s}', me.messages.priceFieldIsNotSupported);
1941
        }
1942
    },
1943
1944
    onShowPriceWindow: function() {
1945
        var me = this;
1946
1947
        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...
1948
            callback: function(){
1949
                me.exportWindow = me.getView('export.price.Window').create({
1950
                    customerGroupStore: me.customerGroupStore
1951
                }).show();
1952
            }
1953
        });
1954
    },
1955
1956
    /**
1957
     * Resets store
1958
     * @param column
1959
     */
1960
    rejectPriceConfigChanges: function (column) {
1961
        var tabs = column.up('panel').up('panel').items;
1962
1963
        tabs.each(function(tab){
1964
            tab.getStore().rejectChanges();
1965
        });
1966
    },
1967
1968
    /**
1969
     * Collects prices params from given tab panel
1970
     *
1971
     * @param tabPanel
1972
     * @param exportMode
1973
     * @param collection
1974
     */
1975
    collectPriceParams: function(tabPanel, exportMode, collection) {
1976
        var me = this,
0 ignored issues
show
Unused Code introduced by
The variable me seems to be never used. Consider removing it.
Loading history...
1977
            priceTypes = ['price', 'pseudoPrice', 'basePrice'],
1978
            exportPriceType;
1979
1980
        switch (exportMode) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1981
            case 'purchasePrice':
1982
                exportPriceType = 'ForPurchasePriceExport';
1983
                break;
1984
            case 'price':
1985
                exportPriceType = 'ForPriceExport';
1986
                break;
1987
        }
1988
1989
        tabPanel.items.each(function(tab) {
1990
            if (tab.getStore().getUpdatedRecords().length > 0) {
1991
                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...
1992
                collection.exportPriceMode.push(exportMode);
1993
1994
                for (var i = 0; i < priceTypes.length; i++){
1995
                    if (tab.getStore().getAt(0).get(priceTypes[i]) == true) {
1996
                        collection['priceField' + exportPriceType] = priceTypes[i];
1997
                    }
1998
                }
1999
            }
2000
        });
2001
    },
2002
2003
    /**
2004
     * Convert number of seconds into time object
2005
     *
2006
     * @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...
2007
     * @return object
2008
     */
2009
    secondsToTime: function (secs) {
2010
        var hours = parseInt( secs / 3600 ) % 24;
2011
        var minutes = parseInt( secs / 60 ) % 60;
2012
        var seconds = secs % 60;
2013
2014
        var obj = {
2015
            "h": hours,
2016
            "m": minutes,
2017
            "s": seconds
2018
        };
2019
        return obj;
2020
    },
2021
2022
    /**
2023
     * Reset spent time used for synchronization bar
2024
     */
2025
    resetSpentTime: function() {
2026
        var me = this;
2027
        me.spentTime = 0;
2028
    },
2029
2030
    /**
2031
     * Reset time used for synchronization bar
2032
     */
2033
    resetTime: function() {
2034
        var me = this;
2035
        me.time = 0;
2036
    }
2037
});
2038
//{/block}
2039