refinerycms-polls 0.0.1.dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/.gitignore +55 -0
  2. data/Gemfile +71 -0
  3. data/Guardfile +27 -0
  4. data/README.md +35 -0
  5. data/Rakefile +20 -0
  6. data/app/assets/images/refinery/polls/pollbg.gif +0 -0
  7. data/app/assets/javascripts/refinery/polls/poll_form.js +8 -0
  8. data/app/assets/stylesheets/refinery/polls/poll_form.css.scss +31 -0
  9. data/app/controllers/refinery/polls/admin/answers_controller.rb +55 -0
  10. data/app/controllers/refinery/polls/admin/questions_controller.rb +11 -0
  11. data/app/controllers/refinery/polls/questions_controller.rb +62 -0
  12. data/app/models/refinery/polls/answer.rb +39 -0
  13. data/app/models/refinery/polls/question.rb +60 -0
  14. data/app/models/refinery/polls/setting.rb +62 -0
  15. data/app/models/refinery/polls/vote.rb +34 -0
  16. data/app/views/refinery/polls/admin/answers/_actions.html.erb +25 -0
  17. data/app/views/refinery/polls/admin/answers/_answer.html.erb +16 -0
  18. data/app/views/refinery/polls/admin/answers/_answers.html.erb +2 -0
  19. data/app/views/refinery/polls/admin/answers/_form.html.erb +17 -0
  20. data/app/views/refinery/polls/admin/answers/_records.html.erb +18 -0
  21. data/app/views/refinery/polls/admin/answers/_sorteable_list.html.erb +5 -0
  22. data/app/views/refinery/polls/admin/answers/edit.html.erb +1 -0
  23. data/app/views/refinery/polls/admin/answers/index.html.erb +7 -0
  24. data/app/views/refinery/polls/admin/answers/new.html.erb +1 -0
  25. data/app/views/refinery/polls/admin/questions/_actions.html.erb +25 -0
  26. data/app/views/refinery/polls/admin/questions/_form.html.erb +29 -0
  27. data/app/views/refinery/polls/admin/questions/_question.html.erb +22 -0
  28. data/app/views/refinery/polls/admin/questions/_questions.html.erb +2 -0
  29. data/app/views/refinery/polls/admin/questions/_records.html.erb +18 -0
  30. data/app/views/refinery/polls/admin/questions/_sortable_list.html.erb +5 -0
  31. data/app/views/refinery/polls/admin/questions/edit.html.erb +1 -0
  32. data/app/views/refinery/polls/admin/questions/index.html.erb +7 -0
  33. data/app/views/refinery/polls/admin/questions/new.html.erb +1 -0
  34. data/app/views/refinery/polls/questions/_answers_form.html.erb +10 -0
  35. data/app/views/refinery/polls/questions/_poll.html.erb +10 -0
  36. data/app/views/refinery/polls/questions/_results.html.erb +14 -0
  37. data/app/views/refinery/polls/questions/index.html.erb +11 -0
  38. data/app/views/refinery/polls/questions/results.html.erb +0 -0
  39. data/app/views/refinery/polls/questions/show.html.erb +39 -0
  40. data/app/views/refinery/polls/questions/submit.js.erb +1 -0
  41. data/config/locales/en.yml +44 -0
  42. data/config/locales/es.yml +31 -0
  43. data/config/locales/fr.yml +30 -0
  44. data/config/locales/nb.yml +30 -0
  45. data/config/locales/nl.yml +30 -0
  46. data/config/routes.rb +33 -0
  47. data/db/migrate/1_create_polls_questions.rb +41 -0
  48. data/db/migrate/2_create_polls_answers.rb +25 -0
  49. data/db/migrate/3_create_polls_votes.rb +14 -0
  50. data/db/migrate/4_add_slug_to_questions_and_answers.rb +9 -0
  51. data/db/migrate/5_create_polls_translations.rb +22 -0
  52. data/db/seeds.rb +24 -0
  53. data/lib/generators/refinery/polls_generator.rb +25 -0
  54. data/lib/generators/refinery/templates/config/initializers/refinery/poll.rb.erb +4 -0
  55. data/lib/refinery/polls/configuration.rb +10 -0
  56. data/lib/refinery/polls/engine.rb +26 -0
  57. data/lib/refinery/polls/version.rb +18 -0
  58. data/lib/refinery/polls.rb +21 -0
  59. data/lib/refinerycms-polls.rb +1 -0
  60. data/lib/tasks/refinery/polls.rake +13 -0
  61. data/refinerycms-polls.gemspec +27 -0
  62. data/spec/models/refinery/polls/question_spec.rb +18 -0
  63. data/spec/requests/refinery/polls/admin/questions_spec.rb +101 -0
  64. data/spec/spec_helper.rb +50 -0
  65. data/spec/support/factories/refinery/polls.rb +7 -0
  66. data/tasks/rspec.rake +6 -0
  67. data/tasks/testing.rake +8 -0
  68. metadata +163 -0
