This is a migrated thread and some comments may be shown as answers.

How to print an appointment?

3 Answers 135 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Nick McConnell
Top achievements
Rank 1
Nick McConnell asked on 08 Dec 2008, 02:58 AM
Does anyone know how to programmtically print an appointment from the AdvacnedForm? In other words, I simply want to know how to print appointment details while editing/inserting. There has to be a better way than just printing from the browser...

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 09 Dec 2008, 03:02 PM
Hi David,

Currently, RadScheduler does not provide any special printing capabilities and the only way to print it is throught the browser. We will consider imlementing such functionality in the future.


Regards,
Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nick McConnell
Top achievements
Rank 1
answered on 15 Dec 2008, 01:00 AM
No worries, I created a solution that you may wish to consider.

Steps to create an appointment printing function (caveat: must be using AdvancedTemplates).

1. In both the ButtonsPanel in the custom controls AdvancedEditForm.ascx and 
    AdvancedInsertForm.ascx, add the following code just before the
    UpdateButton reference:

 

<a href="javascript:PrintAppointment();" id="PrintButton" class="rsAdvEditCancel"><span>Print</span></a>

 


2. Add the JavaScript function in the below scruot to the page containing the primary RadScheduler control:

   // print selected appointment
    function PrintAppointment() {

        // retrieve scheduler object and current appointment details
        var radscheduler = $find('<%= RadScheduler1.ClientID%>');
        var appt = radscheduler.get_currentAppointment();
        var subject = appt.get_subject();
        var attrib = appt.get_attributes();
        var description = attrib.getAttribute('Description');       // get optional attribute(s)

        if (!subject || subject == '')
            return;
        if (!description || description == '')
            return;

        // handle printing
        gAutoPrint = true;

        var html = '<html>\n<head>\n';

        html += '<title>Appointment</title>\n';
        html += '<style type=\'text/css\'>\n';
        html += 'body {\n';
        html += 'font-family: Arial, Helvetica, sans-serif;\n';
        html += 'font-size: 9pt;\n';
        html += '}\n';
        html += '</style>\n';

        html += '</head>\n<body bgcolor=\'#FFFFFF\'>\n';

        html += subject + '\n\n';
        html += description;

        html += '\n</body>\n</html>';

        html = html.replace(/\n/gi, '<br />');

        var printWin = window.open("", "printAppointment");
        printWin.document.open();
        printWin.document.write(html);
        printWin.document.close();
        if (gAutoPrint) {
            printWin.print();
            printWin.close();
        } else {
            alert("Sorry, appointment printing is not supported.");
        }
    }





Presto, you are done.

Couple of implementation notes:
1. The only real problem with the scripting method I came up with is that if a user edits the text box(es) that comprise the appointment, the printing function isn't aware and prints the contents of the fields that were loaded. Basically, we need to implement a method that indicates the text boxes are "dirty" and possibly warn the user to Save the appointment prior to printing.
2. In the above script function, make sure to customize as you see fit including adding or removing attributes/resources to the printed HTML

0
Peter
Telerik team
answered on 15 Dec 2008, 02:56 PM
Hi David,

Thank you for posting your workaround. I have forwarded it to our developers.

Sincerely yours,
Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Scheduler
Asked by
Nick McConnell
Top achievements
Rank 1
Answers by
Peter
Telerik team
Nick McConnell
Top achievements
Rank 1
Share this question
or