mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-30 11:41:19 +08:00
Change printing status modal logic [SCI-6034]
This commit is contained in:
parent
ccc2964aff
commit
6484dfe630
5 changed files with 41 additions and 36 deletions
|
@ -1,32 +1,33 @@
|
||||||
function updateProgressModal() {
|
(function() {
|
||||||
var status;
|
function updateProgressModal() {
|
||||||
var modal = $(document).find('.label-printing-progress-modal');
|
var modal = $('.label-printing-progress-modal');
|
||||||
|
|
||||||
if (modal.length === 0) {
|
if (modal.length === 0) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.getJSON(
|
$.getJSON(
|
||||||
`/label_printers/${modal.data('labelPrinterId')}/update_progress_modal`
|
modal.data('progress-url'), function(data) {
|
||||||
+ `?starting_item_count=${modal.data('startingItemCount')}`,
|
modal.replaceWith(data.html);
|
||||||
function(data) {
|
let status = modal.data('label-printer-status');
|
||||||
modal.replaceWith(data.html);
|
if (!['done', 'error'].includes(status)) {
|
||||||
|
setTimeout(updateProgressModal, 3000);
|
||||||
status = modal.data('label-printer-status');
|
}
|
||||||
if (status !== 'done' && status !== 'error') {
|
|
||||||
setTimeout(updateProgressModal, 3000);
|
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).on('click', '.label-printing-progress-modal .close', function() {
|
|
||||||
$(this).closest('.label-printing-progress-modal').remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('turbolinks:load', function() {
|
|
||||||
var modal = $(document).find('.label-printing-progress-modal');
|
|
||||||
if (modal.length > 0) {
|
|
||||||
updateProgressModal();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
$(document).on('click', '.label-printing-progress-modal .close', function() {
|
||||||
|
$(this).closest('.label-printing-progress-modal').remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('ajax:success', '.print-label-form', function(e, data) {
|
||||||
|
var modal = $('.label-printing-progress-modal');
|
||||||
|
if (modal.length) {
|
||||||
|
modal.replaceWith(data.html);
|
||||||
|
} else {
|
||||||
|
$('body').append($(data.html));
|
||||||
|
}
|
||||||
|
|
||||||
|
updateProgressModal();
|
||||||
|
$('#modal-print-repository-row-label').modal('hide');
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
|
|
@ -109,7 +109,13 @@ class RepositoryRowsController < ApplicationController
|
||||||
|
|
||||||
label_printer.update!(current_print_job_ids: job_ids * params[:copies].to_i)
|
label_printer.update!(current_print_job_ids: job_ids * params[:copies].to_i)
|
||||||
|
|
||||||
redirect_to repository_path(@repository)
|
render json: {
|
||||||
|
html: render_to_string(
|
||||||
|
partial: 'label_printers/print_progress_modal.html.erb',
|
||||||
|
locals: { starting_item_count: label_printer.current_print_job_ids.length,
|
||||||
|
label_printer: label_printer }
|
||||||
|
)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<div class="label-printing-progress-modal" data-label-printer-status="<%= label_printer.printing_status %>" data-label-printer-id="<%= label_printer.id %>" data-starting-item-count="<%= starting_item_count %>">
|
<div class="label-printing-progress-modal"
|
||||||
|
data-label-printer-status="<%= label_printer.printing_status %>" data-label-printer-id="<%= label_printer.id %>"
|
||||||
|
data-starting-item-count="<%= starting_item_count %>"
|
||||||
|
data-progress-url="<%= update_progress_modal_label_printer_path(label_printer, starting_item_count: starting_item_count) %>">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<%= label_printer.name %>
|
<%= label_printer.name %>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<% if @printers.size > 0 %>
|
<% if @printers.size > 0 %>
|
||||||
<%= form_tag print_repository_repository_rows_path do %>
|
<%= form_tag print_repository_repository_rows_path, { class: 'print-label-form', data: { remote: true } } do %>
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
<h4 class="modal-title">
|
<h4 class="modal-title">
|
||||||
|
|
|
@ -159,11 +159,6 @@
|
||||||
<%= render partial: 'repositories/import_repository_records_modal',
|
<%= render partial: 'repositories/import_repository_records_modal',
|
||||||
locals: { repository: @repository } %>
|
locals: { repository: @repository } %>
|
||||||
|
|
||||||
<% if @busy_printer %>
|
|
||||||
<%= render(
|
|
||||||
partial: 'label_printers/print_progress_modal',
|
|
||||||
locals: { starting_item_count: @busy_printer.current_print_job_ids.length, label_printer: @busy_printer }) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render partial: "repositories/delete_record_modal" %>
|
<%= render partial: "repositories/delete_record_modal" %>
|
||||||
<%= render partial: 'repositories/export_repository_modal',
|
<%= render partial: 'repositories/export_repository_modal',
|
||||||
|
|
Loading…
Reference in a new issue