Skip to content

Commit

Permalink
Merge branch '3-7-stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed Oct 25, 2024
2 parents f865131 + 296ff04 commit 1a84226
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

= 3.7.9 (not released yet)
- Add css_class to action links, to avoid changing name, it may result confusing, deprecate name setter
- Add buttons to check all and uncheck all on :select form ui for collection associations, and draggable lists (active_scaffold_checkbox_list)

= 3.7.8
- Rollback previous behaviour when submitting empty values, broken when default_value was added. Default value set in column is not used when trying to save empty value, DB default is used in that case, and save NULL when string is empty, as before.
Expand Down
1 change: 1 addition & 0 deletions app/assets/images/active_scaffold/fast-arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/images/active_scaffold/fast-arrow-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 25 additions & 4 deletions app/assets/javascripts/jquery/active_scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,15 @@
jQuery(event.target).closest('.action_group.dyn > ul').remove();
});

jQuery(document).on('change', 'input.update_form:not(.recordselect), textarea.update_form, select.update_form, .checkbox-list.update_form input:checkbox', function(event) {
jQuery(document).on('change', 'input.update_form:not(.recordselect), textarea.update_form, select.update_form, .checkbox-list.update_form input:checkbox', function(event, additional_params) {
var element = jQuery(this);
var form_element;
var value, additional_params;
var value;
if (element.is(".checkbox-list input:checkbox")) {
form_element = element.closest('.checkbox-list')
form_element = element.closest('.checkbox-list');
if (form_element.is('.draggable-list')) form_element = form_element.closest('.draggable-lists-container').find('.checkbox-list') // draggable lists will have 2 lists
value = form_element.find(':checked').map(function(item){return $(this).val();}).toArray();
additional_params = (element.is(':checked') ? '_added=' : '_removed=') + element.val();
if (!additional_params) additional_params = (element.is(':checked') ? '_added=' : '_removed=') + element.val();
} else {
value = element.is("input:checkbox:not(:checked)") ? null : element.val();
form_element = element;
Expand Down Expand Up @@ -437,6 +438,14 @@
var search = $(this).find('form.search');
if (search.length) ActiveScaffold.focus_first_element_of_form(search);
});
jQuery(document).on('click', '.active-scaffold form .check-all', function(e) {
e.preventDefault();
ActiveScaffold.update_all_checkboxes($(this), true);
});
jQuery(document).on('click', '.active-scaffold form .uncheck-all', function(e) {
e.preventDefault();
ActiveScaffold.update_all_checkboxes($(this), false);
});
});

jQuery(document).on('turbolinks:load turbo:load', function($) {
Expand Down Expand Up @@ -1169,6 +1178,18 @@
});
},

update_all_checkboxes: function(button, state) {
var lists = button.closest('.check-buttons').parent().find('.checkbox-list'),
checkboxes = lists.find(':checkbox'), key = state ? '_added' : '_removed', params;
params = checkboxes.filter(state ? ':not(:checked)' : ':checked').map(function() { return key + '[]=' + $(this).val(); }).toArray().join('&');
checkboxes.prop('checked', state);
if (lists.filter('.draggable-list').length) {
var parent = state ? lists.filter('.selected') : lists.filter(':not(.selected)');
checkboxes.parent().appendTo(parent);
}
checkboxes.first().trigger('change', params);
},

