Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 829b905

Browse files
author
Charles Ma
committed
ENH: fixed bug #296 Added folder upload
Only works using chrome browser
1 parent 323d892 commit 829b905

File tree

4 files changed

+112
-6
lines changed

4 files changed

+112
-6
lines changed

core/controllers/UploadController.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/** Upload Controller */
1414
class UploadController extends AppController
1515
{
16-
public $_models = array('Assetstore', 'User', 'Item', 'ItemRevision', 'Folder', 'Itempolicyuser', 'Itempolicygroup', 'Group', 'Feed', "Feedpolicygroup", "Feedpolicyuser", 'Bitstream', 'Assetstore');
16+
public $_models = array('Folderpolicygroup', 'Folderpolicyuser', 'Assetstore', 'User', 'Item', 'ItemRevision', 'Folder', 'Itempolicyuser', 'Itempolicygroup', 'Group', 'Feed', "Feedpolicygroup", "Feedpolicyuser", 'Bitstream', 'Assetstore');
1717
public $_daos = array('Assetstore', 'User', 'Item', 'ItemRevision', 'Bitstream', 'Folder');
1818
public $_components = array('Httpupload', 'Upload');
1919
public $_forms = array('Upload');
@@ -242,6 +242,7 @@ public function saveuploadedAction()
242242

243243
$this->disableLayout();
244244
$this->disableView();
245+
$pathClient = $this->_getParam("path");
245246

246247
if($this->isTestingEnv())
247248
{
@@ -259,6 +260,19 @@ public function saveuploadedAction()
259260
$filename = $upload->getFilename(null, false);
260261
}
261262

263+
if(!empty($pathClient))
264+
{
265+
$tmpArray = split(';;', $pathClient);
266+
foreach($tmpArray as $value)
267+
{
268+
if(strpos($value, $filename) !== false)
269+
{
270+
$pathClient = $value;
271+
break;
272+
}
273+
}
274+
}
275+
262276
$parent = $this->_getParam("parent");
263277
$license = $this->_getParam("license");
264278
if(!empty($path) && file_exists($path) && $file_size > 0)
@@ -271,6 +285,40 @@ public function saveuploadedAction()
271285
}
272286
else
273287
{
288+
if(!empty($pathClient))
289+
{
290+
$parentDao = $this->Folder->load($parent);
291+
$this->getLogger()->info($pathClient);
292+
$folders = split('/', $pathClient);
293+
unset($folders[count($folders) - 1]);
294+
foreach($folders as $folderName)
295+
{
296+
if($this->Folder->getFolderExists($folderName, $parentDao))
297+
{
298+
$parentDao = $this->Folder->getFolderByName($parentDao, $folderName);
299+
}
300+
else
301+
{
302+
$new_folder = $this->Folder->createFolder($folderName, '', $parentDao);
303+
$policyGroup = $parentDao->getFolderpolicygroup();
304+
$policyUser = $parentDao->getFolderpolicyuser();
305+
foreach($policyGroup as $policy)
306+
{
307+
$group = $policy->getGroup();
308+
$policyValue = $policy->getPolicy();
309+
$this->Folderpolicygroup->createPolicy($group, $new_folder, $policyValue);
310+
}
311+
foreach($policyUser as $policy)
312+
{
313+
$user = $policy->getUser();
314+
$policyValue = $policy->getPolicy();
315+
$this->Folderpolicyuser->createPolicy($user, $new_folder, $policyValue);
316+
}
317+
$parentDao = $new_folder;
318+
}
319+
}
320+
$parent = $parentDao->getKey();
321+
}
274322
$item = $this->Component->Upload->createUploadedItem($this->userSession->Dao, $filename, $path, $parent, $license);
275323
$this->userSession->uploaded[] = $item->getKey();
276324
}

core/public/js/upload/upload.simpleupload.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,46 @@
1010
//uploadStart(file);
1111
}
1212

