Project

General

Profile

Bug #1220 » MinovaUtil.js

Mr. Yusuf, 06/20/2022 11:57 AM

 
1
/**
2
 *
3
 */
4
Ext.define('MinovaUtil', {});
5
MinovaUtil.executeParamQuery = function (params, fn_success, fn_failed, scope) {
6
    var urlQueryParam = '/workflow/LoadDataQuery';
7
    MinovaAjaxPostSync(urlQueryParam, params, fn_success, fn_failed, scope);
8
}
9
MinovaUtil.buildParamQuery = function (paramKeys) {
10

    
11
    paramKeys = paramKeys ? paramKeys : null
12

    
13
    var buildParams = '';
14

    
15
    Ext.each(paramKeys, function (param) {
16
        var values = param.value;
17
        var name = param.key;
18
        var obj = name + ':"' + values + '",';
19
        buildParams += obj;
20
    })
21
    buildParams = buildParams.substring(0, buildParams.length - 1)
22

    
23
    // Ext.global.console.log(buildParams)
24
    var params = "{params:{" + buildParams + "}}";
25
    // Ext.global.console.log(params)
26
    // Ext.global.console.log(Ext.encode(params))
27
    // Ext.global.console.log(Ext.decode(params))
28

    
29
    return Ext.decode(params)// buildParams;
30
}
31
MinovaUtil.buildFormsFromTable = function (tableName, formSource) {
32
    function buildingForms(data) {
33
        var fields = [];
34
        var form1 = Ext.widget('form', {layout: 'column'})
35
        var container1 = Ext.widget('container', {columnWidth: 0.5});
36
        var container2 = Ext.widget('container', {columnWidth: 0.5});
37
//            var IsCustomColumns = this.visibleColumns != undefined && this.visibleColumns.length > 0;
38
        Ext.each(data, function (p) {
39

    
40
            fields.push(Ext.widget('textfield', {
41
                name: p.column_name,
42
                fieldLabel: p.column_name,
43
                allowBlank: p.is_primary_key == 0,
44
                maxLength: p.max_length
45
            }));
46

    
47
        });
48
        for (i = 0; i <= (fields.length); i++) {
49
            //fields.push(field);
50
            if (i < (fields.length / 2))
51
                container1.add(fields[i])
52
            else
53
                container2.add(fields[i]);
54
        }
55

    
56
        //this.items.items = [ container1, container2]
57
        //this.doLayout();
58
        //formSource.items.clear();
59
        //formSource.apply({layout:'column'});
60
        form1.add(container1);
61
        form1.add(container2);
62
        formSource.add(form1);
63
        //formSource.items.items =  [ container1, container2];
64
        formSource.doLayout();
65
    }
66

    
67
    MinovaUtil.executeParamQuery({
68
            paramid: 'getSysTable',
69
            tableName: tableName},
70
        function (s) {
71
            var data = Ext.decode(s.responseText).data;
72
            return buildingForms(data)
73
        }, function (f) {
74
        });
75
}
76
MinovaUtil.updateSessions = function (dataSessions) {
77

    
78
    if ((dataSessions === null) && (dataSessions === null)) {
79
        // --------- hapus sessions var map
80
        this.SESSIONS.LOGIN.empId !== undefined
81
            ? this.SESSIONS.LOGIN.empId = null
82
            : null;
83
        this.SESSIONS.LOGIN.formatName !== undefined
84
            ? this.SESSIONS.LOGIN.formatName = null
85
            : null;
86
        this.SESSIONS.LOGIN.userId !== undefined
87
            ? this.SESSIONS.LOGIN.userId = null
88
            : null;
89
        // --------- hapus sessions var map
90
        // ---------- hapus setingan applikasi dari store
91
        storeApp = Ext.StoreManager.lookup('base.main.App');
92
        storeApp.removeAll(true);
93
        // ---------- hapus setingan applikasi dari store
94
        return
95
    }
96
    var data = dataSessions;
97
    // --------- sessions var map
98
    this.SESSIONS.LOGIN.empId = data.Sessions.EmpID
99
    this.SESSIONS.LOGIN.formatName = data.Sessions.FormatName
100
    this.SESSIONS.LOGIN.userId = data.Sessions.UserID
101
    // --------- sessions var map
102
    // --------- buat setingan applikasi dari store
103
    storeApp = Ext.StoreManager.lookup('base.main.App');
104
    storeApp.removeAll(true);
105
    storeApp.clearFilter();
106
    storeApp.add(data.AppSettings);
107
    // // --------- buat object sppsetings
108
    var str = "";
109
    storeApp.each(function (r) {
110
        str += '"' + r.data.name + '":"' + r.data.value + '",'
111
    })
112
    var obj = Ext.decode("{" + str.substring(0, str.length - 1) + "}");
113
    MinovaUtil.SESSIONS.APPSETINGS = obj;
114
    // // --------- buat object sppsetings
115
    // --------- buat setingan applikasi dari store
116
}
117
MinovaUtil.getActiveTab = function () {
118
    var mainTab = MinovaUtil.WORKFLOW.getMainTab()
119
    return mainTab !== null ? mainTab.getActiveTab() : null;
120
}
121
/**
122
 * gunakan fungsi ini untuk memunculkan pesan dialog
123
 * @type {{error: Function, alert: Function, confirm: Function, show: Function}}
124
 */
