Small refactoring to have both View and Edit buttons for documents

This commit is contained in:
Aleksander Machniak 2015-11-12 17:50:58 +01:00
parent 02d13ba808
commit ea0b2a60ba
8 changed files with 111 additions and 64 deletions

View file

@ -108,14 +108,17 @@ window.rcmail && window.files_api && rcmail.addEventListener('init', function()
kolab_files_init();
if (rcmail.env.action == 'open') {
if (rcmail.env.action == 'open' || rcmail.env.action == 'edit') {
rcmail.enable_command('files-get', 'files-delete', rcmail.env.file);
if (rcmail.env.file_data.viewer && rcmail.env.file_data.viewer.manticore)
if (rcmail.env.action == 'edit' && rcmail.env.file_data.viewer && rcmail.env.file_data.viewer.manticore)
manticore = new manticore_api({
iframe: $('#fileframe').get(0),
export_menu: rcmail.gui_objects.exportmenu ? $('ul', rcmail.gui_objects.exportmenu).get(0) : null,
title_input: $('#document-title').get(0),
members_list: $('#members').get(0),
photo_url: '?_task=addressbook&_action=photo&_email=%email',
photo_default_url: rcmail.env.photo_placeholder,
ready: function(data) { manticore_init(); },
set_busy: function(state, message) { return rcmail.set_busy(state, message ? 'kolab_files.' + message : ''); },
hide_message: function(id) { return rcmail.hide_message(id); },
@ -825,6 +828,7 @@ function kolab_files_list_select(list)
else
rcmail.env.viewer = 0;
rcmail.enable_command('files-edit', (rcmail.env.viewer & 4) == 4);
rcmail.enable_command('files-open', rcmail.env.viewer);
};
@ -910,11 +914,10 @@ function kolab_files_frame_load(frame)
}
catch (e) {};
if (rcmail.file_editor)
rcmail.enable_command('files-edit', true);
rcmail.enable_command('files-print', (rcmail.file_editor && rcmail.file_editor.printable) ||
(rcmail.env.file_data && /^image\//i.test(rcmail.env.file_data.type)));
rcmail.enable_command('files-edit', rcmail.file_editor
|| (rcmail.env.file_data.viewer && rcmail.env.file_data.viewer.manticore));
rcmail.enable_command('files-print', (rcmail.file_editor && rcmail.file_editor.printable)
|| (rcmail.env.file_data && /^image\//i.test(rcmail.env.file_data.type)));
// detect Print button and check if it can be accessed
try {
@ -1143,6 +1146,16 @@ rcube_webmail.prototype.files_edit = function()
this.file_editor.enable();
this.enable_command('files-save', true);
}
else if (this.env.file) {
var viewer = file_api.file_type_supported(this.env.file_data.type, this.env.files_caps);
file_api.file_open(this.env.file, viewer, 'edit', true);
}
else if (!this.env.action) {
var files = kolab_files_selected();
if (files.length == 1)
file_api.file_open(files[0], this.env.viewer, 'edit');
}
};
rcube_webmail.prototype.files_save = function()
@ -2657,10 +2670,17 @@ function kolab_files_ui()
};
// open file in new window, using file API viewer
this.file_open = function(file, viewer)
this.file_open = function(file, viewer, action, local)
{
var href = '?' + $.param({_task: 'files', _action: 'open', file: file, viewer: viewer || 0});
rcmail.open_window(href, false, true);
var href = '?' + $.param({_task: 'files', _action: action || 'open', file: file, viewer: viewer || 0});
if (rcmail.env.extwin)
href += '&_extwin=1';
if (local)
location.href = href;
else
rcmail.open_window(href, false, true);
};
// save file

View file

@ -49,6 +49,7 @@ class kolab_files extends rcube_plugin
$this->register_action('index', array($this, 'actions'));
$this->register_action('prefs', array($this, 'actions'));
$this->register_action('open', array($this, 'actions'));
$this->register_action('edit', array($this, 'actions'));
// we use libkolab::http_request() from libkolab with its configuration
$this->require_plugin('libkolab');

View file

@ -892,56 +892,16 @@ class kolab_files_engine
*/
protected function action_open()
{
$file = rcube_utils::get_input_value('file', rcube_utils::INPUT_GET);
$viewer = intval($_GET['viewer']);
$this->rc->output->set_env('files_caps', $_SESSION['kolab_files_caps']);
$this->file_opener(intval($_GET['viewer']) & ~4);
}
// get file info
$token = $this->get_api_token();
$request = $this->get_request(array(
'method' => 'file_info',
'file' => $file,
'viewer' => $viewer,
), $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') {
$this->file_data = $body['result'];
}
else {
throw new Exception($body['reason']);
}
}
catch (Exception $e) {
rcube::raise_error(array(
'code' => 500, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__,
'message' => $e->getMessage()),
true, true);
}
$this->file_data['filename'] = $file;
$this->plugin->add_label('filedeleteconfirm', 'filedeleting', 'filedeletenotice');
// register template objects for dialogs (and main interface)
$this->rc->output->add_handlers(array(
'fileinfobox' => array($this, 'file_info_box'),
'filepreviewframe' => array($this, 'file_preview_frame'),
));
$placeholder = $this->rc->output->asset_url('program/resources/blank.gif');
// this one is for styling purpose
$this->rc->output->set_env('extwin', true);
$this->rc->output->set_env('file', $file);
$this->rc->output->set_env('file_data', $this->file_data);
$this->rc->output->set_env('photo_placeholder', $placeholder);
$this->rc->output->set_pagetitle(rcube::Q($file));
$this->rc->output->send('kolab_files.' . ($viewer & 4 ? 'docedit' : 'filepreview'));
/**
* Handler for file open action
*/
protected function action_edit()
{
$this->file_opener(intval($_GET['viewer']));
}
/**
@ -1226,6 +1186,62 @@ class kolab_files_engine
$this->rc->output->send();
}
/**
* Handler for file open/edit action
*/
protected function file_opener($viewer)
{
$file = rcube_utils::get_input_value('file', rcube_utils::INPUT_GET);
// get file info
$token = $this->get_api_token();
$request = $this->get_request(array(
'method' => 'file_info',
'file' => $file,
'viewer' => $viewer,
), $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') {
$this->file_data = $body['result'];
}
else {
throw new Exception($body['reason']);
}
}
catch (Exception $e) {
rcube::raise_error(array(
'code' => 500, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__,
'message' => $e->getMessage()),
true, true);
}
$this->file_data['filename'] = $file;
$this->plugin->add_label('filedeleteconfirm', 'filedeleting', 'filedeletenotice');
// register template objects for dialogs (and main interface)
$this->rc->output->add_handlers(array(
'fileinfobox' => array($this, 'file_info_box'),
'filepreviewframe' => array($this, 'file_preview_frame'),
));
$placeholder = $this->rc->output->asset_url('program/resources/blank.gif');
// this one is for styling purpose
$this->rc->output->set_env('extwin', true);
$this->rc->output->set_env('file', $file);
$this->rc->output->set_env('file_data', $this->file_data);
$this->rc->output->set_env('photo_placeholder', $placeholder);
$this->rc->output->set_pagetitle(rcube::Q($file));
$this->rc->output->send('kolab_files.' . ($viewer & 4 ? 'docedit' : 'filepreview'));
}
/**
* Returns mimetypes supported by File API viewers
*/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View file

@ -49,7 +49,10 @@
background-image: url(../../../../skins/larry/images/buttons.png);
}
#filestoolbar a.button.create,
#filestoolbar a.button.create {
background-position: center -315px;
}
#filestoolbar a.button.edit {
background-position: center -173px;
}

