Implemented quota for files
This commit is contained in:
parent
054807c784
commit
aab2d91b17
4 changed files with 97 additions and 2 deletions
|
@ -632,6 +632,21 @@ rcube_webmail.prototype.files_open = function()
|
|||
file_api.file_open(files[0], rcmail.env.viewer);
|
||||
};
|
||||
|
||||
rcube_webmail.prototype.files_set_quota = function(p)
|
||||
{
|
||||
if (p.total) {
|
||||
p.used *= 1024;
|
||||
p.total *= 1024;
|
||||
p.title = file_api.file_size(p.used) + ' / ' + file_api.file_size(p.total)
|
||||
+ ' (' + p.percent + '%)';
|
||||
}
|
||||
|
||||
p.type = this.env.quota_type;
|
||||
|
||||
this.set_quota(p);
|
||||
};
|
||||
|
||||
|
||||
/**********************************************************/
|
||||
/********* Files API handler **********/
|
||||
/**********************************************************/
|
||||
|
@ -769,6 +784,8 @@ function kolab_files_ui()
|
|||
this.env.collection = null;
|
||||
rcmail.command('files-list', {folder: folder});
|
||||
}
|
||||
|
||||
this.quota();
|
||||
};
|
||||
|
||||
this.folder_unselect = function()
|
||||
|
@ -778,6 +795,8 @@ function kolab_files_ui()
|
|||
rcmail.enable_command('files-folder-delete', 'files-upload', false);
|
||||
this.env.folder = null;
|
||||
this.env.collection = null;
|
||||
|
||||
this.quota();
|
||||
};
|
||||
|
||||
// folder create request
|
||||
|
@ -818,6 +837,23 @@ function kolab_files_ui()
|
|||
|
||||
// refresh folders list
|
||||
this.folder_list();
|
||||
this.quota();
|
||||
};
|
||||
|
||||
// quota request
|
||||
this.quota = function()
|
||||
{
|
||||
if (rcmail.env.files_quota)
|
||||
this.request('quota', {folder: this.env.folder}, 'quota_response');
|
||||
};
|
||||
|
||||
// quota response handler
|
||||
this.quota_response = function(response)
|
||||
{
|
||||
if (!this.response(response))
|
||||
return;
|
||||
|
||||
rcmail.files_set_quota(response.result);
|
||||
};
|
||||
|
||||
this.file_list = function(params)
|
||||
|
@ -1090,8 +1126,10 @@ function kolab_files_ui()
|
|||
// @TODO: reload files list in parent window
|
||||
window.close();
|
||||
}
|
||||
else
|
||||
else {
|
||||
this.file_list();
|
||||
this.quota();
|
||||
}
|
||||
};
|
||||
|
||||
// file(s) move request
|
||||
|
@ -1164,8 +1202,10 @@ function kolab_files_ui()
|
|||
|
||||
if (response.result && response.result.already_exist && response.result.already_exist.length)
|
||||
this.file_move_ask_user(response.result.already_exist);
|
||||
else
|
||||
else {
|
||||
this.display_message('kolab_files.filecopynotice', 'confirmation');
|
||||
this.quota();
|
||||
}
|
||||
};
|
||||
|
||||
// when file move/copy operation returns file-exists error
|
||||
|
@ -1274,6 +1314,7 @@ function kolab_files_ui()
|
|||
// refresh the list on upload success
|
||||
if (file_api.response_parse(response))
|
||||
file_api.file_list();
|
||||
file_api.quota();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -101,6 +101,7 @@ class kolab_files_engine
|
|||
'folder-create-form' => array($this, 'folder_create_form'),
|
||||
'file-search-form' => array($this, 'file_search_form'),
|
||||
'filelist' => array($this, 'file_list'),
|
||||
'filequotadisplay' => array($this, 'quota_display'),
|
||||
));
|
||||
|
||||
if ($this->rc->task != 'files') {
|
||||
|
@ -416,6 +417,48 @@ class kolab_files_engine
|
|||
return html::iframe(array('id' => 'file-content', 'src' => $href));
|
||||
}
|
||||
|
||||
/**
|
||||
* Template object for quota display
|
||||
*/
|
||||
public function quota_display($attrib)
|
||||
{
|
||||
if (!$attrib['id']) {
|
||||
$attrib['id'] = 'rcmquotadisplay';
|
||||
}
|
||||
|
||||
$quota_type = !empty($attrib['display']) ? $attrib['display'] : 'text';
|
||||
|
||||
$this->rc->output->add_gui_object('quotadisplay', $attrib['id']);
|
||||
$this->rc->output->set_env('quota_type', $quota_type);
|
||||
|
||||
// get quota
|
||||
$token = $this->get_api_token();
|
||||
$request = $this->get_request(array('method' => 'quota'), $token);
|
||||
|
||||
// send request to the API
|
||||
try {
|
||||
$response = $request->send();
|
||||
$status = $response->getStatus();
|
||||
$body = @json_decode($response->getBody(), true);
|
||||
|
||||
if ($status == 200 && $body['status'] == 'OK') {
|
||||
$quota = $body['result'];
|
||||
}
|
||||
else {
|
||||
throw new Exception($body['reason']);
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$quota = array('total' => 0, 'percent' => 0);
|
||||
}
|
||||
|
||||
$quota = rcube_output::json_serialize($quota);
|
||||
|
||||
$this->rc->output->add_script(rcmail_output::JS_OBJECT_NAME . ".files_set_quota($quota);", 'docready');
|
||||
|
||||
return html::span($attrib, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API token for current user session, authenticate if needed
|
||||
*/
|
||||
|
@ -463,6 +506,7 @@ class kolab_files_engine
|
|||
if ($token) {
|
||||
$_SESSION['kolab_files_token'] = $token;
|
||||
$_SESSION['kolab_files_time'] = time();
|
||||
$_SESSION['kolab_files_caps'] = $body['result']['capabilities'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -542,6 +586,7 @@ class kolab_files_engine
|
|||
|
||||
$this->rc->output->set_pagetitle($this->plugin->gettext('files'));
|
||||
$this->rc->output->set_env('file_mimetypes', $this->get_mimetypes());
|
||||
$this->rc->output->set_env('files_quota', $_SESSION['kolab_files_caps']['QUOTA']);
|
||||
$this->rc->output->send('kolab_files.files');
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
</div>
|
||||
<div id="folderlist-footer" class="boxfooter">
|
||||
<roundcube:button name="folder-create" type="link" title="kolab_files.foldercreate" class="listbutton add" classAct="listbutton add" innerClass="inner" content="+" onclick="kolab_files_folder_create_dialog()" /><roundcube:button name="folderoptions" id="folderoptionslink" type="link" title="moreactions" class="listbutton groupactions" onclick="UI.show_popup('folderoptions', undefined, {above: 1});return false" innerClass="inner" content="⚙" />
|
||||
<roundcube:if condition="env:files_quota" />
|
||||
<roundcube:object name="filequotadisplay" id="quotadisplay" class="countdisplay" display="text" />
|
||||
<roundcube:endif />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ function kolab_files_ui_init()
|
|||
$(document).ready(function() {
|
||||
rcmail.addEventListener('menu-open', kolab_files_show_listoptions);
|
||||
rcmail.addEventListener('menu-save', kolab_files_save_listoptions);
|
||||
rcmail.addEventListener('setquota', kolab_files_update_quota);
|
||||
|
||||
var menu = $('#dragfilemenu');
|
||||
if (menu.length) {
|
||||
|
@ -27,6 +28,11 @@ function kolab_files_ui_init()
|
|||
kolab_files_upload_input('#filestoolbar a.upload');
|
||||
};
|
||||
|
||||
function kolab_files_update_quota(p)
|
||||
{
|
||||
return UI.update_quota(p);
|
||||
}
|
||||
|
||||
function kolab_files_show_listoptions()
|
||||
{
|
||||
var $dialog = $('#listoptions');
|
||||
|
|
Loading…
Add table
Reference in a new issue