Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix: On update of IFC model don't lose title changes.

Wieland Lindenthal848b41222502
diff --git a/modules/bim/app/views/bim/ifc_models/ifc_models/_form.html.erb b/modules/bim/app/views/bim/ifc_models/ifc_models/_form.html.erb
index d976dacfb61..3d04f19dca3 100644
--- a/modules/bim/app/views/bim/ifc_models/ifc_models/_form.html.erb
+++ b/modules/bim/app/views/bim/ifc_models/ifc_models/_form.html.erb
@@ -58,18 +58,35 @@ See doc/COPYRIGHT.rdoc for more details.
<%= nonced_javascript_tag do %>
jQuery(document).ready(function() {
- jQuery("input[type=file]").change(function(e){
- var fileName = e.target.files[0].name;
+ var setDirectUploadFileName = function () {
+ var fileName = jQuery('input[type=file]')[0].files[0].name;
+ var titleField = jQuery("#bim_ifc_models_ifc_model_title");
+
+ <%# When creating a new model, there is no titleField. %>
+ var titleFieldValue = '';
+ if (titleField) {
+ titleFieldValue = jQuery("#bim_ifc_models_ifc_model_title").val();
+ };
+
+ var title = '';
+ if (titleFieldValue.length > 0) {
+ title = titleFieldValue;
+ } else {
+ title = fileName;
+ }
- jQuery.post(
+ return jQuery.post(
"<%= set_direct_upload_file_name_bcf_project_ifc_models_path %>",
{
- title: fileName,
+ title: title,
isDefault: jQuery("#bim_ifc_models_ifc_model_is_default").is(":checked") ? 1 : 0
}
);
+ };
+ jQuery("input[type=file]").change(function(e){
+ setDirectUploadFileName();
- // rebuild form to post to S3 directly
+ <%# rebuild form to post to S3 directly %>
if (jQuery("input[name=utf8]").length == 1) {
jQuery("input[name=utf8]").remove();
jQuery("input[name=authenticity_token]").remove();
@@ -87,6 +104,23 @@ See doc/COPYRIGHT.rdoc for more details.
});
}
});
+ <% unless @ifc_model.new_record? %>
+ <%# The titleField might have changed AFTER selecting a file. Therefore,
+ we need to intercept form submits to first send the file name etc and
+ then submit.
+
+ Also, we need take care not to end up in a submit loop. So prevent it to
+ be submitted several times. %>
+ var submitted = false;
+ var form = jQuery("form#edit_bim_ifc_models_ifc_model_<%= @ifc_model.id %>")
+ form.submit((e) => {
+ if (submitted) { return };
+
+ e.preventDefault();
+ setDirectUploadFileName().always(() => form.submit());
+ submitted = true;
+ });
+ <% end %>
});
<% end %>