         @targetCalendar = @calendarCombo.value()
         if not @targetCalendar? or @targetCalendar is ''
             @targetCalendar = t('default calendar name')
-        @calendarCombo.save()
-
-        # Initialize counter.
-        @initCounter()
-
-        # Show loading spinner.
-        @confirmButton.html '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
-        @confirmButton.spin 'tiny'
-
-        # Save every imported events to the database.
-        async.eachSeries @eventLists, @importEvents, (err) =>
-
-            # When import is finished, the import form is reset and the
-            # calendar view is displayed.
-            alert t 'import finished'
-            @$(".confirmation").fadeOut()
-
-            @$(".results").slideUp =>
-                @$(".import-form").fadeIn()
-                @confirmButton.html t 'confirm import'
-
-                if $('.import-errors').html().length is 0
-                    app.router.navigate "calendar", true
+
+        calendar = new Calendar name: @targetCalendar
+        calendar.save calendar.attributes,
+        success: =>
+            app.calendars.add calendar
+
+            # Initialize counter.
+            @initCounter()
+
+            # Show loading spinner.
+            @confirmButton.html '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
+            @confirmButton.spin 'tiny'
+
+            # Save every imported events to the database.
+            async.eachSeries @eventLists, @importEvents, (err) =>
+
+                # When import is finished, the import form is reset and the
+                # calendar view is displayed.
+                alert t 'import finished'
+                @$(".confirmation").fadeOut()
+
+                @$(".results").slideUp =>
+                    @$(".import-form").fadeIn()
+                    @confirmButton.html t 'confirm import'
+
+                    if $('.import-errors').html().length is 0
+                        app.router.navigate "calendar", true
 
 
     # Create events by sending them all via a single request to the backend.

            else
                # When an element is successfully imported, it is added
                # to the current calendar view.
                #app.events.add event for event in result.events

                # Events which was not properly imported are listed.
                for event in result.errors

helpers = require '../helpers'
request = require '../lib/request'

Calendar = require '../models/calendar'
Event = require '../models/event'
EventList = require './import_event_list'

