@@ -6,7 +6,7 @@ import templates from 'js/templates'
66export default StudentView . extend ( {
77 events : {
88 'click button[name=upload]' : 'fileUpload' ,
9- 'click button[name=Speichern ]' : 'saveLicenses' ,
9+ 'click button.button[type=submit ]' : 'saveLicenses' ,
1010 'click a.cancel.button' : 'cancelLicenses' ,
1111 'click button[name=unzip]' : 'unzipFile' ,
1212 'click button[name=dontunzip]' : 'dontunzipFile' ,
@@ -29,6 +29,11 @@ export default StudentView.extend({
2929 this . $ ( '.cw-folder-title' ) . hide ( ) ;
3030 this . $ ( '.cw-folder' ) . hide ( ) ;
3131 }
32+ let dummy = this . $ ( '.documents.dummy-table' ) . get ( 0 ) ;
33+ if ( dummy ) {
34+ dummy . config = { } ;
35+ dummy . config . sortList = { } ;
36+ }
3237 } ,
3338
3439 fileUpload ( ) {
@@ -37,7 +42,7 @@ export default StudentView.extend({
3742 folder_id = this . $ ( 'input[name="folder_id"]' ) . val ( ) ,
3843 data = new FormData ( ) ,
3944 view = this ;
40-
45+
4146 $ . each ( filelist , function ( index , file ) {
4247 if ( STUDIP . Files . validateUpload ( file ) ) {
4348 data . append ( 'file[]' , file , file . name ) ;
@@ -46,7 +51,7 @@ export default StudentView.extend({
4651 alert ( file . name + 'ist zu groß oder hat eine nicht erlaubte Endung.' )
4752 }
4853 } ) ;
49-
54+
5055 if ( files > 0 ) {
5156 this . setupModel ( ) ;
5257 $ . get ( STUDIP . URLHelper . getURL ( 'dispatch.php/file/upload_window' ) , function ( data ) {
@@ -77,19 +82,22 @@ export default StudentView.extend({
7782 }
7883 } ) . done ( function ( json ) {
7984 view . $ ( '.file_upload_window .uploadbar' ) . css ( 'background-size' , '100% 100%' ) ;
80-
8185 if ( json . redirect ) {
8286 $ . get ( json . redirect , function ( data ) {
8387 view . $el . find ( '.cw-folder' ) . html ( data ) ;
8488 } )
85- } else {
86- view . $ ( '.errorbox' ) . show ( ) . html ( json . message )
87- view . $ ( '.file_upload_window .uploadbar' ) . hide ( )
89+ }
90+ if ( json . message ) {
91+ view . $ ( '.errorbox' ) . show ( ) . html ( json . message ) ;
92+ view . $ ( '.file_upload_window .uploadbar' ) . hide ( ) ;
93+ }
94+ if ( json . added_files ) {
95+ view . reloadFiles ( ) ;
8896 }
8997 } ) ;
9098 }
9199 } ,
92-
100+
93101 unzipFile ( event ) {
94102 event . preventDefault ( ) ;
95103 this . unzipEvent ( true ) ;
@@ -133,6 +141,20 @@ export default StudentView.extend({
133141 return files ;
134142 } ,
135143
144+ reloadFiles ( ) {
145+ let view = this ;
146+ helper
147+ . callHandler ( this . model . id , 'reload' , { } )
148+ . then ( function ( response ) {
149+ view . model . set ( 'files' , response . files ) ;
150+ view . model . set ( 'homework_files' , response . homework_files ) ;
151+ view . $el . html ( templates ( 'FolderBlock' , 'student_view' , { ...view . model . attributes } ) ) ;
152+ view . postRender ( ) ;
153+ } ) . catch ( function ( error ) {
154+ console . log ( error ) ;
155+ } ) ;
156+ } ,
157+
136158 unzipEvent ( unzip ) {
137159 var data = new FormData ( ) ,
138160 form = this . $ ( 'form' ) [ 0 ] ,
@@ -162,7 +184,7 @@ export default StudentView.extend({
162184 $ ( 'form input[name="file_refs[]"]' ) . each ( function ( ) {
163185 data . append ( 'file_refs[]' , this . value )
164186 } )
165-
187+
166188 data . append ( 'content_terms_of_use_id' , set_license ? this . $ ( 'input[name="content_terms_of_use_id"]:checked' ) . val ( ) : 'UNDEF_LICENSE' )
167189 $ . ajax ( {
168190 type : 'POST' ,
@@ -172,30 +194,31 @@ export default StudentView.extend({
172194 contentType : false ,
173195 processData : false
174196 } ) . done ( function ( data ) {
175- view . updateView ( data [ 'html' ] ) ;
197+ view . reloadFiles ( ) ;
198+ //view.updateView(data['html']);
176199 } ) ;
177200 } ,
178201
179- updateView ( data ) {
180- var view = this ,
181- files = [ ] ;
182- data . forEach ( function ( entry ) {
183- var file = {
184- 'id' : entry . match ( / i d = " f i l e r e f _ ( .* ) \" / ) [ 1 ] ,
185- 'name' : entry . match ( / < t d d a t a - s o r t - v a l u e = \" ( .* ) \" > / ) [ 1 ] ,
186- 'icon' : entry . match ( / a l t = \" f i l e - ( .* ?) \" / ) [ 1 ] ,
187- 'url' : entry . match ( / < a h r e f = \" ( .* ?) \" / ) [ 1 ] . replace ( / & a m p ; / g, '&' ) . replace ( 'sendfile.php?' , 'sendfile.php?force_download=1&' ) ,
188- 'downloadable' : '1'
189- } ;
190- files . push ( file ) ;
191- } ) ;
192- files = this . model . get ( 'files' ) . concat ( files ) ;
193- files . sort ( function ( a , b ) {
194- return a [ 'name' ] . localeCompare ( b [ 'name' ] )
195- } )
196- this . model . set ( 'files' , files ) ;
197- this . $el . html ( templates ( 'FolderBlock' , 'student_view' , { ...this . model . attributes } ) ) ;
198- } ,
202+ // updateView(data) {
203+ // var view = this,
204+ // files = [];
205+ // data.forEach(function (entry) {
206+ // var file = {
207+ // 'id': entry.match(/id="fileref_(.*)\"/)[1],
208+ // 'name': entry.match(/<td data-sort-value=\"(.*)\">/)[1],
209+ // 'icon': entry.match(/alt=\"file-(.*?)\"/)[1],
210+ // 'url': entry.match(/<a href=\"(.*?)\"/)[1].replace(/&/g,'&').replace('sendfile.php?', 'sendfile.php?force_download=1&'),
211+ // 'downloadable': '1'
212+ // };
213+ // files.push(file);
214+ // });
215+ // files = this.model.get('files').concat(files);
216+ // files.sort(function (a,b) {
217+ // return a['name'].localeCompare(b['name'])
218+ // })
219+ // this.model.set('files', files);
220+ // this.$el.html(templates('FolderBlock', 'student_view', { ...this.model.attributes }));
221+ // },
199222
200223 triggerFileSelector ( ) {
201224 this . $ ( '.cw-folder-file-upload' ) . click ( ) ;
0 commit comments