Skip to content

Commit 7c20a8a

Browse files
author
Ron Lucke
committed
FolderBlock: fix upload issues
1 parent 1e89c7f commit 7c20a8a

4 files changed

Lines changed: 98 additions & 30 deletions

File tree

blocks/FolderBlock/FolderBlock.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,44 @@ public function save_handler(array $data)
193193
return;
194194
}
195195

196+
public function reload_handler()
197+
{
198+
$user = $this->container['current_user'];
199+
$files = array();
200+
$folder_content = json_decode($this->folder_content);
201+
$folder = \Folder::find($folder_content->folder_id);
202+
203+
if ($folder){
204+
$typed_folder = $folder->getTypedFolder();
205+
$folder_type = $typed_folder->folder_type;
206+
if($typed_folder->isVisible($user->id)) {
207+
$folder_name = $folder->name;
208+
209+
if($typed_folder->isReadable($user->id)) {
210+
$files = $this->showFiles($folder_content->folder_id);
211+
$homework_files = false;
212+
} else {
213+
if($folder_type === 'HomeworkFolder') {
214+
foreach ($typed_folder->getFiles() as $file) {
215+
if($file->user_id == $user->id) {
216+
$homework_files['details'][] = array('name' => $file->name,
217+
'date' => strftime('%x %X', $file->chdate));
218+
}
219+
}
220+
}
221+
$files = array();
222+
}
223+
$allow_upload = ($folder_content->allow_upload && $typed_folder->isWritable($user->id));
224+
}
225+
226+
}
227+
228+
return array(
229+
'files' => $files,
230+
'homework_files' => $homework_files
231+
);
232+
}
233+
196234
private function showFiles($folder_id)
197235
{
198236
$folder = \Folder::find($folder_id);

blocks/FolderBlock/css/folder_block.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ section#courseware .block-content:not([data-view="student"]){
268268
}
269269
}
270270

271+
.documents.dummy-table {
272+
display: none;
273+
}
274+
271275
/* AssortBlock special */
272276

273277
.assortblock-content div {

blocks/FolderBlock/js/student_view.js

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import templates from 'js/templates'
66
export 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(/id="fileref_(.*)\"/)[1],
185-
'name': entry.match(/<td data-sort-value=\"(.*)\">/)[1],
186-
'icon': entry.match(/alt=\"file-(.*?)\"/)[1],
187-
'url': entry.match(/<a href=\"(.*?)\"/)[1].replace(/&amp;/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(/&amp;/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();

blocks/FolderBlock/templates/student_view.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
<input type="hidden" name="folder_title" value="{{folder_title}}" />
8888
<input type="hidden" name="allow_upload" value="{{allow_upload}}" />
8989
<input type="hidden" name="file_counter" value="{{{file_counter}}}" />
90+
91+
<table class="documents dummy-table">
92+
</table>
9093
{{/viewable}}
9194
{{^viewable}}
9295
{{#no_folder}}

0 commit comments

Comments
 (0)