diff --git a/app/views/dmsf_upload/_form.html.erb b/app/views/dmsf_upload/_form.html.erb index a3fb198e..ac130c2a 100644 --- a/app/views/dmsf_upload/_form.html.erb +++ b/app/views/dmsf_upload/_form.html.erb @@ -80,7 +80,9 @@ files = [] project_or_folder.dmsf_files.visible.each do |dmsf_file| rev = dmsf_file.last_revision - files << [dmsf_file.name, rev.major_version, rev.minor_version, rev.patch_version ] if rev + if rev + files << [dmsf_file.name, rev.major_version, rev.minor_version, rev.patch_version, dmsf_file.locked_for_user? ] + end end %> <%= file_field_tag 'dmsf_attachments[dummy][file]', @@ -100,6 +102,9 @@ dmsf_file_details_form: controller.send(:render_to_string, { partial: 'dmsf_upload/upload_file', locals: { upload: DmsfUpload.new(project, folder, nil), i: 0 } }), + dmsf_file_details_form_locked: controller.send(:render_to_string, + { partial: 'dmsf_upload/upload_file_locked', + locals: { upload: DmsfUpload.new(project, folder, nil), i: 0 } }), files: JSON.generate(files) } %> diff --git a/app/views/dmsf_upload/_upload_file_locked.html.erb b/app/views/dmsf_upload/_upload_file_locked.html.erb index 6685cb72..49fef6e9 100644 --- a/app/views/dmsf_upload/_upload_file_locked.html.erb +++ b/app/views/dmsf_upload/_upload_file_locked.html.erb @@ -19,68 +19,48 @@ %>
- <%= hidden_field_tag "committed_files[#{i}][disk_filename]", upload.disk_filename %> - <%= hidden_field_tag "committed_files[#{i}][token]", upload.token %> - <%= hidden_field_tag "committed_files[#{i}][size]", upload.size %> - <%= hidden_field_tag "committed_files[#{i}][mime_type]", upload.mime_type %> - <%= hidden_field_tag "committed_files[#{i}][name]", upload.name %> - <%= hidden_field_tag "committed_files[#{i}][digest]", upload.digest %>

<%= l(:info_file_locked) %>

- <%= label_tag '', l(:label_title) %> - <%= text_field_tag :name, h(upload.title), readonly: true %> + <%= label_tag "committed_files[#{i}][title]", l(:label_title) %> + <%= text_field_tag "committed_files[#{i}][title]", upload.title, readonly: true %>

- <%= label_tag '', l(:label_filename) %> - <%= text_field_tag :name, h(upload.name), readonly: true %> + <%= label_tag "committed_files[#{i}][name]", l(:label_filename) %> + <%= text_field_tag "committed_files[#{i}][name]", upload.name, readonly: true %>

- <% if upload.description.present? %> -

- <%= label_tag '', l(:label_description) %> -

- <%= textilizable upload.description %> -
-

- <% end %>

- <%= label_tag '', l(:label_dmsf_version) %> - <%= text_field_tag :name, + <%= label_tag "committed_files[#{i}][version]", l(:label_dmsf_version) %> + <%= text_field_tag "committed_files[#{i}][version]", "#{DmsfUploadHelper::gui_version(upload.major_version)}.#{DmsfUploadHelper::gui_version(upload.minor_version)}", readonly: true %>

- <%= label_tag '', l(:label_mime) %> - <%= text_field_tag :name, h(upload.mime_type), readonly: true %> + <%= label_tag "committed_files[#{i}][mime_type]", l(:label_mime) %> + <%= text_field_tag "committed_files[#{i}][mime_type]", upload.mime_type, readonly: true %>

- <%= label_tag '', l(:label_size) %> - <%= text_field_tag :name, h(number_to_human_size(upload.size)), readonly: true %> + <%= label_tag "committed_files[#{i}][size]", l(:label_size) %> + <%= text_field_tag "committed_files[#{i}][size]", number_to_human_size(upload.size), readonly: true %>

<% upload.custom_values.each do |value| %>

