diff --git a/lib/software_communities_plugin.rb b/lib/software_communities_plugin.rb index 5fa7e7b..6c26dca 100644 --- a/lib/software_communities_plugin.rb +++ b/lib/software_communities_plugin.rb @@ -128,6 +128,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin lib/auto-complete.js views/control-panel.js views/edit-software.js + views/new-software.js initializer.js app.js mpog-user-validations.js diff --git a/public/initializer.js b/public/initializer.js index 20b50d8..8783c37 100644 --- a/public/initializer.js +++ b/public/initializer.js @@ -1,10 +1,11 @@ var dependencies = [ 'ControlPanel', - 'EditSoftware' + 'EditSoftware', + 'NewSoftware' ]; -modulejs.define('Initializer', dependencies, function(cp, es) { +modulejs.define('Initializer', dependencies, function(cp, es, ns) { 'use strict'; @@ -18,6 +19,11 @@ modulejs.define('Initializer', dependencies, function(cp, es) { if( es.isEditSoftware() ) { es.init(); } + + + if( ns.isNewSoftware() ) { + ns.init(); + } } }; }); diff --git a/public/views/edit-software.js b/public/views/edit-software.js index d920747..3c2b6ea 100644 --- a/public/views/edit-software.js +++ b/public/views/edit-software.js @@ -1,11 +1,9 @@ -modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], function($, NoosferoRoot, AutoComplete) { +modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete', 'NewSoftware'], function($, NoosferoRoot, AutoComplete, NewSoftware) { 'use strict'; var AJAX_URL = { get_field_data: - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_field_data"), - get_license_data: - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_license_data") + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_field_data") }; @@ -48,11 +46,6 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func } - function show_another_license_on_page_load() { - $("#license_info_id").trigger("change"); - } - - function hide_show_public_software_fields() { if ($("#software_public_software").is(":checked")) { $(".public-software-fields").show(); @@ -71,34 +64,6 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func } - function display_another_license_fields(selected) { - if( selected === "Another" ) { - $("#another_license").removeClass("hide-field"); - $("#version_link").addClass("hide-field"); - console.log($("#version_link")); - } else { - $("#another_license").addClass("hide-field"); - $("#version_link").removeClass("hide-field"); - } - } - - - function display_license_link_on_autocomplete(selected) { - var link = $("#version_" + selected.item.id).val(); - $("#version_link").attr("href", link); - - display_another_license_fields(selected.item.label); - } - - - function license_info_autocomplete() { - AutoComplete.enable( - "license_info", ".license_info_id", ".license_info_version", - AJAX_URL.get_license_data, display_license_link_on_autocomplete - ); - } - - return { isEditSoftware: function() { return $("#especific-info").length === 1; @@ -194,7 +159,7 @@ modulejs.define('EditSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], func replace_software_creations_step(); - license_info_autocomplete(); + NewSoftware.init(); } } }); diff --git a/public/views/new-software.js b/public/views/new-software.js new file mode 100644 index 0000000..196b69e --- /dev/null +++ b/public/views/new-software.js @@ -0,0 +1,52 @@ +modulejs.define('NewSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], function($, NoosferoRoot, AutoComplete) { + 'use strict'; + + var AJAX_URL = { + get_license_data: + NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_license_data") + }; + + + function show_another_license_on_page_load() { + $("#license_info_id").trigger("change"); + } + + + function display_another_license_fields(selected) { + if( selected === "Another" ) { + $("#another_license").removeClass("hide-field"); + $("#version_link").addClass("hide-field"); + } else { + $("#another_license").addClass("hide-field"); + $("#version_link").removeClass("hide-field"); + } + } + + + function display_license_link_on_autocomplete(selected) { + var link = $("#version_" + selected.item.id).val(); + $("#version_link").attr("href", link); + + display_another_license_fields(selected.item.label); + } + + + function license_info_autocomplete() { + AutoComplete.enable( + "license_info", ".license_info_id", ".license_info_version", + AJAX_URL.get_license_data, display_license_link_on_autocomplete + ); + } + + + return { + init: function() { + license_info_autocomplete(); + }, + + + isNewSoftware: function() { + return $('#new-software-page').length === 1; + } + } +}); diff --git a/views/software_communities_plugin_myprofile/new_software.html.erb b/views/software_communities_plugin_myprofile/new_software.html.erb index dfeac85..b8e1512 100644 --- a/views/software_communities_plugin_myprofile/new_software.html.erb +++ b/views/software_communities_plugin_myprofile/new_software.html.erb @@ -1,4 +1,4 @@ -<%= stylesheet_link_tag('plugins/software_communities/mpog-software') %> +