text: define(['marionette',
      'models/visit',
      'collections/visits',
      
      'modules/assign/views/selectvisit',
      'modules/assign/views/assign',
      ], function(Marionette, Visit, Visits, SelectVisitView, AssignView) {
      
      var bc = { title: 'Assign Containers', url: '/assign' }
      
      var controller = {
          
          // Select visit to assign
          selectVisit: function(visit) {
              app.loading()
              var visits = new Visits(null, { queryParams: { next: 1 } })
              visits.fetch({
                  success: function() {
                      app.bc.reset([bc]),
                      app.content.show(new SelectVisitView({ collection: visits }))
                  },
                  error: function() {
                      app.bc.reset([bc, { title: 'Error' }])
                      app.message({ title: 'Couldnt load visit list', message: 'Couldnt load visit list please try again' })
                  }
              })
          },
              
              
          // Assign containers to visit
          assignVisit: function(vis, page) {
              app.loading()
              var visit = new Visit({ VISIT: vis })
              
              visit.fetch({
                  success: function() {
                      app.bc.reset([bc,
                          {title: vis, url: '/dc/visit/'+vis }]),
                      page = page ? parseInt(page) : 1
                      app.content.show(new AssignView({ visit: visit, page: page }))
                  },
                  error: function() {
                      app.bc.reset([bc, { title: 'Error' }])
                      app.message({ title: 'No such visit', message: 'The specified visit doesnt exist' })
                  }
              })
          }
      }
         
      app.addInitializer(function() {
          app.on('assign:visit', function(visit) {
              app.navigate('assign/visit/'+visit)
              controller.assign(visit)
          })
      })
         
      return controller
  })