diff --git a/public/blocks/software-download.js b/public/blocks/software-download.js index d4f7da0..8716d24 100644 --- a/public/blocks/software-download.js +++ b/public/blocks/software-download.js @@ -1,33 +1,38 @@ modulejs.define('SoftwareDownload', ['jquery'], function($) { 'use strict'; - function add_new_link(){ - var newDownload = $(window.download_list_template); - newDownload.attr('data-counter-id', 1); - $("#droppable-list-downloads").append(newDownload); - } - - - function delete_link(add_element){ - var deleteDownload = $(add_element).parent().parent().parent(); - deleteDownload.remove(); - } + var $download_html_template; + function getDownloadListTemplate() { + var block_template = sessionStorage.getItem('download_list_block_template'); - function get_download_list_template() { - var blockTemplate = sessionStorage.getItem('download_list_block_template'); - - if(blockTemplate && blockTemplate.length > 0) { - window.download_list_template = blockTemplate; + if(block_template && block_template.length > 0) { + $download_html_template = block_template; } else { $.get('/plugin/software_communities/get_block_template', function(response) { - window.download_list_template = response; + $download_html_template = response; sessionStorage.setItem('download_list_block_template', response); }); } } + function SoftwareDownload() { + getDownloadListTemplate(); + } + + + SoftwareDownload.prototype.addNewDonwload = function() { + var new_download = $($download_html_template); + $("#droppable-list-downloads").append(new_download); + } + + + SoftwareDownload.prototype.deleteDownload = function(element) { + var delete_download = $(element).parent().parent().parent().remove(); + } + + return { isCurrentPage: function() { return $('.download-block').length !== 0; @@ -35,12 +40,7 @@ modulejs.define('SoftwareDownload', ['jquery'], function($) { init: function() { - window.add_new_link = add_new_link; - window.delete_link = delete_link; - - if( window.download_list_template === undefined ) { - get_download_list_template(); - } + window.softwareDownload = new SoftwareDownload(); } } }); diff --git a/views/box_organizer/_download_block.html.erb b/views/box_organizer/_download_block.html.erb index 950c1ab..6a621ec 100644 --- a/views/box_organizer/_download_block.html.erb +++ b/views/box_organizer/_download_block.html.erb @@ -8,22 +8,10 @@
- <% if @block.downloads.count > 0 %> - <% for download in @block.downloads %> - <%= render :partial => 'download_list', :locals => {:download => download} %> - <% end %> - <% else %> -
- <% new = {'icon' => 'ok'} %> - <%= render :partial => 'download_list', :locals => {:download => new} %> -
- <% end %> + <% @block.downloads.each do |download| %> + <%= render :partial => 'download_list', :locals => {:download => download} %> + <% end %>
- - -<%= link_to_function _('New link'), 'add_new_link(); return false', :class => 'button icon-add with-text download-new-link-button' %> + <%= link_to_function _('New link'), 'softwareDownload.addNewDonwload(); return false', :class => 'button icon-add with-text download-new-link-button' %> diff --git a/views/box_organizer/_download_list.html.erb b/views/box_organizer/_download_list.html.erb index 2552704..1cbd524 100644 --- a/views/box_organizer/_download_list.html.erb +++ b/views/box_organizer/_download_list.html.erb @@ -1,10 +1,10 @@
  • - +
  • diff --git a/views/box_organizer/_download_list_template.html.erb b/views/box_organizer/_download_list_template.html.erb index 630e70a..eb9e4cf 100644 --- a/views/box_organizer/_download_list_template.html.erb +++ b/views/box_organizer/_download_list_template.html.erb @@ -1,10 +1,10 @@
  • - +
  • -- libgit2 0.21.2