Skip to content

Commit 1a74b0a

Browse files
committedApr 7, 2017
Check if xslt is present or not, before checking the other file upload in the edit front-end logic
1 parent 8bebab9 commit 1a74b0a

File tree

4 files changed

+46
-40
lines changed

4 files changed

+46
-40
lines changed
 

‎app/Tdt/Core/Definitions/DefinitionController.php

+2
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ public function patch($uri)
496496
$input['username'] = $definition['username'];
497497
$input['xslt_file'] = $definition['xslt_file'];
498498

499+
\Log::info($input['xslt_file']);
500+
499501
// Keep associated job
500502
$input['job_id'] = $definition['job_id'];
501503

‎app/routes.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,27 @@
5252
'/ /' => '_', // nonbreaking space (equiv. to 0x160)
5353
];
5454

55-
$file = strtolower(preg_replace(array_keys($utf8), array_values($utf8), Input::file('fileupload')->getClientOriginalName()));
56-
57-
$file_xslt_upload=Input::file('fileupload_xslt');
55+
$file_xslt_upload = Input::file('fileupload_xslt');
5856

5957
if(isset($file_xslt_upload)) {
6058
$file_xslt = strtolower(preg_replace(array_keys($utf8), array_values($utf8), Input::file('fileupload_xslt')->getClientOriginalName()));
6159
}
60+
6261
if(isset($file_xslt)){
6362
Input::file('fileupload_xslt')->move(
6463
app_path() . '/storage/app/',
65-
$file_xslt . '_' . date('Y-m-d'). '.' . Input::file('fileupload_xslt')->getClientOriginalExtension()
64+
$file_xslt . '_' . date('Y-m-d') . '.' . Input::file('fileupload_xslt')->getClientOriginalExtension()
6665
);
6766
}
6867

69-
return Input::file('fileupload')->move(
70-
app_path() . '/storage/app/',
71-
$file . '_' . time() . '.' . Input::file('fileupload')->getClientOriginalExtension()
72-
);
68+
if (! empty(Input::file('fileupload'))) {
69+
$file = strtolower(preg_replace(array_keys($utf8), array_values($utf8), Input::file('fileupload')->getClientOriginalName()));
70+
71+
return Input::file('fileupload')->move(
72+
app_path() . '/storage/app/',
73+
$file . '_' . time() . '.' . Input::file('fileupload')->getClientOriginalExtension()
74+
);
75+
}
7376
});
7477

7578
/* Autocomplete endpoint "Linking Datasets" */

‎dev/js/admin.js

+32-31
Original file line numberDiff line numberDiff line change
@@ -339,40 +339,13 @@ $('.btn-edit-dataset').on('click', function(e){
339339
});
340340

341341
// Check uri source (fileupload field)
342-
if( form.find("#fileupload").length == 0 || form.find("#fileupload")[0].files.length == 0 ){
343-
// Ajax call: no file selected
344-
$.ajax({
345-
url: baseURL + "api/definitions/" + identifier,
346-
data: JSON.stringify(data),
347-
method: "POST",
348-
headers: {
349-
'Accept' : 'application/json',
350-
'Authorization': authHeader
351-
},
352-
success: function(e){
353-
// Done, redirect to datets page
354-
window.location = baseURL + 'api/admin/datasets';
355-
},
356-
error: function(e){
357-
if(e.status != 405){
358-
var error = JSON.parse(e.responseText);
359-
if(error.error && error.error.message){
360-
$('.error .text').html(error.error.message);
361-
$('.error').removeClass('hide').show().focus();
362-
}
363-
}else{
364-
// Ajax followed location header -> ignore
365-
window.location = baseURL + 'api/admin/datasets';
366-
}
367-
}
368-
})
369-
} else if(form.find("#fileupload_xslt").length && (form.find("#fileupload_xslt").length != 0 || form.find("#fileupload_xslt")[0].files.length != 0) ){
342+
if(form.find("#fileupload_xslt").length && (form.find("#fileupload_xslt").length != 0 || form.find("#fileupload_xslt")[0].files.length != 0) ){
370343
// Upload dataset file
344+
console.log("upload");
371345
var file = form.find('input[type=file]')[0].files[0];
372346
var fd = new FormData();
373347
fd.append("fileupload", file);
374348

375-
376349
// Upload xslt file
377350
var fileupload_xslt = form.find('#fileupload_xslt')[0].files[0];
378351
fd.append("fileupload_xslt", fileupload_xslt);
@@ -417,13 +390,41 @@ $('.btn-edit-dataset').on('click', function(e){
417390
},
418391
timeout: 10000
419392
});
420-
}
393+
} else if(form.find("#fileupload").length == 0 || form.find("#fileupload")[0].files.length == 0 ){
394+
// Ajax call: no file selected
395+
console.log("no upload");
396+
$.ajax({
397+
url: baseURL + "api/definitions/" + identifier,
398+
data: JSON.stringify(data),
399+
method: "POST",
400+
headers: {
401+
'Accept' : 'application/json',
402+
'Authorization': authHeader
403+
},
404+
success: function(e){
405+
// Done, redirect to datets page
406+
window.location = baseURL + 'api/admin/datasets';
407+
},
408+
error: function(e){
409+
if(e.status != 405){
410+
var error = JSON.parse(e.responseText);
411+
if(error.error && error.error.message){
412+
$('.error .text').html(error.error.message);
413+
$('.error').removeClass('hide').show().focus();
414+
}
415+
}else{
416+
// Ajax followed location header -> ignore
417+
window.location = baseURL + 'api/admin/datasets';
418+
}
419+
}
420+
})
421+
}
421422
else {
422423
// Upload dataset file
423424
var file = form.find('input[type=file]')[0].files[0];
424425
var fd = new FormData();
425426
fd.append("fileupload", file);
426-
427+
console.log("upload the normal file");
427428
// Ajax call: upload file
428429
$.ajax({
429430
async: true,

‎public/js/admin.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.