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 %>
-
- <% new = {'icon' => 'ok'} %>
- <%= render :partial => 'download_list', :locals => {:download => new} %>
-
-
-<%= 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 @@
-
- - <%= text_field_tag('block[downloads][][name]', download[:name], :class => "block_download_name") %>
- - <%= text_field_tag('block[downloads][][link]', download[:link], :class => "block_download_link") %>
- - <%= text_field_tag('block[downloads][][software_description]', download[:software_description], :class => "block_download_software_description") %>
- - <%= text_field_tag('block[downloads][][minimum_requirements]', download[:minimum_requirements], :class => "block_download_minimum_requirements") %>
- - <%= text_field_tag('block[downloads][][size]', download[:size], :class => "block_download_size") %>
- - <%= button_without_text(:delete, _('Delete'), "#" , { :onclick => 'delete_link(this); return false', :class=>"delete-link-list-row" }) %>
-
+
+ - <%= text_field_tag('block[downloads][][name]', download[:name], :class => "block_download_name") %>
+ - <%= text_field_tag('block[downloads][][link]', download[:link], :class => "block_download_link") %>
+ - <%= text_field_tag('block[downloads][][software_description]', download[:software_description], :class => "block_download_software_description") %>
+ - <%= text_field_tag('block[downloads][][minimum_requirements]', download[:minimum_requirements], :class => "block_download_minimum_requirements") %>
+ - <%= text_field_tag('block[downloads][][size]', download[:size], :class => "block_download_size") %>
+ - <%= button_without_text(:delete, _('Delete'), "#" , { :onclick => 'softwareDownload.deleteDownload(this); return false', :class=>"delete-link-list-row" }) %>
+
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 @@
-
- - <%= text_field_tag('block[downloads][][name]', '', :class => "block_download_name") %>
- - <%= text_field_tag('block[downloads][][link]', '', :class => "block_download_link") %>
- - <%= text_field_tag('block[downloads][][software_description]', '', :class => "block_download_software_description") %>
- - <%= text_field_tag('block[downloads][][minimum_requirements]', '', :class => "block_download_minimum_requirements") %>
- - <%= text_field_tag('block[downloads][][size]', '', :class => "block_download_size") %>
- - <%= button_without_text(:delete, _('Delete'), "#" , { :onclick => 'delete_link(this); return false', :class=>"delete-link-list-row" }) %>
-
+
+ - <%= text_field_tag('block[downloads][][name]', '', :class => "block_download_name") %>
+ - <%= text_field_tag('block[downloads][][link]', '', :class => "block_download_link") %>
+ - <%= text_field_tag('block[downloads][][software_description]', '', :class => "block_download_software_description") %>
+ - <%= text_field_tag('block[downloads][][minimum_requirements]', '', :class => "block_download_minimum_requirements") %>
+ - <%= text_field_tag('block[downloads][][size]', '', :class => "block_download_size") %>
+ - <%= button_without_text(:delete, _('Delete'), "#" , { :onclick => 'softwareDownload.deleteDownload(this); return false', :class=>"delete-link-list-row" }) %>
+
--
libgit2 0.21.2