From 526afc86795c7be79e5482289edc15bde058a9f5 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Tue, 10 Feb 2015 16:05:38 -0200 Subject: [PATCH] Set lincense to use the same ajax as software's dynamic tables --- controllers/mpog_software_plugin_myprofile_controller.rb | 3 +++ public/mpog-software-validations.js | 51 ++++++++++++++++++++++----------------------------- views/mpog_software_plugin_myprofile/_license_info_fields.html.erb | 15 +++++++++++++++ views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb | 24 +++++++----------------- views/mpog_software_plugin_myprofile/new_software.html.erb | 23 ++++++----------------- 5 files changed, 53 insertions(+), 63 deletions(-) create mode 100644 views/mpog_software_plugin_myprofile/_license_info_fields.html.erb diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index 0317c93..852a56c 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -180,11 +180,14 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @list_operating_systems = @software_info.operating_systems @disabled_public_software_field = disabled_public_software_field + @license_version = @software_info.license_info.version + @license_id = @software_info.license_info.id @another_license_version = "" @another_license_link = "" license_another = LicenseInfo.find_by_version("Another") if license_another && @software_info.license_info_id == license_another.id + @license_version = "Another" @another_license_version = @software_info.license_info.version @another_license_link = @software_info.license_info.link end diff --git a/public/mpog-software-validations.js b/public/mpog-software-validations.js index ab327df..d4dff98 100644 --- a/public/mpog-software-validations.js +++ b/public/mpog-software-validations.js @@ -21,7 +21,7 @@ if( field.length === 0 || selected.val().length === 0 ) { message_error.removeClass("hide-field"); - selected_value.val(""); + selected.val(""); message_error.show(); } else { @@ -32,21 +32,21 @@ function database_autocomplete() { - enable_autocomplete("database", ".database_description_id", ".database_autocomplete"); + enable_autocomplete("database", ".database_description_id", ".database_autocomplete", AJAX_URL.get_field_data); } function language_autocomplete() { - enable_autocomplete("software_language", ".programming_language_id", ".language_autocomplete"); + enable_autocomplete("software_language", ".programming_language_id", ".language_autocomplete", AJAX_URL.get_field_data); } - function enable_autocomplete(field_name, field_value_class, autocomplete_class) { + function enable_autocomplete(field_name, field_value_class, autocomplete_class, ajax_url, select_callback) { $(autocomplete_class).autocomplete({ source : function(request, response){ $.ajax({ type: "GET", - url: AJAX_URL.get_field_data, + url: ajax_url, data: {query: request.term, field: field_name}, success: function(result){ response(result); @@ -60,6 +60,10 @@ var description = get_hidden_description_field(this, field_value_class); description.val(selected.item.id); description.attr("data-label", selected.item.label); + + if( select_callback !== undefined ) { + select_callback(selected); + } } }).blur(function(){ verify_autocomplete(this, field_value_class); @@ -135,39 +139,27 @@ 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 trigger_license_info_events() { - $("#license_info_version").autocomplete({ - source : function(request, response){ - $.ajax({ - type: "GET", - url: AJAX_URL.get_license_data, - data: {query: request.term}, - success: function(result){ - response(result); - } - }); - }, - minLength: 0, + function display_license_link_on_autocomplete(selected) { + var link = $("#version_" + selected.item.id).val(); + $("#version_link").attr("href", link); - select : function (event, selected) { - $("#license_info_id").val(selected.item.id); - var link = $("#version_" + selected.item.id).val(); + display_another_license_fields(selected.item.label); + } - console.log(link); - display_another_license_fields(selected.item.label); - $("#version_link").attr("href", link).text(link); - } - }).click(function(){ - $(this).autocomplete("search", this.value); - }); + function license_info_autocomplete() { + enable_autocomplete( + "license_info", ".license_info_id", ".license_info_version", + AJAX_URL.get_license_data, display_license_link_on_autocomplete + ); } @@ -196,6 +188,7 @@ return false; }); + $(".language-button-hide").click(function(event){ event.preventDefault(); $(".language-info").hide(); @@ -257,6 +250,6 @@ replace_software_creations_step(); - trigger_license_info_events(); + license_info_autocomplete(); }); })(jQuery); diff --git a/views/mpog_software_plugin_myprofile/_license_info_fields.html.erb b/views/mpog_software_plugin_myprofile/_license_info_fields.html.erb new file mode 100644 index 0000000..84b71e7 --- /dev/null +++ b/views/mpog_software_plugin_myprofile/_license_info_fields.html.erb @@ -0,0 +1,15 @@ +<% LicenseHelper.getListLicenses.each do | license | %> + +<% end %> + +