13+
// detect chrom or firefox 7+
14+
try {
15+
var is_chrome = /chrome/.test( navigator.userAgent.toLowerCase() );
16+
var version = jQuery.browser.version.split('.');
17+
version = parseInt(version[0]);
18+
var is_firefox = jQuery.browser.mozilla != undefined && version > 6;
19+
20+
if(is_chrome)
21+
{
22+
$('#changeUploadMode').show();
23+
}
24+
} catch (exception) { }
25+
26+
var mode = "file";
27+
var htmlFileMode = $('.file_upload_label').html();
28+
var htmlFolderMode = $('.file_upload_label_folder').html();
29+
$('#uploadModeFileLink').hide();
30+
$('.uploadModeLink').click(function(){
31+
if(mode == 'file')
32+
{
33+
mode = 'folder';
34+
$('#fileUploaderInput').attr('webkitdirectory', '');
35+
$('#fileUploaderInput').attr('directory', '');
36+
$('#fileUploaderInput').attr('mozdirectory', '');
37+
$('.file_upload_label').html(htmlFolderMode);
38+
$('#uploadModeFileLink').show();
39+
$('#uploadModeFolderLink').hide();
40+
}
41+
else
42+
{
43+
mode = 'file';
44+
$('#fileUploaderInput').removeAttr('webkitdirectory');
45+
$('#fileUploaderInput').removeAttr('directory');
46+
$('#fileUploaderInput').removeAttr('mozdirectory');
47+
$('.file_upload_label').html(htmlFileMode);
48+
$('#uploadModeFileLink').hide();
49+
$('#uploadModeFolderLink').show();
50+
}
51+
});
52+
1353

1454
$( "#uploadTabs" ).tabs({
1555
ajaxOptions: {
@@ -78,12 +118,23 @@
78118
$('#file_upload').fileUploadUIX({
79119
beforeSend: function (event, files, index, xhr, handler, callBack) {
80120
handler.uploadRow.find('.file_upload_start').click(function () {
121+
var path = '';
122+
$.each(files, function (index, file) {
123+
path += file.webkitRelativePath+';;';
124+
});
81125
handler.formData = {
82126
parent: $('#destinationId').val(),
127+
path: path,
83128
license: $('select[name=licenseSelect]').val()
84129
};
85130
callBack();
86131
});
132+
$('.file_name').each(function(){
133+
if($(this).html() == '.' || $(this).html() == '..' )
134+
{
135+
$(this).parent('tr').find('.file_upload_cancel button').click();
136+
}
137+
});
87138
},
88139
onComplete: function (event, files, index, xhr, handler) {
89140
$('.uploadedSimple').val(parseInt($('.uploadedSimple').val())+1);

core/translation/fr-main.csv

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,7 @@ Add Metadata;Ajouter M
255255
Name of the folder;Nom du r�pertoire
256256
Optional;Optionel
257257
Teaser;Courte descriptionMy Language;Ma Langue
258-
Delete the post;Supprimer la publication
258+
Delete the post;Supprimer la publication
259+
or;ou
260+
upload a folder;ajouter un r�pertoire
261+
upload files;ajouter des fichiers

core/views/upload/simpleupload.phtml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ PURPOSE. See the above copyright notices for more information.
2626
<div id="jqueryFileUploadContent">
2727
<div id="file_upload">
2828
<form action="<?php echo $this->webroot?>/upload/saveuploaded" method="POST" enctype="multipart/form-data">
29-
<input type="file" name="file[]" multiple>
29+
<input id="fileUploaderInput" type="file" name="file[]" multiple>
3030
<button type="submit">Upload</button>
3131
<div class="file_upload_label"><?php echo $this->t('Browse or drop files')?></div>
32+
<div class="file_upload_label_folder"><?php echo $this->t('Browse')?></div>
3233
</form>
34+
<div id="changeUploadMode" style="display:none;">
35+
<br/>
36+
<?php echo $this->t('or')?> <a style="color:blue; cursor:pointer;" class="uploadModeLink" id="uploadModeFolderLink"><?php echo $this->t('upload a folder')?></a>
37+
<a style="color:#56758B; cursor:pointer;" class="uploadModeLink" id="uploadModeFileLink"><?php echo $this->t('upload files')?></a>
38+
</div>
3339
<table class="files">
3440
<tr class="file_upload_template" style="display:none;">
3541
<td class="file_name"></td>
@@ -142,6 +148,4 @@ PURPOSE. See the above copyright notices for more information.
142148
<?php
143149
}
144150
?>
145-
<script type="text/javascript" src="<?php echo $this->coreWebroot?>/public/js/upload/upload.simpleupload.js"></script>
146-
147-
151+
<script type="text/javascript" src="<?php echo $this->coreWebroot?>/public/js/upload/upload.simpleupload.js"></script>

0 commit comments

Comments
 (0)