Skip to content

Commit

Permalink
Fixed similar tags while editing the idea
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturG committed Feb 19, 2013
1 parent 73c42a2 commit 3077efa
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
26 changes: 13 additions & 13 deletions app/assets/javascripts/ideas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@ var suggested_tag = []

$(document).ready(function($) {

var idea_title = $('input#idea_title');
var idea_summary = $('textarea#idea_summary');
var idea_body = $('textarea#idea_body');
var idea_id = $('input#idea_id');

$('input#idea_tag_list').tokenInput("/tags.json",
{ theme: "facebook",
prePopulate: $('input#idea_tag_list').data('load'),
onAdd: function (item) {
tags.push(item.name);
send_data(idea_title.val(), idea_summary.val(), idea_body.val());
send_data(idea_title.val(), idea_summary.val(), idea_body.val(), idea_id.val());
},
onDelete: function (item) {
tags.splice(tags.indexOf(item.name), 1 );
send_data(idea_title.val(), idea_summary.val(), idea_body.val());
send_data(idea_title.val(), idea_summary.val(), idea_body.val(), idea_id.val());
}
});

$('.response').hide();
$('.tag_input_box').hide();

var idea_title = $('input#idea_title');
var idea_summary = $('textarea#idea_summary');
var idea_body = $('textarea#idea_body');


idea_title.focus();

idea_title.keyup(function() {
send_data(idea_title.val(), idea_summary.val(), idea_body.val());
send_data(idea_title.val(), idea_summary.val(), idea_body.val(), idea_id.val());
});

idea_summary.keyup(function() {
send_data(idea_title.val(), idea_summary.val(), idea_body.val());
send_data(idea_title.val(), idea_summary.val(), idea_body.val(), idea_id.val());
});

idea_body.keyup(function() {
send_data(idea_title.val(), idea_summary.val(), idea_body.val());
send_data(idea_title.val(), idea_summary.val(), idea_body.val(), idea_id.val());
});
})

function send_data(title_text, summary_text, body_text) {
function send_data(title_text, summary_text, body_text, idea_id) {
$.ajax({
type:'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))
},
url: '../ideas/lda?title_text=' + title_text + '&summary_text=' + summary_text + '&body_text=' + body_text + '&tags=' + tags ,
url: '../ideas/lda?title_text=' + title_text + '&summary_text=' + summary_text + '&body_text=' + body_text + '&tags=' + tags + '&idea_id=' + idea_id ,
success:function(data){
//
}
Expand Down
3 changes: 1 addition & 2 deletions app/assets/stylesheets/ideas.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,7 @@ input#idea_title {
width: 66%;
}

#lda_response {
padding-top: 38px;
#lda_response {
float: right;
width: 45%;
}
Expand Down
1 change: 1 addition & 0 deletions app/controllers/ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def lda
tag_ids = Tag.get_ids_by_name(params[:tags])
@lda_respond = @title_text + @summary_text + @body_text
@ideas_suggested_by_tags = Idea.find_similar(tag_ids)
@idea = Idea.find(params[:idea_id])
respond_to do |format|
format.js { render :respond, locals: { lda_respond: @lda_respond, ideas_suggested_by_tags: @ideas_suggested_by_tags } }
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/ideas/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
= f.input :summary, as: :text
.grid_16
= f.input :body, as: :text
.grid_16
= f.hidden_field :id, :value => @idea.id
.grid_16
= f.submit @idea.new_record? ? I18n.t("buttons.create") : I18n.t("buttons.update")
5 changes: 2 additions & 3 deletions app/views/ideas/_respond.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ Please, check ideas below before creating new one.
#tag_cloud
%h2 Tags Suggested for your idea:
%ul.cloud
- Idea.tag_counts.limit(5).sort_by(&:count).reverse.each do |tag|
- @idea.possible_tags.sort_by(&:count).reverse.each do |tag|
%li.cloud{:id => "#{tag.name}"}
%p= tag.name
%span.add_token
= link_to "\u2714", '#', :onclick => "$('input#idea_tag_list').tokenInput('add', {id: #{tag.id}, name: '#{tag.name}'});"

= link_to "\u2714", '#', :onclick => "$('input#idea_tag_list').tokenInput('add', {id: #{tag.id}, name: '#{tag.name}'});"
6 changes: 4 additions & 2 deletions app/views/tags/_tags.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
%p= tag.name
%span.add_token
= link_to "\u2714", add_to_suggested_tag_path(:tag_id => tag), remote: true
= link_to "Show all", '#'
#suggested_tags_form
Or create a new one:
= form_for @idea, :url => {:controller => 'ideas', :action => 'suggest_tags', :id => @idea.id }, :remote => true, :html => { :method => :post } do |f|
Expand All @@ -38,5 +39,6 @@
- @idea.tags.each do |tag|
- tag_ids << tag.id
- Idea.find_similar(tag_ids).each do |idea|
= link_to idea.title, idea
%br
- if idea != @idea
= link_to idea.title, idea
%br
4 changes: 2 additions & 2 deletions app/views/tags/citizen_voted.js.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$("#tag_cloud").html("<%= escape_javascript(render(:partial => 'tags', :locals => {:idea => @idea})).html_safe %>");
$("li#<%= @tag.id %>.approved_tags span.score").show();
$("li#<%= @tag.id %>.suggested_tags span.score").show();
$("li#<%= @tag.id %>.approved_tags span.score").fadeOut(6000);
$("li#<%= @tag.id %>.suggested_tags span.score").fadeOut(6000);
$("li#<%= @tag.id %>.approved_tags span.score").fadeOut(600);
$("li#<%= @tag.id %>.suggested_tags span.score").fadeOut(600);

0 comments on commit 3077efa

Please sign in to comment.