- <%= label_tag '', h(value.custom_field.name) %> + <%= label_tag "committed_files[#{i}][#{value.custom_field.id}]", value.custom_field.name %> <% value.value = nil if value.custom_field.dmsf_not_inheritable %> - <%= text_field_tag :name, h(value.value), readonly: true %> + <%= text_field_tag "committed_files[#{i}][#{value.custom_field.id}]", value.value, readonly: true %>

<% end %>
- <% if upload.comment.present? %> -

- <%= label_tag '', l(:label_comment) %> -

<%= textilizable upload.comment %>
-

- <% end %>
diff --git a/assets/javascripts/attachments_dmsf.js b/assets/javascripts/attachments_dmsf.js index 333c569d..357ed155 100644 --- a/assets/javascripts/attachments_dmsf.js +++ b/assets/javascripts/attachments_dmsf.js @@ -97,6 +97,36 @@ function getNextVersion(filename, files) { return [0, 1, null]; } +/* Get the current version */ +function getCurrentVersion(filename, files) { + for(let i = 0; i < files.length; i++) { + if (filename === files[i][0]) { + let res = ''; + if (files[i][3] != null) { + res = '.' + files[i][3]; + } + if (files[i][2] != null) { + res = '.' + files[i][2] + res; + } + if (files[i][1] != null) { + res = files[i][1] + res; + } + return res; + } + } + return '0.1.0'; +} + +/* Detects locked file */ +function isFileLocked(filename, files) { + for(let i = 0; i < files.length; i++) { + if (filename === files[i][0]) { + return files[i][4]; + } + } + return false; +} + /* Replace selected version */ function replaceVersion(detailsForm, attachmentId, name, version) { let index = detailsForm.search('id="committed_files_' + attachmentId + '_version_' + name + '"'); @@ -149,10 +179,9 @@ function dmsfAddFile(inputEl, file, eagerUpload) { } // Details - let detailsForm = $(inputEl).data('dmsf-file-details-form'); let detailsDiv = $('
').attr({id: 'dmsf_attachments_details_' + attachmentId}); let detailsArrow = $(''); - + detailsArrow.text('[+]'); detailsArrow.attr({href: "#", 'data-cy': 'toggle__new_revision_from_content--dmsf', title: 'Details'}); detailsArrow.attr( @@ -164,6 +193,10 @@ function dmsfAddFile(inputEl, file, eagerUpload) { "$('#dmsf-upload-button').hide();" + "return false;" }); + let files = $(inputEl).data('files'); + let locked = isFileLocked(file.name, files); + let detailsForm = $(inputEl).data(locked ? 'dmsf-file-details-form-locked' : 'dmsf-file-details-form'); + // Index detailsForm = detailsForm.replace(/\[0\]/g, '[' + attachmentId + ']'); detailsForm = detailsForm.replace(/_0/g, '_' + attachmentId); @@ -180,10 +213,17 @@ function dmsfAddFile(inputEl, file, eagerUpload) { detailsForm = detailsForm.replace('id="committed_files_' + attachmentId + '_mime_type"', 'id="committed_files_' + attachmentId + '_mime_type" value = "' + file.type + '"'); // Version - let version = getNextVersion(file.name, $(inputEl).data('files')); - detailsForm = replaceVersion(detailsForm, attachmentId, 'patch', version[2]); - detailsForm = replaceVersion(detailsForm, attachmentId, 'minor', version[1]); - detailsForm = replaceVersion(detailsForm, attachmentId, 'major', version[0]); + let version; + if(locked) { + version = getCurrentVersion(file.name, files); + detailsForm = detailsForm.replace('id="committed_files_' + attachmentId + '_version" value="0.0"', + 'id="committed_files_' + attachmentId + '_version" value="' + version + '"'); + } else { + version = getNextVersion(file.name, files); + detailsForm = replaceVersion(detailsForm, attachmentId, 'patch', version[2]); + detailsForm = replaceVersion(detailsForm, attachmentId, 'minor', version[1]); + detailsForm = replaceVersion(detailsForm, attachmentId, 'major', version[0]); + } detailsDiv.append(detailsForm); detailsDiv.hide();