#1548 '[+]' locked files
This commit is contained in:
parent
a56fcc33a2
commit
911d03af5e
@ -80,7 +80,9 @@
|
|||||||
files = []
|
files = []
|
||||||
project_or_folder.dmsf_files.visible.each do |dmsf_file|
|
project_or_folder.dmsf_files.visible.each do |dmsf_file|
|
||||||
rev = dmsf_file.last_revision
|
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
|
end
|
||||||
%>
|
%>
|
||||||
<%= file_field_tag 'dmsf_attachments[dummy][file]',
|
<%= file_field_tag 'dmsf_attachments[dummy][file]',
|
||||||
@ -100,6 +102,9 @@
|
|||||||
dmsf_file_details_form: controller.send(:render_to_string,
|
dmsf_file_details_form: controller.send(:render_to_string,
|
||||||
{ partial: 'dmsf_upload/upload_file',
|
{ partial: 'dmsf_upload/upload_file',
|
||||||
locals: { upload: DmsfUpload.new(project, folder, nil), i: 0 } }),
|
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)
|
files: JSON.generate(files)
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
|
|||||||
@ -19,68 +19,48 @@
|
|||||||
%>
|
%>
|
||||||
|
|
||||||
<div class="box tabular dmfs-box-tabular">
|
<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>
|
<p class="warning"><%= l(:info_file_locked) %></p>
|
||||||
<div class="splitcontent">
|
<div class="splitcontent">
|
||||||
<div class="splitcontentleft">
|
<div class="splitcontentleft">
|
||||||
<p>
|
<p>
|
||||||
<%= label_tag '', l(:label_title) %>
|
<%= label_tag "committed_files[#{i}][title]", l(:label_title) %>
|
||||||
<%= text_field_tag :name, h(upload.title), readonly: true %>
|
<%= text_field_tag "committed_files[#{i}][title]", upload.title, readonly: true %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="splitcontentright">
|
<div class="splitcontentright">
|
||||||
<p>
|
<p>
|
||||||
<%= label_tag '', l(:label_filename) %>
|
<%= label_tag "committed_files[#{i}][name]", l(:label_filename) %>
|
||||||
<%= text_field_tag :name, h(upload.name), readonly: true %>
|
<%= text_field_tag "committed_files[#{i}][name]", upload.name, readonly: true %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</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="splitcontent">
|
||||||
<div class="splitcontentleft">
|
<div class="splitcontentleft">
|
||||||
<p>
|
<p>
|
||||||
<%= label_tag '', l(:label_dmsf_version) %>
|
<%= label_tag "committed_files[#{i}][version]", l(:label_dmsf_version) %>
|
||||||
<%= text_field_tag :name,
|
<%= text_field_tag "committed_files[#{i}][version]",
|
||||||
"#{DmsfUploadHelper::gui_version(upload.major_version)}.#{DmsfUploadHelper::gui_version(upload.minor_version)}",
|
"#{DmsfUploadHelper::gui_version(upload.major_version)}.#{DmsfUploadHelper::gui_version(upload.minor_version)}",
|
||||||
readonly: true %>
|
readonly: true %>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<%= label_tag '', l(:label_mime) %>
|
<%= label_tag "committed_files[#{i}][mime_type]", l(:label_mime) %>
|
||||||
<%= text_field_tag :name, h(upload.mime_type), readonly: true %>
|
<%= text_field_tag "committed_files[#{i}][mime_type]", upload.mime_type, readonly: true %>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<%= label_tag '', l(:label_size) %>
|
<%= label_tag "committed_files[#{i}][size]", l(:label_size) %>
|
||||||
<%= text_field_tag :name, h(number_to_human_size(upload.size)), readonly: true %>
|
<%= text_field_tag "committed_files[#{i}][size]", number_to_human_size(upload.size), readonly: true %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="splitcontentright">
|
<div class="splitcontentright">
|
||||||
<div class="custom_fields">
|
<div class="custom_fields">
|
||||||
<% upload.custom_values.each do |value| %>
|
<% upload.custom_values.each do |value| %>
|
||||||
<p>
|
<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 %>
|
<% 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>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% if upload.comment.present? %>
|
|
||||||
<p>
|
|
||||||
<%= label_tag '', l(:label_comment) %>
|
|
||||||
<div class="wiki"><%= textilizable upload.comment %></div>
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -97,6 +97,36 @@ function getNextVersion(filename, files) {
|
|||||||
return [0, 1, null];
|
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 */
|
/* Replace selected version */
|
||||||
function replaceVersion(detailsForm, attachmentId, name, version) {
|
function replaceVersion(detailsForm, attachmentId, name, version) {
|
||||||
let index = detailsForm.search('id="committed_files_' + attachmentId + '_version_' + name + '"');
|
let index = detailsForm.search('id="committed_files_' + attachmentId + '_version_' + name + '"');
|
||||||
@ -149,7 +179,6 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Details
|
// Details
|
||||||
let detailsForm = $(inputEl).data('dmsf-file-details-form');
|
|
||||||
let detailsDiv = $('<div>').attr({id: 'dmsf_attachments_details_' + attachmentId});
|
let detailsDiv = $('<div>').attr({id: 'dmsf_attachments_details_' + attachmentId});
|
||||||
let detailsArrow = $('<a>');
|
let detailsArrow = $('<a>');
|
||||||
|
|
||||||
@ -164,6 +193,10 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
|
|||||||
"$('#dmsf-upload-button').hide();" +
|
"$('#dmsf-upload-button').hide();" +
|
||||||
"return false;"
|
"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
|
// Index
|
||||||
detailsForm = detailsForm.replace(/\[0\]/g, '[' + attachmentId + ']');
|
detailsForm = detailsForm.replace(/\[0\]/g, '[' + attachmentId + ']');
|
||||||
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"',
|
detailsForm = detailsForm.replace('id="committed_files_' + attachmentId + '_mime_type"',
|
||||||
'id="committed_files_' + attachmentId + '_mime_type" value = "' + file.type + '"');
|
'id="committed_files_' + attachmentId + '_mime_type" value = "' + file.type + '"');
|
||||||
// Version
|
// 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, 'patch', version[2]);
|
||||||
detailsForm = replaceVersion(detailsForm, attachmentId, 'minor', version[1]);
|
detailsForm = replaceVersion(detailsForm, attachmentId, 'minor', version[1]);
|
||||||
detailsForm = replaceVersion(detailsForm, attachmentId, 'major', version[0]);
|
detailsForm = replaceVersion(detailsForm, attachmentId, 'major', version[0]);
|
||||||
|
}
|
||||||
|
|
||||||
detailsDiv.append(detailsForm);
|
detailsDiv.append(detailsForm);
|
||||||
detailsDiv.hide();
|
detailsDiv.hide();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user