125
MinovaUtil.MESSAGE = {
126
    /**
127
     * memunculkan pesan error
128
     * @param msg
129
     */
130
    error: function (msg) {
131
        this.show('Error', msg, Ext.Msg.OK, Ext.Msg.ERROR);
132
    },
133
    /**
134
     * memunculkan pesan/alert
135
     * @param msg
136
     */
137
    alert: function (msg) {
138
        this.show('Information', msg, Ext.Msg.OK, Ext.Msg.INFO);
139
    },
140
    /**
141
     * memunculkan pesan konfirmasi
142
     * @param msg
143
     * @param fnResponse
144
     * @returns {*|Ext.window.MessageBox}
145
     */
146
    confirm: function (msg, fnResponse) {
147
        return Ext.MessageBox.confirm('Confirmation', msg,
148
            function (btnTxt) {
149
                if (typeof(fnResponse) === 'function') {
150
                    new fnResponse(btnTxt);
151
                }
152
            })
153
    },
154
    /**
155
     * memunculkan pesan secara custom
156
     * @param title
157
     * @param message
158
     * @param buttons
159
     * @param icon
160
     */
161
    show: function (title, message, buttons, icon) {
162
        Ext.Msg.show({
163
            title: title,
164
            msg: message,
165
            buttons: buttons, // Ext.Msg.OK,
166
            icon: icon
167
            // Ext.Msg.ERROR
168
        });
169
    }
170
}
171
MinovaUtil.CRUD = {
172
    addRecord: function (button, rec) {
173
        var r = rec ? rec : Ext.data.Model();
174
        button.up('grid').store.add(r);
175
    },
176
    copyRecord: function (button) {
177
        var selRec = button.up('grid').getSelectionModel().getSelection()[0];
178
        var rec = selRec.copy(); // clone the record
179
        Ext.data.Model.id(rec); // automatically generate a unique
180
        // sequential id
181
        button.up('grid').store.add(rec);
182
    },
183
    removeRecord: function (button) {
184
        var selRecs = button.up('grid').getSelectionModel().getSelection();
185
        Ext.each(selRecs, function (rec) {
186
            rec.reject(true);
187
        });
188
        button.up('grid').store.remove(selRecs);
189
    }
190
}
191
/**
192
 *
193
 * @type {{autoShowAfterLogin: Function, loadControllerByViewClass: Function, compareWorkplace: Function, isCreatorLogin: Function, isRequest: Function, isInbox: Function, isOutbox: Function, isDraft: Function, isArchive: Function, setReadOnlyViewByProperty: Function, setReadOnlyViewBodyWorkflow: Function, setReadOnlyView: Function, setReadOnlyGridByName: Function, setReadOnlyFormByName: Function, setViewBodyWorkflowFormContent: Function, getViewWorkPlace: Function, getMainTab: Function, getViewHeaderWorkflow: Function, getViewFooterWorkflow: Function, getViewInfoWorkflow: Function, showViewInfoWorkflow: Function, getViewWorkPlaceInbox: Function, getViewWorkflow: Function, getViewActive: Function, getViewBodyWorkflow: Function, getTaskId: Function, getFlowId: Function, getBizprocId: Function, getBizflowId: Function, getRegId: Function, getEmpId: Function, getTaskIdFromView: Function}}
194
 */
