Add config page and settings

This commit is contained in:
Victor Dubiniuk 2014-03-31 20:27:07 +03:00
parent 29fd4ecf69
commit 1bbcd7f6af
6 changed files with 109 additions and 0 deletions

11
admin.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace OCA\Documents;
\OCP\Util::addScript('documents', 'admin');
$tmpl = new \OCP\Template('documents', 'admin');
$tmpl->assign('converter', Config::getConverter());
$tmpl->assign('converter_url', Config::getConverterUrl());
return $tmpl->fetchPage();

33
ajax/admin.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace OCA\Documents;
\OCP\JSON::callCheck();
\OCP\JSON::checkAdminUser();
$l10n = \OCP\Util::getL10N('documents');
$converter = isset($_POST['converter']) ? $_POST['converter'] : null;
$url = isset($_POST['url']) ? $_POST['url'] : null;
try {
if (!is_null($converter)){
Config::setConverter($converter);
}
if (!is_null($url)){
Config::setConverterUrl($url);
}
if (Config::getConverter()!='local'){
if (!Converter::checkConnection()){
Helper::warnLog('Bad response from Format Filter Server');
\OCP\JSON::error(array('message' => $l10n->t('Format filter server is down or misconfigured') ));
exit();
}
}
\OCP\JSON::success();
} catch (\Exception $e){
\OCP\JSON::error();
}
exit();

View File

@ -23,6 +23,7 @@
OCP\App::register(array('order' => 70, 'id' => 'documents', 'name' => 'Documents')); OCP\App::register(array('order' => 70, 'id' => 'documents', 'name' => 'Documents'));
//OCP\App::registerAdmin('documents', 'settings'); //OCP\App::registerAdmin('documents', 'settings');
\OCP\App::registerAdmin('documents', 'admin');
OCP\App::registerPersonal('documents', 'personal'); OCP\App::registerPersonal('documents', 'personal');
$l10n = \OCP\Util::getL10N('documents'); $l10n = \OCP\Util::getL10N('documents');

37
js/admin.js Normal file
View File

@ -0,0 +1,37 @@
/*global OC, $ */
$(document).ready(function(){
var documentsSettings = {
converter : '',
save : function() {
$('#docs_apply').attr('disabled', true);
var data = {
converter : documentsSettings.converter
};
if (documentsSettings.converter !== 'local'){
data.url = $('#docs_url').val();
}
$.post(
OC.filePath('documents', 'ajax', 'admin.php'),
data,
documentsSettings.afterSave
);
},
afterSave : function(response){
$('#docs_apply').attr('disabled', false);
if (response && response.message) {
OC.Notification.show(response.message);
}
}
};
$('#docs_converter_external, #docs_converter_local').on('click', function(){
documentsSettings.converter = $(this).val();
$('#docs_extra').toggle(documentsSettings.converter !== 'local');
});
$('#docs_apply').on('click', documentsSettings.save);
});

BIN
lib/response.odt Normal file

Binary file not shown.

27
templates/admin.php Normal file
View File

@ -0,0 +1,27 @@
<?php $isLocal = $_['converter']=='local' ?>
<fieldset class="personalblock" id="documents">
<h2><?php p($l->t('Documents')) ?></h2>
<p>
<input type="radio" name="docs_converter" value="local" id="docs_converter_local"
<?php print_unescaped($isLocal ? 'checked="checked"' : '') ?>
/>
<label for="docs_converter_local"><?php p($l->t('Local')) ?></label><br>
<em><?php p($l->t('openOffice/libreOffice is installed on this server')) ?></em>
</p>
<p>
<input type="radio" name="docs_converter" value="external" id="docs_converter_external"
<?php print_unescaped(!$isLocal ? 'checked="checked"' : '') ?>
/>
<label for="docs_converter_external"><?php p($l->t('External')) ?></label><br>
<em><?php p($l->t('openOffice/libreOffice is installed on another server')) ?></em>
</p>
<div id="docs_extra" <?php print_unescaped($isLocal ? 'style="display:none"' : '') ?>>
<input type="text" name="docs_url" id="docs_url"
value="<?php p($_['converter_url'])?>"
original-title="<?php p($l->t('scheme://domain.tld[:port]')) ?>"
style="width:250px;"
/>
<br /><em><?php p($l->t('Server URL')) ?></em>
</div>
<br /><button type="button" id="docs_apply"><?php p($l->t('Apply')) ?></button>
</fieldset>