<commit_before><%= javascript_include_tag 'attachments', 'models' %>

<%
   # determine the asset type from the controller
   upload_field = controller_name.downcase.singularize.underscore
   # inject the attributes data_url and local_copy in the asset type, e.g. @model. This keeps the form clean.
   resource=eval("@"+upload_field)
   class << resource
       attr_accessor :data_url, :local_copy
   end unless resource.nil?
   resource.local_copy=1 unless resource.nil?
   asset_name = text_for_resource upload_field
   @content_blob ||= ContentBlob.new
   with_image_file = resource && resource.kind_of?(Model) && (mine?(resource) || resource.can_edit?)
   original_filename=nil
-%>

<%
   if params[upload_field.to_sym]
     resource.data_url=params[upload_field.to_sym][:data_url] if params[upload_field.to_sym][:data_url]
     original_filename = params[upload_field.to_sym][:original_filename] if params[upload_field.to_sym][:original_filename]
   end
-%>

<div class="box_infotext">
  <p>
    You can register a <%= asset_name.pluralize -%> by either directly uploading one/multiple files, or registering one/multiple URLs or uploading a image file. Please test the URLs
    before
    submitting.
    <%= link_to_function "More info "+image("expand"), :id => 'more_info_expand_image' do |page|
      page.visual_effect(:toggle_appear, "more_upload_info", :duration => 0.3)
      page["more_info_expand_image"].toggle
      page["more_info_collapse_image"].toggle
    end
    -%>
    <%= link_to_function "More info "+image("collapse"), :id => 'more_info_collapse_image', :style => "display:none" do |page|
      page.visual_effect(:toggle_appear, "more_upload_info", :duration => 0.3)
      page["more_info_expand_image"].toggle
      page["more_info_collapse_image"].toggle
    end
    -%>
  </p>
    <span id="more_upload_info" style="display:none;">
        <p>
          When registering a URL you can specify that a copy of the data should be stored
          within SEEK. This is recommended and is equivalent to uploading a file. It also means that should the data
          behind the URL the data is still available from SEEK.
        </p>
    </span>
  <% if new_version -%>
      <p>
        You are about to upload a new version of this <%= resource.class.name.humanize -%>. You should only upload a new version if you have made minor modifications, such as tidying up or fixing errors, that do not change the original purpose
        of the file. If you think this new version changes the original purpose or meaning of the <%= resource.class.name.humanize -%>, then you should <span style="text-decoration: underline"><%= link_to "upload it as a new item",polymorphic_path(resource,:action=>:new) -%> </span>
        rather than create a new version.
      </p>
  <% end -%>
</div>

<div class="yui-g">
  <div class="yui-u first" style="width: <%= with_image_file ? '42%' : '100%'%>; margin-left: 2em; margin-top: 1em; margin-bottom: 1em;">

  <div id="upload_type_selection">
    <ul id="switch_upload_buttons">
      <li>
        <%= link_to_function image("file_large"), "from_file_selected(); return (false);", :class=>"block_link_active", :id=>"upload_from_file_button", :title=>tooltip_title_attrib('Add from a local file') -%>
      </li>
      <li>
        <%= link_to_function image("internet_large"), "from_url_selected(); return (false);", :class=>"block_link", :id=>"upload_from_url_button", :title=>tooltip_title_attrib('Add from a remote URL') -%>
      </li>
      <li id="upload_options">
        <div id="upload_from_file">
          <p>
            <b>File to upload:</b>
            <br/>
            <%#= file_field upload_field, :data -%>


                <% fields_for @content_blob do |content_blob| -%>
                    <input id="content_blob_data" type="file">
                <% end %>
          </p>

        </div>
        <div id="upload_from_url" style="display:none;">
          <p>
            <b>URL:</b>You can register a
            <span class="required">*</span>


            <%= text_field_tag "content_blob[data_url]", resource.data_url, :size => 55 %>

                <%= link_to_function (image("new") + "Add"), "addToList()" %>
                <%= link_to_remote image("test", :title=>"Test", :alt=>"Test")+" Test",
                                   :url=>{:action=>:test_asset_url, :symb=>"content_blob"},
                                   :method=>:post,
                                   :with=>"multi_selector.current_url_element.serialize()",
                                   :before=>"$('test_url_msg').innerHTML='';show_ajax_loader('test_url_result_icon');" -%>

                <br/>
                <p style="clear:both;">
                  <b>Make a copy?</b>
                  <%= check_box upload_field, :local_copy, :id=>"local_copy" -%>
                </p>
            <%= hidden_field_tag "content_blob[original_filename_0]", original_filename -%>
            </p>
            <p>
              <span id="test_url_result_icon"></span>
              <span id="test_url_msg" style="display:none;"></span>
            </p>
          </div>
      </li>
    </ul>
  </div>

  <table id="pending_files">
  </table>
</div>

<div class="yui-u" style="width: <%= with_image_file ? '42%' : '0%'%>;margin-right: 2em; margin-top: 1em; margin-bottom: 1em;">
<% if with_image_file -%>
    <%resource_name = resource.class.name.underscore%>
    <%= hidden_field_tag("#{resource_name}_id", resource.id) -%>
      <p>
        <b>Image file: </b>
        <%= file_field "#{resource_name}_image", :image_file, :onchange => "detectFileFormat('#{resource_name}_image_image_file')" %>
      </p>
<% end -%>
</div>
</div>

<script type="text/javascript">
    var multi_selector = new MultiSelector($('pending_files'));

         multi_selector.addElement($('content_blob_data'));
         multi_selector.addElement($('content_blob_data_url'));

    <% if resource.data_url.blank? -%>
        from_file_selected();
    <% else -%>
        from_url_selected();
    <% end -%>


    function addToList() {
        var url = multi_selector.current_original_filename_url_element.value || parseUri(multi_selector.current_url_element.value).file;

        if (url != "" && url != null) {
            var new_element = document.createElement('input');
            new_element.type = 'text';
            new_element.size = '55';
            var old_element = document.getElementsByName('content_blob[url_' + (multi_selector.id_url - 1) + ']')[0];
            var original_filename_element = document.createElement('input');
            original_filename_element.type = 'hidden';
            original_filename_element.name = 'content_blob[original_filename_' + (multi_selector.id_url) + ']';
            $('upload_from_url').appendChild(original_filename_element);
            if (old_element.value != "") {
                old_element.parentNode.insertBefore(new_element, old_element);
                old_element.multi_selector.addElement(new_element);
                old_element.multi_selector.addListRow(old_element, old_element.multi_selector.object_name, old_element.multi_selector.method);
                old_element.type = 'hidden';
            } else {
                old_element.focus();
            }

        }else{
            alert("The URL cannot be parsed. The data behind the URL may not exist or be available from SEEK");
        }
    }
</script><commit_msg>notice of image file of previous version will be used if no image file is selected, when uploading new model version<commit_after><%= javascript_include_tag 'attachments', 'models' %>

<%
   # determine the asset type from the controller
   upload_field = controller_name.downcase.singularize.underscore
   # inject the attributes data_url and local_copy in the asset type, e.g. @model. This keeps the form clean.
   resource=eval("@"+upload_field)
   class << resource
       attr_accessor :data_url, :local_copy
   end unless resource.nil?
   resource.local_copy=1 unless resource.nil?
   asset_name = text_for_resource upload_field
   @content_blob ||= ContentBlob.new
   with_image_file = resource && resource.kind_of?(Model) && (mine?(resource) || resource.can_edit?)
   original_filename=nil
-%>

<%
   if params[upload_field.to_sym]
     resource.data_url=params[upload_field.to_sym][:data_url] if params[upload_field.to_sym][:data_url]
     original_filename = params[upload_field.to_sym][:original_filename] if params[upload_field.to_sym][:original_filename]
   end
-%>

<div class="box_infotext">
  <p>
    You can register a <%= asset_name.pluralize -%> by either directly uploading one/multiple files, or registering one/multiple URLs or uploading a image file. Please test the URLs
    before
    submitting.
    <%= link_to_function "More info "+image("expand"), :id => 'more_info_expand_image' do |page|
      page.visual_effect(:toggle_appear, "more_upload_info", :duration => 0.3)
      page["more_info_expand_image"].toggle
      page["more_info_collapse_image"].toggle
    end
    -%>
    <%= link_to_function "More info "+image("collapse"), :id => 'more_info_collapse_image', :style => "display:none" do |page|
      page.visual_effect(:toggle_appear, "more_upload_info", :duration => 0.3)
      page["more_info_expand_image"].toggle
      page["more_info_collapse_image"].toggle
    end
    -%>
  </p>
    <span id="more_upload_info" style="display:none;">
        <p>
          When registering a URL you can specify that a copy of the data should be stored
          within SEEK. This is recommended and is equivalent to uploading a file. It also means that should the data
          behind the URL the data is still available from SEEK.
        </p>
    </span>
  <% if new_version -%>
      <p>
        You are about to upload a new version of this <%= resource.class.name.humanize -%>. You should only upload a new version if you have made minor modifications, such as tidying up or fixing errors, that do not change the original purpose
        of the file. If you think this new version changes the original purpose or meaning of the <%= resource.class.name.humanize -%>, then you should <span style="text-decoration: underline"><%= link_to "upload it as a new item",polymorphic_path(resource,:action=>:new) -%> </span>
        rather than create a new version.
      </p>
  <% end -%>
</div>

<div class="yui-g">
  <div class="yui-u first" style="width: <%= with_image_file ? '42%' : '100%'%>; margin-left: 2em; margin-top: 1em; margin-bottom: 1em;">

  <div id="upload_type_selection">
    <ul id="switch_upload_buttons">
      <li>
        <%= link_to_function image("file_large"), "from_file_selected(); return (false);", :class=>"block_link_active", :id=>"upload_from_file_button", :title=>tooltip_title_attrib('Add from a local file') -%>
      </li>
      <li>
        <%= link_to_function image("internet_large"), "from_url_selected(); return (false);", :class=>"block_link", :id=>"upload_from_url_button", :title=>tooltip_title_attrib('Add from a remote URL') -%>
      </li>
      <li id="upload_options">
        <div id="upload_from_file">
          <p>
            <b>File to upload:</b>
            <br/>
            <%#= file_field upload_field, :data -%>


                <% fields_for @content_blob do |content_blob| -%>
                    <input id="content_blob_data" type="file">
                <% end %>
          </p>

        </div>
        <div id="upload_from_url" style="display:none;">
          <p>
            <b>URL:</b>You can register a
            <span class="required">*</span>


            <%= text_field_tag "content_blob[data_url]", resource.data_url, :size => 55 %>

                <%= link_to_function (image("new") + "Add"), "addToList()" %>
                <%= link_to_remote image("test", :title=>"Test", :alt=>"Test")+" Test",
                                   :url=>{:action=>:test_asset_url, :symb=>"content_blob"},
                                   :method=>:post,
                                   :with=>"multi_selector.current_url_element.serialize()",
                                   :before=>"$('test_url_msg').innerHTML='';show_ajax_loader('test_url_result_icon');" -%>

                <br/>
                <p style="clear:both;">
                  <b>Make a copy?</b>
                  <%= check_box upload_field, :local_copy, :id=>"local_copy" -%>
                </p>
            <%= hidden_field_tag "content_blob[original_filename_0]", original_filename -%>
            </p>
            <p>
              <span id="test_url_result_icon"></span>
              <span id="test_url_msg" style="display:none;"></span>
            </p>
          </div>
      </li>
    </ul>
  </div>

  <table id="pending_files">
  </table>
</div>

<div class="yui-u" style="width: <%= with_image_file ? '42%' : '0%'%>;margin-right: 2em; margin-top: 1em; margin-bottom: 1em;">
<% if with_image_file -%>
    <%resource_name = resource.class.name.underscore%>
    <%= hidden_field_tag("#{resource_name}_id", resource.id) -%>
      <p>
        <b>Image file: </b>
        <%= file_field "#{resource_name}_image", :image_file, :onchange => "detectFileFormat('#{resource_name}_image_image_file')" %>
      </p>
      <% if new_version && previous_version_image_file = resource.latest_version.model_image.try(:original_filename) -%>
          <p>
            The image file of previous version <span style="font-weight: bold;"><%= previous_version_image_file %> </span> will be used if you dont specify model image file
          </p>
      <% end -%>
<% end -%>
</div>
</div>

<script type="text/javascript">
    var multi_selector = new MultiSelector($('pending_files'));

         multi_selector.addElement($('content_blob_data'));
         multi_selector.addElement($('content_blob_data_url'));

    <% if resource.data_url.blank? -%>
        from_file_selected();
    <% else -%>
        from_url_selected();
    <% end -%>


    function addToList() {
        var url = multi_selector.current_original_filename_url_element.value || parseUri(multi_selector.current_url_element.value).file;

        if (url != "" && url != null) {
            var new_element = document.createElement('input');
            new_element.type = 'text';
            new_element.size = '55';
            var old_element = document.getElementsByName('content_blob[url_' + (multi_selector.id_url - 1) + ']')[0];
            var original_filename_element = document.createElement('input');
            original_filename_element.type = 'hidden';
            original_filename_element.name = 'content_blob[original_filename_' + (multi_selector.id_url) + ']';
            $('upload_from_url').appendChild(original_filename_element);
            if (old_element.value != "") {
                old_element.parentNode.insertBefore(new_element, old_element);
                old_element.multi_selector.addElement(new_element);
                old_element.multi_selector.addListRow(old_element, old_element.multi_selector.object_name, old_element.multi_selector.method);
                old_element.type = 'hidden';
            } else {
                old_element.focus();
            }

        }else{
            alert("The URL cannot be parsed. The data behind the URL may not exist or be available from SEEK");
        }
    }
</script>
{'fraction_non_alphanumeric': 0.1403588907014682, 'fraction_numerical': 0.003393148450244698, 'mean_word_length': 2.8372558838257387, 'pattern_counts': {'":': 0, '<': 202, '<?xml version=': 0, '>': 244, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6424733', 'n_tokens_mistral': 4829, 'n_tokens_neox': 4594, 'n_words': 1037}