Skip to content

Commit

Permalink
Reuse selector
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Jul 3, 2018
1 parent 91c0a21 commit 0dff292
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/private/Helper/LocaleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function getNormalizedLanguages(IFactory $langFactory, $activeLangCode) {

// TRANSLATORS this is a self-name of your language for the language switcher
$endonym = (string)$l->t('__language_name__');
//Check if the language name is in the translation file
// Fallback to hardcoded language name if translation is
// Check if the language name is in the translation file
// Fallback to hardcoded language name if it isn't
$languageName = ($l->getLanguageCode() === $languageCode
&& \substr($endonym, 0, 1) !== '_'
) ? $endonym
Expand Down
34 changes: 34 additions & 0 deletions settings/Panels/Admin/FileSharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace OC\Settings\Panels\Admin;

use OC\Helper\LocaleHelper;
use OC\Settings\Panels\Helper;
use OCP\IConfig;
use OCP\Settings\ISettings;
Expand All @@ -47,6 +48,38 @@ public function getPriority() {
}

public function getPanel() {
$this->lfactory = \OC::$server->getL10NFactory();
$activeLangCode = $this->config->getAppValue(
'core',
'shareapi_public_notification_lang',
'owner'
);
$this->localeHelper = new LocaleHelper();
list($userLang, $commonLanguages, $languages) = $this->localeHelper->getNormalizedLanguages(
$this->lfactory,
$activeLangCode
);

// Allow reset to the defaults when mail notification is sent in the lang of owner
if ($userLang['code'] === "owner") {
$userLang['name'] = $this->l->t("Owner language");
} else {
\array_push(
$commonLanguages,
[
'code' => 'owner',
'name' => $this->l->t("Owner language")
]
);
}

$selector = new Template('settings', 'language');
$selector->assign('selectName', 'shareapi_public_notification_lang');
$selector->assign('selectId', 'shareapiPublicNotificationLang');
$selector->assign('activelanguage', $userLang);
$selector->assign('commonlanguages', $commonLanguages);
$selector->assign('languages', $languages);

$template = new Template('settings', 'panels/admin/filesharing');
$template->assign('allowResharing', $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'));
$template->assign('shareAPIEnabled', $this->config->getAppValue('core', 'shareapi_enabled', 'yes'));
Expand All @@ -57,6 +90,7 @@ public function getPanel() {
$template->assign('enforceLinkPasswordWriteOnly', $this->config->getAppValue('core', 'shareapi_enforce_links_password_write_only', 'no'));
$template->assign('shareDefaultExpireDateSet', $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'));
$template->assign('allowPublicMailNotification', $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no'));
$template->assign('publicMailNotificationLang', $selector->fetchPage());
$template->assign('allowSocialShare', $this->config->getAppValue('core', 'shareapi_allow_social_share', 'yes'));
$template->assign('allowGroupSharing', $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'));
$template->assign('onlyShareWithGroupMembers', $this->helper->shareWithGroupMembersOnly());
Expand Down
1 change: 1 addition & 0 deletions settings/Panels/Personal/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function getPanel() {
);

$selector = new Template('settings', 'language');
$selector->assign('selectName', 'lang');
$selector->assign('selectId', 'languageinput');
$selector->assign('activelanguage', $userLang);
$selector->assign('commonlanguages', $commonLanguages);
Expand Down
13 changes: 13 additions & 0 deletions settings/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ $(document).ready(function(){
$('#setDefaultExpireDate').toggleClass('hidden', !(this.checked && $('#shareapiDefaultExpireDate')[0].checked));
});

$('#allowPublicMailNotification').change(function() {
$("#publicMailNotificationLang").toggleClass('hidden', !this.checked);
});

$('#shareapiPublicNotificationLang').change(function() {
var value = $(this).val();
if (value === 'owner') {
OC.AppConfig.deleteKey('core', $(this).attr('name'));
} else {
OC.AppConfig.setValue('core', $(this).attr('name'), $(this).val());
}
});


$('#allowGroupSharing').change(function() {
$('#allowGroupSharing').toggleClass('hidden', !this.checked);
Expand Down
2 changes: 1 addition & 1 deletion settings/templates/language.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<select id="<?php p($_['selectId'])?>" name="lang" data-placeholder="<?php p($l->t('Language'));?>">
<select id="<?php p($_['selectId'])?>" name="<?php p($_['selectName'])?>" data-placeholder="<?php p($l->t('Language'));?>">
<option value="<?php p($_['activelanguage']['code']);?>">
<?php p($_['activelanguage']['name']);?>
</option>
Expand Down
8 changes: 8 additions & 0 deletions settings/templates/panels/admin/filesharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
print_unescaped('checked="checked"');
} ?> />
<label for="allowPublicMailNotification"><?php p($l->t('Allow users to send mail notification for shared files'));?></label><br/>
<span id="publicMailNotificationLang" <?php if ($_['allowPublicMailNotification'] == 'no') {
print_unescaped('class="hidden"');
} ?>>
<label><?php p($l->t('Language used for public mail notifications for shared files'));?></label>
<?php print_unescaped($_['publicMailNotificationLang']); ?>
<br>
</span>


<input type="checkbox" name="shareapi_allow_social_share" id="allowSocialShare" class="checkbox"
value="1" <?php if ($_['allowSocialShare'] == 'yes') {
Expand Down
2 changes: 1 addition & 1 deletion tests/Settings/Panels/Personal/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public function testGetPanel() {
$this->assertContains('test@example.com', $templateHtml);
$this->assertContains('<div id="groups" class="section">', $templateHtml);
$this->assertContains('group2', $templateHtml);
$this->assertContains('<form id="language" class="section">', $templateHtml);
$this->assertContains('<select id="languageinput" name="lang"', $templateHtml);
}
}

0 comments on commit 0dff292

Please sign in to comment.