195
MinovaUtil.WORKFLOW = {
196
    /**
197
     * fungsi ini digunakan untuk memunculkan program/applikasi secara default
198
     * @param loginInfo
199
     */
200
    autoShowAfterLogin: function (loginInfo) {
201
        // auto show module after login
202
        Ext.global.console.log('configuration ...AUTOSHOWMODULE');
203
        MinovaUtil.executeParamQuery({
204
                paramid: 'wf_base_module_auto_show'
205
            },
206
            function (s) {
207
                //[instance],[seq],[title],[controller],[active],[active_function]
208
                var datas = Ext.decode(s.responseText).data;
209
                if (datas) {
210
                    Ext.each(datas, function (d) {
211
                        var activeFn = false;
212
                        var isFunction = typeof(Ext.decode(d.active_function)) === 'function';
213
                        activeFn = isFunction ? (function () {
214
                            try {
215
                                return Ext.decode(d.active_function)(loginInfo)
216
                            } catch (e) {
217
                                Ext.global.console.error('try load ' + d.title + '\n' + e);
218
                                return false
219
                            }
220
                        })() : true;
221
                        if (activeFn)
222
                            MinovaOpenProgram({
223
                                title: d.title,
224
                                controller: d.controller
225
                            });
226
                    });
227
                }
228
            },
229
            function (f) {
230
            }
231
        );
232
    },
233
    /**
234
     * fungsi ini digunakan untuk mengambil controller by view class name
235
     * @param viewClass
236
     * @returns {null}
237
     */
238
    loadControllerByViewClass: function (viewClass) {
239
        // mencari controller dari view
240
        // return controller
241
        var minovaClassView = "MinovaIS.ERP.Web.view";
242
        if (viewClass.indexOf(minovaClassView) >= 0) {
243
            viewClass = viewClass.substring(minovaClassView.length + 1/*plus koma*/);
244
        }
245

    
246
        var hasil = null;
247
        Ext.each(MinovaApp.controllers.items, function (c) {
248
            try {
249
                var found = c.views.indexOf(viewClass);
250
                if (found >= 0)
251
                    hasil = c;
252
            } catch (e) {
253
            }
254
        })
255
        return hasil;
256
    },
257
    compareWorkplace: function (workplaceXtype) {
258
        var hasil = false;
259
        var _curXtype = MinovaUtil.WORKFLOW.getViewWorkPlace().xtype;
260
        if (_curXtype == workplaceXtype)
261
            hasil = true
262
        return hasil;
263
    },
264
    /**
265
     * cek apakah user login = creator
266
     * @returns {boolean}
267
     */
268
    isCreatorLogin: function () {
269
        return MinovaUtil.SESSIONS.LOGIN.empId == MinovaUtil.WORKFLOW
270
            .getEmpId() ? true : false;
271
    },
272
    /**
273
     * cek apakah dalam operasi request
274
     * @returns {boolean}
275
     */
276
    isRequest: function () {
277
        var result = false;
278
        try {
279
            result = this.getViewWorkPlace().getLayout().activeItem.name == 'content' ||
280
                MinovaUtil.WORKFLOW.isDraft();
281
        } catch (e) {
282
        }
283
        return result;
284
        // return this.compareWorkplace('wf-request-requestScreen');
285
    },
286
    /**
287
     * cek apakah dalam operasi inbox
288
     * @returns {*}
289
     */
290
    isInbox: function () {
291
        return this.compareWorkplace('wf-inbox-InboxScreen');
292
    },
293
    /**
294
     * cek apakah dalam operasi outbox
295
     * @returns {*}
296
     */
297
    isOutbox: function () {
298
        return this.compareWorkplace('wf-outbox-outboxScreen');
299
    },
300
    /**
301
     * cek apakah dalam operasi draft
302
     * @returns {*}
303
     */
304
    isDraft: function () {
305
        return this.compareWorkplace('wf-draft-draftScreen');
306
    },
307
    /**
308
     * cek apakah dalam operasi archive
309
     * @returns {*}
310
     */
311
    isArchive: function () {
312
        return this.compareWorkplace('wf-archive-archiveScreen');
313
    },
314

    
315
    setReadOnlyViewByProperty: function (opt, bit) {
316
        var view = this.getViewWorkflow().down(opt.xtype + '[name='
317
            + opt.name + ']');
318
        this.setReadOnlyView(view, bit);
319
    },
320
    setReadOnlyViewBodyWorkflow: function (bit) {
321
        this.setReadOnlyView(this.getViewBodyWorkflow(), bit);
322
    },
323

    
324
    setReadOnlyView: function (view, bit) {
325
        function hasEditorProperty(o) {
326
            var hasil = false;
327
            try {
328
                if (o.getEditor()) {
329
                    hasil = !hasil;
330
                }
331
            } catch (e) {
332
            }
333
            return hasil;
334
        }
335

    
336
        function setObjReadOnly(obj, bit) {
337
            if (hasEditorProperty(obj))
338
                try {
339
                    var editor = obj.getEditor();
340
                    editor.setReadOnly(bit);
341
                } catch (e) {
342
                }
343
            else {
344
                if (obj.xtype == 'button')
345
                    obj.setDisabled(bit);
346
                else if (obj.xtype == 'grid') {
347
                    this.setReadOnlyGridByName(obj.name, bit)
348
                    // Ext.each(obj.columns, function(b) {
349
                    // if (hasEditorProperty(b)) {
350
                    // var gEditor = b.getEditor();
351
                    // // gEditor.setEditable(c);
352
                    // gEditor.setReadOnly(c);
353
                    // }
354
                    // });
355
                } else {
356
                    try {
357
                        obj.setReadOnly(bit);
358
                    } catch (e) {
359
                    }
360
                }
361
            }
362
        }
363

    
364
        bit = bit == undefined ? true : bit;
365
        // var obj = this.getViewWorkflow().down(opt.xtype + "[name="
366
        // + opt.name + "]");
367
        var obj = view;
368
        if (obj == null)
369
            return;
370

    
371
        if (!obj.hasOwnProperty('items')) {
372
            setObjReadOnly(obj, bit);
373
        } else
374
            Ext.each(obj.query(), function (o) {
375
                try {
376
                    // o.setReadOnly(bit)
377
                    setObjReadOnly(o, bit);
378
                } catch (e) {
379
                }
380
            })
381
    },
382

    
383
    setReadOnlyGridByName: function (gridName, bit) {
384
        bit = bit == undefined ? true : bit;
385
        var obj = this.getViewWorkflow()
386
            .down('grid[name=' + gridName + ']');
387
        if (obj == null)
388
            return;
389
        Ext.each(obj.query('button'), function (c) {
390
            c.setDisabled(bit);
391
        });
392
        Ext.each(obj.columns, function (b) {
393
            try {
394
                var gEditor = b.getEditor();
395
                // gEditor.setEditable(false);
396
                gEditor.setReadOnly(bit);
397
            } catch (e) {
398
            }
399
        });
400
    },
401

    
402
    setReadOnlyFormByName: function (formName, bit) {
403
        // default true
404
        bit = bit == undefined ? true : bit;
405
        var obj = this.getViewWorkflow().down('panel[name=' + formName
406
            + ']')
407
        if (obj == null)
408
            return;
409

    
410
        Ext.each(obj.getForm().items, function (frms) {
411
            Ext.each(frms.items, function (fld) {
412
                try {
413
                    obj.down(fld.xtype + '[name='
414
                            + fld.name + ']')
415
                        .setReadOnly(bit)
416
                } catch (e) {
417
                }
418

    
419
            })
420
        })
421

    
422
    },
423
    /**
424
     * set value by name
425
     * @param record
426
     */
427
    setViewBodyWorkflowFormContent: function (record) {
428
        var forms = MinovaUtil.WORKFLOW.getViewBodyWorkflow().query('form');
429
        //if (forms !== 'object') return false;
430
        Ext.each(forms, function (form) {
431
            form.getForm().setValues(record);
432
        });
433
    },
434
    /**
435
     *
436
     * @param viewXtype
437
     * @returns {null}
438
     */
439
    getViewWorkPlace: function (viewXtype) {
440
        var hasil = null;
441
        try {
442
            switch (viewXtype) {
443
                case 'home' :
444
                    hasil = searchWP('panel');
445
                    break;
446
                case 'request' :
447
                    hasil = searchWP('wf-request-requestScreen');
448
                    break;
449
                case 'inbox' :
450
                    hasil = searchWP('wf-inbox-InboxScreen');
451
                    break;
452
                case 'outbox' :
453
                    hasil = searchWP('wf-outbox-outboxScreen');
454
                    break;
455
                case 'draft' :
456
                    hasil = searchWP('wf-draft-draftScreen');
457
                    break;
458
                case 'archive' :
459
                    hasil = searchWP('wf-archive-archiveScreen');
460
                    break;
461

    
462
                default :
463
                    if (DesktopUIFront != "1") {
464
                        hasil = this.getMainTab().getLayout()
465
                            .getActiveItem();
466
                    } else {
467
                        hasil = this.getMainTab().getActiveWindow().items.items[0];
468
                    }
469
                    break;
470
            }
471
            return hasil;
472
        } catch (e) {
473
            return null
474
        }
475

    
476
        function searchWP(viewXtype) {
477
            var _tab = null;
478
            var tabs;
479
            if (DesktopUIFront != "1") {
480
                tabs = hasil = this.MinovaUtil.WORKFLOW.getMainTab().items.items;
481
            } else {
482
                tabs = hasil = this.MinovaUtil.WORKFLOW.getMainTab().windows.items;
483
            }
484
            Ext.Array.each(tabs, function (tab) {
485
                if (DesktopUIFront != "1") {
486
                    if (tab.xtype == viewXtype) {
487
                        _tab = tab;
488
                        return false;
489
                    }
490
                } else {
491
                    if (tab.items.items[0].xtype == viewXtype) {
492
                        _tab = tab.items.items[0];
493
                        return false;
494
                    }
495
                }
496
            });
497
            return _tab;
498
        }
499
    },
500

    
501
    getMainTab: function () {
502
        try {
503
            if (DesktopUIFront != "1") {
504
                return Ext.ComponentQuery.query('base-main-Tab')[0]
505
            } else {
506
                return MyDesktopApp.getDesktop();
507
            }
508
        } catch (e) {
509
            return null
510
        }
511
    },
512
    /**
513
     *
514
     * @returns {null}
515
     */
516
    getViewHeaderWorkflow: function () {
517
        var hasil = null;
518
        try {
519
            hasil = this.getViewActive().down('panel[name=wf_form_header]');
520
        } catch (e) {
521
        }
522
        return hasil;
523
    },
524
    /**
525
     *
526
     * @returns {null}
527
     */
528
    getViewFooterWorkflow: function () {
529
        var hasil = null;
530
        try {
531
            hasil = this.getViewActive().down('panel[name=wf_form_footer]');
532
        } catch (e) {
533
        }
534
        return hasil;
535
    },
536
    /**
537
     *
538
     * @returns {null}
539
     */
540
    getViewInfoWorkflow: function () {
541
        var hasil = null;
542
        try {
543
            if (this.getViewActive().query('wf-run-formInformation').length > 0) {
544
                hasil = this.getViewActive()
545
                    .query('wf-run-formInformation')[0];
546
            } else {
547

    
548
                hasil = this.getViewWorkPlace()
549
                    .query('wf-request-formInformation')[0];
550
            }
551
        } catch (e) {
552
        }
553
        return hasil;
554
    },
555
    /**
556
     *
557
     * @returns {null}
558
     */
559
    showViewInfoWorkflow: function () {
560
        var hasil = null;
561
        try {
562
            if (this.getViewActive().query('wf-run-formInformation').length > 0) {
563
                var hasil = MinovaUtil.WORKFLOW.getViewInfoWorkflow()
564
                    .up('panel').getLayout().setActiveItem(1);
565
            } else {
566
                var hasil = MinovaUtil.WORKFLOW.getViewInfoWorkflow()
567
                    .up('panel').getLayout().setActiveItem(3);
568
            }
569
        } catch (e) {
570
        }
571
        return hasil;
572
    },
573
    getViewWorkPlaceInbox: function () {
574
        var hasil = null;
575
        try {
576
            var workPlaces = this.MinovaUtil.WORKFLOW.getMainTab().items.items
577
            Ext.Array.each(workPlaces, function (wp) {
578

    
579
            });
580
            this.MinovaUtil.WORKFLOW.getMainTab().items.items[1].xtype
581
        } catch (e) {
582
        }
583
        return hasil;
584
    },
585
    getViewWorkflow: function (viewXtype) {
586
        var hasil = null;
587
        viewXtype = viewXtype != undefined ? viewXtype : this
588
            .getViewWorkPlace().xtype;
589
        try {
590
            switch (viewXtype) {
591
                case 'wf-request-requestScreen' :
592
                    hasil = MinovaUtil.WORKFLOW.getViewWorkPlace().items.items[2];
593
                    break;
594
                case 'wf-inbox-InboxScreen' :
595
                    hasil = MinovaUtil.WORKFLOW.getViewWorkPlace()
596
                        .down('tabpanel').activeTab.down('tabpanel').activeTab;
597
                    break;
598
                case 'wf-draft-draftScreen' :
599
                    hasil = MinovaUtil.WORKFLOW.getViewWorkPlace()
600
                        .down('tabpanel').activeTab.activeTab;
601
                    break;
602
                case 'wf-archive-archiveScreen' :
603
                    hasil = MinovaUtil.WORKFLOW.getViewWorkPlace()
604
                        .down('tabpanel').activeTab.down('tabpanel').activeTab;
605
                    break;
606
                case 'wf-outbox-outboxScreen' :
607
                    hasil = MinovaUtil.WORKFLOW.getViewWorkPlace()
608
                        .down('tabpanel').activeTab.down('tabpanel').activeTab;
609
                    break;
610
                default :
611
                    break;
612

    
613
            }
614

    
615
            // if (this.getViewWorkPlace().xtype ==
616
            // 'wf-request-requestScreen') {
617
            // hasil = this.getViewActive().items.items[1]
618
            // } else {
619
            // var mainTab = this.getViewActive()
620
            // hasil = mainTab.down('wf-run-formData').down('panel')
621
            // }
622
        } catch (e) {
623
        }
624
        return hasil;
625
    },
626
    getViewActive: function () {
627
        var hasil = null;
628
        try {
629
            hasil = this.getViewWorkflow()
630
        } catch (e) {
631
        }
632
        return hasil;
633
    },
634
    /**
635
     * untuk mendapatkan panel body
636
     * @returns {null}
637
     */
638
    getViewBodyWorkflow: function () {
639
        var hasil = null;
640
        try {
641

    
642
            if (this.getViewWorkPlace().xtype == 'wf-request-requestScreen') {
643
                hasil = this.getViewActive().items.items[1]
644
            } else {
645
                var mainTab = this.getViewActive()
646
                hasil = mainTab.down('wf-run-formData').down('panel')
647
            }
648
        } catch (e) {
649
        }
650
        return hasil;
651
    },
652
    /**
653
     * untuk mendapatkan task id
654
     * @returns {null}
655
     */
656
    getTaskId: function () {
657
        var hasil = null;
658
        try {
659
            var obj = this.getViewActive()
660
                .down('textfield[name=task_id_run]');
661
            if (obj) {
662
                hasil = obj.getValue();
663
            }
664
        } catch (e) {
665
        }
666
        return hasil;
667
    },
668
    /**
669
     *
670
     * @param view
671
     * @returns {null}
672
     */
673
    getFlowId: function (view) {
674
        var hasil = null;
675
        try {
676
            var obj = this.getViewActive().down('combobox[name=action]');
677
            if (obj) {
678
                hasil = obj.getValue();
679
            }
680
        } catch (e) {
681
        }
682
        return hasil;
683
    },
684
    getFlowType: function (view) {
685
        var hasil = null;
686
        try {
687
            var obj = this.getViewActive().down('combobox[name=action]');
688
            if (obj) {
689
                var rec = obj.store.findRecord('code', obj.getValue());
690
                if (rec)
691
                    hasil = rec.data.group;
692
            }
693
        } catch (e) {
694
        }
695
        return hasil;
696
    },
697
    /**
698
     *
699
     * @returns {null}
700
     */
701
    getBizprocId: function () {
702
        var hasil = null;
703
        try {
704
            var obj = this.getViewActive()
705
                .down('textfield[name=bizproc_id]');
706
            if (obj) {
707
                hasil = obj.getValue();
708
            }
709
        } catch (e) {
710
        }
711
        return hasil;
712
    },
713
    /**
714
     *
715
     * @returns {null}
716
     */
717
    getBizflowId: function () {
718
        var hasil = null;
719
        try {
720
            var obj = this.getViewActive()
721
                .down('textfield[name=bizflow_id]');
722
            if (obj) {
723
                hasil = obj.getValue();
724
            }
725
        } catch (e) {
726
        }
727
        return hasil;
728
    },
729
    /**
730
     * untuk mendapatkan register id
731
     * @returns {null}
732
     */
733
    getRegId: function () {
734
        var hasil = null;
735
        try {
736
            var obj = this.getViewActive()
737
                .down('textfield[name=request_id]');
738
            if (obj) {
739
                hasil = obj.getValue();
740
            }
741
        } catch (e) {
742
        }
743
        return hasil;
744
    },
745
    /**
746
     * untuk mendapatkan employee i yang request
747
     * @returns {null}
748
     */
749
    getEmpId: function () {
750
        var hasil = null;
751
        try {
752
            var obj = this.getViewActive()
753
                .down('textfield[name=employee_id]');
754
            if (obj) {
755
                hasil = obj.getValue();
756
            }
757
        } catch (e) {
758
        }
759
        return hasil;
760
    },
761
    getTaskIdFromView: function (view) {
762
        var hasil = null;
763
        try {
764
            var objTaskIdRun = view.up('panel[name=content]')
765
                .down('textfield[name=task_id_run]');
766

    
767
            if (objTaskIdRun) {
768
                hasil = objTaskIdRun.getValue();
769
            }
770
        } catch (e) {
771
        }
772
        return hasil;
773
    }
774

    
775
}
776
/**
777
 *
778
 * @type {{LOGIN: {userId: null, empId: null, formatName: null}, APPSETINGS: {}, TASK: {config: {timerWarning: number, timerWarningTimeout: number}, run: Function, runIdle: Function, stop: Function, methods: {startTimerWarning: Function, stopTimerWarning: Function, startTimerWarningTimeout: Function, stopTimerWarningTimeout: Function, warningTASK: Function, logout2: Function}}}}
779
 */
780
MinovaUtil.SESSIONS = {
781
    LOGIN: {
782
        userId: null,
783
        empId: null,
784
        formatName: null
785
    },
786
    APPSETINGS: {},
787
    TASK: {
788
        config: {
789
            timerWarning: 1000 * 60 * 10,
790
            timerWarningTimeout: 1000 * 60
791

    
792
        },
793
        run: function () {
794
            // disable all timer
795
            this.stop();
796
            this.methods.stopTimerWarning();
797
            this.methods.stopTimerWarningTimeout();
798
            this.runIdle(false);
799

    
800
            // start
801
            this.methods.startTimerWarning();
802
            this.runIdle(true);
803
            try {
804
                clearTimeout(tiemrAutoLogout);
805
            } catch (e) {
806
            }
807
        },
808
        runIdle: function (yes) {
809
            if (yes == true) {
810
                document.onclick = function () {
811
                    // console.log('reset idle timeout')
812
                    MinovaUtil.SESSIONS.TASK.stop();
813
                    MinovaUtil.SESSIONS.TASK.methods.startTimerWarning();
814
                }
815
                document.onmousemove = function () {
816
                    // console.log('reset idle timeout')
817
                    // MinovaUtil.SESSIONS.TASK.stop();
818
                    // MinovaUtil.SESSIONS.TASK.methods.startTimerWarning();
819
                }
820
                document.onkeydown = function () {
821
                    // console.log('reset idle timeout')
822
                    MinovaUtil.SESSIONS.TASK.stop();
823
                    MinovaUtil.SESSIONS.TASK.methods.startTimerWarning();
824
                }
825
            } else {
826
                document.onclick = null;
827
                document.onmousemove = null;
828
                document.onkeydown = null;
829
            }
830
        },
831
        stop: function () {
832
            // this.runIdle(false)
833
            this.methods.stopTimerWarning();
834
            this.methods.stopTimerWarningTimeout();
835

    
836
        },
837
        methods: {
838
            startTimerWarning: function () {
839
                sesWarn = setTimeout(this.warningTASK,
840
                    MinovaUtil.SESSIONS.TASK.config.timerWarning);
841
                // Ext.global.console.log('init sesWarn (' + sesWarn + ')'
842
                // + MinovaUtil.SESSIONS.TASK.config.timerWarning);
843
            },
844
            stopTimerWarning: function () {
845

    
846
                try {
847
                    clearTimeout(sesWarn)
848
                    // Ext.global.console
849
                    // .log('stop sesWarn (' + sesWarn + ')');
850
                } catch (e) {
851
                }
852
            },
853
            startTimerWarningTimeout: function () {
854

    
855
                sesWarnTimeout = setTimeout(this.logout2,
856
                    MinovaUtil.SESSIONS.TASK.config.timerWarningTimeout);
857
                // Ext.global.console
858
                // .log('init sesWarnTimeout ('
859
                // + sesWarnTimeout
860
                // + ')'
861
                // + +MinovaUtil.SESSIONS.TASK.config.timerWarningTimeout);
862
            },
863
            stopTimerWarningTimeout: function () {
864

    
865
                try {
866
                    clearTimeout(sesWarnTimeout)
867
                    // Ext.global.console.log('stop sesWarnTimeout ('
868
                    // + sesWarnTimeout + ')');
869
                } catch (e) {
870
                }
871
            },
872

    
873
            warningTASK: function () {
874
                // check ajax request
875

    
876
                if (checkAjaxRequests())
877
                    return false
878

    
879
                MinovaUtil.SESSIONS.TASK.methods.startTimerWarningTimeout();
880
                MinovaUtil.SESSIONS.TASK.runIdle(false)
881
                return call5();
882

    
883
                function checkAjaxRequests() {
884
                    var b = Ext.Ajax.requests, a;
885
                    for (a in b) {
886
                        if (b.hasOwnProperty(a)) {
887
                            // this.abort(b[a])
888
                            // console.log(a)
889
                            // MinovaUtil.SESSIONS.TASK.run()
890
                            MinovaUtil.SESSIONS.TASK.stop();
891
                            MinovaUtil.SESSIONS.TASK.methods
892
                                .startTimerWarning();
893
                            return true;
894
                        }
895
                    }
896
                }
897

    
898
                function call1() {
899
                    Ext.Msg
900
                        .prompt(
901
                        'Session will be expired in '
902
                            + MinovaUtil.SESSIONS.TASK.config.timerWarningTimeout
903
                            / 1000 + ' second',
904
                        'Please enter your password:',
905
                        function (btn, text) {
906
                            if (btn == 'ok') {
907
                                // lanjut
908
                                MinovaUtil.SESSIONS.TASK.methods
909
                                    .stopTimerWarningTimeout();
910
                                MinovaUtil.SESSIONS.TASK.methods
911
                                    .startTimerWarning();
912
                            } else {
913
                                // logout
914
                                MinovaUtil.SESSIONS.TASK.methods
915
                                    .logout2()
916
                            }
917
                        })
918
                }
919

    
920
                function call2() {
921
                    var _confirm = Ext.Msg
922
                        .confirm('Session will be expired in '
923
                            + MinovaUtil.SESSIONS.TASK.config.timerWarningTimeout
924
                            / 1000
925
                            + ' second. press OK to continue or Cancel for logout')
926
                    if (_confirm) {
927
                        // lanjut
928
                        MinovaUtil.SESSIONS.TASK.methods
929
                            .stopTimerWarningTimeout();
930
                        MinovaUtil.SESSIONS.TASK.methods
931
                            .startTimerWarning();
932
                    } else {
933
                        // logout
934
                        MinovaUtil.SESSIONS.TASK.methods.logout2()
935
                    }
936
                }
937

    
938
                function call3() {
939

    
940
                    var popupRelogin = Ext.create('Ext.window.Window', {
941
                        title: 'Session will be expired',
942
                        closable: false,
943
                        modal: true,
944
                        height: 200,
945
                        width: 400,
946
                        layout: 'fit',
947
                        items: [
948
                            {
949
                                xtype: 'form',
950
                                items: [
951
                                    {
952
                                        fieldLabel: 'Enter your password to continue'
953
                                    }
954
                                ]
955
                            }
956
                        ]
957
                    }).show();
958
                }
959

    
960
                function call4() {
961
                    var popTitle = 'Automatic logout';
962
                    tiemrAutoLogout = setInterval(textUpd, 1000);
963
                    var cd = MinovaUtil.SESSIONS.TASK.config.timerWarningTimeout
964
                        / 1000;
965

    
966
                    function textUpd() {
967
                        cd = cd - 1;
968
                        try {
969
                            var win = Ext.ComponentQuery
970
                                .query('window[title=' + popTitle + ']')[0];
971
                            var bt = win.down('button[itemId=no]');
972
                            bt.setText('No(' + cd + 's)');
973
                        } catch (e) {
974
                            // Ext.global.console.log(e)
975
                        }
976
                    }
977

    
978
                    return Ext.Msg.confirm(popTitle,
979
                        'Do you want to continue session?', function (btn, text) {
980
                            if (btn == 'yes') {
981
                                // lanjut
982
                                clearTimeout(tiemrAutoLogout);
983
                                MinovaUtil.SESSIONS.TASK.methods
984
                                    .stopTimerWarningTimeout();
985
                                MinovaUtil.SESSIONS.TASK.methods
986
                                    .startTimerWarning();
987
                                MinovaUtil.SESSIONS.TASK.runIdle(true)
988
                            } else {
989
                                // logout
990
                                MinovaUtil.SESSIONS.TASK.methods
991
                                    .logout2()
992
                            }
993
                        });
994
                }
995

    
996
                function call5() {
997
                    tiemrAutoLogout = setInterval(textUpd, 1000);
998
                    var cd = MinovaUtil.SESSIONS.TASK.config.timerWarningTimeout
999
                        / 1000;
1000
                    var Vrelogin = getViewRelogin();
1001
                    Vrelogin.down('button[name=login]').setText('Relogin');
1002
                    Vrelogin.down('button[name=cancel]').setText('Logout');
1003
                    Vrelogin.down('textfield[name=user]')
1004
                        .setValue(MinovaUtil.SESSIONS.LOGIN.userId);
1005
                    Vrelogin.down('textfield[name=user]').setReadOnly(true);
1006
                    Vrelogin.down('textfield[name=pass]').setValue('');
1007

    
1008
                    function textUpd() {
1009
                        cd = cd - 1;
1010
                        try {
1011
                            var bt = Vrelogin.down('button[name=cancel]');
1012
                            bt.setText('Logout(' + cd + 's)');
1013
                        } catch (e) {
1014
                            // Ext.global.console.log(e)
1015
                        }
1016
                    }
1017

    
1018
                    function getViewRelogin() {
1019
                        var _dialogLogin = null;
1020
                        // Get Controller Login
1021
                        var _controller = MinovaApp.getController(appName
1022
                            + '.controller.base.main.Login');
1023
                        var _curView = Ext.ComponentQuery
1024
                            .query('base-main-Login')[0]
1025
                        if (_curView != undefined) {
1026
                            _dialogLogin = _curView;
1027
                        } else {
1028
                            _dialogLogin = Ext.create(_controller.views[0]);
1029
                            _controller.init();
1030
                        }
1031

    
1032
                        return _dialogLogin;
1033
                    }
1034

    
1035
                    return _dialogLogin.show();
1036

    
1037
                }
1038
            },
1039
            logout2: function () {
1040
                // window.location.reload();
1041
                // Ext.global.console.log('Logout')
1042
                try {
1043
                    logout();
1044
                } catch (e) {
1045
                    window.location.reload();
1046
                }
1047
            }
1048
        }
1049

    
1050
    },
1051
    TASK2: {
1052
        config: {
1053
            timerWarning: 1000 * 60 * 30,
1054
            timerRemain: null,
1055
            _interval_check_session: null,
1056
            _setInterval_warning_expired: null
1057
        },
1058
        run: function () {
1059
            // stop
1060
            MinovaUtil.SESSIONS.TASK2.methods.stop_warning();
1061
            MinovaUtil.SESSIONS.TASK2.methods.stop_check_sessions();
1062
            // start
1063
            MinovaUtil.SESSIONS.TASK2.methods.start_check_sessions();
1064
        },
1065
        methods: {
1066
            check_sessions: function () {
1067
                MinovaAjaxPost('/Devt/CheckSession2/', {}, function (s) {
1068
                    var result = Ext.decode(s.responseText);
1069
                    var data = result.data;
1070
                    MinovaUtil.SESSIONS.TASK2.config.timerWarning = data.SessionWarning;
1071
                    MinovaUtil.SESSIONS.TASK2.config.timerRemain = data.SessionRemain;
1072
                    if (data.SessionRemain <= data.SessionWarning) {
1073
                        if (data.SessionRemain <= 0) {
1074
                            console.log('Session Expired')
1075
                            MinovaUtil.SESSIONS.TASK2.methods.alert_session_expired();
1076
                        }
1077
                        else {
1078
                            console.log('Session expiired in ' + data.SessionRemain / 1000 + 's')
1079
                            MinovaUtil.SESSIONS.TASK2.methods.start_warning();
1080
                        }
1081
                    } else {
1082
                        MinovaUtil.SESSIONS.TASK2.methods.stop_warning();
1083

    
1084
                    }
1085
                }, function (f) {
1086
                });
1087
            },
1088
            stop_warning: function () {
1089
                function getViewRelogin() {
1090
                    var _dialogLogin = null;
1091
                    // Get Controller Login
1092
                    var _controller = MinovaApp.getController(appName
1093
                        + '.controller.base.main.Login');
1094
                    var _curView = Ext.ComponentQuery
1095
                        .query('base-main-Login')[0]
1096
                    if (_curView != undefined) {
1097
                        _dialogLogin = _curView;
1098
                    } else {
1099
                        _dialogLogin = Ext.create(_controller.views[0]);
1100
                        _controller.init();
1101
                    }
1102

    
1103
                    return _dialogLogin;
1104
                }
1105

    
1106
                getViewRelogin().hide();
1107
                if (!Ext.isEmpty(MinovaUtil.SESSIONS.TASK2.config._setInterval_warning_expired)) {
1108
                    clearInterval(MinovaUtil.SESSIONS.TASK2.config._setInterval_warning_expired);
1109
                    MinovaUtil.SESSIONS.TASK2.config._setInterval_warning_expired = null;
1110
                }
1111
            },
1112
            stop_check_sessions: function () {
1113
                if (!Ext.isEmpty(MinovaUtil.SESSIONS.TASK2.config._interval_check_session)) {
1114
                    clearInterval(MinovaUtil.SESSIONS.TASK2.config._interval_check_session);
1115
                    MinovaUtil.SESSIONS.TASK2.config._interval_check_session = null;
1116
                }
1117
            },
1118
            start_check_sessions: function () {
1119
                if (Ext.isEmpty(MinovaUtil.SESSIONS.TASK2.config._interval_check_session))
1120
                    MinovaUtil.SESSIONS.TASK2.config._interval_check_session = setInterval(
1121
                        function () {
1122
                            console.log('execute MinovaUtil.SESSIONS.TASK2.methods.check_sessions()')
1123
                            MinovaUtil.SESSIONS.TASK2.methods.check_sessions()
1124
                        }, 5000);
1125
            },
1126
            start_warning: function () {
1127
                function _count_down() {
1128
                    cd = cd - 1;
1129
                    try {
1130
                        var bt = Vrelogin.down('button[name=cancel]');
1131
                        bt.setText('Logout(' + cd + 's)');
1132

    
1133
                        if (cd <= 0) {
1134
                            MinovaUtil.SESSIONS.TASK2.methods.stop_warning();
1135
                            MinovaUtil.SESSIONS.TASK2.methods.alert_session_expired();
1136
                        }
1137
                    } catch (e) {
1138
                        // Ext.global.console.log(e)
1139
                    }
1140
                }
1141

    
1142
                function getViewRelogin() {
1143
                    var _dialogLogin = null;
1144
                    // Get Controller Login
1145
                    var _controller = MinovaApp.getController(appName
1146
                        + '.controller.base.main.Login');
1147
                    var _curView = Ext.ComponentQuery
1148
                        .query('base-main-Login')[0]
1149
                    if (_curView != undefined) {
1150
                        _dialogLogin = _curView;
1151
                    } else {
1152
                        _dialogLogin = Ext.create(_controller.views[0]);
1153
                        _controller.init();
1154
                    }
1155

    
1156
                    return _dialogLogin;
1157
                }
1158

    
1159
                if (Ext.isEmpty(MinovaUtil.SESSIONS.TASK2.config._setInterval_warning_expired)) {
1160
                    MinovaUtil.SESSIONS.TASK2.config._setInterval_warning_expired = setInterval(_count_down, 1000);
1161
                    var cd = Math.round(MinovaUtil.SESSIONS.TASK2.config.timerRemain / 1000);
1162

    
1163
                    var Vrelogin = getViewRelogin();
1164
                    Vrelogin.down('button[name=login]').setText('Relogin');
1165
                    Vrelogin.down('button[name=cancel]').setText('Logout');
1166
                    Vrelogin.down('textfield[name=user]').setReadOnly(true);
1167
                    Vrelogin.down('textfield[name=user]').setValue(MinovaUtil.SESSIONS.LOGIN.userId);
1168
//                Vrelogin.down('combobox[name=instance]').setReadOnly(true);
1169
                    Vrelogin.down('textfield[name=pass]').setValue('');
1170
                }
1171

    
1172
//                var p1 = "";
1173
//                var p2 = "";
1174
//                var _params = Ext.decode('{"param1":"' + p1 + '","param2":"' + p2 + '"}');
1175
//                showLoadingMask('Please Wait....');
1176

    
1177
//                MinovaAjaxPostSync('/Devt/CheckSession2/', _params, function (response) {
1178
//
1179
//                    var result = Ext.decode(response.responseText);
1180
//
1181
//                    if (result.SessionRemain <= result.SessionWarning) { // Not Validate
1182
//                        //_dialogLogin.show();
1183
//                        loginButtonMode('logout');
1184
//                        isAppLogged = false;
1185
//                    }
1186
//                    else { // Valid
1187
//                        Vrelogin.down('textfield[name=user]')
1188
//                            .setValue(result.data.UserID);
1189
////                        Vrelogin.down('combobox[name=instance]')
1190
////                            .setValue(result.data.Instance);
1191
//                    }
1192
//                });
1193

    
1194
                return _dialogLogin.show();
1195
            },
1196
            alert_session_expired: function () {
1197
                Ext.global.console.log('Sessions has expired.');
1198
                alert('Sessions has expired.');
1199
                location.reload();
1200
            },
1201
            logoutFunc: function () {
1202
                // window.location.reload();
1203
                Ext.global.console.log('Logout');
1204
                logout();
1205
                //location.reload()
1206

    
1207
            }
1208
        }
1209

    
1210
    }
1211

    
1212
}
1213
/**
1214
 * auto generate by H/V view
1215
 * @type {{title: string, data: Array, topheader: boolean, add: Function, show: Function}}
1216
 */
