Commit 2b0ca56f1b385f5a1a42cf1d10487f1bb618cd4d
Committed by
Gabriela Navarro
1 parent
3db6dbf0
Exists in
master
and in
5 other branches
Execute new_software's javascript only when needed
Showing
5 changed files
with
65 additions
and
41 deletions
Show diff stats
lib/software_communities_plugin.rb
@@ -128,6 +128,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -128,6 +128,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
128 | lib/auto-complete.js | 128 | lib/auto-complete.js |
129 | views/control-panel.js | 129 | views/control-panel.js |
130 | views/edit-software.js | 130 | views/edit-software.js |
131 | + views/new-software.js | ||
131 | initializer.js | 132 | initializer.js |
132 | app.js | 133 | app.js |
133 | mpog-user-validations.js | 134 | mpog-user-validations.js |
public/initializer.js
1 | var dependencies = [ | 1 | var dependencies = [ |
2 | 'ControlPanel', | 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 | 'use strict'; | 9 | 'use strict'; |
9 | 10 | ||
10 | 11 | ||
@@ -18,6 +19,11 @@ modulejs.define('Initializer', dependencies, function(cp, es) { | @@ -18,6 +19,11 @@ modulejs.define('Initializer', dependencies, function(cp, es) { | ||
18 | if( es.isEditSoftware() ) { | 19 | if( es.isEditSoftware() ) { |
19 | es.init(); | 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 | 'use strict'; | 2 | 'use strict'; |
3 | 3 | ||
4 | var AJAX_URL = { | 4 | var AJAX_URL = { |
5 | get_field_data: | 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,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 | function hide_show_public_software_fields() { | 49 | function hide_show_public_software_fields() { |
57 | if ($("#software_public_software").is(":checked")) { | 50 | if ($("#software_public_software").is(":checked")) { |
58 | $(".public-software-fields").show(); | 51 | $(".public-software-fields").show(); |
@@ -71,34 +64,6 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func | @@ -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 | return { | 67 | return { |
103 | isEditSoftware: function() { | 68 | isEditSoftware: function() { |
104 | return $("#especific-info").length === 1; | 69 | return $("#especific-info").length === 1; |
@@ -194,7 +159,7 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func | @@ -194,7 +159,7 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func | ||
194 | 159 | ||
195 | replace_software_creations_step(); | 160 | replace_software_creations_step(); |
196 | 161 | ||
197 | - license_info_autocomplete(); | 162 | + NewSoftware.init(); |
198 | } | 163 | } |
199 | } | 164 | } |
200 | }); | 165 | }); |
@@ -0,0 +1,52 @@ | @@ -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