From 783d5d03ab820e881b701d7bc509c6fa17362f59 Mon Sep 17 00:00:00 2001 From: ajugo Date: Mon, 8 May 2023 11:27:29 +0200 Subject: [PATCH] Add edit button to label templates and fix last updated by [SCI-8373] (#5376) --- .../label_templates/label_templates_datatable.js | 14 ++++++++++++-- app/controllers/label_templates_controller.rb | 3 ++- app/views/label_templates/_index_toolbar.html.erb | 4 ++++ config/locales/en.yml | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/label_templates/label_templates_datatable.js b/app/assets/javascripts/label_templates/label_templates_datatable.js index 5b9288737..369747a45 100644 --- a/app/assets/javascripts/label_templates/label_templates_datatable.js +++ b/app/assets/javascripts/label_templates/label_templates_datatable.js @@ -38,8 +38,7 @@ function renderNameHTML(data, type, row) { return `${data.icon_image_tag}${data.name}`; } @@ -79,6 +78,14 @@ }); } + function initEditButton() { + $('#editTemplate').on('click', function() { + if (rowsSelected.length === 1) { + window.location.href = rowsSelected[0].editUrl; + } + }); + } + function initDuplicateButton() { $('#duplicateLabelTemplate').on('click', function() { if (rowsSelected.length > 0) { @@ -138,6 +145,7 @@ $('.fluics-warning').addClass('hidden'); $('.selected-actions').removeClass('hidden'); $('.nonselected-actions').addClass('hidden'); + $('.selected-one-actions').toggleClass('hidden', (rowsSelected.length > 1)); if (labelFormats() === 'ZPL') { $('#deleteLabelTemplate').toggleClass('hidden', defaultSelected()); $('#setZplDefaultLabelTemplate').toggleClass('hidden', (rowsSelected.length > 1 || defaultSelected())); @@ -149,6 +157,7 @@ $('#setFluicsDefaultLabelTemplate').toggleClass('hidden', (rowsSelected.length > 1 || defaultSelected())); $('.fluics-warning').removeClass('hidden'); } else { + $('.selected-one-actions').addClass('hidden'); $('.fluics-warning').removeClass('hidden'); $('.selected-actions').addClass('hidden'); } @@ -281,6 +290,7 @@ let toolBar = $($('#labelTemplatesToolbar').html()); $('.label-buttons-container').html(toolBar); initCreateButton(); + initEditButton(); initSetDefaultButton(); initDuplicateButton(); initDeleteModal(); diff --git a/app/controllers/label_templates_controller.rb b/app/controllers/label_templates_controller.rb index 1577219df..b7ca710ce 100644 --- a/app/controllers/label_templates_controller.rb +++ b/app/controllers/label_templates_controller.rb @@ -63,7 +63,8 @@ class LabelTemplatesController < ApplicationController def update @label_template.transaction do - @label_template.update!(label_template_params) + update_label_template_params = label_template_params.merge(last_modified_by_id: current_user.id) + @label_template.update!(update_label_template_params) log_activity(:label_template_edited, @label_template) end render json: @label_template, serializer: LabelTemplateSerializer, user: current_user diff --git a/app/views/label_templates/_index_toolbar.html.erb b/app/views/label_templates/_index_toolbar.html.erb index 16d948755..63d6652a5 100644 --- a/app/views/label_templates/_index_toolbar.html.erb +++ b/app/views/label_templates/_index_toolbar.html.erb @@ -10,6 +10,10 @@ <%= image_tag 'label_template_icons/fluics_update.svg' %> <%= t('label_templates.index.toolbar.check_for_updates') %> +