<%= _("License Version: ") %>

+<%= text_field_tag "license_info[version]", license_version, :id=>"license_info_version", :class=>"license_info_version", :placeholder=>_('Autocomplete field, type some license') %> +<%= hidden_field_tag "license[license_infos_id]", license_id, :id=>"license_info_id", :class=>"license_info_id", :data => {:label=>license_version} %> + +<%= _("Read license") %> + +
+ <%= labelled_text_field "Licence version", "license[version]", another_version, :id=>"licence_version" %> +
+ <%= labelled_text_field "Licence link", "license[link]", another_link, :id=>"licence_link" %> +
diff --git a/views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb b/views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb index a8d5d34..3f0c2bf 100644 --- a/views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb +++ b/views/mpog_software_plugin_myprofile/_main_software_editor_extras.html.erb @@ -10,24 +10,14 @@ <%= text_area_tag "software[finality]", @profile.software_info.finality, :placeholder => _("It is a software of..."), :cols => 40, :rows => 5, :maxlength => 140%> -

<%= _("Licenses") %>

- <%= select_tag("license[license_infos_id]", options_for_select(LicenseHelper.getListLicenses.collect{|l| [l.version, l.id]}, :selected => @profile.software_info.license_info_id), :id => "license_info_id") %> - - <%= labelled_text_field _("License Version: "), "license_info[version]", @profile.software_info.license_info.version, :id=>"license_info_version" %> - <%= hidden_field_tag "license[license_infos_id]", @profile.software_info.license_info_id, :id=>"license_info_id" %> -
- -

<%= _("License link") %>

- <% LicenseHelper.getListLicenses.each do | license | %> - - <% end %> - <%= @profile.software_info.license_info.link %> -
- <%= labelled_text_field "Licence version", "license[version]", "#{@another_license_version}", :id=>"licence_version" %> -
- <%= labelled_text_field "Licence link", "license[link]", "#{@another_license_link}", :id=>"licence_link" %> -
+ <%= render :partial => "license_info_fields", :locals => { + :license_version => @license_version, + :license_id => @license_id, + :another_version => @another_license_version, + :another_link => @another_license_link + } + %>

<%= _("Link to Repository") %>

diff --git a/views/mpog_software_plugin_myprofile/new_software.html.erb b/views/mpog_software_plugin_myprofile/new_software.html.erb index 8cb9816..396e2fd 100644 --- a/views/mpog_software_plugin_myprofile/new_software.html.erb +++ b/views/mpog_software_plugin_myprofile/new_software.html.erb @@ -42,25 +42,14 @@ <% end %> - <%= fields_for @license_info do |lcv| %>
- <%= labelled_text_field _("License Version: "), "license_info[version]", "", :id=>"license_info_version" %> - <%= hidden_field_tag "license[license_infos_id]", "", :id=>"license_info_id" %> - -

<%= _("License link") %>

- <% LicenseHelper.getListLicenses.each do | license | %> - - <% end %> - <%=LicenseInfo.first.link %> - -
- <%= labelled_text_field "Licence version", "license[version]", "", :id=>"licence_version" %> -
- <%= labelled_text_field "Licence link", "license[link]", "", :id=>"licence_link" %> -
+ <%= render :partial => "license_info_fields", :locals => { + :license_version => "", + :license_id => "", + :another_version=>"", + :another_link=>"" + } %>
- <% end %> - <%= fields_for @software_info do |swf| %>
-- libgit2 0.21.2