Connect update fluics template button with controller action [SCI-7261]

This commit is contained in:
Oleksii Kriuchykhin 2022-09-26 22:58:09 +02:00
parent 8ca02ec619
commit 0e95b7ea66
5 changed files with 21 additions and 15 deletions

View file

@ -113,7 +113,18 @@
});
}
function tableDrowCallback() {
function initRefreshFluicsButton() {
$('#syncFluicsTemplates').on('click', function() {
$.post(this.dataset.url, function(response) {
reloadTable();
HelperModule.flashAlertMsg(response.message, 'success');
}).error((response) => {
HelperModule.flashAlertMsg(response.responseJSON.error, 'danger');
});
});
}
function tableDrawCallback() {
initToggleAllCheckboxes();
initRowSelection();
}
@ -256,7 +267,7 @@
oLanguage: {
sSearch: I18n.t('general.filter')
},
fnDrawCallback: tableDrowCallback,
fnDrawCallback: tableDrawCallback,
createdRow: addAttributesToRow,
fnInitComplete: function() {
DataTableHelpers.initLengthAppearance($table.closest('.dataTables_wrapper'));
@ -272,6 +283,7 @@
initSetDefaultButton();
initDuplicateButton();
initDeleteModal();
initRefreshFluicsButton();
}
});
}

View file

@ -144,7 +144,7 @@ class LabelTemplatesController < ApplicationController
sync_service = LabelPrinters::Fluics::SyncService.new(current_user, current_team)
sync_service.sync_templates!
render json: { message: t('label_templates.fluics.sync.success') }
rescue ActiveRecord::RecordInvalid => e
rescue StandardError => e
Rails.logger.error e.message
render json: { error: t('label_templates.fluics.sync.error') }, status: :unprocessable_entity
end

View file

@ -6,7 +6,7 @@
<span class="button-text"><%= t('label_templates.index.toolbar.new') %></span>
</button>
<button title="<%= t('label_templates.index.toolbar.check_for_updates') %>"
class="btn btn-light auto-shrink-button nonselected-actions " id="checkFluicsUpdates">
class="btn btn-light auto-shrink-button nonselected-actions" id="syncFluicsTemplates" data-url="<%= sync_fluics_templates_label_templates_path %>">
<%= image_tag 'label_template_icons/fluics_update.svg' %>
<span class="button-text"><%= t('label_templates.index.toolbar.check_for_updates') %></span>
</button>

View file

@ -805,16 +805,6 @@ en:
normal_user: "Normal user"
admin: "Administrator"
label_templates:
fluics:
sync:
success: 'Refresh successful'
error: 'Refresh unsuccessful'
repository_row:
errors:
unsupported_key: "Key %{key} is not supported by this label template renderer."
column_not_found: "Column '%{column}' not found on inventory item."
user_projects:
view_users:
modal_title: "Members of %{name}"
@ -834,12 +824,15 @@ en:
default_zebra_name: 'SciNote Item (ZPL)'
default_fluics_name: 'SciNote Item (Fluics)'
new_label_template: 'New label'
fluics:
sync:
success: 'Fluics label templates successfully updated'
error: 'Update of Fluics label templates was unsuccessful'
repository_row:
errors:
unsupported_key: "Key %{key} is not supported by this label template renderer."
column_not_found: "This Label template contains placeholders for inventory columns that are not present in this Inventory. Some data might not be printed on the label. Please check the label preview and label template before printing."
logo_not_supported: "The company logo cannot be printed on the label, as it is not set up in your SciNote. Please upload company logo in Settings."
index:
head_title: 'Label templates'
search_templates: 'Filter templates'

View file

@ -55,6 +55,7 @@ Rails.application.routes.draw do
get :datatable
get :template_tags
get :zpl_preview
post :sync_fluics_templates
end
end