Commit 0ea945930459a774f00f9e34045b8d0540ede5d7

Authored by Gabriel Silva
1 parent 95558007

Adds formsets to block edition

Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Signed-off-by: ArthurJahn <stutrzbecher@gmail.com>
src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb
@@ -14,13 +14,6 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController @@ -14,13 +14,6 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController
14 14
15 end 15 end
16 16
17 - def get_block_template  
18 - # render 'box_organizer/_download_list_template', :layout => false  
19 - profile = Profile.find_by_identifier(params[:profile])  
20 - downloads_folder = Folder.where(name: "Downloads", type: "Folder", profile_id: profile.id)  
21 - render 'box_organizer/_download_uploaded_files', :locals=>{ :uploaded_files => get_node(downloads_folder) }  
22 - end  
23 -  
24 def get_field_data 17 def get_field_data
25 condition = !request.xhr? || params[:query].nil? || params[:field].nil? 18 condition = !request.xhr? || params[:query].nil? || params[:field].nil?
26 return render :json=>{} if condition 19 return render :json=>{} if condition
@@ -48,15 +41,4 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController @@ -48,15 +41,4 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController
48 return DatabaseDescription unless params[:field] == "software_language" 41 return DatabaseDescription unless params[:field] == "software_language"
49 return ProgrammingLanguage 42 return ProgrammingLanguage
50 end 43 end
51 -  
52 - def get_node(articles)  
53 - nodes = []  
54 - articles.each do |article|  
55 - if article.type == "UploadedFile"  
56 - nodes << article  
57 - end  
58 - nodes += get_node(article.children)  
59 - end  
60 - nodes  
61 - end  
62 end 44 end
src/noosfero-spb/software_communities/lib/download_block.rb
@@ -33,4 +33,22 @@ class DownloadBlock &lt; Block @@ -33,4 +33,22 @@ class DownloadBlock &lt; Block
33 def cacheable? 33 def cacheable?
34 false 34 false
35 end 35 end
  36 +
  37 + def uploaded_files
  38 + downloads_folder = Folder.where(name: "Downloads", type: "Folder", profile_id: owner.id)
  39 + get_nodes(downloads_folder)
  40 + end
  41 +
  42 + private
  43 +
  44 + def get_nodes(folder)
  45 + nodes = []
  46 + folder.each do |article|
  47 + if article.type == "UploadedFile"
  48 + nodes << article
  49 + end
  50 + nodes += get_nodes(article.children)
  51 + end
  52 + nodes
  53 + end