1217
MinovaUtil.PDF = {
1218
    title: 'Default title',
1219
    data: [],
1220
    topheader: true,
1221
    add: function (r) {
1222
        this.data.push(r)
1223
    },
1224
    show: function () {
1225
        // window.open('/workflow/generatepdf/?title=' + (this.title)
1226
        // + '&topheader=' + this.topheader + '&data='
1227
        // + Base64.encode(Ext.encode(this.data)));
1228

    
1229
        // build params object
1230
        var aaa = (typeof(data))
1231

    
1232
        var obj = [];
1233
        obj.push({
1234
            title: this.title
1235
        });
1236
        obj.push({
1237
            topheader: this.topheader
1238
        });
1239
        obj.push({
1240
            data: this.data
1241
        });
1242

    
1243
        window.open('/workflow/generatepdf/?obj='
1244
            + Base64.encode(Ext.encode(obj)));
1245
    }
1246
}
1247
MinovaUtil.UTILITY = {
1248
    RENDERER: {
1249
        formatDate: function (value, metaData, record, rowIndex, colIndex, store, view) {
1250
            try {
1251
                return Ext.Date.format(Ext.Date.parse(value, 'Ymd'),
1252
                    MinovaUtil.SESSIONS.APPSETINGS.dateFormat);
1253
            } catch (e) {
1254
                return value;
1255
            }
1256
        }
1257
    },
1258

    
1259
    /*
1260
     * IntegraXor Web SCADA - JavaScript Number Formatter
1261
     * http://www.integraxor.com/ author: KPL, KHL (c)2011 ecava Dual
1262
     * licensed under the MIT or GPL Version 2 licenses.
1263
     */
1264
    // window.format = function(b, a) {
1265
    format: function (b, a) {
1266
        if (!b || isNaN(+a))
1267
            return a;
1268
        var a = b.charAt(0) == "-" ? -a : +a, j = a < 0 ? a = -a : 0, e = b
1269
            .match(/[^\d\-\+#]/g), h = e && e[e.length - 1] || ".", e = e
1270
            && e[1] && e[0] || ",", b = b.split(h), a = a.toFixed(b[1]
1271
            && b[1].length), a = +a + "", d = b[1]
1272
            && b[1].lastIndexOf("0"), c = a.split(".");
1273
        if (!c[1] || c[1] && c[1].length <= d)
1274
            a = (+a).toFixed(d + 1);
1275
        d = b[0].split(e);
1276
        b[0] = d.join("");
1277
        var f = b[0] && b[0].indexOf("0");
1278
        if (f > -1)
1279
            for (; c[0].length < b[0].length - f;)
1280
                c[0] = "0" + c[0];
1281
        else
1282
            +c[0] == 0 && (c[0] = "");
1283
        a = a.split(".");
1284
        a[0] = c[0];
1285
        if (c = d[1] && d[d.length - 1].length) {
1286
            for (var d = a[0], f = "", k = d.length % c, g = 0, i = d.length; g < i; g++)
1287
                f += d.charAt(g), !((g - k + 1) % c) && g < i - c
1288
                    && (f += e);
1289
            a[0] = f
1290
        }
1291
        a[1] = b[1] && a[1] ? h + a[1] : "";
1292
        return (j ? "-" : "") + a[0] + a[1]
1293
    },
1294
	dateDiff: function (dateFrom, dateTo, diffType) {
1295
        var year = dateFrom.substring(0, 4);
1296
        var month = dateFrom.substring(4, 6);
1297
        var day = dateFrom.substring(6, 8);
1298

    
1299
        var df = new Date(year, month - 1, day);
1300

    
1301
        year = dateTo.substring(0, 4);
1302
        month = dateTo.substring(4, 6);
1303
        day = dateTo.substring(6, 8);
1304

    
1305
        var dt = new Date(year, month - 1, day);
1306

    
1307
        var diff = 0;
1308

    
1309
        if (diffType === 'day') {
1310
            var diffDays = (dt.getTime() - df.getTime()) / (1000 * 60 * 60 * 24);
1311

    
1312
            diff = diffDays;
1313
        } else if (diffType === 'month') {
1314
            var months;
1315
            months = (dt.getFullYear() - df.getFullYear()) * 12;
1316
            months -= df.getMonth();
1317
            months += dt.getMonth();
1318
            diff = months;
1319
        } else {
1320
            var diffYears = (dt.getFullYear() - df.getFullYear());
1321
            diff = diffYears;
1322
        }
1323

    
1324
        return diff;
1325
    }
1326
}
1327

    
1328
//}
(4-4/6)