Completed
Push — master ( ad8ce0...eb51fb )
by David
09:59
created

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 3
1
/**
2
 * Query Manager
3
 * Copyright (c) Webmatch GmbH
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 */
15
16
//{namespace name=backend/plugins/wbm/querymanager}
17
//
18
Ext.define('Shopware.apps.WbmQueryManager.view.main.Detail', {
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...
19
    extend:'Ext.form.Panel',
20
    alias:'widget.query-manager-detail',
21
    cls:'query-manager-detail',
22
    collapsible : false,
23
    bodyPadding : 10,
24
    split       : false,
25
    region      : 'center',
26
    defaultType : 'textfield',
27
    autoScroll  : true,
28
    layout      : {
29
        type: 'vbox',
30
        align : 'stretch',
31
        pack  : 'start'
32
    },
33
    items : [],
34
    initComponent: function() {
35
        var me = this;
36
        
37
        me.dockedItems = [
38
            {
39
                xtype: 'toolbar',
40
                dock: 'bottom',
41
                cls: 'shopware-toolbar',
42
                ui: 'shopware-ui',
43
                items: me.getButtons()
44
            },{
45
                xtype: 'toolbar',
46
                dock: 'bottom',
47
                cls: 'shopware-toolbar',
48
                ui: 'shopware-ui',
49
                items: me.getActions()
50
            }
51
        ];
52
    
53
        me.editorField = Ext.create('Shopware.form.field.CodeMirror', {
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...
54
            fieldLabel: '{s name="sqlFieldLabel"}SQL{/s}',
55
            xtype: 'codemirrorfield',
56
            mode: 'sql',
57
            labelAlign: 'top',
58
            anchor: '100%',
59
            name: 'sqlString',
60
            flex: 1,
61
            allowBlank: true
62
        });
63
        
64
        me.editorField.on('editorready', function(editorField, editor) {
65
            editor.setOption("mode", 'text/x-mysql');
66
            //{if $autocompleteActive}
67
            //
68
            editor.setOption("extraKeys", { "Ctrl-Space": "autocomplete" });
69
            editor.setOption("hintOptions", {
70
                tables: Ext.decode('{$hintOptions}')
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...
71
            });
72
            var hintDelay = null;
0 ignored issues
show
Unused Code introduced by
The variable hintDelay seems to be never used. Consider removing it.
Loading history...
73
            editor.on("keyup", function (instance, event) {
0 ignored issues
show
Unused Code introduced by
The parameter event 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...
74
                if (instance.state.completionActive) {
75
                    return;
76
                }
77
                var cur = instance.getCursor(),
78
                    token = instance.getTokenAt(cur),
79
                    string = '';
80
                if (token.string.match(/^[.`\w@]\w*$/)) {
81
                    string = token.string;
82
                }
83
                if (string.length > 0) {
84
                    CodeMirror.commands.autocomplete(instance, null, {
0 ignored issues
show
Bug introduced by
The variable CodeMirror seems to be never declared. If this is a global, consider adding a /** global: CodeMirror */ 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
                        completeSingle: false
86
                    });
87
                }
88
            });
89
            //{/if}
90
            //
91
        });
92
93
        me.on('resize', function(cmp, width, height) {
94
            me.resizeEditor(cmp, cmp.editorField, width, height);
95
        });
96
        
97
        me.items = me.getItems();
98
        
99
        me.callParent(arguments);
100
        me.loadRecord(me.record);
101
    },  
102
    getItems:function () {
103
        var me = this;
104
        return [
105
            {
106
                fieldLabel: '{s name="nameFieldLabel"}Name{/s}',
107
                labelWidth: 50,
108
                anchor: '100%',
109
                name: 'name',
110
                allowBlank: false
111
            },
112
            me.editorField,
113
            {
114
                xtype: 'fieldset',
115
                title: '{s name="cronJobTitle"}Cron-Job{/s}',
116
                defaultType: 'textfield',
117
                layout: 'column',
118
                items :[
119
                    {
120
                        fieldLabel: '{s name="activeFieldLabel"}aktiv{/s}',
121
                        labelWidth: 30,
122
                        name: 'hasCronjob',
123
                        xtype: 'checkbox',
124
                        inputValue: 1,
125
                        uncheckedValue: 0,
126
                        columnWidth: .15
127
                    },{
128
                        fieldLabel: '{s name="clearCacheFieldLabel"}Cache leeren{/s}',
129
                        labelWidth: 75,
130
                        name: 'clearCache',
131
                        xtype: 'checkbox',
132
                        inputValue: 1,
133
                        uncheckedValue: 0,
134
                        columnWidth: .25
135
                    },{
136
                        xtype: 'combo',
137
                        fieldLabel: '{s name="intervalFieldLabel"}Intervall{/s}',
138
                        labelWidth: 50,
139
                        name: 'intervalInt',
140
                        displayField: 'description',
141
                        valueField: 'value',
142
                        store: Ext.create('Ext.data.Store', {
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...
143
                            fields: ['value', 'description'],
144
                            data : [
145
                                { value:0, description:"{s name='0secDesc'}Kein (0 Sek.){/s}" },
146
                                { value:120, description:"{s name='120secDesc'}2 Minuten (120 Sek.){/s}" },
147
                                { value:600, description:"{s name='600secDesc'}10 Minuten (600 Sek.){/s}" },
148
                                { value:900, description:"{s name='900secDesc'}15 Minuten (900 Sek.){/s}" },
149
                                { value:1800, description:"{s name='1800secDesc'}30 Minuten (1800 Sek.){/s}" },
150
                                { value:3600, description:"{s name='3600secDesc'}1 Stunde (3600 Sek.){/s}" },
151
                                { value:7200, description:"{s name='7200secDesc'}2 Stunden (7200 Sek.){/s}" },
152
                                { value:14400, description:"{s name='14400secDesc'}4 Stunden (14400 Sek.){/s}" },
153
                                { value:28800, description:"{s name='28800secDesc'}12 Stunden (28800 Sek.){/s}" },
154
                                { value:86400, description:"{s name='86400secDesc'}1 Tag (86400 Sek.){/s}" },
155
                                { value:172800, description:"{s name='172800secDesc'}2 Tage (172800 Sek.){/s}" },
156
                                { value:604800, description:"{s name='604800secDesc'}1 Woche (604800 Sek.){/s}" }
157
                            ]
158
                        }),
159
                        mode: 'local',
160
                        columnWidth: .40
161
                    },{
162
                        xtype: 'button',
163
                        text : '{s name="lastLogFieldLabel"}Letztes Log{/s}',
164
                        handler: 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...
165
                            var me = this,
166
                            win = me.up('window'),
167
                            form = win.down('form');
168
                            Ext.MessageBox.alert('{s name="resultLastRun"}Ergebnis letzter Lauf{/s}', form.getForm().getRecord().get('lastLog'));
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...
169
                        },
170
                        columnWidth: .20
171
                    },{
172
                        fieldLabel: '{s name="nextRunFieldLabel"}Nächster Lauf{/s}',
173
                        labelWidth: 80,
174
                        name: 'nextRun',
175
                        xtype: 'xdatetime',
176
                        columnWidth: .65
177
                    },{
178
                        fieldLabel: '{s name="lastRunFieldLabel"}Letzter Lauf{/s}',
179
                        labelWidth: 80,
180
                        name: 'lastRun',
181
                        xtype: 'displayfield',
182
                        columnWidth: .35,
183
                        renderer: Ext.util.Format.dateRenderer('d.m.Y H:i:s')
184
                    }
185
                ]
186
            }
187
        ];
188
    },
189
    getButtons : function()
190
    {
191
        var me = this;
192
        return [
193
            {
194
                text    : '{s name="reload"}Reload{/s}',
195
                scope   : me,
196
                cls: 'secondary',
197
                action  : 'reload'
198
            }, '->',
199
            {
200
                text    : '{s name="reset"}Reset{/s}',
201
                scope   : me,
202
                cls: 'secondary',
203
                action  : 'reset'
204
            },
205
            {
206
                text    : '{s name="save"}Save{/s}',
207
                action  : 'save',
208
                cls     : 'primary',
209
                formBind: true
210
            }
211
        ];
212
    },
213
    getActions : function()
214
    {
215
        var me = this;
0 ignored issues
show
Unused Code introduced by
The variable me seems to be never used. Consider removing it.
Loading history...
216
        return [
217
            {
218
                xtype: 'button',
219
                text : '{s name="runQuery"}Query ausführen{/s}',
220
                cls  : 'primary',
221
                handler: function() {
222
                    var me = this,
223
                    win = me.up('window'),
224
                    form = win.down('form'),
225
                    query = form.getForm().findField('sqlString').getSubmitValue();
226
                    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...
227
                        url: '{url controller="WbmQueryManager" action="run"}',
228
                        method: 'POST',          
229
                        params: {
230
                            query: query
231
                        },
232
                        success: function(response){
233
                            var result = 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...
234
235
                            if(result.success){
236
                                Ext.each(result.data, function(rowset) {
237
                                    if(rowset.fetchData){
238
                                        Ext.create('Ext.window.Window', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

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

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

Loading history...
239
                                            width: 500,
240
                                            height: 120,
241
                                            autoDestroy: true,
242
                                            title:'{s name="queryResult"}Query Resultat{/s}',
243
                                            layout: 'fit',
244
                                            buttonAlign: 'center',
245
                                            items: [
246
                                                {
247
                                                    xtype: 'container',
248
                                                    padding: 10,
249
                                                    html: '{s name="showOrDownload"}Resultat anzeigen oder als CSV downloaden?{/s}'
250
                                                }
251
                                            ],
252
                                            buttons: [
253
                                                {
254
                                                    text: '{s name="show"}Anzeigen{/s}',
255
                                                    cls: 'primary',
256
                                                    listeners: {
257
                                                        click: {
258
                                                            fn: function (item, e) {
0 ignored issues
show
Unused Code introduced by
The parameter e 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 item 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...
259
                                                                this.up('window').close();
260
                                                                Ext.create('Shopware.apps.WbmQueryManager.view.result.Window', {
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
                                                                    jsonData: rowset.fetchData
262
                                                                });
263
                                                            }
264
                                                        }
265
                                                    }
266
                                                },
267
                                                {
268
                                                    text: '{s name="download"}Downloaden{/s}',
269
                                                    cls: 'primary',
270
                                                    listeners: {
271
                                                        click: {
272
                                                            fn: function (item, e) {
0 ignored issues
show
Unused Code introduced by
The parameter item 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 e 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...
273
                                                                this.up('window').close();
274
                                                                var form = Ext.create('Ext.form.Panel', {
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...
275
                                                                    standardSubmit: true,
276
                                                                    url: '{url controller="WbmQueryManager" action="run" download=1}',
277
                                                                    method: 'POST'
278
                                                                });
279
280
                                                                form.submit({
281
                                                                    target: '_blank', // Avoids leaving the page.
282
                                                                    params: {
283
                                                                        query: query,
284
                                                                        rowset: rowset.rowsetKey
285
                                                                    }
286
                                                                });
287
                                                            }
288
                                                        }
289
                                                    }
290
                                                },
291
                                                {
292
                                                    text: '{s name="cancel"}Abbrechen{/s}',
293
                                                    cls: 'secondary',
294
                                                    listeners: {
295
                                                        click: {
296
                                                            fn: function (item, e) {
0 ignored issues
show
Unused Code introduced by
The parameter item 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 e 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...
297
                                                                this.up('window').close();
298
                                                            }
299
                                                        }
300
                                                    }
301
                                                }
302
                                            ]
303
                                        }).show();
304
                                    } else {
305
                                        Ext.create('Ext.window.Window', {
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...
306
                                            width: 300,
307
                                            height: 120,
308
                                            autoDestroy: true,
309
                                            title:'{s name="querySuccess"}Query erfolgreich{/s}',
310
                                            layout: 'fit',
311
                                            buttonAlign: 'center',
312
                                            items: [
313
                                                {
314
                                                    xtype: 'container',
315
                                                    padding: 10,
316
                                                    html: rowset.rowCount + ' {s name="rowsAffected"}Reihen betroffen{/s}'
317
                                                }
318
                                            ],
319
                                            buttons: [
320
                                                {
321
                                                    text: '{s name="ok"}OK{/s}',
322
                                                    cls: 'primary',
323
                                                    listeners: {
324
                                                        click: {
325
                                                            fn: function (item, e) {
0 ignored issues
show
Unused Code introduced by
The parameter item 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 e 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...
326
                                                                this.up('window').close();
327
                                                            }
328
                                                        }
329
                                                    }
330
                                                }
331
                                            ]
332
                                        }).show();
333
                                    }
334
                                });
335
                            } else {
336
                                Ext.MessageBox.alert('{s name="queryError"}Query fehlerhaft{/s}', result.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...
337
                            }
338
                        },
339
                        failure: function(){
340
                        }
341
                    });
342
                }
343
            }
344
        ];
345
    },
346
    resizeEditor : function(cmp, editorField, width, height) {
347
        var editor = editorField.editor;
348
349
        if(!editor || !editor.hasOwnProperty('display')) {
350
            return false;
351
        }
352
353
        editor.setSize(0, 0);
354
355
        width = editorField.getEl().down('tbody').getWidth();
356
        height = editorField.getEl().down('tbody').getHeight() - 20;
357
358
        editor.setSize(width, height);
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...
359
    }
360
});