diff options
author | Julius Härtl <jus@bitgrid.net> | 2018-11-08 19:10:03 +0300 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-12-20 09:38:45 +0300 |
commit | b56d63b227991208c7fa65c4c36524678b97e3b9 (patch) | |
tree | d7ddbbcc883765b3a9f2e25636a09e7ddc894ca4 | |
parent | 129516e4f5f8576765faf000b461398075153c87 (diff) |
Add personal settings for template folder
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | appinfo/routes.php | 1 | ||||
-rw-r--r-- | js/personal.js | 63 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 43 | ||||
-rw-r--r-- | lib/Settings/Personal.php | 12 | ||||
-rw-r--r-- | templates/personal.php | 12 |
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> |