data/.gitignore ADDED
@@ -0,0 +1,55 @@
1
+ .bundle
2
+ *.gem
3
+ *.info
4
+ *.DS_Store
5
+
6
+ # Documentation
7
+ doc/api
8
+ doc/app
9
+ doc/*
10
+ .yardoc
11
+ .yardopts
12
+
13
+ # Refinery Specific
14
+ *.tmproj
15
+ *.autobackupbyrefinery.*
16
+ /refinerycms-blog*.gem
17
+ .autotest
18
+ spec/dummy
19
+
20
+ # Mac
21
+ .DS_Store
22
+
23
+ # NetBeans
24
+ nbproject
25
+
26
+ # Eclipse
27
+ .project
28
+
29
+ # Redcar
30
+ .redcar
31
+
32
+ # Rubinius
33
+ *.rbc
34
+
35
+ # Vim
36
+ *.swp
37
+ *.swo
38
+
39
+ # RubyMine
40
+ .idea
41
+
42
+ # Backup
43
+ *~
44
+
45
+ # Capybara Bug
46
+ capybara-*html
47
+
48
+ # rvm
49
+ .rvmrc
50
+
51
+ #rbenv
52
+ .rbenv-version
53
+
54
+ Gemfile.lock
55
+ .rbx
data/Gemfile ADDED
@@ -0,0 +1,71 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'refinerycms', '~> 2.0.0', :git => 'git://github.com/resolve/refinerycms.git'
6
+ gem 'refinerycms-i18n', :git => 'git://github.com/parndt/refinerycms-i18n.git'
7
+ gem 'refinerycms-settings', :git => 'git://github.com/parndt/refinerycms-settings.git'
8
+
9
+ # Refinery/rails should pull in the proper versions of these
10
+ group :assets do
11
+ gem 'sass-rails'
12
+ gem 'coffee-rails'
13
+ gem 'uglifier'
14
+ end
15
+
16
+ gem 'jquery-rails'
17
+
18
+ group :development, :test do
19
+ gem 'refinerycms-testing', '~> 2.0.0'
20
+ gem 'factory_girl_rails'
21
+ gem 'generator_spec'
22
+
23
+ require 'rbconfig'
24
+
25
+ platforms :jruby do
26
+ gem 'activerecord-jdbcsqlite3-adapter'
27
+ gem 'activerecord-jdbcmysql-adapter'
28
+ gem 'activerecord-jdbcpostgresql-adapter'
29
+ gem 'jruby-openssl'
30
+ end
31
+
32
+ unless defined?(JRUBY_VERSION)
33
+ gem 'sqlite3'
34
+ gem 'mysql2'
35
+ gem 'pg'
36
+ end
37
+
38
+ platforms :mswin, :mingw do
39
+ gem 'win32console'
40
+ gem 'rb-fchange', '~> 0.0.5'
41
+ gem 'rb-notifu', '~> 0.0.4'
42
+ end
43
+
44
+ platforms :ruby do
45
+ gem 'spork', '0.9.0.rc9'
46
+ gem 'guard-spork'
47
+
48
+ unless ENV['TRAVIS']
49
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
50
+ gem 'rb-fsevent', '>= 0.3.9'
51
+ gem 'growl', '~> 1.0.3'
52
+ end
53
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
54
+ gem 'rb-inotify', '>= 0.5.1'
55
+ gem 'libnotify', '~> 0.1.3'
56
+ end
57
+ end
58
+ end
59
+
60
+ platforms :jruby do
61
+ unless ENV['TRAVIS']
62
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
63
+ gem 'growl', '~> 1.0.3'
64
+ end
65
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
66
+ gem 'rb-inotify', '>= 0.5.1'
67
+ gem 'libnotify', '~> 0.1.3'
68
+ end
69
+ end
70
+ end
71
+ end
data/Guardfile ADDED
@@ -0,0 +1,27 @@
1
+ guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
2
+ watch('config/application.rb')
3
+ watch('config/environment.rb')
4
+ watch(%r{^config/environments/.+\.rb$})
5
+ watch(%r{^config/initializers/.+\.rb$})
6
+ watch('spec/spec_helper.rb')
7
+ watch(%r{^spec/support/.+\.rb$})
8
+ watch(%r{^vendor/extensions/(.+)/spec/support/.+\.rb$})
9
+ end
10
+
11
+ guard 'rspec', :version => 2, :cli => "--color --drb --format Fuubar", :all_on_start => false, :all_after_pass => false do
12
+ watch(%r{^spec/.+_spec\.rb$})
13
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
14
+ watch('spec/spec_helper.rb') { "spec" }
15
+
16
+ # Rails example
17
+ watch(%r{^spec/.+_spec\.rb$})
18
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
20
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
21
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
22
+ watch('spec/spec_helper.rb') { "spec" }
23
+ watch('config/routes.rb') { "spec/routing" }
24
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
25
+ # Capybara request specs
26
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
27
+ end
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ ### IMPORTANT:
2
+ This is a very early version, is not finished for production. This is only some push to the repo for all saved
3
+ ### Gem Installation using Bundler (The very best way)
4
+
5
+ Include the latest [gem](http://rubygems.org/gems/refinerycms-polls) into your Refinery CMS application's Gemfile:
6
+
7
+ gem 'refinerycms-polls', '~> 2.0.1.dev'
8
+
9
+ Then type the following at command line inside your Refinery CMS application's root directory:
10
+
11
+ bundle install
12
+
13
+ #### Installation on Refinery 2.0.0 or above.
14
+
15
+ To install the migrations, run:
16
+
17
+ rails generate refinery:polls
18
+ rake db:migrate
19
+
20
+ Add pages to the database and you're done:
21
+
22
+ rake db:seed
23
+
24
+ ## About
25
+
26
+ __Add polls to your Refinery site.__
27
+
28
+ In summary you can:
29
+
30
+ * Create Polls.
31
+ * Set anwsers for your polls.
32
+ * Set when starts and ends your polls.
33
+ * Show results for your polls.
34
+ * Set votes for anonymous users by IP addres
35
+ * Set aa duration period to vote. (if a guest vote it will need to wait x time to vote again)
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ ENGINE_PATH = File.dirname(__FILE__)
9
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
10
+
11
+ if File.exists?(APP_RAKEFILE)
12
+ load 'rails/tasks/engine.rake'
13
+ end
14
+
15
+ require "refinerycms-testing"
16
+ Refinery::Testing::Railtie.load_tasks
17
+ Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
18
+
19
+ load File.expand_path('../tasks/testing.rake', __FILE__)
20
+ load File.expand_path('../tasks/rspec.rake', __FILE__)
@@ -0,0 +1,8 @@
1
+ function do_vote(element) {
2
+ $(element).parents().find('form').submit();
3
+ }
4
+ $(document).ready(function(){
5
+ $("input[type=radio][name=answer_id]").click(function() {
6
+ do_vote(this);
7
+ });
8
+ })
@@ -0,0 +1,31 @@
1
+ .reinerycms-polls-form h3{
2
+ padding:5px;
3
+ }
4
+ .reinerycms-polls-form h5{
5
+ padding:5px 5px 0 5px;
6
+ font-size:1em;
7
+ margin:0px;
8
+ }
9
+ .reinerycms-polls-form ul{
10
+ list-style-type: none;
11
+ padding: 10px;
12
+ margin: 0;
13
+ }
14
+ .reinerycms-polls-pollbar {
15
+ margin: 1px;
16
+ font-size: 13px;
17
+ line-height: 15px;
18
+ height: 15px;
19
+ background-image: image_url('refinery/polls/pollbg.gif');
20
+ border: 1px solid #ffffff;
21
+ }
22
+ .reinerycms-polls-pollbar IMG {
23
+ display: inline;
24
+ border: 0px;
25
+ padding: 0px;
26
+ margin: 0px;
27
+ }
28
+ .reinerycms-polls-results{
29
+ /*max-width:300px;*/
30
+ border:1px solid #CCC;
31
+ }
@@ -0,0 +1,55 @@
1
+ module Refinery
2
+ module Polls
3
+ module Admin
4
+ class AnswersController < ::Refinery::AdminController
5
+
6
+ crudify :'refinery/polls/answer', :title_attribute => 'title', :xhr_paging => true
7
+ before_filter :find_question
8
+ before_filter :find_answer, :only => [:edit, :update]
9
+
10
+ def index
11
+ paginate_all_answers
12
+ end
13
+ def edit
14
+
15
+ end
16
+
17
+ def create
18
+ if (@answer = ::Refinery::Polls::Answer.create({:question_id => @question.id}.merge(params[:answer]))).valid?
19
+ flash.now[:notice] = "#{@answer.title} was successfully created."
20
+ self.index
21
+ @dialog_successful = true
22
+ render :index
23
+ else
24
+ render :action => 'new'
25
+ end
26
+ end
27
+
28
+ def update
29
+ if @answer.update_attributes({:question_id => @question.id}.merge(params[:answer]))
30
+ flash.now[:notice] = "#{@answer.title} was successfully updated."
31
+ self.index
32
+ @dialog_successful = true
33
+ render :index
34
+ else
35
+ render :action => 'edit'
36
+ end
37
+ end
38
+
39
+ private
40
+ def find_answer
41
+ @answer = ::Refinery::Polls::Answer.find_by_slug_or_id(params[:id])
42
+ end
43
+
44
+ def find_question
45
+ @question = ::Refinery::Polls::Question.find_by_slug_or_id(params[:question_id])
46
+ end
47
+
48
+ def paginate_all_answers
49
+ @answers = ::Refinery::Polls::Answer.paginate :page => params[:page],
50
+ :conditions => {:question_id => @question.id} if Refinery::Polls::Admin::QuestionsController.pageable?
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ module Refinery
2
+ module Polls
3
+ module Admin
4
+ class QuestionsController < ::Refinery::AdminController
5
+
6
+ crudify :'refinery/polls/question', :title_attribute => 'title', :xhr_paging => true
7
+
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,62 @@
1
+ module Refinery
2
+ module Polls
3
+ class QuestionsController < ::ApplicationController
4
+
5
+ before_filter :find_all_questions, :only => [:index]
6
+ before_filter :find_page, :except => [:submit]
7
+ before_filter :find_vote, :only => [:show, :create]
8
+ before_filter :find_answer, :only => [:submit]
9
+ before_filter :find_question, :only => [:submit, :show]
10
+ respond_to :html, :js, :json
11
+ def index
12
+ # you can use meta fields from your model instead (e.g. browser_title)
13
+ # by swapping @page for @poll in the line below:
14
+ present(@page)
15
+ end
16
+
17
+ def show
18
+ # you can use meta fields from your model instead (e.g. browser_title)
19
+ # by swapping @page for @poll in the line below:
20
+ present(@page)
21
+ end
22
+
23
+ def submit
24
+ @vote = nil
25
+ if @answer.nil?
26
+ flash[:notice] = t(".no_answer_selected")
27
+ else
28
+ unless @vote
29
+ @answer.votes_count += 1
30
+ @answer.save
31
+ @vote = ::Refinery::Polls::Vote.vote_by_ip(@question, @answer, request.remote_ip)
32
+ end
33
+ respond_to do |format|
34
+ format.js
35
+ format.html
36
+ end
37
+ end
38
+ end
39
+
40
+ protected
41
+ def find_question
42
+ @question = ::Refinery::Polls::Question.find_by_slug_or_id(params[:id])
43
+ end
44
+
45
+ def find_answer
46
+ @answer = ::Refinery::Polls::Answer.find_by_slug_or_id(params[:answer_id])
47
+ end
48
+
49
+ def find_all_questions
50
+ @questions = ::Refinery::Polls::Question.order('position ASC')
51
+ end
52
+
53
+ def find_page
54
+ @page = ::Refinery::Page.where(:link_url => "/polls").first
55
+ end
56
+
57
+ def find_vote
58
+ @vote = ::Refinery::Polls::Vote.where("ip=? AND created_at > ?", request.remote_ip, Time.now - Refinery::Polls.vote_duration).first
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,39 @@
1
+ module Refinery
2
+ module Polls
3
+ class Answer < Refinery::Core::BaseModel
4
+
5
+ translates :title, :slug
6
+ extend FriendlyId
7
+ friendly_id :title, :use => [:slugged, :globalize]
8
+
9
+ acts_as_indexed :fields => [:title]
10
+
11
+ validates :title, :presence => true, :uniqueness => true
12
+
13
+ attr_accessible :title, :question_id, :position
14
+ attr_accessor :locale
15
+
16
+ belongs_to :question, :class_name => '::Refinery::Polls::Question'
17
+ has_many :votes, :class_name => '::Refinery::Polls::Vote'
18
+
19
+ default_scope order("position ASC")
20
+
21
+ class Translation
22
+ attr_accessible :locale
23
+ end
24
+
25
+ def self.translated
26
+ with_translations(::Globalize.locale)
27
+ end
28
+ class << self
29
+ def find_by_slug_or_id(slug_or_id)
30
+ if slug_or_id.friendly_id?
31
+ find_by_slug(slug_or_id)
32
+ else
33
+ find(slug_or_id)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,60 @@
1
+ module Refinery
2
+ module Polls
3
+ class Question < Refinery::Core::BaseModel
4
+
5
+ translates :title, :slug
6
+
7
+ extend FriendlyId
8
+ friendly_id :title, :use => [:slugged, :globalize]
9
+
10
+ acts_as_indexed :fields => [:title]
11
+
12
+ validates :title, :presence => true, :uniqueness => true
13
+
14
+ attr_accessible :title, :start_date, :end_date, :position
15
+ attr_accessor :locale
16
+
17
+ class Translation
18
+ attr_accessible :locale
19
+ end
20
+
21
+ def self.translated
22
+ with_translations(::Globalize.locale)
23
+ end
24
+
25
+ has_many :answers, :class_name => '::Refinery::Polls::Answer'
26
+
27
+ def self.actives
28
+ where("start_date >= ? and end_date <= ?", Date.today, Date.today)
29
+ end
30
+
31
+ def answers_with_data
32
+ results, votes_total = [], 0
33
+ answers.each do |answer|
34
+ results << [answer.title, answer.votes_count]
35
+ votes_total += answer.votes_count
36
+ end
37
+ return results, votes_total
38
+ end
39
+
40
+ class << self
41
+ def find_by_slug_or_id(slug_or_id)
42
+ if slug_or_id.friendly_id?
43
+ find_by_slug(slug_or_id)
44
+ else
45
+ find(slug_or_id)
46
+ end
47
+ end
48
+ end
49
+ # def self.active_poll(user_id)
50
+ # users_polls = UsersPoll.find_all_by_user_id(user_id, :select => :poll_id)
51
+ # polls = users_polls.count > 0 ? Poll.active.find(:all, :conditions => ["id NOT IN (?)", users_polls.collect {|up| up.poll_id } ]) : Poll.active
52
+ # polls.count > 0 ? polls.first : nil
53
+ # end
54
+
55
+
56
+ # acceso a variables connfiguradas
57
+ #self.per_page = Refinery::Blog.posts_per_page
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,62 @@
1
+ module Refinery
2
+ module Polls
3
+ class Setting
4
+ class << self
5
+ # def confirmation_body
6
+ # Refinery::Setting.find_or_set(:inquiry_confirmation_body,
7
+ # "Thank you for your inquiry %name%,\n\nThis email is a receipt to confirm we have received your inquiry and we'll be in touch shortly.\n\nThanks."
8
+ # )
9
+ # end
10
+ #
11
+ # def confirmation_subject(locale='en')
12
+ # Refinery::Setting.find_or_set("inquiry_confirmation_subject_#{locale}".to_sym,
13
+ # "Thank you for your inquiry",
14
+ # :scoping => "inquiries")
15
+ # end
16
+ #
17
+ # def confirmation_subject=(value)
18
+ # value.first.keys.each do |locale|
19
+ # Refinery::Setting.set("inquiry_confirmation_subject_#{locale}".to_sym, {
20
+ # :value => value.first[locale.to_sym],
21
+ # :scoping => "inquiries"
22
+ # })
23
+ # end
24
+ # end
25
+ #
26
+ # def confirmation_message(locale='en')
27
+ # Refinery::Setting.find_or_set("inquiry_confirmation_message_#{locale}".to_sym,
28
+ # Refinery::Setting[:inquiry_confirmation_body],
29
+ # :scoping => "inquiries")
30
+ # end
31
+ #
32
+ #
33
+ # def confirmation_message=(value)
34
+ # value.first.keys.each do |locale|
35
+ # Refinery::Setting.set("inquiry_confirmation_message_#{locale}".to_sym, {
36
+ # :value => value.first[locale.to_sym],
37
+ # :scoping => "inquiries"
38
+ # })
39
+ # end
40
+ # end
41
+ #
42
+ # def notification_recipients
43
+ # Refinery::Setting.find_or_set(:inquiry_notification_recipients,
44
+ # ((Refinery::Role[:refinery].users.first.email rescue nil) if defined?(Refinery::Role)).to_s,
45
+ # :scoping => "inquiries")
46
+ # end
47
+ #
48
+ # def notification_subject
49
+ # Refinery::Setting.find_or_set(:inquiry_notification_subject,
50
+ # "New inquiry from your website",
51
+ # :scoping => "inquiries")
52
+ # end
53
+ #
54
+ # def send_confirmation?
55
+ # Refinery::Setting.find_or_set(:inquiry_send_confirmation,
56
+ # true,
57
+ # :scoping => "inquiries")
58
+ # end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,34 @@
1
+ module Refinery
2
+ module Polls
3
+ class Vote < Refinery::Core::BaseModel
4
+
5
+ acts_as_indexed :fields => [:question_id, :answer_id, :ip]
6
+
7
+ belongs_to :question, :class_name => '::Refinery::Polls::Question'
8
+ belongs_to :answer, :class_name => '::Refinery::Polls::Answer'
9
+
10
+ attr_accessible :question_id, :answer_id, :ip
11
+
12
+ # Create Vote for Question, Answer and IP
13
+ # @param [::Refinery::Polls::Question] Question object
14
+ # @parama [::Refinery::Polls::Answer] Answer object
15
+ # @return [::Refinery::Polls::Vote] Vote object created
16
+
17
+ def self.vote_by_ip(question, answer, ip)
18
+ self.create(:answer_id => answer.id, :question_id => question.id, :ip => ip)
19
+ end
20
+
21
+ # Find vote for Question by IP
22
+ # @param [::Refinery::Polls::Question] Question object
23
+ # @parama [Request] Request object to use remote_ip
24
+ # @return [::Refinery::Polls::Vote] Vote object created
25
+ def self.get_vote(question, ip)
26
+ if ip.is_a?(String) && question.is_a?(::Refinery::Polls::Question)
27
+ where("question_id=? AND ip=? AND created_at > ?", question.id, ip, Time.now - Refinery::Polls.vote_duration).first
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ <ul>
2
+ <% if ::Refinery::Polls::Admin::AnswersController.searchable? %>
3
+ <li>
4
+ <%= render '/refinery/admin/search', :url => refinery.polls_admin_question_answers_path(@question) %>
5
+ </li>
6
+ <% end %>
7
+ <li>
8
+ <%= link_to t('.create_new'), refinery.new_polls_admin_question_answer_path(@question),
9
+ :class => "add_icon" %>
10
+ </li>
11
+ <% if !searching? && ::Refinery::Polls::Admin::AnswersController.sortable? && ::Refinery::Polls::Answer.any? %>
12
+ <li>
13
+ <%= link_to t('.reorder', :what => "Questions"),
14
+ refinery.polls_admin_question_answers_path(@question),
15
+ :id => "reorder_action",
16
+ :class => "reorder_icon" %>
17
+
18
+ <%= link_to t('.reorder_done', :what => "Answers"),
19
+ refinery.polls_admin_question_answers_path(@question),
20
+ :id => "reorder_action_done",
21
+ :style => "display: none;",
22
+ :class => "reorder_icon" %>
23
+ </li>
24
+ <% end %>
25
+ </ul>
@@ -0,0 +1,16 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(answer) -%>">
2
+ <span class='title'>
3
+ <%= answer.title %>
4
+
5
+ </span>
6
+ <span class='actions'>
7
+
8
+ <%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_polls_admin_question_answer_path(answer.question, answer),
9
+ :title => t('.edit') %>
10
+ <%= link_to refinery_icon_tag("delete.png"), refinery.polls_admin_question_answer_path(answer.question, answer),
11
+ :class => "cancel confirm-delete",
12
+ :title => t('.delete'),
13
+ :confirm => t('message', :scope => 'refinery.admin.delete', :title => answer.title),
14
+ :method => :delete %>
15
+ </span>
16
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @answers if Refinery::Polls::Admin::AnswersController.pageable? %>
2
+ <%= render 'sorteable_list' %>
@@ -0,0 +1,17 @@
1
+ <%= form_for [refinery, :polls_admin, @question, @answer] do |f| -%>
2
+ <%= render '/refinery/admin/error_messages',
3
+ :object => @answer,
4
+ :include_object_name => true %>
5
+
6
+
7
+ <div class='field'>
8
+ <%= f.label :title -%>
9
+ <%= f.text_field :title, :class => 'larger widest' -%>
10
+
11
+ </div>
12
+
13
+ <%= render '/refinery/admin/form_actions', :f => f,
14
+ :continue_editing => false,
15
+ :delete_title => t('delete', :scope => 'refinery.poll_answers.admin.answers.answer'),
16
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @answer.title) %>
17
+ <% end -%>
@@ -0,0 +1,18 @@
1
+ <% if searching? %>
2
+ <h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
3
+ <% end %>
4
+ <div class='pagination_container'>
5
+ <% if @answers.any? %>
6
+ <%= render 'answers' %>
7
+ <% else %>
8
+ <p>
9
+ <% unless searching? %>
10
+ <strong>
11
+ <%= t('.no_items_yet') %>
12
+ </strong>
13
+ <% else %>
14
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
15
+ <% end %>
16
+ </p>
17
+ <% end %>
18
+ </div>
@@ -0,0 +1,5 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'answer', :collection => @answers %>
3
+ </ul>
4
+ <%= render '/refinery/admin/sortable_list',
5
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>