Skip to content

Commit

Permalink
Add support for creating ODF files by default
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Kim <[email protected]>
  • Loading branch information
gary-kim committed Mar 28, 2020
1 parent 49ab32e commit 2c0625a
Show file tree
Hide file tree
Showing 60 changed files with 95 additions and 37 deletions.
Binary file added assets/bg/new.odp
Binary file not shown.
Binary file added assets/bg/new.ods
Binary file not shown.
Binary file added assets/bg/new.odt
Binary file not shown.
Binary file added assets/cs/new.odp
Binary file not shown.
Binary file added assets/cs/new.ods
Binary file not shown.
Binary file added assets/cs/new.odt
Binary file not shown.
Binary file added assets/de/new.odp
Binary file not shown.
Binary file added assets/de/new.ods
Binary file not shown.
Binary file added assets/de/new.odt
Binary file not shown.
Binary file added assets/de_DE/new.odp
Binary file not shown.
Binary file added assets/de_DE/new.ods
Binary file not shown.
Binary file added assets/de_DE/new.odt
Binary file not shown.
Binary file added assets/el/new.odp
Binary file not shown.
Binary file added assets/el/new.ods
Binary file not shown.
Binary file added assets/el/new.odt
Binary file not shown.
Binary file added assets/en/new.odp
Binary file not shown.
Binary file added assets/en/new.ods
Binary file not shown.
Binary file added assets/en/new.odt
Binary file not shown.
Binary file added assets/en_GB/new.odp
Binary file not shown.
Binary file added assets/en_GB/new.ods
Binary file not shown.
Binary file added assets/en_GB/new.odt
Binary file not shown.
Binary file added assets/es/new.odp
Binary file not shown.
Binary file added assets/es/new.ods
Binary file not shown.
Binary file added assets/es/new.odt
Binary file not shown.
Binary file added assets/fr/new.odp
Binary file not shown.
Binary file added assets/fr/new.ods
Binary file not shown.
Binary file added assets/fr/new.odt
Binary file not shown.
Binary file added assets/it/new.odp
Binary file not shown.
Binary file added assets/it/new.ods
Binary file not shown.
Binary file added assets/it/new.odt
Binary file not shown.
Binary file added assets/ko/new.odp
Binary file not shown.
Binary file added assets/ko/new.ods
Binary file not shown.
Binary file added assets/ko/new.odt
Binary file not shown.
Binary file added assets/nl/new.odp
Binary file not shown.
Binary file added assets/nl/new.ods
Binary file not shown.
Binary file added assets/nl/new.odt
Binary file not shown.
Binary file added assets/pl/new.odp
Binary file not shown.
Binary file added assets/pl/new.ods
Binary file not shown.
Binary file added assets/pl/new.odt
Binary file not shown.
Binary file added assets/pt_BR/new.odp
Binary file not shown.
Binary file added assets/pt_BR/new.ods
Binary file not shown.
Binary file added assets/pt_BR/new.odt
Binary file not shown.
Binary file added assets/pt_PT/new.odp
Binary file not shown.
Binary file added assets/pt_PT/new.ods
Binary file not shown.
Binary file added assets/pt_PT/new.odt
Binary file not shown.
Binary file added assets/ru/new.odp
Binary file not shown.
Binary file added assets/ru/new.ods
Binary file not shown.
Binary file added assets/ru/new.odt
Binary file not shown.
Binary file added assets/sv/new.odp
Binary file not shown.
Binary file added assets/sv/new.ods
Binary file not shown.
Binary file added assets/sv/new.odt
Binary file not shown.
Binary file added assets/zh_CN/new.odp
Binary file not shown.
Binary file added assets/zh_CN/new.ods
Binary file not shown.
Binary file added assets/zh_CN/new.odt
Binary file not shown.
11 changes: 8 additions & 3 deletions controller/settingscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public function index() {
"toolbarNoTabs" => $this->config->GetCustomizationToolbarNoTabs(),
"successful" => $this->config->SettingsAreSuccessful(),
"watermark" => $this->config->GetWatermarkSettings(),
"tagsEnabled" => App::isEnabled("systemtags")
"tagsEnabled" => App::isEnabled("systemtags"),
"odf" => $this->config->GetOdfDefault(),
];
return new TemplateResponse($this->appName, "settings", $data, "blank");
}
Expand Down Expand Up @@ -192,6 +193,7 @@ public function SaveAddress($documentserver,
* @param bool $feedback - display feedback
* @param bool $help - display help
* @param bool $toolbarNoTabs - display toolbar tab
* @param bool $odf - create ODF files by default
*
* @return array
*/
Expand All @@ -203,7 +205,8 @@ public function SaveCommon($defFormats,
$compactHeader,
$feedback,
$help,
$toolbarNoTabs
$toolbarNoTabs,
$odf
) {

$this->config->SetDefaultFormats($defFormats);
Expand All @@ -215,6 +218,7 @@ public function SaveCommon($defFormats,
$this->config->SetCustomizationFeedback($feedback);
$this->config->SetCustomizationHelp($help);
$this->config->SetCustomizationToolbarNoTabs($toolbarNoTabs);
$this->config->SetOdfDefault($odf);

return [
];
Expand Down Expand Up @@ -253,7 +257,8 @@ public function SaveWatermark($settings) {
public function GetSettings() {
$result = [
"formats" => $this->config->FormatsSetting(),
"sameTab" => $this->config->GetSameTab()
"sameTab" => $this->config->GetSameTab(),
"odf" => $this->config->GetOdfDefault(),
];
return $result;
}
Expand Down
66 changes: 35 additions & 31 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,39 +309,43 @@
return;
}

menu.addMenuEntry({
id: "onlyofficeDocx",
displayName: t(OCA.Onlyoffice.AppName, "Document"),
templateName: t(OCA.Onlyoffice.AppName, "Document"),
iconClass: "icon-onlyoffice-new-docx",
fileType: "docx",
actionHandler: function (name) {
OCA.Onlyoffice.CreateFile(name + ".docx", fileList);
}
});
var register = function() {
const odf = OCA.Onlyoffice.setting.odf;
menu.addMenuEntry({
id: "onlyofficeDocx",
displayName: t(OCA.Onlyoffice.AppName, "Document"),
templateName: t(OCA.Onlyoffice.AppName, "Document"),
iconClass: "icon-onlyoffice-new-docx",
fileType: "docx",
actionHandler: function (name) {
OCA.Onlyoffice.CreateFile(name + (odf ? ".odt" : ".docx"), fileList);
}
});

menu.addMenuEntry({
id: "onlyofficeXlsx",
displayName: t(OCA.Onlyoffice.AppName, "Spreadsheet"),
templateName: t(OCA.Onlyoffice.AppName, "Spreadsheet"),
iconClass: "icon-onlyoffice-new-xlsx",
fileType: "xlsx",
actionHandler: function (name) {
OCA.Onlyoffice.CreateFile(name + ".xlsx", fileList);
}
});
menu.addMenuEntry({
id: "onlyofficeXlsx",
displayName: t(OCA.Onlyoffice.AppName, "Spreadsheet"),
templateName: t(OCA.Onlyoffice.AppName, "Spreadsheet"),
iconClass: "icon-onlyoffice-new-xlsx",
fileType: "xlsx",
actionHandler: function (name) {
OCA.Onlyoffice.CreateFile(name + (odf ? ".ods" : ".xlsx"), fileList);
}
});

menu.addMenuEntry({
id: "onlyofficePpts",
displayName: t(OCA.Onlyoffice.AppName, "Presentation"),
templateName: t(OCA.Onlyoffice.AppName, "Presentation"),
iconClass: "icon-onlyoffice-new-pptx",
fileType: "pptx",
actionHandler: function (name) {
OCA.Onlyoffice.CreateFile(name + ".pptx", fileList);
}
});
}
menu.addMenuEntry({
id: "onlyofficePpts",
displayName: t(OCA.Onlyoffice.AppName, "Presentation"),
templateName: t(OCA.Onlyoffice.AppName, "Presentation"),
iconClass: "icon-onlyoffice-new-pptx",
fileType: "pptx",
actionHandler: function (name) {
OCA.Onlyoffice.CreateFile(name + (odf ? ".odp" : ".pptx"), fileList);
}
});
};
OCA.Onlyoffice.GetSettings(register);
},
};

