1 function remove_scheduled_str(in_str)
3 in_str = in_str.replace(/\*/g, '');
4 in_str = in_str.replace(" ( " + _scheduled_label + " )", '');
8 function create_filename()
10 if (!$('#saved_report_id option:selected').val()) {
11 $('input[name=filename]').val('');
14 var new_filename = $('#saved_report_id option:selected').text();
15 new_filename = remove_scheduled_str(new_filename);
16 new_filename += '_' + $('#period option:selected').text() + '.pdf';
17 new_filename = new_filename.replace(/ /g, '_');
18 $('input[name=filename]').val(new_filename);
22 function fill_saved_reports() {
23 var report_type = this.value;
25 _site_domain + _index_page + "/schedule/list_by_type/"+report_type,
27 error: function(xhr) {
28 alert(xhr.responseText);
30 success: function(response) {
31 var saved_reports = document.getElementById("saved_report_id");
32 var default_opt = saved_reports.children[0];
33 saved_reports.length = 1;
34 var options = document.createDocumentFragment();
35 for(var i = 0; i < response.length; i++) {
36 var option = document.createElement("option");
37 var result = response[i];
38 option.appendChild(document.createTextNode(result.report_name));
39 option.setAttribute("value", result.id);
40 options.appendChild(option);
42 saved_reports.appendChild(options);
50 $(document).ready(function() {
51 $("#saved_report_id, #period").change(create_filename);
55 // delete single schedule
56 $('body').on('click', '.delete_schedule', schedule_delete);
57 $('body').on('click', '.send_report_now', send_report_now);
59 $("#type").change(fill_saved_reports).each(fill_saved_reports);
61 $('#new_schedule_report_form').submit(function(ev) {
64 var rep_type_str = $('#type option:selected').val();
66 var recipients = $.trim($('#recipients').fieldValue()[0]);
67 if (recipients.indexOf('@') === -1) {
68 alert(_reports_invalid_email);
72 if(!validate_form()) {
75 show_progress('progress', _wait_str);
77 url: _site_domain + _index_page + '/schedule/schedule',
81 type: $('#type').fieldValue()[0],
82 saved_report_id: $('#saved_report_id').fieldValue()[0],
83 period: $('#period').fieldValue()[0],
84 recipients: recipients,
85 filename: $('#filename').fieldValue()[0],
86 description: $('#description').fieldValue()[0],
87 attach_description: $('#attach_description').fieldValue()[0],
88 local_persistent_filepath: $.trim($('#local_persistent_filepath').val())
90 complete: function() {
91 $('#progress').hide();
92 // make sure we hide message about no schedules and show table headers
93 $('#' + rep_type_str + '_no_result').hide();
94 $('#' + rep_type_str + '_headers').show();
96 error: function(data) {
97 jgrowl_message(data.responseText, _reports_error);
99 success: function(data) {
100 var rep_type = $('#type').attr('value');
101 var saved_report_id = $('#saved_report_id').attr('value');
102 var report_name = $('#saved_report_id option:selected').text();
103 var period_str = $('#period option:selected').text();
104 var recipients = $('#recipients').attr('value');
105 var filename = $('#filename').attr('value');
106 var local_persistent_filepath = $('#local_persistent_filepath').attr('value');
107 var description = $('#description').attr('value');
108 var attach_description = $('#attach_description').attr('value');
109 create_new_schedule_rows(data.id, rep_type, report_name, saved_report_id, period_str, recipients, filename, local_persistent_filepath, description, attach_description)
111 $('#new_schedule_report_form').clearForm();
113 jgrowl_message(_reports_schedule_create_ok, _reports_success);
120 function schedule_delete(ev)
123 if (!confirm(_reports_confirm_delete_schedule)) {
128 var type = elem.data('type');
129 var schedule_id = elem.data('schedule');
130 var report_id = elem.data('report_id');
132 var img = $('img', elem);
133 var img_src = img.attr('src');
134 img.attr('src', loadimg_sml.src);
137 url:_site_domain + _index_page + '/schedule/delete_schedule',
138 data: {'id': schedule_id},
139 complete: function() {
140 img.attr('src', img_src);
142 success: function(data) {
143 jgrowl_message(data, _reports_success);
144 var table = $('#'+type+'_scheduled_reports_table tbody');
145 $('tr#report-'+schedule_id, table).detach();
146 if (!$(':visible', table).length)
147 $('.no-result', table).show();
149 error: function(data) {
150 jgrowl_message(data, _reports_error);
157 function send_report_now(ev)
161 var type = elem.data('type');
162 var sched_id = elem.data('schedule');
163 var report_id = elem.data('report_id');
164 var img = $('img', elem);
165 var img_src = img.attr('src');
166 img.attr('src', loadimg_sml.src);
169 url: _site_domain + _index_page + '/schedule/send_now/' + sched_id,
171 complete: function() {
172 img.attr('src', img_src);
174 success: function(data) {
175 jgrowl_message(data, _reports_success);
177 error: function(data) {
178 if(data.responseText) {
179 jgrowl_message(_reports_schedule_send_error + ': ' + data.responseText, _reports_error);
181 jgrowl_message(_reports_schedule_send_error, _reports_error);
183 img.attr('src', img_src);
189 function setup_editable()
191 var save_url = _site_domain + _index_page + "/schedule/save_schedule_item/";
192 $(".iseditable").editable(save_url, {
200 cancel : _cancel_str,
201 placeholder:_reports_edit_information
203 $(".period_select").editable(save_url, {
204 data : function(value) {
206 $('#period option').map(function() {
207 intervals.push("'"+$(this).val()+"': '"+$(this).text()+"' ");
209 intervals = "{"+intervals.join(",")+"}";
219 $(".iseditable_txtarea").editable(save_url, {
220 indicator : "<img src='" + _site_domain + "application/media/images/loading.gif'>",
227 cancel : _cancel_str,
229 placeholder:_reports_edit_information
231 $(".report_name").editable(save_url, {
233 switch (_report_types_json[this.id.split('-')[0].split('.')[0]]) {
235 return _saved_avail_reports;
237 return _saved_sla_reports;
239 return _saved_summary_reports;
250 $(".attach_description").editable(save_url, {
251 data : {0: "No", 1: "Yes"},
261 function create_new_schedule_rows(schedule_id, rep_type, report_name, report_id, report_period, recipients, filename, local_persistent_filepath, description, attach_description)
263 var template_row = $('#schedule_template tr');
265 var report_type_id = -1;
266 for (var i in _report_types_json) {
267 if (_report_types_json[i] == rep_type) {
272 template_row = template_row.clone()
273 $('#' + rep_type + '_scheduled_reports_table .no-result').hide();
274 template_row.attr('id', 'report-'+schedule_id);
275 $('.report_name', template_row)
276 .attr('id', '' + report_type_id + '.report_id-'+schedule_id)
277 .text(report_name.replace(/ \( \*Scheduled\* \)$/, ""));
278 $('.description', template_row)
279 .attr('id', 'description-'+schedule_id)
281 $('.period_select', template_row)
282 .attr('id', 'period_id-'+schedule_id)
283 .text(report_period);
284 $('.recipients', template_row)
285 .attr('id', 'recipients-'+schedule_id)
287 $('.filename', template_row)
288 .attr('id', 'filename-'+schedule_id)
290 $('.local-path', template_row)
291 .attr('id', 'local_persistent_filepath-'+schedule_id)
292 .text(local_persistent_filepath);
293 $('.attach_description', template_row)
294 .attr('id', 'attach_description-'+schedule_id)
295 .text(parseInt(attach_description) ? 'Yes' : 'No');
296 var actions = $('.action', template_row);
297 $('.direct_link', actions).attr('href', _site_domain + _index_page + '/' + rep_type + '/generate?report_id=' + report_id);
298 $('.send_report_now, .delete_schedule', actions).data('schedule', schedule_id).data('report_id', report_id).data('type', rep_type);
299 var par = $('#' + rep_type + '_scheduled_reports_table tbody');
300 if (par.children().last().hasClass('odd'))
301 template_row.attr('class', 'even');
303 template_row.attr('class', 'odd');
304 par.append(template_row);
307 function fill_scheduled() {
308 for (var type in _scheduled_reports) {
309 if (!_scheduled_reports[type].length) {
310 $('#' + type + '_scheduled_reports_table .no-result').show();
313 for (var i = 0; i < _scheduled_reports[type].length; i++) {
314 var report = _scheduled_reports[type][i];
315 create_new_schedule_rows(report.id, type, report.reportname, report.report_id, report.periodname, report.recipients, report.filename, report.local_persistent_filepath, report.description, report.attach_description);
321 * Make sure all values are properly entered
323 function validate_form(formData, jqForm, options) {
324 var interval = $('#period').val();
325 var recipients = $('input[name=recipients]').attr('value');
326 var filename = $('input[name=filename]').attr('value');
327 var description = $('input[name=description]').attr('value');
328 var saved_report_id = $('input[name=saved_report_id]').attr('value');
329 if (!saved_report_id) {
330 saved_report_id = $('#saved_report_id').attr('value');
332 var report_id = $('input[name=report_id]').attr('value');
333 if (report_id == '' || report_id == undefined) {
334 report_id = $('#report_id').val();
336 var fatal_err_str = _reports_fatal_err_str;// + "<br />";
337 $('.schedule_error').hide();
341 if (interval == '' || !interval) {
342 err_str += _reports_schedule_interval_error + "<br />";
346 recipients = recipients.replace(/;/g, ',');
347 // @@@FIXME: split multiple addresses on ',' and check each one using regexp
348 if ($.trim(recipients) == '') {
349 err_str += _reports_schedule_recipient_error + "<br />";
352 if (!saved_report_id) {
353 alert(fatal_err_str);
359 $('#response').attr("style", "");
360 $('#response').html("<ul class=\"error\">" + err_str + "</ul>").show();
362 var str = _reports_errors_found + ':<br />' + err_str + '<br />' + _reports_please_correct + '<br />';
363 $("#new_schedule_area").prepend("<div id=\"response\" class=\"schedule_err_display\"><ul class=\"error\">" + str + "</ul></div>");
364 window.scrollTo(0,0); // make sure user sees the error message
367 $('.schedule_err_display').remove();