Commit 2b0ca56f1b385f5a1a42cf1d10487f1bb618cd4d

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent 3db6dbf0
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 new_software's javascript only when needed

lib/software_communities_plugin.rb
... ... @@ -128,6 +128,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin
128 128 lib/auto-complete.js
129 129 views/control-panel.js
130 130 views/edit-software.js
  131 + views/new-software.js
131 132 initializer.js
132 133 app.js
133 134 mpog-user-validations.js
... ...
public/initializer.js
1 1 var dependencies = [
2 2 'ControlPanel',
3   - 'EditSoftware'
  3 + 'EditSoftware',
  4 + 'NewSoftware'
4 5 ];
5 6  
6 7  
7   -modulejs.define('Initializer', dependencies, function(cp, es) {
  8 +modulejs.define('Initializer', dependencies, function(cp, es, ns) {
8 9 'use strict';
9 10  
10 11  
... ... @@ -18,6 +19,11 @@ modulejs.define('Initializer', dependencies, function(cp, es) {
18 19 if( es.isEditSoftware() ) {
19 20 es.init();
20 21 }
  22 +
  23 +
  24 + if( ns.isNewSoftware() ) {
  25 + ns.init();
  26 + }
21 27 }
22 28 };
23 29 });
... ...
public/views/edit-software.js
1   -modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], function($, NoosferoRoot, AutoComplete) {
  1 +modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete', 'NewSoftware'], function($, NoosferoRoot, AutoComplete, NewSoftware) {
2 2 'use strict';
3 3  
4 4 var AJAX_URL = {
5 5 get_field_data:
6   - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_field_data"),
7   - get_license_data:
8   - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_license_data")
  6 + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_field_data")
9 7 };
10 8  
11 9  
... ... @@ -48,11 +46,6 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func
48 46 }
49 47  
50 48  
51   - function show_another_license_on_page_load() {
52   - $("#license_info_id").trigger("change");
53   - }
54   -
55   -
56 49 function hide_show_public_software_fields() {
57 50 if ($("#software_public_software").is(":checked")) {
58 51 $(".public-software-fields").show();
... ... @@ -71,34 +64,6 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func
71 64 }
72 65  
73 66  
74   - function display_another_license_fields(selected) {
75   - if( selected === "Another" ) {
76   - $("#another_license").removeClass("hide-field");
77   - $("#version_link").addClass("hide-field");
78   - console.log($("#version_link"));
79   - } else {
80   - $("#another_license").addClass("hide-field");
81   - $("#version_link").removeClass("hide-field");
82   - }
83   - }
84   -
85   -
86   - function display_license_link_on_autocomplete(selected) {
87   - var link = $("#version_" + selected.item.id).val();
88   - $("#version_link").attr("href", link);
89   -
90   - display_another_license_fields(selected.item.label);
91   - }
92   -
93   -
94   - function license_info_autocomplete() {
95   - AutoComplete.enable(
96   - "license_info", ".license_info_id", ".license_info_version",
97   - AJAX_URL.get_license_data, display_license_link_on_autocomplete
98   - );
99   - }
100   -
101   -
102 67 return {
103 68 isEditSoftware: function() {
104 69 return $("#especific-info").length === 1;
... ... @@ -194,7 +159,7 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func
194 159  
195 160 replace_software_creations_step();
196 161  
197   - license_info_autocomplete();
  162 + NewSoftware.init();
198 163 }
199 164 }
200 165 });
... ...
public/views/new-software.js 0 → 100644
... ... @@ -0,0 +1,52 @@
  1 +modulejs.define('NewSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], function($, NoosferoRoot, AutoComplete) {
  2 + 'use strict';
  3 +
  4 + var AJAX_URL = {
  5 + get_license_data:
  6 + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_license_data")
  7 + };
  8 +
  9 +
  10 + function show_another_license_on_page_load() {
  11 + $("#license_info_id").trigger("change");
  12 + }
  13 +
  14 +
  15 + function display_another_license_fields(selected) {
  16 + if( selected === "Another" ) {
  17 + $("#another_license").removeClass("hide-field");
  18 + $("#version_link").addClass("hide-field");
  19 + } else {
  20 + $("#another_license").addClass("hide-field");
  21 + $("#version_link").removeClass("hide-field");
  22 + }
  23 + }
  24 +
  25 +
  26 + function display_license_link_on_autocomplete(selected) {
  27 + var link = $("#version_" + selected.item.id).val();
  28 + $("#version_link").attr("href", link);
  29 +
  30 + display_another_license_fields(selected.item.label);
  31 + }
  32 +
  33 +
  34 + function license_info_autocomplete() {
  35 + AutoComplete.enable(
  36 + "license_info", ".license_info_id", ".license_info_version",
  37 + AJAX_URL.get_license_data, display_license_link_on_autocomplete
  38 + );
  39 + }
  40 +
  41 +
  42 + return {
  43 + init: function() {
  44 + license_info_autocomplete();
  45 + },
  46 +
  47 +
  48 + isNewSoftware: function() {
  49 + return $('#new-software-page').length === 1;
  50 + }
  51 + }
  52 +});
... ...
views/software_communities_plugin_myprofile/new_software.html.erb
1   -<%= stylesheet_link_tag('plugins/software_communities/mpog-software') %>
  1 +<span id="new-software-page"></span>
2 2  
3 3 <div class="software-step-info">
4 4 <h3><%= _("Step 1 - Software Creation")%></h3>
... ...