diff --git a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb index 46c7481..4105735 100644 --- a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb +++ b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb @@ -14,13 +14,6 @@ class SoftwareCommunitiesPluginController < ApplicationController end - def get_block_template - # render 'box_organizer/_download_list_template', :layout => false - profile = Profile.find_by_identifier(params[:profile]) - downloads_folder = Folder.where(name: "Downloads", type: "Folder", profile_id: profile.id) - render 'box_organizer/_download_uploaded_files', :locals=>{ :uploaded_files => get_node(downloads_folder) } - end - def get_field_data condition = !request.xhr? || params[:query].nil? || params[:field].nil? return render :json=>{} if condition @@ -48,15 +41,4 @@ class SoftwareCommunitiesPluginController < ApplicationController return DatabaseDescription unless params[:field] == "software_language" return ProgrammingLanguage end - - def get_node(articles) - nodes = [] - articles.each do |article| - if article.type == "UploadedFile" - nodes << article - end - nodes += get_node(article.children) - end - nodes - end end diff --git a/src/noosfero-spb/software_communities/lib/download_block.rb b/src/noosfero-spb/software_communities/lib/download_block.rb index 58048b7..ba5ad64 100644 --- a/src/noosfero-spb/software_communities/lib/download_block.rb +++ b/src/noosfero-spb/software_communities/lib/download_block.rb @@ -33,4 +33,22 @@ class DownloadBlock < Block def cacheable? false end + + def uploaded_files + downloads_folder = Folder.where(name: "Downloads", type: "Folder", profile_id: owner.id) + get_nodes(downloads_folder) + end + + private + + def get_nodes(folder) + nodes = [] + folder.each do |article| + if article.type == "UploadedFile" + nodes << article + end + nodes += get_nodes(article.children) + end + nodes + end end diff --git a/src/noosfero-spb/software_communities/public/blocks/software-download.js b/src/noosfero-spb/software_communities/public/blocks/software-download.js index c546bf1..ba563cb 100644 --- a/src/noosfero-spb/software_communities/public/blocks/software-download.js +++ b/src/noosfero-spb/software_communities/public/blocks/software-download.js @@ -1,37 +1,28 @@ modulejs.define('SoftwareDownload', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) { 'use strict'; - var AJAX_URL = { - get_download_template: - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_block_template") - }; - - var $download_html_template; - - function getDownloadListTemplate() { - $.get(AJAX_URL.get_download_template, { profile: noosfero.profile }) - .done(function(response) { - $download_html_template = response; - }); - } - - function SoftwareDownload() { - getDownloadListTemplate(); } SoftwareDownload.prototype.addNewDonwload = function() { - var new_download = $($download_html_template); + var new_download = $('#download-list-item-template').html(); $("#droppable-list-downloads").append(new_download); } + SoftwareDownload.prototype.selectFile = function(element) { + var path = $(element).find('.file-path').html(); + var size = $(element).find('.file-size').html(); + + var download_option = $(element).find('.file-size').closest('.download-option'); + download_option.find('#block_downloads__link').val(path); + download_option.find('#block_downloads__size').val(size); + } SoftwareDownload.prototype.deleteDownload = function(element) { var delete_download = $(element).parent().parent().parent().remove(); } - return { isCurrentPage: function() { return $('.download-block').length !== 0; diff --git a/src/noosfero-spb/software_communities/views/box_organizer/_download_block.html.erb b/src/noosfero-spb/software_communities/views/box_organizer/_download_block.html.erb index c40c7e7..173a1ee 100644 --- a/src/noosfero-spb/software_communities/views/box_organizer/_download_block.html.erb +++ b/src/noosfero-spb/software_communities/views/box_organizer/_download_block.html.erb @@ -1,11 +1,15 @@