         """
         input = $ template
         # Keeps a reference to the text element so we can re-append it later
-        rawTextElement = @$('.calendar-name').detach()
-        input.insertAfter @$('.badge')
+        @rawTextElement = @$('.calendar-name').detach()
 
         # hides the menu during edition
         @$('.dropdown-toggle').hide()

        'click .dropdown-toggle': 'hideColorPicker'
        'click .calendar-color': 'showColorPicker'
        'change .color-picker': 'setColor'



    getRenderData: ->
        label: @model.get 'name'

        # Gone after succefull color pick, put it back.
        @$('.dropdown-toggle').on 'click', @hideColorPicker

    #setting rename validation function to handle esc / return key, and blur event
    onRenameValidation: (event) ->

        input = $(event.target)
        calendarName = @model.get 'name'
        @startSpinner()

        # removes the binding to prevent memory leak
        key = event.keyCode or event.charCode
        if key is 27 # escape key
            input.remove()
            # re-appends text element
            @rawTextElement.insertAfter @$('.badge')
            # Restores the badge color
            @buildBadge calendarName
            # Shows the menu again
            @$('.dropdown-toggle').show()
            @stopSpinner()
        #blur and enter have the same effect
        else if (key is 13 or event.type is 'focusout')
            app.calendars.rename calendarName, input.val(), =>
                @stopSpinner()

    onRenameCalendar: ->
        calendarName = @model.get 'name'
