-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateNewJavaScript.html
149 lines (131 loc) · 4.07 KB
/
CreateNewJavaScript.html
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
<script>
$(function() {
$('#sidebar-fillup-frequency').change(onFrequencyChanged);
$('#sidebar-create-button').click(onCreateClick);
// TODO: on date change, update weekly options
$("#sidebar-fillup-start-date").datepicker({
altFormat: "dd-MM-yy",
dateFormat: "dd-M-yy",
showOn: "focus"
});
$("#sidebar-fillup-end-date").datepicker({
altFormat: "dd-MM-yy",
dateFormat: "dd-M-yy",
showOn: "focus"
});
utils.disableButtons();
clearOptions();
onFrequencyChanged();
utils.enableButtons();
});
/**
* Show the start/end date if frequency is Daily/Weekly
*/
function updateStartEndDates() {
var freq = $('#sidebar-fillup-frequency').find(":selected").val();
var $startDate = $('#sidebar-fillup-start-date-panel');
var $endDate = $('#sidebar-fillup-end-date-panel');
if (freq === 'd' || freq === 'w') {
// daily or weekly
$startDate.removeClass('hidden');
$endDate.removeClass('hidden');
} else {
// others
$startDate.addClass('hidden');
$endDate.addClass('hidden');
}
}
/**
* TODO
* Show the ?? if frequency is Daily
*/
function updateFrequencyDaily() {
var freq = $('#sidebar-fillup-frequency').find(":selected").val();
if (freq === 'd') {
// daily
// TODO
} else {
// others
// TODO
}
}
/**
* Show the selection of days in week if frequency is Weekly
*/
function updateFrequencyWeekly() {
var freq = $('#sidebar-fillup-frequency').find(":selected").val();
var $daysInWeek = $('#sidebar-fillup-days-in-week-panel');
if (freq === 'w') {
// weekly
$daysInWeek.removeClass('hidden');
} else {
// others
$daysInWeek.addClass('hidden');
}
}
/**
* Show the sheet name and range for custom dates if frequency is Custom Dates
*/
function updateFrequencyCustomDates() {
var freq = $('#sidebar-fillup-frequency').find(":selected").val();
var $customDates = $('#sidebar-fillup-custom-dates-panel');
if (freq === 'c') {
// custom dates
$customDates.removeClass('hidden');
} else {
// others
$customDates.addClass('hidden');
}
}
function onFrequencyChanged() {
updateStartEndDates();
updateFrequencyDaily();
updateFrequencyWeekly();
updateFrequencyCustomDates();
}
function onCreateClick() {
utils.disableButtons();
utils.enableLoader();
var createOptions = getOptions();
google.script.run
.withSuccessHandler(
function(msg) {
utils.success('Success! The roster timetable has been created');
})
.withFailureHandler(
function(msg) {
utils.failure(msg);
})
.createNew(
createOptions.sheetname,
createOptions.frequency,
createOptions.startDate.toISOString(),
createOptions.endDate.toISOString(),
createOptions.daysInWeek,
createOptions.customSheetname,
createOptions.customRange
);
}
function getOptions() {
return {
sheetname: $('#sidebar-fillup-sheetname').val().trim(),
frequency: $('#sidebar-fillup-frequency').val(),
startDate: $('#sidebar-fillup-start-date').datepicker("getDate"),
endDate: $('#sidebar-fillup-end-date').datepicker("getDate"),
daysInWeek: $.map($('#sidebar-fillup-days-in-week-panel input:checked'), function(e) {
return $(e).val();
}),
customSheetname: $('#sidebar-fillup-custom-dates-sheetname').val(),
customRange: $('#sidebar-fillup-custom-dates-range').val()
};
}
function clearOptions() {
$('#sidebar-fillup-sheetname').val($('#sidebar-fillup-sheetname-default').val());
$('#sidebar-fillup-frequency').val('d');
$('#sidebar-fillup-start-date').datepicker("setDate", new Date());
$('#sidebar-fillup-end-date').datepicker("setDate", new Date());
$('#sidebar-fillup-days-in-week-panel input:checkbox').removeAttr('checked');
$('#sidebar-fillup-custom-dates-sheetname').val('');
$('#sidebar-fillup-custom-dates-range').val('');
}
</script>