#1548 '[+]' locked files
This commit is contained in:
parent
a56fcc33a2
commit
911d03af5e
@ -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)
|
||||
}
|
||||
%>
|
||||
|
||||
@ -19,68 +19,48 @@
|
||||
%>
|
||||
|
||||
<div class="box tabular dmfs-box-tabular">
|
||||
<%= 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 %>
|
||||
<p class="warning"><%= l(:info_file_locked) %></p>
|
||||
<div class="splitcontent">
|
||||
<div class="splitcontentleft">
|
||||
<p>
|
||||
<%= 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 %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="splitcontentright">
|
||||
<p>
|
||||
<%= 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 %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<% if upload.description.present? %>
|
||||
<p>
|
||||
<%= label_tag '', l(:label_description) %>
|
||||
<div class="wiki">
|
||||
<%= textilizable upload.description %>
|
||||
</div>
|
||||
</p>
|
||||
<% end %>
|
||||
<div class="splitcontent">
|
||||
<div class="splitcontentleft">
|
||||
<p>
|
||||
<%= 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 %>
|
||||
</p>
|
||||
<p>
|
||||
<%= 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 %>
|
||||
</p>
|
||||
<p>
|
||||
<%= 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 %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="splitcontentright">
|
||||
<div class="custom_fields">
|
||||
<% upload.custom_values.each do |value| %>
|
||||
<p>
|
||||
<%= 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 %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% if upload.comment.present? %>
|
||||
<p>
|
||||
<%= label_tag '', l(:label_comment) %>
|
||||
<div class="wiki"><%= textilizable upload.comment %></div>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@ -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,7 +179,6 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
|
||||
}
|
||||
|
||||
// Details
|
||||
let detailsForm = $(inputEl).data('dmsf-file-details-form');
|
||||
let detailsDiv = $('<div>').attr({id: 'dmsf_attachments_details_' + attachmentId});
|
||||
let detailsArrow = $('<a>');
|
||||
|
||||
@ -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'));
|
||||
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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user