36 end 54 end
src/noosfero-spb/software_communities/public/blocks/software-download.js
1 modulejs.define('SoftwareDownload', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) { 1 modulejs.define('SoftwareDownload', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) {
2 'use strict'; 2 'use strict';
3 3
4 - var AJAX_URL = {  
5 - get_download_template:  
6 - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_block_template")  
7 - };  
8 -  
9 - var $download_html_template;  
10 -  
11 - function getDownloadListTemplate() {  
12 - $.get(AJAX_URL.get_download_template, { profile: noosfero.profile })  
13 - .done(function(response) {  
14 - $download_html_template = response;  
15 - });  
16 - }  
17 -  
18 -  
19 function SoftwareDownload() { 4 function SoftwareDownload() {
20 - getDownloadListTemplate();  
21 } 5 }
22 6
23 7
24 SoftwareDownload.prototype.addNewDonwload = function() { 8 SoftwareDownload.prototype.addNewDonwload = function() {
25 - var new_download = $($download_html_template); 9 + var new_download = $('#download-list-item-template').html();
26 $("#droppable-list-downloads").append(new_download); 10 $("#droppable-list-downloads").append(new_download);
27 } 11 }
28 12
  13 + SoftwareDownload.prototype.selectFile = function(element) {
  14 + var path = $(element).find('.file-path').html();
  15 + var size = $(element).find('.file-size').html();
  16 +
  17 + var download_option = $(element).find('.file-size').closest('.download-option');
  18 + download_option.find('#block_downloads__link').val(path);
  19 + download_option.find('#block_downloads__size').val(size);
  20 + }
29 21
30 SoftwareDownload.prototype.deleteDownload = function(element) { 22 SoftwareDownload.prototype.deleteDownload = function(element) {
31 var delete_download = $(element).parent().parent().parent().remove(); 23 var delete_download = $(element).parent().parent().parent().remove();
32 } 24 }
33 25
34 -  
35 return { 26 return {
36 isCurrentPage: function() { 27 isCurrentPage: function() {
37 return $('.download-block').length !== 0; 28 return $('.download-block').length !== 0;
src/noosfero-spb/software_communities/views/box_organizer/_download_block.html.erb
1 <div id='edit-download-block'> 1 <div id='edit-download-block'>
2 2
3 <h3><%= _('Download options') %></h3> 3 <h3><%= _('Download options') %></h3>
4 - <div id ="droppable-list-downloads"> 4 + <div id="droppable-list-downloads">
5 <% @block.downloads.each do |download| %> 5 <% @block.downloads.each do |download| %>
6 - <%= render :partial => 'download_list', :locals => {:download => download, :uploaded_files => uploaded_files} %> 6 + <%= render :partial => 'download_list_item', :locals => {:download => download} %>
7 <% end %> 7 <% end %>
8 </div> 8 </div>
9 9
10 <%= link_to_function _('New link'), 'softwareDownload.addNewDonwload(); return false', :class => 'button icon-add with-text download-new-link-button' %> 10 <%= link_to_function _('New link'), 'softwareDownload.addNewDonwload(); return false', :class => 'button icon-add with-text download-new-link-button' %>
  11 +
  12 + <div id="download-list-item-template" style="display: none;">
  13 + <%= render :partial => 'download_list_item' %>
  14 + </div>
11 </div> 15 </div>
src/noosfero-spb/software_communities/views/box_organizer/_download_file.html.erb
1 <li> 1 <li>
2 - <span>  
3 - <%= file.path%>  
4 - </span> 2 + <a onclick="softwareDownload.selectFile(this)">
  3 + <span class="file-path"><%= file.full_name%></span> - <span class="file-size"><%= number_to_human_size(file.size, precision: 2) %></span>
  4 + </a>
5 </li> 5 </li>
src/noosfero-spb/software_communities/views/box_organizer/_download_list.html.erb
@@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
1 -<li class='download-option download-forms'>  
2 - <ul>  
3 - <li>  
4 - <%= labelled_form_field(_('Name'), text_field_tag('block[downloads][][name]', (defined? download) ? download[:name] : '')) %>  
5 - </li>  
6 - <li>  
7 - <%= labelled_form_field(_('Link'), text_field_tag('block[downloads][][link]', (defined? download) ? download[:link] : '')) %>  
8 - <div>  
9 - <ul>  
10 - <% uploaded_files.each do |file| %>  
11 - <%= render :partial => 'download_file', :locals => {:file => file} %>  
12 - <% end %>  
13 - <li style="clear: both">  
14 - </li>  
15 - </ul>  
16 - </div>  
17 - </li>  
18 -  
19 - <li>  
20 - <%= labelled_form_field(_('Platforms'), text_field_tag('block[downloads][][software_description]', (defined? download) ? download[:software_description] : '')) %>  
21 - </li>  
22 -  
23 - <li>  
24 - <%= labelled_form_field(_('Minimum Requirements'), text_field_tag('block[downloads][][minimum_requirements]', (defined? download) ? download[:minimum_requirements] : '')) %>  
25 - </li>  
26 -  
27 - <li>  
28 - <%= labelled_form_field(_('Size'), text_field_tag('block[downloads][][size]', (defined? download) ? download[:size] : '')) %>  
29 - </li>  
30 -  
31 - <li class='delete-download-button'><%= button_without_text(:delete, _('Delete'), "#" , { :onclick => 'softwareDownload.deleteDownload(this); return false', :class=>"delete-link-list-row" }) %></li>  
32 - </ul>  
33 -</li>  
src/noosfero-spb/software_communities/views/box_organizer/_download_list_item.html.erb 0 → 100644
@@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
  1 +<li class='download-option download-forms'>
  2 + <ul>
  3 + <li>
  4 + <%= labelled_form_field(_('Name'), text_field_tag('block[downloads][][name]', (defined? download) ? download[:name] : '')) %>
  5 + </li>
  6 + <li>
  7 + <%= labelled_form_field(_('Link'), text_field_tag('block[downloads][][link]', (defined? download) ? download[:link] : '')) %>
  8 + <div class=<%= (defined? download) ? "closed" : "opened" %>>
  9 + <ul>
  10 + <% @block.uploaded_files.each do |file| %>
  11 + <%= render :partial => 'download_file', :locals => {:file => file} %>
  12 + <% end %>
  13 + <li style="clear: both">
  14 + </li>
  15 + </ul>
  16 + </div>
  17 + </li>
  18 +
  19 + <li>
  20 + <%= labelled_form_field(_('Platforms'), text_field_tag('block[downloads][][software_description]', (defined? download) ? download[:software_description] : '')) %>
  21 + </li>
  22 +
  23 + <li>
  24 + <%= labelled_form_field(_('Minimum Requirements'), text_field_tag('block[downloads][][minimum_requirements]', (defined? download) ? download[:minimum_requirements] : '')) %>
  25 + </li>
  26 +
  27 + <li>
  28 + <%= labelled_form_field(_('Size'), text_field_tag('block[downloads][][size]', (defined? download) ? download[:size] : '')) %>
  29 + </li>
  30 +
  31 + <li class='delete-download-button'><%= button_without_text(:delete, _('Delete'), "#" , { :onclick => 'softwareDownload.deleteDownload(this); return false', :class=>"delete-link-list-row" }) %></li>
  32 + </ul>
  33 +</li>