View file

@ -15,15 +15,17 @@
<h2 id="aria-label-toolbar" class="voice"><roundcube:label name="arialabeltoolbar" /></h2>
<div id="filestoolbar" class="toolbar" role="toolbar" aria-labelledby="aria-label-toolbar">
<!--
<roundcube:button command="files-delete" type="link" class="button delete disabled" classAct="button delete" classSel="button delete pressed" label="delete" title="kolab_files.deletefile" />
-->
<span class="dropbutton">
<roundcube:button command="document-export" type="link" class="button export disabled" classAct="button export" classSel="button export pressed" label="kolab_files.get" title="kolab_files.getfile" />
<a href="#export" class="dropbuttontip" id="exportmenulink" onclick="UI.toggle_popup('exportmenu',event);return false" aria-haspopup="true" aria-expanded="false" aria-owns="exportmenu-menu" tabindex="0">Export options</a>
</span>
<!--
<roundcube:button command="document-print" type="link" class="button print disabled" classAct="button print" classSel="button print pressed" label="print" title="kolab_files.printfile" />
-->
<span class="spacer"></span>
-->
<roundcube:button command="document-save" type="link" class="button save disabled" classAct="button save" classSel="button save pressed" label="kolab_files.save" title="kolab_files.savefile" />
<span class="spacer"></span>
<label for="document-title"><roundcube:label name="kolab_files.documenttitle" />&nbsp;<input id="document-title" type="text" value="" /></label>
@ -46,7 +48,11 @@
<h3 id="aria-label-exportmenu" class="voice"><roundcube:label name="kolab_files.arialabelexportoptions" /></h3>
<ul id="exportmenu-menu" class="toolbarmenu" role="menu" aria-labelledby="aria-label-exportmenu"></ul>
</div>
<!--
<div id="editors-dialog" class="uidialog" data-editable="true" role="dialog" aria-labelledby="aria-label-doceditorsdialog" aria-hidden="true">
<h3 id="aria-label-doceditorsdialog" class="voice"><roundcube:label name="kolab_files.arialabeldoceditorsdialog" /></h3>
</div>
-->
<roundcube:include file="/includes/footer.html" />
<script type="text/javascript">

View file

@ -19,8 +19,9 @@
<roundcube:button command="files-upload" type="link" class="button upload disabled" classAct="button upload" classSel="button upload pressed" label="kolab_files.upload" title="kolab_files.uploadfile" />
</form>
<roundcube:button command="files-get" type="link" class="button get disabled" classAct="button get" classSel="button get pressed" label="kolab_files.get" title="kolab_files.getfile" />
<roundcube:button command="files-create" type="link" class="button create disabled" classAct="button create" classSel="button create pressed" label="kolab_files.create" title="kolab_files.createfile" />
<roundcube:button command="files-open" type="link" class="button open disabled" classAct="button open" classSel="button open pressed" label="kolab_files.view" title="kolab_files.viewfile" />
<roundcube:button command="files-edit" type="link" class="button edit disabled" classAct="button edit" classSel="button edit pressed" label="kolab_files.edit" title="kolab_files.editfile" />
<roundcube:button command="files-create" type="link" class="button create disabled" classAct="button create" classSel="button create pressed" label="kolab_files.create" title="kolab_files.createfile" />
<roundcube:button command="files-delete" type="link" class="button delete disabled" classAct="button delete" classSel="button delete pressed" label="delete" title="kolab_files.deletefile" />
</div>

View file

@ -1,6 +1,6 @@
function kolab_files_ui_init()
{
if (rcmail.env.action == 'open') {
if (rcmail.env.action == 'open' || rcmail.env.action == 'edit') {
var filesviewsplit = new rcube_splitter({ id:'filesopensplitter', p1:'#fileinfobox', p2:'#filecontent',
orientation:'v', relative:true, start:226, min:150, size:12 }).init();