mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-28 07:00:24 +08:00
Update archive action for protocol templates [SCI-7898]
This commit is contained in:
parent
23e50cf710
commit
b55f68c0dc
5 changed files with 22 additions and 34 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
//= require protocols/import_export/import
|
//= require protocols/import_export/import
|
||||||
/* eslint-disable no-use-before-define, no-underscore-dangle, max-len */
|
/* eslint-disable no-use-before-define, no-underscore-dangle, max-len */
|
||||||
/* global ProtocolRepositoryHeader PdfPreview DataTableHelpers importProtocolFromFile _
|
/* global ProtocolRepositoryHeader PdfPreview DataTableHelpers importProtocolFromFile _
|
||||||
dropdownSelector filterDropdown I18n animateSpinner initHandsOnTable inlineEditing */
|
dropdownSelector filterDropdown I18n animateSpinner initHandsOnTable inlineEditing HelperModule */
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
var ProtocolsIndex = (function() {
|
var ProtocolsIndex = (function() {
|
||||||
|
|
@ -410,6 +410,21 @@ var ProtocolsIndex = (function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initArchiveMyModules() {
|
||||||
|
$('.protocols-index').on('click', '#archiveProtocol', function(e) {
|
||||||
|
archiveMyModules(e.currentTarget.dataset.url, rowsSelected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function archiveMyModules(url, ids) {
|
||||||
|
$.post(url, { protocol_ids: ids }, (data) => {
|
||||||
|
HelperModule.flashAlertMsg(data.message, 'success');
|
||||||
|
protocolsDatatable.ajax.reload();
|
||||||
|
}).error((data) => {
|
||||||
|
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function initLinkedChildrenModal() {
|
function initLinkedChildrenModal() {
|
||||||
// Only do this if the repository is public/private
|
// Only do this if the repository is public/private
|
||||||
if (repositoryType !== 'archive') {
|
if (repositoryType !== 'archive') {
|
||||||
|
|
@ -926,6 +941,7 @@ var ProtocolsIndex = (function() {
|
||||||
|
|
||||||
init();
|
init();
|
||||||
initManageAccessButton();
|
initManageAccessButton();
|
||||||
|
initArchiveMyModules();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
reloadTable: function() {
|
reloadTable: function() {
|
||||||
|
|
|
||||||
|
|
@ -1080,26 +1080,10 @@ class ProtocolsController < ApplicationController
|
||||||
|
|
||||||
def move_protocol(action)
|
def move_protocol(action)
|
||||||
rollbacked = false
|
rollbacked = false
|
||||||
results = []
|
|
||||||
begin
|
begin
|
||||||
Protocol.transaction do
|
Protocol.transaction do
|
||||||
@protocols.find_each do |protocol|
|
@protocols.find_each do |protocol|
|
||||||
result = {
|
protocol.method(action).call(current_user)
|
||||||
name: protocol.name
|
|
||||||
}
|
|
||||||
|
|
||||||
success = protocol.method(action).call(current_user)
|
|
||||||
|
|
||||||
# Try renaming protocol
|
|
||||||
unless success
|
|
||||||
rename_record(protocol, :name)
|
|
||||||
success = protocol.method(action).call(current_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
result[:new_name] = protocol.name
|
|
||||||
result[:type] = protocol.protocol_type
|
|
||||||
result[:success] = success
|
|
||||||
results << result
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
|
|
@ -1113,12 +1097,7 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
format.json do
|
format.json do
|
||||||
render json: {
|
render json: { message: t("protocols.index.#{action}_flash_html", count: @protocols.size) }
|
||||||
html: render_to_string({
|
|
||||||
partial: "protocols/index/results_modal_body.html.erb",
|
|
||||||
locals: { results: results, en_action: "#{action}_results" }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -445,20 +445,12 @@ class Protocol < ApplicationRecord
|
||||||
self.archived_on = Time.now
|
self.archived_on = Time.now
|
||||||
self.restored_by = nil
|
self.restored_by = nil
|
||||||
self.restored_on = nil
|
self.restored_on = nil
|
||||||
self.protocol_type = Protocol.protocol_types[:in_repository_archived]
|
self.archived = true
|
||||||
result = save
|
result = save
|
||||||
|
|
||||||
# Update all module protocols that had
|
# Update all module protocols that had
|
||||||
# parent set to this protocol
|
# parent set to this protocol
|
||||||
if result
|
if result
|
||||||
Protocol.where(parent: self).find_each do |p|
|
|
||||||
p.update(
|
|
||||||
parent: nil,
|
|
||||||
parent_updated_at: nil,
|
|
||||||
protocol_type: :unlinked
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
Activities::CreateActivityService
|
Activities::CreateActivityService
|
||||||
.call(activity_type: :archive_protocol_in_repository,
|
.call(activity_type: :archive_protocol_in_repository,
|
||||||
owner: user,
|
owner: user,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<i class="fas fa-download"></i>
|
<i class="fas fa-download"></i>
|
||||||
<span class="button-text"><%= t("protocols.index.action_toolbar.export") %></span>
|
<span class="button-text"><%= t("protocols.index.action_toolbar.export") %></span>
|
||||||
</button>
|
</button>
|
||||||
<button id="archiveProtocol" class="btn btn-light multiple-object-action hidden only-active" data-for="archivable">
|
<button id="archiveProtocol" class="btn btn-light multiple-object-action hidden only-active" data-url="<%= archive_protocols_path %>" data-for="archivable">
|
||||||
<i class="fas fa-archive"></i>
|
<i class="fas fa-archive"></i>
|
||||||
<span class="button-text"><%= t("protocols.index.action_toolbar.archive") %></span>
|
<span class="button-text"><%= t("protocols.index.action_toolbar.archive") %></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
|
|
@ -2584,6 +2584,7 @@ en:
|
||||||
make_private: "Move to My Protocols"
|
make_private: "Move to My Protocols"
|
||||||
publish: "Move to Team protocols"
|
publish: "Move to Team protocols"
|
||||||
archive_action: "Archive"
|
archive_action: "Archive"
|
||||||
|
archive_flash_html: "<b>%{count} protocol</b> template(s) successfully archived."
|
||||||
thead:
|
thead:
|
||||||
name: "Name"
|
name: "Name"
|
||||||
id: "ID"
|
id: "ID"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue