/*
 * Copyright (C) 2013 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import $ from 'jquery'
import UserCollection from '@canvas/users/backbone/collections/UserCollection.coffee'
import progressionsIndexTemplate from './jst/ProgressionsIndex.handlebars'
import PaginatedCollectionView from '@canvas/pagination/backbone/views/PaginatedCollectionView.coffee'
import ProgressionStudentView from './backbone/views/ProgressionStudentView'

let students
$(document.body).addClass('context_modules2')

if (ENV.RESTRICTED_LIST) {
  students = new UserCollection(ENV.VISIBLE_STUDENTS)
  students.urls = null
} else {
  students = new UserCollection(null, {
    params: {
      per_page: 50,
      enrollment_type: 'student'
    }
  })
}

const indexView = new PaginatedCollectionView({
  collection: students,
  itemView: ProgressionStudentView,
  template: progressionsIndexTemplate,
  modules_url: ENV.MODULES_URL,
  autoFetch: true
})

if (!ENV.RESTRICTED_LIST) {
  // attach the view's scroll container once it's populated
  students.fetch({
    success() {
      if (students.length === 0) return
      indexView.resetScrollContainer(
        indexView.$el.find('#progression_students .collectionViewItems')
      )
    }
  })
}

indexView.render()
if (ENV.RESTRICTED_LIST && ENV.VISIBLE_STUDENTS.length === 1) {
  indexView.$el.find('#progression_students').hide()
}
indexView.$el.appendTo($('#content'))

@@ -716,16 +716,55 @@
 jquery'%0A
+import ready from '@instructure/ready'%0A
 import U
@@ -1097,16 +1097,32 @@
 tView'%0A%0A
+ready(() =%3E %7B%0A  
 let stud
@@ -1126,16 +1126,18 @@
 tudents%0A
+  
 $(docume
@@ -1175,16 +1175,18 @@
 les2')%0A%0A
+  
 if (ENV.
@@ -1204,16 +1204,18 @@
 LIST) %7B%0A
+  
   studen
@@ -1262,16 +1262,18 @@
 ENTS)%0A  
+ 
+ 
 students
@@ -1285,16 +1285,18 @@
  = null%0A
+  
 %7D else %7B
@@ -1296,16 +1296,18 @@
  else %7B%0A
+  
   studen
@@ -1342,16 +1342,18 @@
 , %7B%0A    
+ 
+ 
 params: 
@@ -1354,16 +1354,18 @@
 rams: %7B%0A
+  
       pe
@@ -1376,16 +1376,18 @@
 ge: 50,%0A
+  
       en
@@ -1415,26 +1415,34 @@
 nt'%0A    
-%7D%0A
+  %7D%0A  
   %7D)%0A
+  
 %7D%0A%0A
+  
 const in
@@ -1481,16 +1481,18 @@
 nView(%7B%0A
+  
   collec
@@ -1509,16 +1509,18 @@
 ents,%0A  
+ 
+ 
 itemView
@@ -1545,16 +1545,18 @@
 ntView,%0A
+  
   templa
@@ -1586,16 +1586,18 @@
 mplate,%0A
+  
   module
@@ -1622,16 +1622,18 @@
 _URL,%0A  
+ 
+ 
 autoFetc
@@ -1644,12 +1644,16 @@
 rue%0A
+  
 %7D)%0A%0A
+  
 if (
@@ -1676,16 +1676,18 @@
 LIST) %7B%0A
+  
   // att
@@ -1738,16 +1738,18 @@
 pulated%0A
+  
   studen
@@ -1759,16 +1759,18 @@
 fetch(%7B%0A
+  
     succ
@@ -1783,16 +1783,18 @@
 %7B%0A      
+  
 if (stud
@@ -1821,24 +1821,26 @@
 eturn%0A      
+  
 indexView.re
@@ -1859,32 +1859,34 @@
 tainer(%0A        
+ 
+ 
 indexView.$el.fi
@@ -1944,24 +1944,34 @@
     
+  
 )%0A    
+ 
+ 
 %7D%0A  
+ 
+ 
 %7D)%0A
+  
 %7D%0A%0A
+  
 inde
@@ -1985,16 +1985,18 @@
 ender()%0A
+  
 if (ENV.
@@ -2051,16 +2051,18 @@
 == 1) %7B%0A
+  
   indexV
@@ -2106,18 +2106,22 @@
 .hide()%0A
-%7D%0A
+  %7D%0A  
 indexVie
@@ -2150,8 +2150,11 @@
 tent'))%0A
+%7D)%0A

Wait for dom-ready in modules progressions