-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
423 lines (376 loc) · 11.2 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/*
pitt phunsanit
default fetch api options
version 1
*/
let fetchOptions = {
"headers": {
'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
"method": "post"
};
/*
pitt phunsanit
custom user menu
version 1
*/
function anonymousUserBadge() {
let badge = $('.user-link > a:first').closest('li');
let emp_code = sessionStorage.getItem('emp_code');
let emp_name = sessionStorage.getItem('emp_name');
let navigation = $('#navigation');
if (emp_name === null) {
badge.replaceWith('<li class="user-link"><a href="/jw/web/login" class="btn waves-effect btn waves-button waves-float"><i class="fa fa-user white"></i> Login</a></li>');
$('a[href$="/anonymousLogin"]', navigation).show();
$('a[href$="_anonymous"]', navigation).hide();
} else {
$('a[href$="/anonymousLogin"]', navigation).closest('li').hide();
$('a[href$="_anonymous"]', navigation).each(function (index, value) {
let a = $(this);
let href = a.attr('href');
href += '?or_requester_id=' + emp_code + '&or_preparer_id=' + emp_code + '&pr_requester_id=' + emp_code + '&pr_preparer_id=' + emp_code;
a.attr('href', href).show();
});
setTimeout(function () {
badge.replaceWith('<li class="user-link dropdown"><a data-toggle="dropdown" class="btn dropdown-toggle waves-effect btn waves-button waves-float"><i class="fa fa-user-secret"></i> ' + emp_name + '<span class="caret"></span></a><ul class="dropdown-menu"><li><a id="logoutBtn"><i class="fa fa-power-off"></i> Logout</a></li></ul></li>');
}, 1000);
}
}
/*
pitt phunsanit
custom display user name for anonymous
version 1
*/
function anonymousUser() {
anonymousUserBadge();
$(document).on('click', '#logoutBtn', function () {
localStorage.removeItem('emp_code');
localStorage.removeItem('emp_name');
sessionStorage.removeItem('emp_code');
sessionStorage.removeItem('emp_name');
anonymousUserBadge('');
window.location.href = '/jw/web/login';
});
}
/*
pitt phunsanit
editable input
version 1
*/
function beforeSubmit() {
if ($("form.readonly").length == 0) {
setTimeout(function () {
$("#section-actions button, #section-actions input")
.off("click")
.on("click", function () {
$("#visibilityControl").val("all");
$(":disabled").prop("disabled", false);
$("[readonly]").prop("readonly", false);
});
}, 1000);
}
}
/*
pitt phunsanit
editable input
version 1
*/
function clickToEdit(inputs) {
$.each(inputs, function (key, value) {
let id = value + "EditFlag";
let input = FormUtil.getField(value);
input
.attr("readonly", true)
.closest(".form-cell")
.append(
'<label style="display: inline;"><input id="' +
id +
'" name="' +
id +
'" type="checkbox" value="Y"> Click to Edit</label>'
);
$("#" + id).on("change", function () {
if ($(this).prop("checked") == true) {
input.prop("readonly", false);
} else {
input.prop("readonly", true);
}
});
});
}
/*
pitt phunsanit
confirm submit form
version 1
*/
function confirmSubmit(
confirmMessage = "Are you sure to submit ?",
message = "Please wait...",
delay = 1000
) {
setTimeout(function () {
$("#submit").on("click", function (event) {
if (confirm(confirmMessage)) {
$.blockUI({
css: {
"-moz-border-radius": "10px",
"-webkit-border-radius": "10px",
backgroundColor: "#000",
border: "none",
color: "#fff",
opacity: 0.3,
padding: "15px"
},
message: "<h1>" + message + "</h1>"
});
return true;
}
});
}, delay);
}
/*
pitt phunsanit
email attachment preview
version 1
*/
function emailAttachment(lists) {
let accordionA = $("#accordionA");
let expaned = "";
$.each(lists, function (a, item) {
let itemNo = a + 1;
$("#mailAttachName" + itemNo).val(item.name);
$("#mailAttachPath" + itemNo).val(item.url);
let id = "attach" + itemNo;
if (a == 0) {
expaned = " in";
} else {
expaned = "";
}
let card =
'<div class="accordion-group">' +
'<div class="accordion-heading">' +
'<input checked style="float: left; margin: 10px 10px 0 10px;" type="checkbox" value="' +
itemNo +
'">' +
'<a class="accordion-toggle" data-parent="#accordionA" data-toggle="collapse" href="#' +
id +
'" style="margin: 0px 10px; width: 90%;">' +
item.name +
'</a><a class="fa fa-download" href="' +
item.url +
'" style="float: right; font-size: 30px; margin: -32px 20px;" target="_blank"></a></div>' +
'<div class="accordion-body collapse' +
expaned +
'" id="' +
id +
'"><div class="accordion-inner">' +
'<iframe frameborder="0" height="842" id="attachIframe" src="' +
item.url +
'" width="100%"></iframe>' +
"</div></div></div>" +
"</div>";
accordionA.append(card);
});
accordionA.on("change", 'input[type="checkbox"]', function () {
let checkbox = $(this);
let itemNo = checkbox.val();
let mailAttachName = $("#mailAttachName" + itemNo);
let mailAttachPath = $("#mailAttachPath" + itemNo);
if (checkbox.is(":checked")) {
mailAttachPath.prop("disabled", false);
mailAttachName.prop("disabled", false);
} else {
mailAttachPath.prop("disabled", true);
mailAttachName.prop("disabled", true);
}
});
}
/*
pitt phunsanit
get file name from fetch api
version 1
*/
function fetchGetFilename(response) {
let filename = '';
let disposition = response.headers.get('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
let matches = filenameRegex.exec(disposition);
if (matches != null && matches[1]) {
filename = matches[1].replace(/['"]/g, '');
}
}
return filename;
}
/*
pitt phunsanit
get status from fetch api
version 1
*/
function fetchStatus(Response) {
if (Response.status >= 200 && Response.status < 300) {
return Promise.resolve(Response);
} else {
return Promise.reject(new Error(Response.status + ' : ' + Response.statusText));
}
}
/*
pitt phunsanit
email attachment preview
version 1
*/
function flexfieldsInit(form, inputSelector, flexfieldsSelector) {
let input = $(inputSelector, form);
let parentSubFormId = $(flexfieldsSelector, form);
flexfieldsLabels(form);
flexfieldsSorts(inputSelector);
let name = input.attr("name");
input.on("change", function () {
parentSubFormId.val(name + "=" + $(this).val()).trigger("change");
});
}
/*
pitt phunsanit
email attachment preview
version 1
*/
function flexfieldsLabels(form) {
items = $('input[name$="labels"]').val();
if (items == "") {
return true;
}
try {
let temp = JSON.parse(items);
$.each(temp, function (index, value) {
if (value.trim() == "") {
$("#" + index)
.closest("div")
.hide();
} else {
let input = $("#" + index);
input.siblings("label").text(value);
input.closest("div").show();
}
});
} catch (e) {
console.log(e.message);
html = "<h1>Error!!</h1>";
}
}
/*
pitt phunsanit
email attachment preview
version 1
*/
function flexfieldsSorts(inputSelector) {
let items = $('input[name$="sorts"]').val();
if (items == "") {
return true;
}
try {
let temp = JSON.parse(items);
$.each(temp, function (index, value) {
if (index == value) {
} else if (value == 1) {
$("#" + index)
.closest(":parent")
.insertAfter(inputSelector);
} else {
$("#" + index)
.closest(":parent")
.insertAfter("#attribute" + (value - 1) + ":parent");
}
});
} catch (e) {
console.log(e.message);
html = "<h1>Error!!</h1>";
}
}
/*
pitt phunsanit
resize iframe
version 1
*/
function iframeHeight(obj) {
the_height = obj.contentWindow.document.body.offsetHeight;
obj.height = the_height + 10;
}
/*
pitt phunsanit
show / hide section with joget Visibility
version 1
*/
function navSection() {
let hash = window.location.hash.substr(1);
let tabsA = $("#tabsA");
let visibilityControl = $("#visibilityControl");
if (hash != "" && hash != visibilityControl.val()) {
$('a[href="#' + hash).click();
visibilityControl.val(hash);
}
$("li > a", tabsA).on("click", function () {
visibilityControl
.val(
$(this)
.attr("href")
.substr(1)
)
.trigger("change");
});
}
/*
pitt phunsanit
show / hide section with bootstrapt tabs
version 1
*/
function navSectionTabs() {
let hash = window.location.hash.substr(1);
let tabsA = $("#tabsA");
let visibilityControl = $("#visibilityControl");
$(".form-section:first").after('<div class="tab-content"></div>');
$("a", tabsA).each(function () {
$($(this).attr("href")).appendTo(".tab-content");
});
setTimeout(function () {
$('a[href="#' + visibilityControl.val() + '"]').trigger("click");
}, 300);
$(".form-section").each(function () {
$(this).addClass("fade tab-pane");
});
$("#" + visibilityControl.val()).addClass("fade tab-pane active show");
if (hash != "" && hash != visibilityControl.val()) {
$('a[href="#' + hash).click();
visibilityControl.val(hash);
}
$("li > a", tabsA).on("click", function () {
let target = $(this)
.attr("href")
.substr(1);
visibilityControl.val(target).trigger("change");
$(".form-section").each(function () {
$(this)
.addClass("fade in tab-pane")
.removeClass("active show");
});
$("#" + target).addClass("fade tab-pane active show");
});
}
/*
pitt phunsanit
Please wait
version 1
*/
function preloader(message = 'Please wait...') {
$.blockUI({
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .3,
color: '#fff'
},
message: "<h1>" + message + "</h1>"
});
}