Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appinfo/routes.php1
-rw-r--r--js/personal.js63
-rw-r--r--lib/Controller/SettingsController.php43
-rw-r--r--lib/Settings/Personal.php12
-rw-r--r--templates/personal.php12
5 files changed, 129 insertions, 2 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 30baf711..b4fb1e68 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -43,6 +43,7 @@ return [
['name' => 'wopi#putRelativeFile', 'url' => 'wopi/files/{fileId}', 'verb' => 'POST'],
//settings
+ ['name' => 'settings#setPersonalSettings', 'url' => 'ajax/personal.php', 'verb' => 'POST'],
['name' => 'settings#setSettings', 'url' => 'ajax/admin.php', 'verb' => 'POST'],
['name' => 'settings#getSettings', 'url' => 'ajax/settings.php', 'verb' => 'GET'],
diff --git a/js/personal.js b/js/personal.js
new file mode 100644
index 00000000..9afae561
--- /dev/null
+++ b/js/personal.js
@@ -0,0 +1,63 @@
+$(function () {
+
+ $('[data-toggle="tooltip"]').tooltip();
+
+ var PersonalSettings = function () {
+ this.templateInput = document.getElementById('templateInputField');
+ this.templateSelectButton = document.getElementById('templateSelectButton');
+ this.templateResetButton = document.getElementById('templateResetButton');
+
+ var self = this;
+ this.templateSelectButton.addEventListener('click', function() {
+ OC.dialogs.filepicker(t('richdocuments', 'Select a personal template folder'), function(datapath, returntype) {
+ self.updateSetting(datapath);
+ }, false, ['httpd/unix-directory'], true, OC.dialogs.FILEPICKER_TYPE_CHOOSE);
+ });
+
+ this.templateResetButton.addEventListener('click', this.resetSettings.bind(this));
+ };
+
+ PersonalSettings.prototype.updateSetting = function (path) {
+ var self = this;
+ this._updateSetting({templateFolder: path}, function() {
+ self.templateInput.value = path;
+ }, function () {
+
+ });
+ };
+
+ PersonalSettings.prototype.resetSettings = function() {
+ var self = this;
+ this._updateSetting({templateFolder: ''}, function() {
+ self.templateInput.value = '';
+ }, function () {
+
+ });
+ }
+
+ PersonalSettings.prototype._updateSetting = function(data, successCallback, errorCallback) {
+ OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving…'));
+ var request = new XMLHttpRequest();
+ request.open('POST', OC.filePath('richdocuments', 'ajax', 'personal.php'), true);
+ request.setRequestHeader("Content-Type", "application/json");
+ request.setRequestHeader("requesttoken", OC.requestToken);
+ request.onload = function() {
+ if (request.status >= 200 && request.status < 400) {
+ var response = JSON.parse(request.response);
+ OC.msg.finishedAction('#documents-admin-msg', response);
+ successCallback(response);
+ } else {
+ errorCallback(this.response);
+ }
+ };
+
+ request.onerror = function() {
+ errorCallback(this.response);
+ };
+
+ request.send(JSON.stringify(data));
+ }
+
+ new PersonalSettings();
+
+});
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
index 2d7222f3..122cf116 100644
--- a/lib/Controller/SettingsController.php
+++ b/lib/Controller/SettingsController.php
@@ -17,31 +17,43 @@ use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
use \OCP\IL10N;
use OCA\Richdocuments\AppConfig;
+use OCP\IConfig;
+use OCP\PreConditionNotMetException;
class SettingsController extends Controller{
/** @var IL10N */
private $l10n;
/** @var AppConfig */
private $appConfig;
+ /** @var IConfig */
+ private $config;
/** @var DiscoveryManager */
private $discoveryManager;
+ /** @var string */
+ private $userId;
/**
* @param string $appName
* @param IRequest $request
* @param IL10N $l10n
* @param AppConfig $appConfig
+ * @param IConfig $config
* @param DiscoveryManager $discoveryManager
+ * @param string $userId
*/
public function __construct($appName,
IRequest $request,
IL10N $l10n,
AppConfig $appConfig,
- DiscoveryManager $discoveryManager) {
+ IConfig $config,
+ DiscoveryManager $discoveryManager,
+ $userId) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
$this->appConfig = $appConfig;
+ $this->config = $config;
$this->discoveryManager = $discoveryManager;
+ $this->userId = $userId;
}
/**
@@ -113,4 +125,33 @@ class SettingsController extends Controller{
return new JSONResponse($response);
}
+
+ /**
+ * @NoAdminRequired
+ *
+ * @param $key
+ * @param $value
+ * @return JSONResponse
+ */
+ public function setPersonalSettings($templateFolder) {
+ $message = $this->l10n->t('Saved');
+ $status = 'success';
+
+ if ($templateFolder !== null){
+ try {
+ $this->config->setUserValue($this->userId, 'richdocuments', 'templateFolder', $templateFolder);
+ } catch (PreConditionNotMetException $e) {
+ $message = $this->l10n->t('Error when saving');
+ $status = 'error';
+ }
+ }
+
+ $response = [
+ 'status' => $status,
+ 'data' => ['message' => $message]
+ ];
+
+ return new JSONResponse($response);
+
+ }
}
diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php
index bc224bbc..838b5938 100644
--- a/lib/Settings/Personal.php
+++ b/lib/Settings/Personal.php
@@ -30,6 +30,14 @@ use OCP\Settings\ISettings;
class Personal implements ISettings {
+ private $config;
+ private $userId;
+
+ public function __construct(IConfig $config, $userId) {
+ $this->config = $config;
+ $this->userId = $userId;
+ }
+
/**
* @return TemplateResponse
*/
@@ -37,7 +45,9 @@ class Personal implements ISettings {
return new TemplateResponse(
'richdocuments',
'personal',
- [],
+ [
+ 'templateFolder' => $this->config->getUserValue($this->userId, 'richdocuments', 'templateFolder', '')
+ ],
'blank'
);
}
diff --git a/templates/personal.php b/templates/personal.php
index 24807f32..9ba9e3d4 100644
--- a/templates/personal.php
+++ b/templates/personal.php
@@ -1,5 +1,17 @@
+<?php
+style('richdocuments', 'admin');
+script('richdocuments', 'personal');
+?>
<div class="section" id="richdocuments">
<h2>
<?php p($l->t('Collabora Online')) ?>
</h2>
+ <span id="documents-admin-msg" class="msg"></span>
+ <p><label for="templateInputField"><?php p($l->t('Select a template directory')); ?></label><br />
+ <input type="text" name="templateInputField" id="templateInputField" value="<?php p($_['templateFolder']); ?>" disabled />
+ <button id="templateSelectButton"><span class="icon-folder" title="<?php p($l->t('Select a personal template folder')); ?>" data-toggle="tooltip"></span></button>
+ <button id="templateResetButton"><span class="icon-delete" title="<?php p($l->t('Remove personal template folder')); ?>" data-toggle="tooltip"></span></button>
+ </p>
+ <p><em><?php p($l->t('Templates inside of this directory will be added to the template selector of Collabora online.')); ?></em></p>
+ </div>
</div>