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

Commit dfc705e

Browse files
committed
ENH: refs #0377. Improve quota admin form and make it only visible to admins
1 parent 6d5d9d6 commit dfc705e

File tree

5 files changed

+124
-33
lines changed

5 files changed

+124
-33
lines changed

modules/sizequota/Notification.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class Sizequota_Notification extends MIDAS_Notification
2323
{
2424
public $moduleName = 'sizequota';
2525
public $_moduleComponents = array();
26-
public $_models = array();
26+
public $_models = array('Folder');
2727

2828
/** init notification process */
2929
public function init()
3030
{
31-
//$this->addCallBack('CALLBACK_CORE_GET_MANAGE_COMMUNITY_TABS', 'getCommunityTab');
31+
$this->addCallBack('CALLBACK_CORE_GET_MANAGE_COMMUNITY_TABS', 'getCommunityTab');
3232
$this->addCallBack('CALLBACK_CORE_GET_USER_TABS', 'getUserTab');
3333
//$this->addCallBack('CALLBACK_CORE_VALIDATE_UPLOAD', 'validateUpload');
3434
}
@@ -43,9 +43,16 @@ public function getCommunityTab($args)
4343
public function getUserTab($args)
4444
{
4545
$user = $args['user'];
46-
$fc = Zend_Controller_Front::getInstance();
47-
$moduleWebroot = $fc->getBaseUrl().'/'.$this->moduleName;
48-
return array($this->t('Storage Quota') => $moduleWebroot.'/config/folder?folderId='.$user->getFolderId());
46+
if($this->Folder->policyCheck($user->getFolder(), $this->userSession->Dao, MIDAS_POLICY_READ))
47+
{
48+
$fc = Zend_Controller_Front::getInstance();
49+
$moduleWebroot = $fc->getBaseUrl().'/'.$this->moduleName;
50+
return array($this->t('Storage Quota') => $moduleWebroot.'/config/folder?folderId='.$user->getFolderId());
51+
}
52+
else
53+
{
54+
return array();
55+
}
4956
}
5057

5158
/** Return whether or not the upload is allowed. If uploading the file

modules/sizequota/controllers/ConfigController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ public function folderAction()
117117
$formArray['quota']->setValue($currentQuota->getQuota());
118118
$this->view->quota = $currentQuota->getQuota();
119119
}
120+
$usedSpace = $this->Folder->getSizeFiltered($folder, $this->userSession->Dao);
121+
$this->view->usedSpace = $usedSpace[0]->size;
120122
$this->view->configForm = $formArray;
121123
$this->view->folder = $folder;
122-
$this->view->usedSpace = $this->Folder->getSizeFiltered($folder, $this->userSession->Dao);
124+
$this->view->isAdmin = $this->userSession->Dao->isAdmin();
123125
}
124126

125127
/** Used to manage folder-specific quotas (form handler) */
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
form.quotaConfigForm div label{
2+
display: inline;
3+
margin-right: 5px;
4+
text-align: left;
5+
line-height: 2em;
6+
}
7+
8+
form.quotaConfigForm input[type=text],form.quotaConfigForm input[type=password] ,form.quotaConfigForm textarea{
9+
margin-right: 10px;
10+
background: #F3F1EC;
11+
border: 1px solid grey;
12+
color: black;
13+
height: 18px;
14+
}
15+
16+
form.quotaConfigForm input[type=text]:hover,form.quotaConfigForm input[type=password]:hover, form.quotaConfigForm textarea:hover{
17+
background: white;
18+
}
19+
20+
form.quotaConfigForm div input[type=submit], input.globalButton ,form.quotaConfigForm input[type=button]
21+
{
22+
border: 1px solid grey;
23+
color: #2E6E9E;
24+
font-weight: bold;
25+
cursor: pointer;
26+
cursor: pointer;
27+
display: inline-block;
28+
margin-right: 0.1em;
29+
overflow: visible;
30+
position: relative;
31+
text-align: center;
32+
text-decoration: none !important;
33+
zoom: 1;
34+
-webkit-box-align: center;
35+
-webkit-box-sizing: border-box;
36+
line-height: 1.4;
37+
}
38+
39+
form.quotaConfigForm input[type=submit]:hover ,input.globalButton:hover
40+
{
41+
color: #1d5987;
42+
text-decoration: none;
43+
background: #cbd9e3;
44+
background-image: none;
45+
}
Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
$(document).ready(function() {
2-
$('#configForm').ajaxForm( {beforeSubmit: validateConfig, success: successConfig} );
3-
});
4-
5-
function validateConfig(formData, jqForm, options) {
6-
7-
}
1+
var midas = midas || {};
2+
midas.sizequota = midas.sizequota || {};
3+
midas.sizequota.folder = midas.sizequota.folder || {};
4+
midas.sizequota.constant = { MIDAS_USE_DEFAULT_QUOTA : "0", MIDAS_USE_SPECIFIC_QUOTA : "1" };
5+
6+
midas.sizequota.folder.validateConfig = function(formData, jqForm, options)
7+
{
8+
}
89

9-
function successConfig(responseText, statusText, xhr, form)
10-
{
11-
try {
12-
jsonResponse = jQuery.parseJSON(responseText);
13-
} catch (e) {
14-
alert("An error occured. Please check the logs.");
15-
return false;
10+
midas.sizequota.folder.successConfig = function(responseText, statusText, xhr, form)
11+
{
12+
try
13+
{
14+
jsonResponse = jQuery.parseJSON(responseText);
15+
}
16+
catch(e)
17+
{
18+
alert("An error occured. Please check the logs.");
19+
return false;
1620
}
1721
if(jsonResponse==null)
1822
{
@@ -27,4 +31,28 @@ function successConfig(responseText, statusText, xhr, form)
2731
{
2832
createNotice(jsonResponse[1],4000);
2933
}
30-
}
34+
}
35+
36+
midas.sizequota.folder.radioButtonChanged = function()
37+
{
38+
var selected = $('input[name="usedefault"]:checked');
39+
40+
if(selected.val() == midas.sizequota.constant.MIDAS_USE_DEFAULT_QUOTA)
41+
{
42+
$('input#quota').attr('disabled', 'disabled');
43+
}
44+
else
45+
{
46+
$('input#quota').removeAttr('disabled');
47+
}
48+
}
49+
50+
$(document).ready(function() {
51+
$('#configForm').ajaxForm({
52+
beforeSubmit: midas.sizequota.folder.validateConfig,
53+
success: midas.sizequota.folder.successConfig
54+
});
55+
56+
$('input[name="usedefault"]').change(midas.sizequota.folder.radioButtonChanged);
57+
midas.sizequota.folder.radioButtonChanged();
58+
});

modules/sizequota/views/config/folder.phtml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,27 @@ echo '<script type="text/javascript" src="'.$this->moduleWebroot.'/public/js/con
2525
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/common/common.genericPage.css" />
2626

2727
</div>
28-
<form class='genericForm' id='configForm' method='<?php echo $this->configForm['method'] ?>' action='<?php echo $this->configForm['action'] ?>'>
29-
<h3><?php echo $this->t('Storage Quota Configuration'); ?></h3>
30-
<div>
31-
<?php
32-
echo $this->configForm['usedefault'];
33-
echo $this->configForm['quota'];
34-
?>
35-
<div>
36-
<?php echo $this->configForm['submitQuota']; ?>
37-
</div>
38-
<input type="hidden" name="folderId" value="<?php echo $this->folder->getKey(); ?>" />
39-
</form>
28+
<span><?php echo 'Current used space: '.$this->usedSpace; ?></span>
29+
<br />
30+
<span><?php echo 'Total space: '.$this->quota; ?></span>
31+
<br />
32+
<?php
33+
if($this->isAdmin)
34+
{ ?>
35+
<hr />
36+
<form class='quotaConfigForm' id='configForm' method='<?php echo $this->configForm['method'] ?>' action='<?php echo $this->configForm['action'] ?>'>
37+
<div>
38+
<?php
39+
echo $this->configForm['usedefault'];
40+
echo $this->configForm['quota'];
41+
?>
42+
<div>
43+
<?php echo $this->configForm['submitQuota']; ?>
44+
</div>
45+
<input type="hidden" name="folderId" value="<?php echo $this->folder->getKey(); ?>" />
46+
</form>
47+
<?php
48+
} ?>
4049
</div>
4150

4251

0 commit comments

Comments
 (0)