var getFileExtension = function (fileName) {
Expand Down
4 changes: 3 additions & 1 deletion js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
var feedback = $("#onlyofficeFeedback").is(":checked");
var help = $("#onlyofficeHelp").is(":checked");
var toolbarNoTabs = !$("#onlyofficeToolbarNoTabs").is(":checked");
var odf = $("#defaultOdf").is(":checked");

$.ajax({
method: "PUT",
Expand All @@ -221,7 +222,8 @@
compactHeader: compactHeader,
feedback: feedback,
help: help,
toolbarNoTabs: toolbarNoTabs
toolbarNoTabs: toolbarNoTabs,
odf: odf,
},
success: function onSuccess(response) {
$(".section-onlyoffice").removeClass("icon-loading");
Expand Down
32 changes: 32 additions & 0 deletions lib/appconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@

use \DateInterval;
use \DateTime;
use \Exception;

use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;

/**
* Application configutarion
Expand Down Expand Up @@ -154,6 +156,13 @@ class AppConfig {
*/
private $_customizationToolbarNoTabs = "customizationToolbarNoTabs";

/**
* The config key for ODF being set as default
*
* @var string
*/
private $_odfDefault = "odf";

/**
* The config key for the setting limit groups
*
Expand Down Expand Up @@ -490,6 +499,29 @@ public function GetStorageUrl() {
return $url;
}

/**
* Set whether default file type is set to ODF
*
* @param bool $default
*/
public function SetOdfDefault($default = false) {
$this->config->setAppValue($this->appName, $this->_odfDefault, $default);
}

/**
* Get whether default file type is set to ODF
*
* @return bool
*/
public function GetOdfDefault() {
$odfDefault = $this->GetSystemValue($this->_odfDefault);

if (empty($odfDefault)) {
$odfDefault = $this->config->getAppValue($this->appName, $this->_odfDefault, false);
}
return $odfDefault;
}

/**
* Save the document service secret key to the application configuration
*
Expand Down
10 changes: 9 additions & 1 deletion lib/filecreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FileCreator extends ACreateEmpty {
* @param string $AppName - application name
* @param IL10N $trans - l10n service
* @param ILogger $logger - logger
* @param string $format - format for creation
* @param string $format - format for creation
*/
public function __construct($AppName,
IL10N $trans,
Expand Down Expand Up @@ -104,8 +104,10 @@ public function getId(): string {
public function getName(): string {
switch ($this->format) {
case "xlsx":
case "ods":
return $this->trans->t("Spreadsheet");
case "pptx":
case "odp":
return $this->trans->t("Presentation");
}
return $this->trans->t("Document");
Expand All @@ -131,6 +133,12 @@ public function getMimetype(): string {
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
case "pptx":
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
case "odt":
return "application/vnd.oasis.opendocument.text";
case "ods":
return "application/vnd.oasis.opendocument.spreadsheet";
case "odp":
return "application/vnd.oasis.opendocument.presentation";
}
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
}
Expand Down
9 changes: 8 additions & 1 deletion templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@
<label for="onlyofficeSameTab"><?php p($l->t("Open file in the same tab")) ?></label>
</p>

<p>
<input type="checkbox" class="checkbox"
id="defaultOdf"
<?php if ($_["odf"]) { ?>checked="checked"<?php } ?> />
<label for="defaultOdf"><?php p($l->t("Create ODF format files by default")) ?></label>
</p>

<p class="onlyoffice-header"><?php p($l->t("The default application for opening the format")) ?></p>
<div class="onlyoffice-exts">
<?php foreach ($_["formats"] as $format => $setting) { ?>
Expand Down Expand Up @@ -271,4 +278,4 @@
<br />
<p><button id="onlyofficeWatermarkSave" class="button"><?php p($l->t("Save")) ?></button></p>

</div>
</div>

0 comments on commit 2c0625a

Please sign in to comment.