Copy/Paste Appointments using keyboard shortcut

Thread is closed for posting
7 posts, 0 answers
  1. D0649704-77A0-4AE3-9DAD-19D64BE2261B
    D0649704-77A0-4AE3-9DAD-19D64BE2261B avatar
    107 posts
    Member since:
    Oct 2010

    Posted 18 Oct 2010 Link to this post

    Requirements

    RadControls version 2010.2.929.40

    .NET version 4.0

    Visual Studio version 2010 Professional

    programming language C#

    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    This will allow you to copy and paste appointments using keyboard shortcuts (ctrl+c & ctrl+v).

    Make sure the body tag has onKeyDown() event.
    <body onkeydown="onKeyDown()">

    Client side code for control+c & control+v
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                var selectedApt;
                var activeTimeslot;
                var copiedApt;
     
    function OnClientAppointmentClick(sender, eventArgs) {
                    if (eventArgs.get_appointment()) {
                        selectedApt = eventArgs.get_appointment();
                    }
                }
     
                function OnClientTimeSlotClick(sender, eventArgs) {
                    if (eventArgs.get_targetSlot()) {
                        activeTimeslot = eventArgs.get_targetSlot();
                    }
                }
     
                function onKeyDown() {
                    // current pressed key
                    var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
     
                    if (event.ctrlKey && pressedKey == "c")
                    {
                        copiedApt = selectedApt;
                    }
     
                    if ((event.ctrlKey && pressedKey == "v") && copiedApt && activeTimeslot) {
                        var newAppointment = new Telerik.Web.UI.SchedulerAppointment();
                        var startTime = activeTimeslot.get_startTime();
                        var endTime = new Date(activeTimeslot.get_startTime());
                        endTime.setTime(endTime.getTime() + copiedApt.get_duration());
                         
     
                        newAppointment.set_start(startTime);
                        newAppointment.set_end(endTime);
                        newAppointment.set_subject(copiedApt.get_subject());
     
                        var scheduler = $find('<%= RadScheduler1.ClientID %>');
                        scheduler.insertAppointment(newAppointment);
     
                        activeTimeslot = null;
                    }
                }
            </script>
        </telerik:RadScriptBlock>


    RadScheduler event bindings
    <telerik:RadScheduler ID="RadScheduler1" runat="server" DataEndField="End" OnClientAppointmentClick="OnClientAppointmentClick" OnClientTimeSlotClick="OnClientTimeSlotClick">

    Daryl
    Software Developer
  2. EFA61FDF-541F-4269-A041-741D8C3E3C43
    EFA61FDF-541F-4269-A041-741D8C3E3C43 avatar
    2 posts
    Member since:
    Sep 2011

    Posted 10 Jul 2012 Link to this post

    Hi all, this works awesome for IE, not for Firefox, anyone with issues on this or recommendations?

  3. D0649704-77A0-4AE3-9DAD-19D64BE2261B
    D0649704-77A0-4AE3-9DAD-19D64BE2261B avatar
    107 posts
    Member since:
    Oct 2010

    Posted 10 Jul 2012 Link to this post

    Hi Terry,

    Could you try to debug javascript using firebug or a similar extension?

    Let me know what error you encounter as this should work on all browsers.

    Thanks,
    Daryl
  4. DF6E1D93-6A62-4A20-816D-F8422B638951
    DF6E1D93-6A62-4A20-816D-F8422B638951 avatar
    14 posts
    Member since:
    Dec 2010

    Posted 09 May 2013 Link to this post

    Hi,
    thanks for the code, it works very well.
    Only one question, I've some custom field in my AdvancedEditorForm that obviously are not replicated during paste.

    For example:

    var subjectcopied = copiedApt.get_subject();
    newAppointment.set_subject = subjectcopied;
     
    var mycustomfieldcopied = copiedApt.???
    newAppointment.??? = mycustomfieldcopied;

    Thanks a lot
  5. D0649704-77A0-4AE3-9DAD-19D64BE2261B
    D0649704-77A0-4AE3-9DAD-19D64BE2261B avatar
    107 posts
    Member since:
    Oct 2010

    Posted 10 May 2013 Link to this post

    Hi  Keiichi-kun,

    I had the same issue and managed to sort it out using hidden fields, not sure  if it's the ideal solution but it got me to where I wanted to get. Hopefully I don't miss any details as it's been quite a while since I created this.

    First and foremost, i created a hidden field:

    <asp:HiddenField ID="docketNoHidden" runat="server" />

    Then I added Custom attribtues to the scheduler, like so:

    CustomAttributeNames="Task, FileCode, DocketNo" AdvancedForm-EnableCustomAttributeEditing="true"

    When pasting, I populate the hidden field:

    if (copiedApt && copiedApt.get_attributes().getAttribute("DocketNo")) {
     document.getElementById('<%= docketNoHidden.ClientID %>').value = copiedApt.get_attributes().getAttribute("DocketNo");
    }

    Finally, in code behind, in the FormCreated event, I'm doing the following:

    if ((e.Container.Mode == SchedulerFormMode.Insert) && (e.Container.Mode != SchedulerFormMode.AdvancedInsert))
    {
        // Setting docket no in case of copy/paste
        RadTextBox docketNo = e.Container.FindControl("DocketNo") as RadTextBox;
        if (docketNo != null)
        {
            docketNo.Text = docketNoHidden.Value;
        }
    }

    If you're using custom editors, you'd need to do something like this:
    if (e.Container.Mode == SchedulerFormMode.AdvancedInsert)
    {
                    RadTextBox docketNo = e.Container.FindControl("AttrDocketNo") as RadTextBox;
                    if (docketNo != null)
                    {
                        docketNo.Text = docketNoHidden.Value;
                    }
     
    }

    Hope this helps, if you need more help let me know.

    Thanks,
    Daryl
  6. DF6E1D93-6A62-4A20-816D-F8422B638951
    DF6E1D93-6A62-4A20-816D-F8422B638951 avatar
    14 posts
    Member since:
    Dec 2010

    Posted 13 May 2013 Link to this post

    Hi,
    thanks for your reply.

    Following your suggestion, I've done the copy&paste in this way

    <asp:hiddenfield ID="CustomFilm1Hidden" runat="server"></asp:hiddenfield>

    Paste event with JQuery

    var f1 = copiedApt.get_attributes().getAttribute("Film 1");
    //alert(f1);
    $("#CustomFilm1Hidden").val(f1);   

    I've had some problems using the FormCreated event so I've used the AppointmentInsert event of the RadScheduler

    if (CustomFilm1Hidden.Value != "")
            {
                e.Appointment.Attributes["Film 1"] = CustomFilm1Hidden.Value.ToString().Trim();
                CustomFilm1Hidden.Value = "";
            }

    I need to reset the value of the hidden field, in other case the value of the hiddenfield will be set on every AppointmentInsert event.
    The code seems to work..

    Thanks again

    K.
  7. DF6E1D93-6A62-4A20-816D-F8422B638951
    DF6E1D93-6A62-4A20-816D-F8422B638951 avatar
    14 posts
    Member since:
    Dec 2010

    Posted 13 May 2013 Link to this post


    Another tip if anyone is doing this.
    If you have a DropDownList connected to an Appointment Resource you could copy this value using a code like this

    Javascript side:
    try
                    {
                        $("#CustomSalaHidden").val(copiedApt.get_resources().getResourceByType("Sala").get_key().valueOf().toString());
                    }
                    catch (err)
                    {
                    }


    CodeBehind:

    if (CustomSalaHidden.Value.ToString().Trim() != "")
           {
               Resource r = new Resource("Sala", CustomSalaHidden.Value, "");
               e.Appointment.Resources.Add(r);
               CustomSalaHidden.Value = "";
           }

    Using as usual the hiddenfield
    Bye

    K.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.