Project

General

Profile

Bug #2357 » wfforwardingtask.js

package_update - M Azid Wahyudi, 10/06/2023 03:46 PM

 
1
Ext.define('MinovaES.controller.workflow.forwardingtask.wfforwardingtask', {
2
    extend: 'Ext.app.ViewController',
3
    alias: 'controller.ctrl-wfforwardingtask',
4
    currentNode: {},
5
    currentWf: {},
6
    onDocAfterRender: null,
7
    onDocBeforeSubmit: null,
8
    init: function () {
9
        this.control({
10
            'view-wfforwardingtask [name=PICType]': {
11
                change: this.changePICtype
12
            },
13
            'view-wfforwardingtask [name=PICTypeTo]': {
14
                change: this.changePICForward
15
            },
16
            '[name=Search]': {
17
                click: this.Search
18
            },
19
            '[name=Execute]': {
20
                click: this.Execute
21
            }
22
        });
23
    },
24
    changePICtype: function (f) {
25
        var me = this;
26
        var PICtype = f.getValue();
27
        var PICEmployee = Ext.ComponentQuery.query('[name=PICEmployee]')[0];
28
		var RoleID = Ext.ComponentQuery.query('[name=RoleID]')[0];
29
		switch(PICtype)
30
		{
31
			case 'Employee':
32
				PICEmployee.setHidden(false);
33
				RoleID.setHidden(true);
34
			break;
35
			case 'Group':
36
				PICEmployee.setHidden(true);
37
				RoleID.setHidden(false);
38
			break;
39
			default:
40
			break;
41
		}        
42
    },
43
    changePICForward: function (f) {
44
        var me = this;
45
        var PICTypeTo = f.getValue();
46
        var PICEmployee = Ext.ComponentQuery.query('[name=EmployeeID]')[0];
47
		var RoleID = Ext.ComponentQuery.query('[name=RoleIDTo]')[0];
48
		switch(PICTypeTo)
49
		{
50
			case 'Employee':
51
				PICEmployee.setHidden(false);
52
				RoleID.setHidden(true);
53
			break;
54
			case 'Group':
55
				PICEmployee.setHidden(true);
56
				RoleID.setHidden(false);
57
			break;
58
			default:
59
			break;
60
		} 
61
    },
62
    Search: function () {
63
        var store = Ext.data.StoreManager.lookup('storewfforwadingtask');
64
        var form = Ext.ComponentQuery.query('[name=formwfforwadingtask]')[0].getForm();
65
        var grid = Ext.ComponentQuery.query('[name=gridwfforwadingtask]')[0];
66
        var values_ = form.getValues();
67
        var fields_ = form.getFields().items;
68
        var param_ = '';
69
        for (var i = 0; i < fields_.length; i++) {
70
            var val_ = form.getFields().items[i].getValue();
71
            var xtype_ = form.getFields().items[i].xtype;
72
            var oprator_ = '[like]';
73
            if (xtype_ == 'combobox' || xtype_ == 'combo' || xtype_ == 'minovacombo' || xtype_ == 'minovacombobox') {
74
                oprator_ = '[Equal]';
75
            }
76
            if (xtype_ == 'datefield') {
77
                if (form.getFields().items[i].name == 'StartDate' || form.getFields().items[i].name == 'ValidForm') {
78
                    oprator_ = '[GreaterThanEqual]';
79
                } else {
80
                    oprator_ = '[LessThanEqual]';
81
                }
82
            }
83
            if (val_ != 'undefined' && val_ != "" && val_ != null) {
84
                param_ = param_ + ',' + form.getFields().items[i].name + oprator_ + val_;
85
            }
86
        }
87
        store.proxy.extraParams = {
88
            tableName: "PDSWFFORWARDTASKRESULT",
89
            param: param_,            
90
        };
91
        store.removeAll();
92
        store.reload();
93
        store.loadPage(1);
94
    },
95
    Execute: function (f) {
96
        var store = Ext.data.StoreManager.lookup('storewfforwadingtask');
97
        var formSelection = Ext.ComponentQuery.query('[name=formwfforwadingtask]')[0];
98
        var form = Ext.ComponentQuery.query('[name=formForwardTo]')[0];
99
        var PICType = Ext.ComponentQuery.query('[name=PICTypeTo]')[0].getValue();
100
		var emp = Ext.ComponentQuery.query('[name=EmployeeID]')[0].getValue();
101
		var group = Ext.ComponentQuery.query('[name=RoleIDTo]')[0].getValue();        
102
        var grid = Ext.ComponentQuery.query('[name=gridwfforwadingtask]')[0];
103
        var selection = grid.getView().getSelectionModel();
104
        var dt = selection.getSelection();
105
		if(dt.length > 0){
106
			if(PICType != ''){
107
				switch(PICType)
108
				{
109
					case 'Employee':
110
						if(emp != undefined && emp != '' && emp != null)
111
						{
112
							var data = [];
113
							for (var i = 0; i < dt.length; i++) {
114
								data = dt[i];            
115
								data.data.PICEmployee = emp;
116
							};
117
							var dataGrid = Ext.encode(Ext.pluck(dt, 'data'));
118
							Ext.Ajax.request({
119
								method: 'POST',
120
								url: '/WorkFlow/UpdatePIC',
121
								params: {
122
									data: dataGrid,
123
								},
124
								waitMsg: 'Saving Data...',
125
								success: function (response) {
126
									var results = Ext.decode(response.responseText); var dt = Ext.decode(results.data);
127
									if (dt.success) {
128
										MinovaMessage('', '000006', '', 'S');
129
										store.removeAll();
130
										form.reset();
131
										formSelection.reset();
132
									} else {
133
										MinovaMessage('', '000005', dt.message.text, 'E');
134
									}
135
								}
136
							});
137
						} else {
138
							MinovaMessage('', '000005', "Employee ID on Forward to must be select", 'E');
139
						}
140
					break;
141
					case 'Group':
142
						if(group != undefined && group != '' && group != null)
143
						{
144
							var data = [];
145
							for (var i = 0; i < dt.length; i++) {
146
								data = dt[i];            
147
								data.data.PICEmployee = group;
148
							};
149
							var dataGrid = Ext.encode(Ext.pluck(dt, 'data'));
150
							Ext.Ajax.request({
151
								method: 'POST',
152
								url: '/WorkFlow/UpdatePICGroup',
153
								params: {
154
									data: dataGrid,
155
								},
156
								waitMsg: 'Saving Data...',
157
								success: function (response) {
158
									var results = Ext.decode(response.responseText); var dt = Ext.decode(results.data);
159
									if (dt.success) {
160
										MinovaMessage('', '000006', '', 'S');
161
										store.removeAll();
162
										form.reset();
163
										formSelection.reset();
164
									} else {
165
										MinovaMessage('', '000005', dt.message.text, 'E');
166
									}
167
								}
168
							});
169
						} else {
170
							MinovaMessage('', '000005', "Group on Forward to must be select", 'E');
171
						}
172
					break;
173
					default:
174
					break;
175
				}							
176
			}
177
			else
178
			{
179
				MinovaMessage('', '000005', "PIC Type must be select", 'E');
180
			}
181
		} else {
182
			MinovaMessage('', '000005', "Please select data first", 'E');
183
		}
184
    },
185
    failure: function (response) {
186
        pnl.unmask();
187
        var result = Ext.decode(response.responseText);
188
        console.log(result);
189
    },            
190
});
(2-2/2)