1
|
Ext.define('MinovaES.controller.workflow.run.utility', {
|
2
|
extend: 'Ext.app.ViewController',
|
3
|
alias: 'controller.run-utility',
|
4
|
url: "/WorkFlow/SaveWFrequestAsync/",
|
5
|
action: {},
|
6
|
init: function () {},
|
7
|
submitWorkflow: function (_action, onDocBeforeSubmit) {
|
8
|
var me = this;
|
9
|
me.action.name = _action.name;
|
10
|
var ActionName = me.action.name;
|
11
|
var flowText = _action.text;
|
12
|
var secondIndex = ActionName.indexOf("[") + 1;
|
13
|
var lastIndex = ActionName.indexOf("]");
|
14
|
var flowType = ActionName.substring(secondIndex, lastIndex);
|
15
|
var paramname = ActionName.split("[" + flowType + "]");
|
16
|
var flowName = paramname[1];
|
17
|
var objErr = [];
|
18
|
function validationBeforeSubmit(submit) {}
|
19
|
function submit() {
|
20
|
|
21
|
function formValidation() {
|
22
|
var hasil = true;
|
23
|
var headerFrm = MinovaUtil.WORKFLOW.getViewHeaderWorkflow().getForm();
|
24
|
Ext.each(headerFrm, function (form) {
|
25
|
var valid = form.isValid();
|
26
|
if (!valid) {
|
27
|
hasil = false;
|
28
|
Ext.each(form.getFields().items, function (f) {
|
29
|
if (!f.validate())
|
30
|
objErr.push(f.fieldLabel + ' on Header Form:' + f.activeError);
|
31
|
});
|
32
|
}
|
33
|
});
|
34
|
var bodyFrm = MinovaUtil.WORKFLOW.getViewBodyWorkflow().getForm();
|
35
|
Ext.each(bodyFrm, function (form) {
|
36
|
var valid = form.isValid();
|
37
|
if (!valid) {
|
38
|
hasil = false;
|
39
|
Ext.each(form.getFields().items, function (f) {
|
40
|
if (!f.validate())
|
41
|
objErr.push(f.fieldLabel + ' on Body Form:' + f.activeError);
|
42
|
});
|
43
|
}
|
44
|
});
|
45
|
|
46
|
var commentFrm = Ext.ComponentQuery.query('form[name=comment]')[0];
|
47
|
if (!commentFrm.isValid()) {
|
48
|
hasil = false;
|
49
|
objErr.push('Comment on Footer');
|
50
|
}
|
51
|
|
52
|
return hasil;
|
53
|
}
|
54
|
function submitWf() {
|
55
|
var objAction = {
|
56
|
code: flowName,
|
57
|
desc: flowText,
|
58
|
group: flowType
|
59
|
};
|
60
|
var myobjHeaderdata = MinovaUtil.WORKFLOW.getViewHeaderWorkflow().getForm().getValues();
|
61
|
var myobjBodydata = MinovaUtil.WORKFLOW.getViewBodyWorkflow().getForm().getValues();
|
62
|
var myduration = myobjBodydata.Duration;
|
63
|
var Mystartdate = myobjBodydata.DateFrom;
|
64
|
var myStartDate = myobjBodydata.DateFrom;
|
65
|
var myEndDate= myobjBodydata.DateTo;
|
66
|
var asnotes = myobjBodydata.Notes;
|
67
|
var myEmployeeID= myobjHeaderdata.RequesterID;
|
68
|
var objHeader = MinovaUtil.WORKFLOW.getViewHeaderWorkflow().getForm().getValues();
|
69
|
var objFooter = MinovaUtil.WORKFLOW.getViewFooterWorkflow().getValues();
|
70
|
var objGuidFiles = [];
|
71
|
MinovaUtil.WORKFLOW.getViewFooterWorkflow().down('grid[name=attachment]').store.each(
|
72
|
function (rec) {
|
73
|
if (rec.data.IsAdd !== undefined && rec.data.IsAdd !== "") {
|
74
|
objGuidFiles.push({
|
75
|
FileName: rec.data.FileName,
|
76
|
Title: rec.data.Title,
|
77
|
RequestNo: rec.data.RequestNo,
|
78
|
WorkflowID: rec.data.WorkflowID,
|
79
|
Notes: rec.data.Notes,
|
80
|
IsPrivate: rec.data.IsPrivate,
|
81
|
FileType: rec.data.FileType
|
82
|
});
|
83
|
}
|
84
|
});
|
85
|
var objData;
|
86
|
var _objGrid;
|
87
|
try {
|
88
|
objData = me.BuildMultiForm();
|
89
|
_objGrid = me.BuildMultiGrid();
|
90
|
for (var i = 0; i < _objGrid.length; i++) {
|
91
|
objData.push(_objGrid[i]);
|
92
|
}
|
93
|
|
94
|
} catch (e) {
|
95
|
Ext.global.console.error('Error build form' + e);
|
96
|
Ext.Msg.alert('Build form error', e);
|
97
|
return;
|
98
|
}
|
99
|
Ext.getBody().mask('Saving...');
|
100
|
MinovaAjaxPost(me.url, {
|
101
|
bizprocid: MinovaUtil.WORKFLOW.GetBizprocId(),
|
102
|
header: Ext.encode(objHeader),
|
103
|
data: Ext.encode(objData),
|
104
|
footer: Ext.encode(objFooter),
|
105
|
action: Ext.encode(objAction),
|
106
|
guidFiles: Ext.encode(objGuidFiles)
|
107
|
}, function (xhr) {
|
108
|
Ext.getBody().unmask('');
|
109
|
var results = Ext.decode(xhr.responseText);
|
110
|
var result = Ext.decode(results.data);
|
111
|
var r = Ext.decode(result);
|
112
|
|
113
|
|
114
|
MinovaUtil.ExecuteParamQuery({
|
115
|
ID: 'CheckLocked',
|
116
|
reg_id: MinovaUtil.WORKFLOW.getRegId(),
|
117
|
emp_id: MinovaUtil.WORKFLOW.getEmpId(),
|
118
|
release: 1,
|
119
|
seq: 0
|
120
|
}, function (xhr) {}, function () {});
|
121
|
if (r.success === true) {
|
122
|
var new_date = moment(Mystartdate, "YYYY-MM-DD").add('days', 14);
|
123
|
var day = new_date.format('DD');
|
124
|
var month = new_date.format('MM');
|
125
|
var year = new_date.format('YYYY');
|
126
|
|
127
|
var data = r.data;
|
128
|
if (data !== null && data !== undefined) {
|
129
|
MinovaUtil.WORKFLOW.getViewInfoWorkflow().getForm().setValues(data);
|
130
|
var Main = Ext.ComponentQuery.query('[name=Main]')[0];
|
131
|
Main.getLayout().setActiveItem(1);
|
132
|
MinovaMessage('', 'WF001', "", "S");
|
133
|
}
|
134
|
var taskidrun = MinovaUtil.WORKFLOW.getTaskId();
|
135
|
if (taskidrun == 'requester_confirm'){
|
136
|
if (asnotes == 001){
|
137
|
if (parseInt(myduration) >= 8){
|
138
|
setTimeout(function(){
|
139
|
try {
|
140
|
MinovaUtil.ExecuteParamQuery({
|
141
|
ID: 'WFSAVEPHRPA0118',
|
142
|
myduration:myduration,
|
143
|
StartDate: myStartDate,
|
144
|
EndDate: myEndDate,
|
145
|
EmployeeID: myEmployeeID,
|
146
|
StartDateDeduction: year+month+day,
|
147
|
EndDateDeduction: year+month+day
|
148
|
}, function (s) {},
|
149
|
function (f) {});
|
150
|
} catch {}
|
151
|
}, 5000);
|
152
|
}
|
153
|
if (parseInt(myduration) < 8){
|
154
|
setTimeout(function(){
|
155
|
try {
|
156
|
MinovaUtil.ExecuteParamQuery({
|
157
|
ID: 'WFSAVEPHRPA0118',
|
158
|
myduration:myduration,
|
159
|
StartDate: myStartDate,
|
160
|
EndDate: myEndDate,
|
161
|
EmployeeID: myEmployeeID,
|
162
|
StartDateDeduction: year+month+day,
|
163
|
EndDateDeduction: year+month+day
|
164
|
}, function (s) {},
|
165
|
function (f) {});
|
166
|
} catch {}
|
167
|
}, 5000);
|
168
|
}
|
169
|
}
|
170
|
}
|
171
|
} else {
|
172
|
if (r.message !== null && r.message !== undefined) {
|
173
|
MinovaMessage('', '000005', r.message.text, "E");
|
174
|
} else if (r.messages !== null && r.messages !== undefined) {
|
175
|
MinovaMessage('', '000005', r.messages[0].text, "E");
|
176
|
}
|
177
|
}
|
178
|
}, function () {
|
179
|
Ext.getBody().unmask('');
|
180
|
});
|
181
|
}
|
182
|
|
183
|
if(flowType == '410' ||flowType == '420') {
|
184
|
MinovaUtil.WORKFLOW.getViewFooterWorkflow().down('[name=Comment]').allowBlank = false;
|
185
|
} else {
|
186
|
MinovaUtil.WORKFLOW.getViewFooterWorkflow().down('[name=Comment]').allowBlank = true;
|
187
|
}
|
188
|
|
189
|
if (formValidation()) {
|
190
|
submitWf();
|
191
|
} else {
|
192
|
var strObjErr = '';
|
193
|
Ext.each(objErr, function (o) {
|
194
|
strObjErr += o + '<br>'
|
195
|
})
|
196
|
Ext.Msg.show({
|
197
|
title: 'Error on validation',
|
198
|
msg: strObjErr,
|
199
|
buttons: Ext.Msg.OK,
|
200
|
icon: Ext.Msg.ERROR
|
201
|
});
|
202
|
}
|
203
|
}
|
204
|
var activeOnBeforeSubmit = false;
|
205
|
if (onDocBeforeSubmit !== null && onDocBeforeSubmit !== undefined && onDocBeforeSubmit !== "") {
|
206
|
eval(onDocBeforeSubmit);
|
207
|
//activeOnBeforeSubmit = true;
|
208
|
} else {
|
209
|
submit();
|
210
|
}
|
211
|
// if (activeOnBeforeSubmit) validationBeforeSubmit(onDocBeforeSubmit);
|
212
|
// });
|
213
|
// else validationBeforeSubmit(submit);
|
214
|
|
215
|
// var _param = {
|
216
|
// tableName: tablename,
|
217
|
// param: 'BizFlowID[=]' + bizFLowid
|
218
|
// }
|
219
|
// MinovaAjaxPost('/UserControl/GetStore/', _param, function (xhr) {
|
220
|
// var result = Ext.decode(xhr.responseText);
|
221
|
// if (result.success) {
|
222
|
// if (result.data == undefined) return;
|
223
|
// store.loadData(result.data);
|
224
|
// newCard.getEl().unmask();
|
225
|
// } else {
|
226
|
// newCard.getEl().unmask();
|
227
|
// }
|
228
|
// });
|
229
|
},
|
230
|
BuildMultiForm: function () {
|
231
|
var PanelData = Ext.ComponentQuery.query('wf-contentbody')[0];
|
232
|
var FormDatas = PanelData.query('minovaworkflowform');
|
233
|
var FormLength = FormDatas.length;
|
234
|
var FormBuildStrings = [];
|
235
|
|
236
|
for (var i = 0; i < FormLength; i++) {
|
237
|
var values = FormDatas[i].getForm().getValues();
|
238
|
var name = FormDatas[i].name;
|
239
|
var obj = Ext.decode('{' + name + ':' + Ext.encode(values) + '}');
|
240
|
FormBuildStrings.push(obj);
|
241
|
}
|
242
|
return FormBuildStrings;
|
243
|
},
|
244
|
BuildMultiGrid: function () {
|
245
|
var PanelData = Ext.ComponentQuery.query('wf-contentbody')[0];
|
246
|
var GridData = PanelData.query('minovaworkfloweditablegrid');
|
247
|
var GridLength = GridData.length;
|
248
|
var GridBuildStrings = [];
|
249
|
for (var i = 0; i < GridLength; i++) {
|
250
|
var records = [];
|
251
|
var grd = GridData[i].query('grid')[0];
|
252
|
if (grd.hasOwnProperty('CRUDflag')) {
|
253
|
records = grd.CRUDflag.getAllRecords(GridData[i].store)
|
254
|
} else {
|
255
|
var recC = grd.store.getNewRecords();
|
256
|
Ext.each(recC, function (rec) {
|
257
|
records.push(rec);
|
258
|
});
|
259
|
var recU = grd.store.getUpdatedRecords();
|
260
|
Ext.each(recU, function (rec) {
|
261
|
records.push(rec);
|
262
|
});
|
263
|
var recD = grd.store.getRemovedRecords();
|
264
|
Ext.each(recD, function (rec) {
|
265
|
records.push(rec);
|
266
|
});
|
267
|
}
|
268
|
Ext.each(records, function (rec) {
|
269
|
var name = GridData[i].name;
|
270
|
var obj = Ext.decode('{' + name + ':' + Ext.encode(rec.data) + '}');
|
271
|
GridBuildStrings.push(obj);
|
272
|
});
|
273
|
}
|
274
|
function getFlag(_recNya) {
|
275
|
var val = '';
|
276
|
return val;
|
277
|
}
|
278
|
return GridBuildStrings;
|
279
|
}
|
280
|
});
|