cloudsuite: Add buttons to create new spreadsheet and new presentation.

pull/1/head
Jan Holesovsky 9 years ago
parent 37f61b4056
commit e6593def87

@ -77,17 +77,34 @@ class DocumentController extends Controller{
* @NoAdminRequired * @NoAdminRequired
*/ */
public function create(){ public function create(){
$mimetype = $this->request->post['mimetype'];
$view = new View('/' . $this->uid . '/files'); $view = new View('/' . $this->uid . '/files');
$dir = $this->settings->getUserValue($this->uid, $this->appName, 'save_path', '/'); $dir = $this->settings->getUserValue($this->uid, $this->appName, 'save_path', '/');
if (!$view->is_dir($dir)){ if (!$view->is_dir($dir)){
$dir = '/'; $dir = '/';
} }
$path = Helper::getNewFileName($view, $dir . '/New Document.odt');
$basename = $this->l10n->t('New Document.odt');
switch ($mimetype) {
case 'application/vnd.oasis.opendocument.spreadsheet':
$basename = $this->l10n->t('New Spreadsheet.ods');
break;
case 'application/vnd.oasis.opendocument.presentation':
$basename = $this->l10n->t('New Presentation.odp');
break;
default:
// to be safe
$mimetype = 'application/vnd.oasis.opendocument.text';
break;
}
$path = Helper::getNewFileName($view, $dir . '/' . $basename);
$content = ''; $content = '';
if (class_exists('\OC\Files\Type\TemplateManager')){ if (class_exists('\OC\Files\Type\TemplateManager')){
$manager = \OC_Helper::getFileTemplateManager(); $manager = \OC_Helper::getFileTemplateManager();
$content = $manager->getTemplate('application/vnd.oasis.opendocument.text'); $content = $manager->getTemplate($mimetype);
} }
if (!$content){ if (!$content){

@ -34,26 +34,29 @@
box-sizing: border-box; box-sizing: border-box;
display: inline-block; display: inline-block;
position: relative; position: relative;
height: 100px; height: 46px;
width: 200px; width: 200px;
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 32px; background-size: 32px;
background-position: 50%; background-position: 3%;
} }
.add-document a.add { .add-document .add-odt,
border-bottom: 1px solid #fff; .add-document .add-ods,
} .add-document .add-odp,
.add-document .add,
.add-document .upload { .add-document .upload {
opacity: .7; opacity: .7;
border: 1px solid #e8e8e8; border: 1px solid #e8e8e8;
} }
.add-document .upload { .add-document .upload {
margin-top: 4px; margin-top: 12px;
} }
.add-document .add:hover, .add-document .add-odt:hover,
.add-document .add:focus, .add-document .add-ods:hover,
.add-document .add-odp:hover,
.add-document .add-odt:focus,
.add-document .add-ods:focus,
.add-document .add-odp:focus,
.add-document #upload:hover .upload, .add-document #upload:hover .upload,
.add-document .upload:focus { .add-document .upload:focus {
opacity: 1; opacity: 1;

@ -374,8 +374,22 @@ var documentsMain = {
}); });
}, },
onCreate: function(event){ onCreateODT: function(event){
event.preventDefault(); event.preventDefault();
documentsMain.create('application/vnd.oasis.opendocument.text');
},
onCreateODS: function(event){
event.preventDefault();
documentsMain.create('application/vnd.oasis.opendocument.spreadsheet');
},
onCreateODP: function(event){
event.preventDefault();
documentsMain.create('application/vnd.oasis.opendocument.presentation');
},
create: function(mimetype){
var docElem = $('.documentslist .template').clone(); var docElem = $('.documentslist .template').clone();
docElem.removeClass('template'); docElem.removeClass('template');
docElem.addClass('document'); docElem.addClass('document');
@ -383,7 +397,7 @@ var documentsMain = {
docElem.show(); docElem.show();
$.post( $.post(
OC.generateUrl('apps/documents/ajax/documents/create'), OC.generateUrl('apps/documents/ajax/documents/create'),
{}, { mimetype : mimetype },
function(response){ function(response){
if (response && response.fileid){ if (response && response.fileid){
documentsMain.prepareSession(); documentsMain.prepareSession();
@ -692,7 +706,9 @@ $(document).ready(function() {
} }
}); });
$('.add-document').on('click', '.add', documentsMain.onCreate); $('.add-document').on('click', '.add-odt', documentsMain.onCreateODT);
$('.add-document').on('click', '.add-ods', documentsMain.onCreateODS);
$('.add-document').on('click', '.add-odp', documentsMain.onCreateODP);
var file_upload_start = $('#file_upload_start'); var file_upload_start = $('#file_upload_start');
if (typeof supportAjaxUploadWithProgress !== 'undefined' && supportAjaxUploadWithProgress()) { if (typeof supportAjaxUploadWithProgress !== 'undefined' && supportAjaxUploadWithProgress()) {

@ -21,7 +21,7 @@ class Helper {
while ($view->file_exists($path)){ while ($view->file_exists($path)){
$fileNum += 1; $fileNum += 1;
$path = preg_replace('/(\.odt|' . $prepend . '\(\d+\)\.odt)$/', $prepend . '(' . $fileNum . ').odt', $path); $path = preg_replace('/(\.|' . $prepend . '\(\d+\)\.)([^.]*)$/', $prepend . '(' . $fileNum . ').$2', $path);
}; };
return $path; return $path;

@ -11,9 +11,15 @@ script('files', 'jquery.fileupload');
<div id="documents-content"> <div id="documents-content">
<ul class="documentslist"> <ul class="documentslist">
<li class="add-document"> <li class="add-document">
<a class="icon-add add svg" target="_blank" href=""> <a class="icon-add add-odt svg" target="_blank" href="">
<label><?php p($l->t('New document')) ?></label> <label><?php p($l->t('New Document')) ?></label>
</a> </a>
<a class="icon-add add-ods svg" target="_blank" href="">
<label><?php p($l->t('New Spreadsheet')) ?></label>
</a>
<a class="icon-add add-odp svg" target="_blank" href="">
<label><?php p($l->t('New Presentation')) ?></label>
</a>
<div id="upload" title="<?php p($l->t('Upload (max. %s)', array($_['uploadMaxHumanFilesize']))) ?>"> <div id="upload" title="<?php p($l->t('Upload (max. %s)', array($_['uploadMaxHumanFilesize']))) ?>">
<form data-upload-id="1" <form data-upload-id="1"
id="data-upload-form" id="data-upload-form"

Loading…
Cancel
Save