draggable_lists: function(selector_or_elements, parent) {
var elements;
if (!jQuery.fn.draggableLists) return;
Expand Down
6 changes: 5 additions & 1 deletion app/assets/javascripts/jquery/draggable_lists.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
(function() {
function enableDraggableLists(element) {
if (element.hasClass('draggable-list')) return;
element.parent().addClass('draggable-lists-container');
element.addClass('draggable-list');
var list_selected = jQuery(element.get(0).cloneNode(false)).addClass('selected');
var list_selected = jQuery(element.get(0).cloneNode(false)).addClass('selected'),
check_buttons = element.siblings('.check-buttons');
list_selected.attr('id', list_selected.attr('id') + '_selected').insertAfter(element);
element.find('input:checkbox').each(function(index, item) {
var li = jQuery(item).closest('li').addClass('draggable-item');
li.children('label').removeAttr('for');
if (jQuery(item).is(':checked')) li.appendTo(list_selected);
});
check_buttons.find('.check-all, .uncheck-all').attr('title', function() { return $(this).text() });
element.after(check_buttons);
var options = {
hoverClass: 'hover',
containment: '',
Expand Down
16 changes: 16 additions & 0 deletions app/assets/stylesheets/active_scaffold_images.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ background-image: image-url('active_scaffold/arrow_up.png');
background-image: image-url('active_scaffold/arrow_down.png');
}


.active-scaffold .draggable-lists-container .check-buttons {
.check-all, .uncheck-all {
background-image: image-url('active_scaffold/fast-arrow-right.svg');
background-repeat: no-repeat;
background-size: contain;
width: 16px;
text-indent: 20px;
overflow: hidden;
white-space: nowrap;
}
.uncheck-all {
background-image: image-url('active_scaffold/fast-arrow-left.svg');
}
}

.active-scaffold th.loading a {
background-image: image-url('active_scaffold/indicator-small.gif');
}
Expand Down
25 changes: 21 additions & 4 deletions app/assets/stylesheets/active_scaffold_layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,9 @@ padding: 0 0 0 2px;
.active-scaffold .checkbox-list + .refresh-link {
float: left;
}

.active-scaffold .draggable-lists + .loading-indicator { float: left; }
.active-scaffold .check-buttons .check-all {
margin-right: 10px;
}

.active-scaffold .draggable-list {
float: left;
Expand All @@ -811,9 +812,25 @@ min-height: 30px;
max-height: 100px;
overflow: auto;
}

.active-scaffold .draggable-list.hover {
opacity: 0.5;
opacity: 0.5;
}
.active-scaffold .draggable-lists-container {
display: flex;
align-items: start;
}
.active-scaffold .draggable-lists-container .loading-indicator { align-self: end; }

.active-scaffold .draggable-lists-container .check-buttons {
margin-right: 15px;
align-self: stretch;
display: flex;
flex-direction: column;
justify-content: center;
}
.active-scaffold .draggable-lists-container .check-buttons a {
display: block;
margin: 0;
}


Expand Down
2 changes: 2 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ de:
cancel: Abbrechen
cant_destroy_record: "%{record} kann nicht gelöscht werden"
changes: Änderungen
check_all:
click_to_edit: Zum Editieren anklicken
click_to_reset: Reset
close: Schließen
Expand Down Expand Up @@ -131,6 +132,7 @@ de:
today: Heute
tomorrow: Morgen
'true': Richtig
uncheck_all:
update: Speichern
update_apply: Bewerben
update_model: Editiere %{model}
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ en:
cancel: Cancel
cant_destroy_record: "%{record} can't be destroyed"
changes: Changes
check_all: Check all
click_to_edit: Click to edit
click_to_reset: Click to reset
close: Close
Expand Down Expand Up @@ -131,6 +132,7 @@ en:
today: Today
tomorrow: Tomorrow
'true': 'True'
uncheck_all: Uncheck all
update: Update
update_apply: Apply
update_model: Update %{model}
Expand Down
2 changes: 2 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ es:
cancel: Cancelar
cant_destroy_record: No se pudo borrar %{record}
changes: Cambios
check_all: Seleccionar todo
click_to_edit: Pulsa para editar
click_to_reset: Pulsa para restaurar
close: Cerrar
Expand Down Expand Up @@ -133,6 +134,7 @@ es:
today: Hoy
tomorrow: Mañana
'true':
uncheck_all: Deseleccionar todo
update: Actualizar
update_apply: Aplicar
update_model: Actualizar %{model}
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fr:
cancel: Annuler
cant_destroy_record: "%{record} ne peut être supprimé"
changes: Changement
check_all:
click_to_edit: Cliquer pour éditer
click_to_reset: Cliquer pour ré-initialiser
close: Fermer
Expand Down Expand Up @@ -131,6 +132,7 @@ fr:
today: Aujourd'hui
tomorrow: Demain
'true': Vrai
uncheck_all:
update: Mettre à jour
update_apply: Appliquer
update_model: Mettre à jour le(/la) %{model}
Expand Down
6 changes: 4 additions & 2 deletions config/locales/hu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ hu:
cancel: Mégse
cant_destroy_record: 'nem törölhető: %{record}'
changes:
check_all:
click_to_edit: Kattints a szerkesztéshez
click_to_reset: Kattints az alapállapothoz
close: Bezárás
Expand All @@ -41,7 +42,7 @@ hu:
closeText:
currentText:
timeText:
timezoneText:
timezoneText: Timezone
days: Days
delete: Törlés
deleted_model: "%{model} törölve"
Expand Down Expand Up @@ -112,7 +113,7 @@ hu:
refresh: Frissítés
remove: Törlés
remove_file: Fájl törlése, vagy cseréje
remove_files:
remove_files: Fájlok törlése, vagy hozzáadása
replace_existing: Replace existing
replace_with_new: Csere újjal
reset: Alapállapot
Expand All @@ -131,6 +132,7 @@ hu:
today: Today
tomorrow: Tomorrow
'true': 'True'
uncheck_all:
update: Modosítás
update_apply:
update_model: "%{model} modosítása"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ja:
cancel: キャンセル
cant_destroy_record: "%{record}を削除できません"
changes: 差分
check_all:
click_to_edit: クリックして編集
click_to_reset: クリックしてリセット
close: 閉じる
Expand Down Expand Up @@ -131,6 +132,7 @@ ja:
today: 今日
tomorrow: 明日
'true':
uncheck_all:
update: 更新
update_apply:
update_model: "%{model}を更新"
Expand Down
4 changes: 3 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ru:
cancel: Отмена
cant_destroy_record: Запись %{record} не может быть удалена
changes:
check_all:
click_to_edit: Нажмите для редактирования
click_to_reset: Нажмите для сброса
close: Закрыть
Expand All @@ -41,7 +42,7 @@ ru:
closeText: Закрыть
currentText: Текущее время
timeText:
timezoneText:
timezoneText: Timezone
days: дней
delete: Удалить
deleted_model: "%{model}: запись удалена"
Expand Down Expand Up @@ -139,6 +140,7 @@ ru:
today: Сегодня
tomorrow: Завтра
'true': Да
uncheck_all:
update: Обновить запись
update_apply:
update_model: "%{model}: обновить запись"
Expand Down
10 changes: 9 additions & 1 deletion lib/active_scaffold/helpers/form_column_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,17 @@ def active_scaffold_checkbox_option(option, label_method, associated_ids, checkb
end
end

def active_scaffold_check_all_buttons(column, options, ui_options: column.options)
content_tag(:div, class: 'check-buttons') do
link_to(as_(:check_all), '#', class: 'check-all') <<
link_to(as_(:uncheck_all), '#', class: 'uncheck-all')
end
end

def active_scaffold_checkbox_list(column, select_options, associated_ids, options, ui_options: column.options)
label_method = ui_options[:label_method] || :to_label
html = hidden_field_tag("#{options[:name]}[]", '', :id => nil)
html = active_scaffold_check_all_buttons(column, options, ui_options: ui_options)
html << hidden_field_tag("#{options[:name]}[]", '', :id => nil)
draggable = options.delete(:draggable_lists) || ui_options[:draggable_lists]
html << content_tag(:ul, options.merge(:class => "#{options[:class]} checkbox-list#{' draggable-lists' if draggable}")) do
content = []
Expand Down

0 comments on commit 1a84226

Please sign in to comment.