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

Commit 3ea0701

Browse files
committed
ENH: refs #446. Client side validation for upload quota on revision upload
1 parent 96500c0 commit 3ea0701

File tree

6 files changed

+113
-11
lines changed

6 files changed

+113
-11
lines changed

core/controllers/UploadController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public function revisionAction()
167167
$this->view->item = $item;
168168
$itemRevision = $this->Item->getLastRevision($item);
169169
$this->view->lastrevision = $itemRevision;
170+
$this->view->extraHtml = Zend_Registry::get('notifier')->callback(
171+
'CALLBACK_CORE_GET_REVISIONUPLOAD_EXTRA_HTML', array('item' => $item));
170172
}//end revisionAction
171173

172174

core/public/css/upload/upload.revision.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ width:94%!important;
1515

1616
}
1717

18+
div.uploadValidationError{
19+
display:none;
20+
}
21+
22+
div.uploadValidationError img{
23+
position: relative;
24+
top: 3px;
25+
}
26+
27+
div.tooBigUpload{
28+
display:none;
29+
}
30+
31+
div.tooBigUpload img{
32+
position: relative;
33+
top: 3px;
34+
}
35+
1836
/* -- Form Styles ------------------------------- */
1937
#swfuploadContent form {
2038
margin: 0;

core/public/js/upload/upload.revision.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ midas.upload.revision.initJqueryFileupload = function()
2525
//see http://aquantum-demo.appspot.com/file-upload
2626
$('.file_upload:visible').fileUploadUIX({
2727
beforeSend: function (event, files, index, xhr, handler, callBack) {
28+
if(index == 0) //only do this once since we have all the files every time
29+
{
30+
var retVal = midas.doCallback('CALLBACK_CORE_VALIDATE_UPLOAD', {files: files, revision: true});
31+
$.each(retVal, function(module, resp) {
32+
if(resp.status === false)
33+
{
34+
$('div.uploadValidationError b').html(resp.message);
35+
$('div.uploadValidationError').show();
36+
}
37+
});
38+
}
39+
2840
handler.uploadRow.find('.file_upload_start').click(function () {
2941
handler.formData = {
3042
parent: $('#destinationId').val(),
@@ -162,3 +174,6 @@ $('#browseMIDASLink').click(function() {
162174
loadDialog("select", "/browse/movecopy/?selectElement=true");
163175
showDialog('Browse');
164176
});
177+
178+
midas.doCallback('CALLBACK_CORE_REVISIONUPLOAD_LOADED');
179+

core/views/upload/revision.phtml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ PURPOSE. See the above copyright notices for more information.
7878
<div class="file_upload_overall_progress" style='display:none;'><div style="display:none;"></div></div>
7979
</div>
8080
</div>
81+
<div class="belowDestinationUpload"></div>
82+
<div class="uploadValidationError"><img src="<?php echo $this->coreWebroot ?>/public/images/icons/close.png" alt=""/><b></b><hr></div>
83+
<div class="tooBigUpload">
84+
<img src="<?php echo $this->coreWebroot ?>/public/images/icons/close.png" alt=""/> <b><?php echo $this->t('Please use the large file tool, the following files are too big:')?></b>
85+
<ul>
86+
87+
</ul>
88+
</div>
89+
<br />
8190
<b><?php echo $this->t('Step 2: Select a license')?></b>
8291
<div>
8392
<?php
@@ -112,6 +121,9 @@ PURPOSE. See the above copyright notices for more information.
112121
<input type="hidden" class="uploadedSimple" value="0"/>
113122
<input type="hidden" class="uploadedJava" value="0"/>
114123
<input type="hidden" class="uploadedLinks" value="0"/>
115-
116-
117-
124+
<?php
125+
foreach($this->extraHtml as $module => $extra)
126+
{
127+
echo $extra."\n";
128+
}
129+
?>

modules/sizequota/Notification.php

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public function init()
3232
$this->addCallBack('CALLBACK_CORE_GET_COMMUNITY_MANAGE_TABS', 'getCommunityTab');
3333
$this->addCallBack('CALLBACK_CORE_GET_USER_TABS', 'getUserTab');
3434
$this->addCallBack('CALLBACK_CORE_GET_FOOTER_LAYOUT', 'getScript');
35-
$this->addCallBack('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', 'getExtraHtml');
36-
$this->addCallBack('CALLBACK_CORE_GET_JAVAUPLOAD_EXTRA_HTML', 'getExtraHtml');
35+
$this->addCallBack('CALLBACK_CORE_GET_SIMPLEUPLOAD_EXTRA_HTML', 'getExtraHtmlSimple');
36+
$this->addCallBack('CALLBACK_CORE_GET_JAVAUPLOAD_EXTRA_HTML', 'getExtraHtmlSimple');
37+
$this->addCallBack('CALLBACK_CORE_GET_REVISIONUPLOAD_EXTRA_HTML', 'getExtraHtmlRevision');
3738
$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');
3839

3940
$this->enableWebAPI($this->moduleName);
@@ -72,8 +73,11 @@ public function getScript()
7273
return '<script type="text/javascript" src="'.$modulePublicWebroot.'/public/js/common/common.notify.js"></script>';
7374
}
7475

75-
/** Add free space information to the dom on the simple upload page */
76-
public function getExtraHtml($args)
76+
/**
77+
* Add free space information to the dom on the simple upload & java upload pages
78+
* @param folder The folder dao that you are uploading into
79+
*/
80+
public function getExtraHtmlSimple($args)
7781
{
7882
$modelLoader = new MIDAS_ModelLoader();
7983
$folderModel = $modelLoader->loadModel('Folder');
@@ -97,6 +101,44 @@ public function getExtraHtml($args)
97101
}
98102
}
99103

104+
/**
105+
* Add free space information to the dom on the revision uploader page
106+
* @param item The item dao that you are uploading a new revision into
107+
*/
108+
public function getExtraHtmlRevision($args)
109+
{
110+
$modelLoader = new MIDAS_ModelLoader();
111+
$folderModel = $modelLoader->loadModel('Folder');
112+
$folderQuotaModel = $modelLoader->loadModel('FolderQuota', $this->moduleName);
113+
114+
$item = $args['item'];
115+
$folders = $item->getFolders();
116+
if(count($folders) == 0)
117+
{
118+
//don't allow any more uploading into an orphaned item
119+
return '<div id="sizequotaFreeSpace" style="display:none;">0</div>'.
120+
'<div id="sizequotaHFreeSpace" style="display:none;">'.$this->t('None').'</div>';
121+
}
122+
else
123+
{
124+
$rootFolder = $folderModel->getRoot($folders[0]);
125+
$quota = $folderQuotaModel->getFolderQuota($rootFolder);
126+
if($quota == '')
127+
{
128+
return '<div id="sizequotaFreeSpace" style="display:none;"></div>'.
129+
'<div id="sizequotaHFreeSpace" style="display:none;">'.$this->t('Unlimited').'</div>';
130+
}
131+
else
132+
{
133+
$used = $folderModel->getSize($rootFolder);
134+
$freeSpace = number_format($quota - $used, 0, '.', '');
135+
$hFreeSpace = UtilityComponent::formatSize($quota - $used);
136+
return '<div id="sizequotaFreeSpace" style="display:none;">'.$freeSpace.'</div>'.
137+
'<div id="sizequotaHFreeSpace" style="display:none;">'.$hFreeSpace.'</div>';
138+
}
139+
}
140+
}
141+
100142
/**
101143
* Return whether or not the upload is allowed. If uploading the file
102144
* will cause the size to surpass the quota, it will be rejected.

modules/sizequota/public/js/common/common.notify.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,22 @@ midas.sizequota.validateUpload = function(args)
1515

1616
if(freeSpace != '' && midas.sizequota.totalSize > parseInt(freeSpace))
1717
{
18-
return {
19-
status: false,
20-
message: 'Uploading these files would exceed the maximum quota for the selected folder. Please choose a different folder or remove some of the files.'
21-
};
18+
if(args.revision)
19+
{
20+
return {
21+
status: false,
22+
message: 'Uploading these files would exceed the maximum quota for the parent folder. '
23+
+ 'Please remove some of the files.'
24+
};
25+
}
26+
else
27+
{
28+
return {
29+
status: false,
30+
message: 'Uploading these files would exceed the maximum quota for the selected folder. '
31+
+ 'Please choose a different folder or remove some of the files.'
32+
};
33+
}
2234
}
2335
else
2436
{
@@ -98,4 +110,5 @@ midas.registerCallback('CALLBACK_CORE_RESET_UPLOAD_TOTAL', 'sizequota', midas.si
98110
midas.registerCallback('CALLBACK_CORE_UPLOAD_FOLDER_CHANGED', 'sizequota', midas.sizequota.folderChanged);
99111
midas.registerCallback('CALLBACK_CORE_SIMPLEUPLOAD_LOADED', 'sizequota', midas.sizequota.onPageLoad);
100112
midas.registerCallback('CALLBACK_CORE_JAVAUPLOAD_LOADED', 'sizequota', midas.sizequota.onPageLoad);
113+
midas.registerCallback('CALLBACK_CORE_REVISIONUPLOAD_LOADED', 'sizequota', midas.sizequota.updateFreeSpaceMessage);
101114

0 commit comments

Comments
 (0)