I'm looking for a part-time remote job.

Hire me


I'm the author of:

Mastering Redmine is a comprehensive guide with tips, tricks and best practices, and an easy-to-learn structure.

Check the book's project or

Buy the book

Social pages of the book:

By buying this book you also donate to Redmine (see this page).


Follow me:

patch.diff

change diff - Martin Corino, 15 Oct 2013 17:00

Download (6.03 KB)

View differences:

app/helpers/download_helper.rb
14 14
                          :locals  => { :label   => download_label(version, download),
15 15
                                        :package => download_package(version, download),
16 16
                                        :link    => download_link(version, download),
17
                                        :files   => download_files(version, download),
17 18
                                        :style   => options[:class],
18 19
                                        :align   => options[:align] })
19 20
        end
......
28 29
        nil
29 30
    end
30 31

  
32
    def download_files(version, download)
33
      if download || !version.attachments.any?|| !version.attachments_visible?
34
        nil
35
      else
36
        version.attachments.collect do |attachment|
37
          [attachment.description,
38
           url_for(
39
               :controller => 'attachments',
40
               :action     => 'download',
41
               :id         => attachment,
42
               :filename   => attachment.filename
43
           )]
44
        end
45
      end
46
    end
47

  
31 48
    def download_link(version, download)
32 49
        if download && download.file_id.to_i < 0
33 50
            download.url
......
41 58
                    :filename   => attachment.filename
42 59
                )
43 60
            end
44
        else
61
        elsif version.attachments_visible?
45 62
            if version.attachments.any?
46 63
                url_for(
47 64
                    :controller => 'attachments',
......
50 67
                    :filename   => version.attachments.last.filename
51 68
                )
52 69
            end
70
        else
71
          url_for(
72
              :controller => 'files',
73
              :action     => 'index',
74
              :project_id => version.project.identifier
75
          )
53 76
        end
54 77
    end
55 78

  
app/views/download/_button.html.erb
1
<% if files %>
2
  <%= javascript_tag do %>
3
    <% if defined? observe_field %>
4
    // Prototype code
5
    function update_download_file(select) {
6
      $('sidebar-download-button').href = select.getValue();
7
    }
8
    <% else %>
9
    // jQuery code
10
    function update_download_file(select) {
11
      $('#sidebar-download-button').attr('href', $(select).val());
12
    }
13
    <% end %>
14
  <% end %>
15
<div class="download">
16
<h3><%= l(:field_downloads) %></h3>
17
<p>
18
  <%= select_tag 'sidebar-download-file', options_for_select(files, files.last.last), :onchange => 'update_download_file(this);' %>
19
</p>
20
<% end %>
21

  
22
<p>
1 23
<% css_classes = style.blank? ? "download" : "download #{style}" %>
2 24
<% css_styles = align && (align.downcase == 'left' || align.downcase == 'right') ? " style=\"float: #{align};\"" : "" %>
3
<a href="<%= h(link) %>" class="<%= h(css_classes) %>"<%= css_styles %>>
25
<a id='sidebar-download-button' href="<%= h(link) %>" class="<%= h(css_classes) %>"<%= css_styles %>>
4 26
  <span class="icon-download">
5 27
    <%= h(label) %>
6 28
    <span class="version"><%= h(package) %></span>
7 29
  </span>
8 30
</a>
31
</p>
32

  
33
<% if files %>
34
</div>
35
<% end %>
app/views/download/_sidebar.html.erb
4 4
    <% if controller.class.name == 'ProjectsController' ||
5 5
          controller.class.name == 'ActivitiesController' ||
6 6
          controller.class.name == 'WikiController' %>
7
      <p><%= download_button(project, download) %></p>
7
      <%= download_button(project, download) %>
8 8
    <% elsif controller.class.name == 'VersionsController' %>
9 9
      <% if params[:action] && params[:action] == 'show' %>
10 10
        <% if version = Version.find_by_id(params[:id]) %>
11 11
          <!-- render(:partial => 'download/version', :locals => { :version => version }) -->
12 12
        <% end %>
13 13
      <% else %>
14
        <p><%= download_button(project, download) %></p>
14
        <%= download_button(project, download) %>
15 15
      <% end %>
16 16
    <% end %>
17 17
  <% end %>
assets/stylesheets/download.css
42 42
#content .wiki a.download {
43 43
    margin: 0.25em 1em;
44 44
}
45

  
46
#sidebar div.download {
47
    background-color: inherit;
48
    padding: 0;
49
    border: 0;
50
    margin-bottom: 3px;
51
    margin-top: 5px;
52
}
53

  
54
#sidebar div.download p {
55
    margin: 6px 0 6px 0;
56
}
assets/stylesheets/remedy.css
1
a.download {
2
    background-color: #536a3f !important;
3
    background-image: url(../images/remedy/button.png) !important;
4
    background-position: left top !important;
5
    border-color: #afc69c #435335 #435335 #afc69c !important;
6
}
7
a.download.old-version {
8
    background-color: #5e5e5e !important;
9
    background-image: url(../images/red-andy/old-button.png) !important;
10
    border-color: #bababa #4b4b4b #4b4b4b #bababa !important;
11
}
12
a.download span.icon-download {
13
    background-image: url(../images/remedy/arrow.gif);
14
    background-position: 7px center;
15
    background-repeat: no-repeat;
16
    padding-left: 30px;
17
    display: block;
18
}
19
#content .wiki a.download {
20
    font-family: Tahoma, Verdana;
21
}
Terms of use | Privacy policy