<commit_before>module MediaRocket
  module Helpers
    module Form
      
      def media_upload_form(options = {}, &block)
        
        case options[:format]
          when "flat" then return media_upload_form_flat(options)
          when "full" then return media_upload_form_full(options)
        end
        
        form :action => slice_url(:upload), :id => "uploadForm" do
          form_content = ""
          
          #
          # You can disallow tag text_field by setting options[:title_enabled] to 0
          #
          form_content << media_title_field(options) if (options[:title_enabled].nil? or options[:title_enabled] != 0)          
          
          #
          # You can disallow tag text_field by setting options[:description_enabled] to 0
          #            
          form_content << media_description_field(options) if (options[:description_enabled].nil? or options[:description_enabled] != 0)
          
          #
          # You can disallow tag text_field by setting options[:tags_enabled] to 0
          #
          form_content << media_tag_field(options) if (options[:tags_enabled].nil? or options[:tags_enabled] != 0)
          
          #
          # Delimiter is not set by default, you have to set options[:delimiter_enabled]
          # to allow user to set it
          #
          form_content << media_delimiter_field(options) if options[:delimiter_enabled] == 1
          
          #
          # Site is not set by default, you have to set options[:site_enabled]
          # to allow user to set it
          #
          form_content << media_site_select(options) if options[:site_enabled] == 1
          
          #
          # Category is not set by default, you have to set options[:category_enabled]
          # to allow user to set it
          #
          form_content << media_category_select(options) if options[:category_enabled] == 1
          
          
          #
          # Build file box
          #
          form_content << media_file_field(options)
          
          #
          # Build submit button
          #
          form_content << tag(:p, submit(options[:submit_label] || "Upload", :id => "media_button"))
          
          # Display form content
          form_content
        end
      end
      
      def media_upload_form_flat(options = {}, &block)
        form :action => slice_url(:upload), :id => "uploadForm" do
          media_file_field(options) + tag(:p, submit(options[:submit_label] || "Upload", :id => "media_button"))
        end
      end
      
      def media_upload_form_full(options = {}, &block)
        form :action => slice_url(:upload), :id => "uploadForm" do
          form_content = media_title_field(options)
          form_content << media_description_field(options)
          form_content << media_tag_field(options)
          form_content << media_delimiter_field(options)
          form_content << media_site_new_field(options)
          form_content << media_site_select(options)
          form_content << media_category_new_field(options)
          form_content << media_category_select(options)
          form_content << media_file_field(options)
          form_content << tag(:p, submit(options[:submit_label] || "Upload", :id => "media_button"))
          form_content
        end
      end
      
      def media_title_field(options = {}, &block)
        content = options[:title_label] || "Title"
        
        title_content = tag(:label, content + tag(:em, '*'), {:for => content})
        title_content << tag(:br)
        title_content << text_field(:name => "title", :id => content, :class => "required")
        
        tag(:p, title_content)
      end
      
      def media_description_field(options = {}, &block)
        content = options[:description_label] || "Description"
        
        description_content = tag(:label, content, {:for => content})
        description_content << tag(:br)
        description_content << text_area(:name => "description", :id => content)
        
        tag(:p, description_content)
      end
      
      def media_tag_field(options = {}, &block)
        content = options[:tags_label] || "Tags"
        
        tag_content = tag(:label, content, {:for => content})
        tag_content << tag(:br)
        tag_content << text_field(:name => "tags", :id => content)
          
        tag(:p, tag_content)
      end
      
      def media_delimiter_field(options = {}, &block)
        content = options[:delimiter_label] || "Tag Delimiter"
        
        delimiter_content = tag(:label, content, {:for => content})
        delimiter_content << tag(:br)
        delimiter_content << text_field(:name => "delimiter", :id => content)
        
        tag(:p, delimiter_content)
      end

      def media_site_select(options = {}, &block)
        sites = ::MediaRocket::Site.all
        
        if sites.empty?
          return ""
        else
          content = options[:site_label] || "Site"
        
          site_content = tag(:label, content, :for => content)
          site_content << tag(:br)
        
        
          choices = ""
          sites.each do |site|
            choices << tag(:option, site.name, :value => site.id)
          end
        
          site_content << tag(:select, choices, {:name => "site_id", :size => sites.size})
        
          tag(:p, site_content)
        end
      end
      
      def media_site_new_field(options = {}, &block)
        content = options[:site_new_label] || "New Site"
        
        site_content = tag(:label, content, {:for => content})
        site_content << tag(:br)
        site_content << text_field(:name => "site_name", :id => content)
          
        tag(:p, site_content)
      end
            
      def media_category_checkboxes(options = {}, &block)
        categories = ::MediaRocket::Gallery.all
        
        if categories.empty?
          return ""
        else
          content = options[:category_label] || "Category"
        
          category_content = tag(:label, content, {:for => content})
          category_content << tag(:br)
        
          categories.each do |category|
            category_content << tag(:input, category.name, {:type => "checkbox", :name => "category", :value => category.name})
            category_content << tag(:br)
          end
        
          tag(:p, category_content)
        end
      end
      
      def media_category_select(options = {}, &block)
        categories = ::MediaRocket::Gallery.all
        
        if categories.empty?
          return ""
        else
          content = options[:category_label] || "Category"
        
          category_content = tag(:label, content, {:for => content})
          category_content << tag(:br)
        
          choices = ""
          level = 1
          categories.select{|cat| cat.parent.nil?}.each do |category|
            choices << media_category_children_option(category)
          end
          
          category_content << tag(:select, choices, {:name => "category_id", :size => categories.size})
          
          tag(:p, category_content)
        end
      end
      
      def media_category_children_option(category, level = 0)
        
        branch = ""
        branch = ("&nbsp;&nbsp;" * level) + "+-&nbsp;" if level > 0
        
        content = tag(:option, branch + category.name, {:value => category.id})
        category.children.each do |child|
          content << media_category_children_option(child, level + 1)
        end
        content
      end
      
      def media_category_new_field(options = {}, &block)
        content = options[:category_new_label] || "New Category"
        
        category_content = tag(:label, content, {:for => content})
        category_content << tag(:br)
        category_content << text_field(:name => "category_name", :id => content)
          
        tag(:p, category_content)
      end
      
      def media_add_category(category, options = {}, &block)
        field_label = options[:field_label] || ""
        submit_label = options[:submit_label] || "Ajouter Sous-Cat&eacute;gorie &rarr;"
        
        form :action => url(:new_media_rocket_category), :method => "GET", :class => "add-category"  do
          category_content = text_field(:name => "name", :value => field_label)
          category_content << hidden_field(:name => "parent_id", :value => category.id)
          category_content << submit(submit_label)
        end
      end
      
      def media_file_field(options = {}, &block)
        content = options[:file_label] || "File"
        
        file_content = tag(:label, content + tag(:em, '*'), {:for => "media_file"})
        file_content << tag(:br)
        file_content << file_field(:name => "file", :id => "media_file", :class => "required")
        
        tag(:p, file_content)
      end
      
      def media_edit_info(media)
        form :action => url(:edit_media_rocket_media, media.id), :method => "GET", :class => "media-info" do
          info = tag(:label, tag(:span, "Titre:"), :for => "title")
          info << text_field(:name => "title", :value => media.title)
          info << self_closing_tag(:br)
          
          info << tag(:label, tag(:span, "Description:"), :for => "description")
          info << text_field(:name => "description", :value => media.description)
          info << self_closing_tag(:br)
          
          info << tag(:label, tag(:span, "Position:"), :for => "position")
          info << text_field(:name => "position", :value => media.position)
          info << self_closing_tag(:br)
          
          info << submit("Modifier")
        end
      end
    end
  end
end<commit_msg>remove required on title<commit_after>module MediaRocket
  module Helpers
    module Form
      
      def media_upload_form(options = {}, &block)
        
        case options[:format]
          when "flat" then return media_upload_form_flat(options)
          when "full" then return media_upload_form_full(options)
        end
        
        form :action => slice_url(:upload), :id => "uploadForm" do
          form_content = ""
          
          #
          # You can disallow tag text_field by setting options[:title_enabled] to 0
          #
          form_content << media_title_field(options) if (options[:title_enabled].nil? or options[:title_enabled] != 0)          
          
          #
          # You can disallow tag text_field by setting options[:description_enabled] to 0
          #            
          form_content << media_description_field(options) if (options[:description_enabled].nil? or options[:description_enabled] != 0)
          
          #
          # You can disallow tag text_field by setting options[:tags_enabled] to 0
          #
          form_content << media_tag_field(options) if (options[:tags_enabled].nil? or options[:tags_enabled] != 0)
          
          #
          # Delimiter is not set by default, you have to set options[:delimiter_enabled]
          # to allow user to set it
          #
          form_content << media_delimiter_field(options) if options[:delimiter_enabled] == 1
          
          #
          # Site is not set by default, you have to set options[:site_enabled]
          # to allow user to set it
          #
          form_content << media_site_select(options) if options[:site_enabled] == 1
          
          #
          # Category is not set by default, you have to set options[:category_enabled]
          # to allow user to set it
          #
          form_content << media_category_select(options) if options[:category_enabled] == 1
          
          
          #
          # Build file box
          #
          form_content << media_file_field(options)
          
          #
          # Build submit button
          #
          form_content << tag(:p, submit(options[:submit_label] || "Upload", :id => "media_button"))
          
          # Display form content
          form_content
        end
      end
      
      def media_upload_form_flat(options = {}, &block)
        form :action => slice_url(:upload), :id => "uploadForm" do
          media_file_field(options) + tag(:p, submit(options[:submit_label] || "Upload", :id => "media_button"))
        end
      end
      
      def media_upload_form_full(options = {}, &block)
        form :action => slice_url(:upload), :id => "uploadForm" do
          form_content = media_title_field(options)
          form_content << media_description_field(options)
          form_content << media_tag_field(options)
          form_content << media_delimiter_field(options)
          form_content << media_site_new_field(options)
          form_content << media_site_select(options)
          form_content << media_category_new_field(options)
          form_content << media_category_select(options)
          form_content << media_file_field(options)
          form_content << tag(:p, submit(options[:submit_label] || "Upload", :id => "media_button"))
          form_content
        end
      end
      
      def media_title_field(options = {}, &block)
        content = options[:title_label] || "Title"
        
        title_content = tag(:label, content, {:for => content})
        title_content << tag(:br)
        title_content << text_field(:name => "title", :id => content)
        
        tag(:p, title_content)
      end
      
      def media_description_field(options = {}, &block)
        content = options[:description_label] || "Description"
        
        description_content = tag(:label, content, {:for => content})
        description_content << tag(:br)
        description_content << text_area(:name => "description", :id => content)
        
        tag(:p, description_content)
      end
      
      def media_tag_field(options = {}, &block)
        content = options[:tags_label] || "Tags"
        
        tag_content = tag(:label, content, {:for => content})
        tag_content << tag(:br)
        tag_content << text_field(:name => "tags", :id => content)
          
        tag(:p, tag_content)
      end
      
      def media_delimiter_field(options = {}, &block)
        content = options[:delimiter_label] || "Tag Delimiter"
        
        delimiter_content = tag(:label, content, {:for => content})
        delimiter_content << tag(:br)
        delimiter_content << text_field(:name => "delimiter", :id => content)
        
        tag(:p, delimiter_content)
      end

      def media_site_select(options = {}, &block)
        sites = ::MediaRocket::Site.all
        
        if sites.empty?
          return ""
        else
          content = options[:site_label] || "Site"
        
          site_content = tag(:label, content, :for => content)
          site_content << tag(:br)
        
        
          choices = ""
          sites.each do |site|
            choices << tag(:option, site.name, :value => site.id)
          end
        
          site_content << tag(:select, choices, {:name => "site_id", :size => sites.size})
        
          tag(:p, site_content)
        end
      end
      
      def media_site_new_field(options = {}, &block)
        content = options[:site_new_label] || "New Site"
        
        site_content = tag(:label, content, {:for => content})
        site_content << tag(:br)
        site_content << text_field(:name => "site_name", :id => content)
          
        tag(:p, site_content)
      end
            
      def media_category_checkboxes(options = {}, &block)
        categories = ::MediaRocket::Gallery.all
        
        if categories.empty?
          return ""
        else
          content = options[:category_label] || "Category"
        
          category_content = tag(:label, content, {:for => content})
          category_content << tag(:br)
        
          categories.each do |category|
            category_content << tag(:input, category.name, {:type => "checkbox", :name => "category", :value => category.name})
            category_content << tag(:br)
          end
        
          tag(:p, category_content)
        end
      end
      
      def media_category_select(options = {}, &block)
        categories = ::MediaRocket::Gallery.all
        
        if categories.empty?
          return ""
        else
          content = options[:category_label] || "Category"
        
          category_content = tag(:label, content, {:for => content})
          category_content << tag(:br)
        
          choices = ""
          level = 1
          categories.select{|cat| cat.parent.nil?}.each do |category|
            choices << media_category_children_option(category)
          end
          
          category_content << tag(:select, choices, {:name => "category_id", :size => categories.size})
          
          tag(:p, category_content)
        end
      end
      
      def media_category_children_option(category, level = 0)
        
        branch = ""
        branch = ("&nbsp;&nbsp;" * level) + "+-&nbsp;" if level > 0
        
        content = tag(:option, branch + category.name, {:value => category.id})
        category.children.each do |child|
          content << media_category_children_option(child, level + 1)
        end
        content
      end
      
      def media_category_new_field(options = {}, &block)
        content = options[:category_new_label] || "New Category"
        
        category_content = tag(:label, content, {:for => content})
        category_content << tag(:br)
        category_content << text_field(:name => "category_name", :id => content)
          
        tag(:p, category_content)
      end
      
      def media_add_category(category, options = {}, &block)
        field_label = options[:field_label] || ""
        submit_label = options[:submit_label] || "Ajouter Sous-Cat&eacute;gorie &rarr;"
        
        form :action => url(:new_media_rocket_category), :method => "GET", :class => "add-category"  do
          category_content = text_field(:name => "name", :value => field_label)
          category_content << hidden_field(:name => "parent_id", :value => category.id)
          category_content << submit(submit_label)
        end
      end
      
      def media_file_field(options = {}, &block)
        content = options[:file_label] || "File"
        
        file_content = tag(:label, content + tag(:em, '*'), {:for => "media_file"})
        file_content << tag(:br)
        file_content << file_field(:name => "file", :id => "media_file", :class => "required")
        
        tag(:p, file_content)
      end
      
      def media_edit_info(media)
        form :action => url(:edit_media_rocket_media, media.id), :method => "GET", :class => "media-info" do
          info = tag(:label, tag(:span, "Titre:"), :for => "title")
          info << text_field(:name => "title", :value => media.title)
          info << self_closing_tag(:br)
          
          info << tag(:label, tag(:span, "Description:"), :for => "description")
          info << text_field(:name => "description", :value => media.description)
          info << self_closing_tag(:br)
          
          info << tag(:label, tag(:span, "Position:"), :for => "position")
          info << text_field(:name => "position", :value => media.position)
          info << self_closing_tag(:br)
          
          info << submit("Modifier")
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12094653812445223, 'fraction_numerical': 0.0013404134659998968, 'mean_word_length': 2.039486054528361, 'pattern_counts': {'":': 0, '<': 211, '<?xml version=': 0, '>': 130, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '104406', 'n_tokens_mistral': 5319, 'n_tokens_neox': 5263, 'n_words': 1221}