Skip to content

Commit

Permalink
feat(forms): added class to fields that have been disabled
Browse files Browse the repository at this point in the history
fixes #13908
  • Loading branch information
jdalsem committed Jun 28, 2022
1 parent 8e857da commit b95821f
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 98 deletions.
31 changes: 31 additions & 0 deletions mod/developers/views/default/theme_sandbox/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
'#help' => 'This is how help text looks',
]);

echo elgg_view_field([
'#type' => 'text',
'required' => true,
'disabled' => true,
'name' => 'f1.1',
'id' => 'f1.2',
'placeholder' => 'placeholder text',
'#label' => 'Text input (.elgg-field-disabled):',
'#help' => 'This is how help text looks',
]);

echo elgg_view_field([
'#type' => 'password',
'name' => 'f2',
Expand All @@ -35,6 +46,19 @@
'#label' => 'Radio input (.elgg-input-radios):',
]);

echo elgg_view_field([
'#type' => 'radio',
'name' => 'f3.1',
'id' => 'f3.1',
'disabled' => true,
'options' => [
'a (.elgg-input-radio)' => 1,
'b (.elgg-input-radio)' => 2
],
'value' => 2,
'#label' => 'Radio input (.elgg-field-disabled):',
]);

echo elgg_view_field([
'#type' => 'radio',
'name' => 'f3a',
Expand Down Expand Up @@ -662,6 +686,13 @@
'text' => 'Save',
'icon' => 'save',
],
[
'#type' => 'button',
'disabled' => true,
'type' => 'submit',
'text' => 'Save (disabled)',
'icon' => 'save',
],
[
'#type' => 'button',
'text' => 'Download',
Expand Down
6 changes: 4 additions & 2 deletions views/default/elements/forms.css.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
display: block;
}

label.elgg-state-disabled, .elgg-field-label.elgg-state-disabled {
opacity: 0.6;
.elgg-field-disabled {
.elgg-field-label {
opacity: 0.6;
}
}

.elgg-required-indicator {
Expand Down
5 changes: 4 additions & 1 deletion views/default/elements/forms/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

$class = elgg_extract_class($vars, 'elgg-field');
if (elgg_extract('required', $vars)) {
$class[] = "elgg-field-required";
$class[] = 'elgg-field-required';
}
if (elgg_extract('disabled', $vars)) {
$class[] = 'elgg-field-disabled';
}

$field = $label . $input . $help;
Expand Down
42 changes: 0 additions & 42 deletions views/default/elgg/admin.js

This file was deleted.

22 changes: 22 additions & 0 deletions views/default/forms/admin/site/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define(['jquery'], function ($) {

$('[name=require_admin_validation]').click(function() {
if ($(this).prop('checked')) {
$('.elgg-admin-users-admin-validation-notification').show();
} else {
$('.elgg-admin-users-admin-validation-notification').hide();
}
});

$('[name=simplecache_enabled]').click(function() {
// when the checkbox is disabled, do not toggle the compression checkboxes
var names = ['simplecache_minify_js', 'simplecache_minify_css', 'cache_symlink_enabled'];
for (var i = 0; i < names.length; i++) {
var $input = $('input[type!=hidden][name="' + names[i] + '"]');
if ($input.length) {
$input.attr('disabled', !$input.prop('disabled'));
$input.closest('.elgg-field').toggleClass('elgg-field-disabled');
}
}
});
});
2 changes: 2 additions & 0 deletions views/default/forms/admin/site/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* The site settings form
*/

elgg_require_js('forms/admin/site/settings');

echo elgg_view('forms/admin/site/settings/basic', $vars);
echo elgg_view('forms/admin/site/settings/i18n', $vars);
echo elgg_view('forms/admin/site/settings/users', $vars);
Expand Down
79 changes: 30 additions & 49 deletions views/default/forms/admin/site/settings/caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,70 @@
$is_simple_cache_on = (bool) elgg_get_config('simplecache_enabled');

$params = [
'label' => elgg_echo('installation:simplecache:label'),
'#type' => 'checkbox',
'#label' => elgg_echo('installation:simplecache:label'),
'#help' => elgg_echo('installation:simplecache:description'),
'name' => 'simplecache_enabled',
'switch' => true,
];

$simple_cache_warning = elgg_echo('installation:simplecache:description');
if (elgg()->config->hasInitialValue('simplecache_enabled')) {
$params['class'] = 'elgg-state-disabled';
$params['label_class'] = 'elgg-state-disabled';
$params['disabled'] = true;

// set checked state based on value in settings.php
$is_simple_cache_on = (bool) elgg()->config->getInitialValue('simplecache_enabled');

$simple_cache_warning .= "<span class=\"elgg-text-help\">" . elgg_echo('admin:settings:in_settings_file') . "</span>";
$params['#help'] .= ' ' . elgg_echo('admin:settings:in_settings_file');
}

$params['checked'] = $is_simple_cache_on;

$simple_cache_disabled_class = $is_simple_cache_on ? '' : 'elgg-state-disabled';

$simple_cache_input = elgg_view('input/checkbox', $params);
$body = elgg_view_field($params);

$cache_symlinked = _elgg_is_cache_symlinked();
$params = [
'label' => elgg_echo('installation:cache_symlink:label'),
'name' => 'cache_symlink_enabled',
'checked' => $cache_symlinked,
'class' => $simple_cache_disabled_class,
'label_class' => $simple_cache_disabled_class,
'switch' => true,
];
$symlink_warning = '<p class="elgg-text-help">' . elgg_echo('installation:cache_symlink:description') . '</p>';

$help = elgg_echo('installation:cache_symlink:description');
$help .= elgg_echo('installation:cache_symlink:paths', [elgg_get_root_path() . 'cache/', elgg_get_asset_path()]);
if ($cache_symlinked) {
$params['class'] = 'elgg-state-disabled';
$params['label_class'] = 'elgg-state-disabled';

$symlink_warning .= elgg_format_element('span', ['class' => 'elgg-text-help'], elgg_echo('installation:cache_symlink:warning'));
$help .= elgg_format_element('p', [], elgg_echo('installation:cache_symlink:warning'));
}

$symlink_input = elgg_view('input/checkbox', $params);
$symlink_source = elgg_get_root_path() . 'cache/';
$symlink_target = elgg_get_asset_path();
$symlink_paths_help = elgg_echo('installation:cache_symlink:paths', [$symlink_source, $symlink_target]);
$symlink_warning .= elgg_format_element('p', ['class' => 'elgg-text-help'], $symlink_paths_help);
$body .= elgg_view_field([
'#type' => 'checkbox',
'#label' => elgg_echo('installation:cache_symlink:label'),
'#help' => $help,
'name' => 'cache_symlink_enabled',
'checked' => $cache_symlinked,
'disabled' => !$is_simple_cache_on,
'switch' => true,
]);

// minify
$minify_description = elgg_echo('installation:minify:description');
$minify_js_input = elgg_view("input/checkbox", [
'label' => elgg_echo('installation:minify_js:label'),
$minify_help = elgg_echo('installation:minify:description');
$body .= elgg_view_field([
'#type' => 'checkbox',
'#label' => elgg_echo('installation:minify_js:label'),
'#help' => $minify_help,
'name' => 'simplecache_minify_js',
'checked' => (bool) elgg_get_config('simplecache_minify_js'),
'disabled' => !$is_simple_cache_on,
'label_class' => $simple_cache_disabled_class,
'switch' => true,
]);

$minify_css_input = elgg_view("input/checkbox", [
'label' => elgg_echo('installation:minify_css:label'),
$body .= elgg_view_field([
'#type' => 'checkbox',
'#label' => elgg_echo('installation:minify_css:label'),
'#help' => $minify_help,
'name' => 'simplecache_minify_css',
'checked' => (bool) elgg_get_config('simplecache_minify_css'),
'disabled' => !$is_simple_cache_on,
'label_class' => $simple_cache_disabled_class,
'switch' => true,
]);

$system_cache_input = elgg_view_field([
$body .= elgg_view_field([
'#type' => 'checkbox',
'#label' => elgg_echo('installation:systemcache:label'),
'#help' => elgg_echo('installation:systemcache:description'),
Expand All @@ -81,22 +80,4 @@
'checked' => elgg_is_system_cache_enabled(),
]);

$body = <<<BODY
<div>
$simple_cache_input
<p class="elgg-text-help">$simple_cache_warning</p>
</div>
<div>
$symlink_input
$symlink_warning
</div>
<div>
<p>$minify_description</p>
$minify_js_input<br />
$minify_css_input
</div>
$system_cache_input
BODY;

echo elgg_view_module('info', elgg_echo('admin:legend:caching'), $body, ['id' => 'elgg-settings-advanced-caching']);
6 changes: 5 additions & 1 deletion views/default/resources/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
// Make sure the 'site' css isn't loaded
elgg_unregister_external_file('css', 'elgg');

elgg_require_js('elgg/admin');
if (elgg_view_exists('elgg/admin.js')) {
elgg_deprecated_notice('No longer rely on the presence of the generic elgg/admin.js. Include your own AMD js module.', '4.3');

elgg_require_js('elgg/admin');
}

$segments = explode('/', trim(elgg_extract('segments', $vars, ''), '/'));

Expand Down
2 changes: 0 additions & 2 deletions views/default/resources/admin/plugin_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// Make sure the 'site' css isn't loaded
elgg_unregister_external_file('css', 'elgg');

elgg_require_js('elgg/admin');

$plugin_id = elgg_extract('plugin_id', $vars);
$plugin = elgg_get_plugin_from_id($plugin_id);
if (!$plugin instanceof ElggPlugin) {
Expand Down
1 change: 0 additions & 1 deletion views/default/resources/admin/plugin_text_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
$filename = elgg_extract('filename', $vars);

elgg_unregister_external_file('css', 'elgg');
elgg_require_js('elgg/admin');

if (!$plugin) {
$error = elgg_echo('admin:plugins:markdown:unknown_plugin');
Expand Down

0 comments on commit b95821f

Please sign in to comment.