improvements to pool add

This commit is contained in:
albert
2013-02-17 23:39:43 -05:00
parent 2af59642f6
commit ae082cda48
4 changed files with 26 additions and 10 deletions

View File

@@ -23,7 +23,7 @@
}
);
},
minLength: 4,
minLength: 2,
});
$("#pool").click(function(e) {

View File

@@ -5,14 +5,12 @@ class PoolElementsController < ApplicationController
def create
@pool = Pool.find_by_name(params[:pool_name]) || Pool.find_by_id(params[:pool_id])
if @pool.nil?
return
if @pool.present?
@post = Post.find(params[:post_id])
@pool.add!(@post)
append_pool_to_session(@pool)
end
@post = Post.find(params[:post_id])
@pool.add!(@post)
append_pool_to_session(@pool)
respond_with(@pool, :location => post_path(@post))
end

View File

@@ -25,6 +25,7 @@ class Pool < ActiveRecord::Base
return q if params.blank?
if params[:name_matches].present?
params[:name_matches] += "*" unless params[:name_matches] =~ /\*/
q = q.where("name like ? escape E'\\\\'", params[:name_matches].to_escaped_for_sql_like)
end
@@ -64,6 +65,10 @@ class Pool < ActiveRecord::Base
select_value_sql("SELECT name FROM pools WHERE id = ?", id)
end
def self.options
select_all_sql("SELECT id, name FROM pools WHERE is_active = true AND is_deleted = false ORDER BY name LIMIT 100").map {|x| [x["name"], x["id"]]}
end
def self.create_anonymous
Pool.new do |pool|
pool.name = "TEMP:#{Time.now.to_f}.#{rand(1_000_000)}"

View File

@@ -1,9 +1,22 @@
<div id="c-pool-elements">
<div id="a-new">
<%= form_tag(pool_element_path) do %>
<%= form_tag(pool_element_path, :class => "simple_form") do %>
<%= hidden_field_tag "post_id", @post.id %>
<%= text_field_tag "pool_name", "", :size => 20 %>
<%= submit_tag "Select" %>
<div class="input">
<label>Pool</label>
<%= select_tag "pool_id", options_for_select([["", ""]] + Pool.options) %>
</div>
<div class="input">
<label>Pool Name</label>
<%= text_field_tag "pool_name", "", :size => 20 %>
<span class="hint">Type the first two characters of a pool name</span>
</div>
<div class="input">
<%= submit_tag "Select" %>
</div>
<% end %>
<% if recent_updated_pools.any? %>