Commit 4a6a65c779a4de11f79fe871193188df6fd3f833

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent 0b5a684a
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Execute download block javascript only when needed

lib/software_communities_plugin.rb
... ... @@ -126,9 +126,9 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin
126 126 views/create-institution.js
127 127 views/complete-registration.js
128 128 views/search-software-catalog.js
  129 + blocks/software-download.js
129 130 initializer.js
130 131 app.js
131   - mpog-download-block.js
132 132 )
133 133 end
134 134  
... ...
public/blocks/software-download.js 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +modulejs.define('SoftwareDownload', ['jquery'], function($) {
  2 + 'use strict';
  3 +
  4 + function add_new_link(){
  5 + var newDownload = $(window.download_list_template);
  6 + newDownload.attr('data-counter-id', 1);
  7 + $("#droppable-list-downloads").append(newDownload);
  8 + }
  9 +
  10 +
  11 + function delete_link(add_element){
  12 + var deleteDownload = $(add_element).parent().parent().parent();
  13 + deleteDownload.remove();
  14 + }
  15 +
  16 +
  17 + function get_download_list_template() {
  18 + var blockTemplate = sessionStorage.getItem('download_list_block_template');
  19 +
  20 + if(blockTemplate && blockTemplate.length > 0) {
  21 + window.download_list_template = blockTemplate;
  22 + } else {
  23 + $.get('/plugin/software_communities/get_block_template', function(response) {
  24 + window.download_list_template = response;
  25 + sessionStorage.setItem('download_list_block_template', response);
  26 + });
  27 + }
  28 + }
  29 +
  30 +
  31 + return {
  32 + isCurrentPage: function() {
  33 + return $('.download-block').length !== 0;
  34 + },
  35 +
  36 +
  37 + init: function() {
  38 + window.add_new_link = add_new_link;
  39 + window.delete_link = delete_link;
  40 +
  41 + if( window.download_list_template === undefined ) {
  42 + get_download_list_template();
  43 + }
  44 + }
  45 + }
  46 +});
... ...
public/initializer.js
1   -var dependencies = [
2   - 'ControlPanel',
3   - 'EditSoftware',
4   - 'NewSoftware',
5   - 'UserEditProfile',
6   - 'CreateInstitution',
7   - 'CompleteRegistration',
8   - 'SearchSoftwareCatalog'
9   -];
  1 +(function() {
  2 + 'use strict';
10 3  
  4 + var dependencies = [
  5 + 'ControlPanel',
  6 + 'EditSoftware',
  7 + 'NewSoftware',
  8 + 'UserEditProfile',
  9 + 'CreateInstitution',
  10 + 'CompleteRegistration',
  11 + 'SearchSoftwareCatalog',
  12 + 'SoftwareDownload'
  13 + ];
11 14  
12   -modulejs.define('Initializer', dependencies, function() {
13   - 'use strict';
14 15  
15   - var __dependencies = arguments;
  16 + modulejs.define('Initializer', dependencies, function() {
  17 + var __dependencies = arguments;
16 18  
17 19  
18   - function call_dependency(dependency) {
19   - if( dependency.isCurrentPage() ) {
20   - dependency.init();
  20 + function call_dependency(dependency) {
  21 + if( dependency.isCurrentPage() ) {
  22 + dependency.init();
  23 + }
21 24 }
22   - }
23 25  
24 26  
25   - return {
26   - init: function() {
27   - for(var i=0, len = __dependencies.length; i < len; i++) {
28   - call_dependency(__dependencies[i]);
  27 + return {
  28 + init: function() {
  29 + for(var i=0, len = __dependencies.length; i < len; i++) {
  30 + call_dependency(__dependencies[i]);
  31 + }
29 32 }
30   - }
31   - };
32   -});
  33 + };
  34 + });
  35 +})();
... ...
public/mpog-download-block.js
... ... @@ -1,38 +0,0 @@
1   -(function($) {
2   - 'use strict';
3   -
4   - function add_new_link(){
5   - var newDownload = $(window.download_list_template);
6   - newDownload.attr('data-counter-id', 1);
7   - $("#droppable-list-downloads").append(newDownload);
8   - }
9   -
10   -
11   - function delete_link(add_element){
12   - var deleteDownload = $(add_element).parent().parent().parent();
13   - deleteDownload.remove();
14   - }
15   -
16   -
17   - function get_download_list_template() {
18   - var blockTemplate = sessionStorage.getItem('download_list_block_template');
19   -
20   - if(blockTemplate && blockTemplate.length > 0) {
21   - window.download_list_template = blockTemplate;
22   - } else {
23   - $.get('/plugin/software_communities/get_block_template', function(response) {
24   - window.download_list_template = response;
25   - sessionStorage.setItem('download_list_block_template', response);
26   - });
27   - }
28   - }
29   -
30   - $(document).ready(function() {
31   - window.add_new_link = add_new_link;
32   - window.delete_link = delete_link;
33   -
34   - if( window.download_list_template === undefined ) {
35   - get_download_list_template();
36   - }
37   - });
38   -})(jQuery);