1 $(document
).ready(function() {
2 // $('.time-entry').timePicker();
3 $("#setup_form").bind('submit', function() {
8 $('.content').on('click', '.recurring_delete', function(ev
) {
10 var this_id
= $(this).data('recurring-id');
12 if (confirm(_('Are you sure that you would like to delete this schedule.\nPlease note that already scheuled downtime won\'t be affected by this and will have to be deleted manually.\nThis action can\'t be undone.'))) {
14 url
:_site_domain
+ _index_page
+ '/recurring_downtime/delete',
16 data
: {schedule_id
: this_id
},
17 success: function(data
) {
20 window
.setTimeout(function() {
21 lsfilter_main
.refresh();
25 $.notify('An unexpected error occured', {'sticky':true});
29 $.notify("An unexpected error occured", {'sticky':true});
36 $('#fixed').bind('change', function() {
37 if ($(this).is(':checked'))
38 $('#triggered_row').hide();
40 $('#triggered_row').show();
42 if ($(this).is(':checked'))
43 $('#triggered_row').hide();
45 $('#triggered_row').show();
48 $('#downtime_type').on('change', function() {
49 var value
= this.value
;
50 $('.object-list-type').text(value
);
51 get_members(value
, function(all_names
) {
52 populate_options($('#objects_tmp'), $('#objects'), all_names
);
55 var val
= $(this).val();
56 $('.object-list-type').text(val
);
57 if (window
['_report_data']) {
58 expand_and_populate(_report_data
);
60 get_members(val
, function(all_names
) {
61 populate_options($('#objects_tmp'), $('#objects'), all_names
);
65 $('#sel_downtime_type').on('click', function() {
66 var value
= this.form
.downtime_type
.value
;
67 $('.object-list-type').text(value
);
68 get_members(value
, function(all_names
) {
69 populate_options($('#objects_tmp'), $('#objects'), all_names
);
73 $('#progress').css('position', 'absolute').css('top', '90px').css('left', '470px');
75 $('#select-all-days').on('click', function() {
76 $('.recurring_day').prop('checked', true);
78 $('#deselect-all-days').on('click', function() {
79 $('.recurring_day').prop('checked', false);
81 $('#select-all-months').on('click', function() {
82 $('.recurring_month').prop('checked', true);
84 $('#deselect-all-months').on('click', function() {
85 $('.recurring_month').prop('checked', false);
89 function check_timestring(timestring
) {
90 if (timestring
.indexOf(':') === -1) {
93 // We have hh:mm or hh:mm:ss
94 var timeparts
= timestring
.split(':');
95 if ((timeparts
.length
!== 2 && timeparts
.length
!== 3) ||
96 isNaN(timeparts
[0]) ||
97 isNaN(timeparts
[1]) ||
98 (timeparts
.length
=== 3 && isNaN(timeparts
[2]))
105 function check_setup()
107 if (!check_form_values()) {
113 var comment
= $.trim($('textarea[name=comment]').val());
114 var start_time
= $.trim($('input[name=start_time]').val());
115 var end_time
= $.trim($('input[name=end_time]').val());
116 var duration
= $.trim($('input[name=duration]').val());
117 var fixed
= $('#fixed').attr('checked');
118 var days
= $('.recurring_day');
119 var months
= $('.recurring_month');
121 if (comment
== '' || start_time
== '' || end_time
== '' || (!fixed
&& duration
== '')) {
122 // required fields are empty
123 // _form_err_empty_fields
124 err_str
+= '<li>' + _form_err_empty_fields
+ '</li>';
126 // check for special input
129 if (!check_timestring(start_time
)) {
130 err_str
+= '<li>' + sprintf(_form_err_bad_timeformat
, _form_field_start_time
) + '</li>';
134 if (!check_timestring(end_time
)) {
135 err_str
+= '<li>' + sprintf(_form_err_bad_timeformat
, _form_field_end_time
) + '</li>';
139 if (!fixed
&& !check_timestring(duration
)) {
140 err_str
+= '<li>' + sprintf(_form_err_bad_timeformat
, _form_field_duration
) + '</li>';
143 days
= days
.filter(function() {
144 return $(this).prop('checked');
146 if (days
.length
=== 0) {
147 err_str
+= '<li>You must check at least one day of the week</li>';
149 months
= months
.filter(function() {
150 return $(this).prop('checked');
152 if (months
.length
=== 0) {
153 err_str
+= '<li>You must check at least one month</li>';
157 $('#response').attr("style", "");
158 $('#response').html("<ul class=\"error\">" + err_str
+ "</ul>");
159 window
.scrollTo(0,0); // make sure user sees the error message
164 * Everything validated ok.
165 * Check if schedule matches today and if so ask the user if a downtime
166 * should be inserted today.
168 var day_values
= Array();
169 var month_values
= Array();
170 days
.each(function() {
171 day_values
.push($(this).val());
173 months
.each(function() {
174 month_values
.push($(this).val());
182 if ($.inArray(d
.getDay().toString(), day_values
) !== -1 && $.inArray((d
.getMonth() +1).toString(), month_values
) !== -1) {
183 if (confirm("The schedule you are creating matches today, would you like to schedule a downtime for today?\nClick 'Cancel' to save your recurring schedule without scheduling a downtime for today or 'Ok' to save recurring schedule and schedule downtimes today.")) {
184 // Downtime type string
185 var object_type
= $('#downtime_type option:selected').val();
186 // Array of selected objects
187 var objects
= $('#objects').val();
189 url
: _site_domain
+ _index_page
+ '/recurring_downtime/insert_downtimes',
194 object_type
: object_type
,
195 start_time
: start_time
,
201 success: function(result
) {
204 error: function(result
) {
205 $.notify(result
.responseText
, {'sticky':true, 'type':'critical'});
214 * Receive params as JSON object
215 * Parse fields and populate corresponding fields in form
218 function expand_and_populate(reportObj
)
220 var field_str
= reportObj
.downtime_type
;
221 get_members(field_str
, function(all_names
) {
222 var mo
= new missing_objects();
223 var from = $('#objects_tmp');
224 var to
= $('#objects');
225 populate_options(from, to
, all_names
);
226 // select report objects
227 for (prop
in reportObj
.objects
) {
228 if (!from.containsOption(reportObj
.objects
[prop
])) {
229 mo
.add(reportObj
.objects
[prop
])
231 from.selectOptions(reportObj
.objects
[prop
]);
235 // move selected options from left -> right
236 moveAndSort(from, to
);