diff --git a/DB specs.txt b/DB specs.txt index 39cdb6c..aa82ac6 100644 --- a/DB specs.txt +++ b/DB specs.txt @@ -22,7 +22,7 @@ - slug : string - info : text -event +*event - title : string - slug : string - conference : [conference] @@ -66,18 +66,12 @@ event - other_option : *boolean - retired : boolean -request - - comment : text - - object : Nto1[object] - - is_invite : boolean - - state : list(string) - *user_organization_relationship - user : [user] - organization : [organization] - relationship : string -workshop +*workshop - title : string - slug : string - info : text @@ -106,4 +100,3 @@ workshop - slug : string - info : text -rails g scaffold \ No newline at end of file diff --git a/Gemfile b/Gemfile index 5bc2d16..7ec2006 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'rails', '4.0.0' # Servers # gem 'puma' # gem 'unicorn' -gem 'thin' +gem 'eventmachine' # Multi-environment configuration # gem 'simpleconfig' @@ -40,15 +40,14 @@ gem 'haml_assets' gem 'handlebars_assets' gem 'i18n-js' gem 'i18n-active_record', - :git => 'git://github.com/svenfuchs/i18n-active_record.git', - :require => 'i18n/active_record' + :git => 'git://github.com/svenfuchs/i18n-active_record.git', + :require => 'i18n/active_record' gem 'jquery-turbolinks' gem 'sass-rails', '~> 4.0.0' gem "compass-rails", "~> 1.1.3" gem 'foundation-rails' gem 'turbolinks' gem 'uglifier', '>= 1.3.0' -#gem 'bcrypt-ruby', git: 'https://github.com/codahale/bcrypt-ruby.git' gem 'sorcery', '>= 0.8.1' gem 'oauth2', '~> 0.8.0' gem 'ruby-drupal-hash' @@ -56,26 +55,29 @@ gem 'redis' gem 'carrierwave' gem 'carrierwave-imageoptimizer' gem 'mini_magick' -gem 'carmen-rails', '~> 1.0.0', github: 'jim/carmen-rails' +#gem 'carmen-rails'#, '~> 1.0.0', github: 'jim/carmen-rails' gem 'nested_form' gem 'acts_as_list' -#gem 'jcrop-rails' -#gem 'rmagick' +##gem 'jcrop-rails' +##gem 'rmagick' gem 'geocoder' gem 'forgery' gem 'paper_trail' + group :development, :test do - gem 'debugger' - gem 'delorean' - gem 'factory_girl_rails' - gem 'faker' - gem 'pry' - gem 'pry-rails' + #gem 'thin' + gem 'debugger' + gem 'delorean' + gem 'factory_girl_rails' + #gem 'faker' + #gem 'pry' + #gem 'pry-rails' end group :development do +<<<<<<< HEAD #gem 'perftools.rb' gem 'bullet' gem 'better_errors' @@ -84,21 +86,30 @@ group :development do gem 'haml-rails' gem 'awesome_print' gem 'rails-footnotes', :github => 'josevalim/rails-footnotes' +======= + #gem 'perftools.rb' + gem 'bullet' + gem 'better_errors' + gem 'binding_of_caller' + gem 'meta_request' + gem 'haml-rails' + gem 'awesome_print' +>>>>>>> FETCH_HEAD end group :test do - gem 'capybara' - gem 'coveralls', require: false - gem 'database_cleaner' - gem 'email_spec' - gem 'launchy' - gem 'rspec' - gem 'rspec-rails' - gem 'selenium-webdriver' - gem 'simplecov', require: false - gem 'webmock', require: false + gem 'capybara' + gem 'coveralls', require: false + gem 'database_cleaner' + gem 'email_spec' + gem 'launchy' + gem 'rspec' + gem 'rspec-rails' + gem 'selenium-webdriver' + gem 'simplecov', require: false + gem 'webmock', require: false end group :staging, :production do - gem 'rails_12factor' + gem 'rails_12factor' end diff --git a/Gemfile.lock b/Gemfile.lock index 0791099..371ab76 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,4 +1,5 @@ GIT +<<<<<<< HEAD remote: git://github.com/jim/carmen-rails.git revision: 076dd251e075d07408e0b5268f886956ef2a347c specs: @@ -14,6 +15,8 @@ GIT rails (>= 3.0.0) GIT +======= +>>>>>>> FETCH_HEAD remote: git://github.com/svenfuchs/i18n-active_record.git revision: 55507cf59f8f2173d38e07e18df0e90d25b1f0f6 specs: @@ -75,8 +78,6 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - carmen (1.0.0) - unicode_utils (~> 1.4.0) carrierwave (0.9.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) @@ -111,7 +112,6 @@ GEM thor crack (0.4.2) safe_yaml (~> 1.0.0) - daemons (1.1.9) database_cleaner (1.2.0) debug_inspector (0.0.2) debugger (1.6.5) @@ -128,7 +128,6 @@ GEM launchy (~> 2.1) mail (~> 2.2) erubis (2.7.0) - eventmachine (1.0.3) eventmachine (1.0.3-x86-mingw32) execjs (2.0.2) factory_girl (4.4.0) @@ -136,8 +135,6 @@ GEM factory_girl_rails (4.4.0) factory_girl (~> 4.4.0) railties (>= 3.0.0) - faker (1.2.0) - i18n (~> 0.5) faraday (0.9.0) multipart-post (>= 1.2, < 3) ffi (1.9.3) @@ -189,7 +186,6 @@ GEM callsite rack-contrib railties - method_source (0.8.2) mime-types (1.25.1) mini_magick (3.7.0) subexec (~> 0.2.1) @@ -198,8 +194,6 @@ GEM multi_json (1.8.4) multipart-post (2.0.0) nested_form (0.3.2) - nokogiri (1.6.1) - mini_portile (~> 0.5.0) nokogiri (1.6.1-x86-mingw32) mini_portile (~> 0.5.0) oauth (0.4.7) @@ -215,17 +209,6 @@ GEM pg (0.17.1) pg (0.17.1-x86-mingw32) polyglot (0.3.3) - pry (0.9.12.6) - coderay (~> 1.0) - method_source (~> 0.8) - slop (~> 3.4) - pry (0.9.12.6-x86-mingw32) - coderay (~> 1.0) - method_source (~> 0.8) - slop (~> 3.4) - win32console (~> 1.3) - pry-rails (0.3.2) - pry (>= 0.9.10) rack (1.5.2) rack-contrib (1.1.0) rack (>= 0.9.1) @@ -287,7 +270,6 @@ GEM multi_json simplecov-html (~> 0.8.0) simplecov-html (0.8.0) - slop (3.4.7) sorcery (0.8.5) bcrypt-ruby (>= 3.0) oauth (~> 0.4.4) @@ -304,10 +286,6 @@ GEM subexec (0.2.3) term-ansicolor (1.3.0) tins (~> 1.0) - thin (1.6.1) - daemons (>= 1.0.9) - eventmachine (>= 1.0.0) - rack (>= 1.0.0) thor (0.18.1) thread_safe (0.1.3) atomic @@ -322,13 +300,11 @@ GEM uglifier (2.4.0) execjs (>= 0.3.0) json (>= 1.8.0) - unicode_utils (1.4.0) uniform_notifier (1.4.0) webmock (1.17.3) addressable (>= 2.2.7) crack (>= 0.3.2) websocket (1.0.7) - win32console (1.3.2-x86-mingw32) xpath (2.0.0) nokogiri (~> 1.3) @@ -343,7 +319,6 @@ DEPENDENCIES binding_of_caller bullet capybara - carmen-rails (~> 1.0.0)! carrierwave carrierwave-imageoptimizer coffee-rails (~> 4.0.0) @@ -353,8 +328,8 @@ DEPENDENCIES debugger delorean email_spec + eventmachine factory_girl_rails - faker forgery foundation-rails geocoder @@ -374,8 +349,6 @@ DEPENDENCIES oauth2 (~> 0.8.0) paper_trail pg - pry - pry-rails rails (= 4.0.0) rails-footnotes! rails_12factor @@ -387,7 +360,6 @@ DEPENDENCIES selenium-webdriver simplecov sorcery (>= 0.8.1) - thin turbolinks uglifier (>= 1.3.0) webmock diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index d420b72..1313f97 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -113,7 +113,6 @@ updateFormFieldList = () -> (json) -> $('#conference-form').html(json.form) $('#registration-form-field-list').html(json.list) - #console.log json updateFormFieldList() return $('#conference-form .remove-form-field').click () -> diff --git a/app/assets/javascripts/event_types.js.coffee b/app/assets/javascripts/event_types.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/event_types.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/events.js.coffee b/app/assets/javascripts/events.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/events.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/workshop_facilitators.js.coffee b/app/assets/javascripts/workshop_facilitators.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/workshop_facilitators.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/workshop_requested_resources.js.coffee b/app/assets/javascripts/workshop_requested_resources.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/workshop_requested_resources.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/workshops.js.coffee b/app/assets/javascripts/workshops.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/workshops.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/event_types.css.scss b/app/assets/stylesheets/event_types.css.scss new file mode 100644 index 0000000..f315e26 --- /dev/null +++ b/app/assets/stylesheets/event_types.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the event_types controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/events.css.scss b/app/assets/stylesheets/events.css.scss new file mode 100644 index 0000000..04d79bd --- /dev/null +++ b/app/assets/stylesheets/events.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the events controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/workshop_facilitators.css.scss b/app/assets/stylesheets/workshop_facilitators.css.scss new file mode 100644 index 0000000..400b70f --- /dev/null +++ b/app/assets/stylesheets/workshop_facilitators.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the workshop_facilitators controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/workshop_requested_resources.css.scss b/app/assets/stylesheets/workshop_requested_resources.css.scss new file mode 100644 index 0000000..f1d8a3b --- /dev/null +++ b/app/assets/stylesheets/workshop_requested_resources.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the workshop_requested_resources controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/workshops.css.scss b/app/assets/stylesheets/workshops.css.scss new file mode 100644 index 0000000..d7f7461 --- /dev/null +++ b/app/assets/stylesheets/workshops.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the workshops controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 6bc80e4..028daa3 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -37,6 +37,7 @@ class ConferencesController < ApplicationController registration = ConferenceRegistration.find_by(:user_id => current_user.id, :conference_id => @conference.id) if registration registration.conference_registration_responses.destroy_all + registration.is_attending = params[:is_attending] else registration = ConferenceRegistration.new(user_id: current_user.id, conference_id: @conference.id, is_attending: params[:is_attending]) end @@ -53,7 +54,7 @@ class ConferencesController < ApplicationController end end data.each do |key, value| - registration.conference_registration_responses << ConferenceRegistrationResponse.new(registration_form_field_id: key.to_i, data: value.to_json.to_s) + registration.conference_registration_responses << ConferenceRegistrationResponse.new(registration_form_field_id: key.to_i, data: value.to_json) end registration.save! render action: 'show' @@ -124,6 +125,12 @@ class ConferencesController < ApplicationController set_conference end + def workshops + set_conference + @workshops = Workshop.where(:conference_id => @conference.id) + render 'workshops/index' + end + # DELETE /conferences/1 def destroy @conference.destroy @@ -133,7 +140,17 @@ class ConferencesController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_conference - @conference = Conference.find_by(slug: params[:slug] || params[:conference_slug]) + @conference = Conference.find_by(slug: params[:conference_slug] || params[:slug]) + set_conference_registration + end + + def set_conference_registration + if !@conference || !current_user + @conference_registration = nil + return + end + + @conference_registration = ConferenceRegistration.find_by(conference_id: @conference.id, user_id: current_user.id) end # Only allow a trusted parameter "white list" through. diff --git a/app/controllers/event_types_controller.rb b/app/controllers/event_types_controller.rb new file mode 100644 index 0000000..b6f03aa --- /dev/null +++ b/app/controllers/event_types_controller.rb @@ -0,0 +1,58 @@ +class EventTypesController < ApplicationController + before_action :set_event_type, only: [:show, :edit, :update, :destroy] + + # GET /event_types + def index + @event_types = EventType.all + end + + # GET /event_types/1 + def show + end + + # GET /event_types/new + def new + @event_type = EventType.new + end + + # GET /event_types/1/edit + def edit + end + + # POST /event_types + def create + @event_type = EventType.new(event_type_params) + + if @event_type.save + redirect_to @event_type, notice: 'Event type was successfully created.' + else + render action: 'new' + end + end + + # PATCH/PUT /event_types/1 + def update + if @event_type.update(event_type_params) + redirect_to @event_type, notice: 'Event type was successfully updated.' + else + render action: 'edit' + end + end + + # DELETE /event_types/1 + def destroy + @event_type.destroy + redirect_to event_types_url, notice: 'Event type was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_event_type + @event_type = EventType.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def event_type_params + params.require(:event_type).permit(:slug, :info) + end +end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb new file mode 100644 index 0000000..96d871a --- /dev/null +++ b/app/controllers/events_controller.rb @@ -0,0 +1,58 @@ +class EventsController < ApplicationController + before_action :set_event, only: [:show, :edit, :update, :destroy] + + # GET /events + def index + @events = Event.all + end + + # GET /events/1 + def show + end + + # GET /events/new + def new + @event = Event.new + end + + # GET /events/1/edit + def edit + end + + # POST /events + def create + @event = Event.new(event_params) + + if @event.save + redirect_to @event, notice: 'Event was successfully created.' + else + render action: 'new' + end + end + + # PATCH/PUT /events/1 + def update + if @event.update(event_params) + redirect_to @event, notice: 'Event was successfully updated.' + else + render action: 'edit' + end + end + + # DELETE /events/1 + def destroy + @event.destroy + redirect_to events_url, notice: 'Event was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_event + @event = Event.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def event_params + params.require(:event).permit(:title, :slug, :event_type_id, :conference, :info, :location, :start_time, :end_time) + end +end diff --git a/app/controllers/registration_form_fields_controller.rb b/app/controllers/registration_form_fields_controller.rb index 335d65d..b6493c2 100644 --- a/app/controllers/registration_form_fields_controller.rb +++ b/app/controllers/registration_form_fields_controller.rb @@ -38,7 +38,10 @@ class RegistrationFormFieldsController < ApplicationController private def ajax_return(success) - @registration_form_fields = RegistrationFormField.all + if params[:conference_id] + @conference = Conference.find(params[:conference_id]) + @registration_form_fields = RegistrationFormField.where(["id NOT IN (?)", @conference.registration_form_fields.map(&:id)]) + end if success @registration_form_field = RegistrationFormField.new end @@ -54,13 +57,11 @@ class RegistrationFormFieldsController < ApplicationController # Only allow a trusted parameter "white list" through. def registration_form_field_params - #type = params[:type] - #allowed = RegistrationFormField::Types[type] - #allowed << 'field_type' rff_params = params.require(:registration_form_field) allowed = RegistrationFormField::GetNonOptionKeys(rff_params[:field_type], rff_params) p = rff_params.send('permit', *allowed)#permit(:title, :help, :required, :field_type, :options, :is_retired) p[:options] = RegistrationFormField::GetOptions(rff_params[:field_type], rff_params).to_json.to_s + p[:field_type] = rff_params[:field_type] p end end diff --git a/app/controllers/workshop_facilitators_controller.rb b/app/controllers/workshop_facilitators_controller.rb new file mode 100644 index 0000000..057a6e6 --- /dev/null +++ b/app/controllers/workshop_facilitators_controller.rb @@ -0,0 +1,58 @@ +class WorkshopFacilitatorsController < ApplicationController + before_action :set_workshop_facilitator, only: [:show, :edit, :update, :destroy] + + # GET /workshop_facilitators + def index + @workshop_facilitators = WorkshopFacilitator.all + end + + # GET /workshop_facilitators/1 + def show + end + + # GET /workshop_facilitators/new + def new + @workshop_facilitator = WorkshopFacilitator.new + end + + # GET /workshop_facilitators/1/edit + def edit + end + + # POST /workshop_facilitators + def create + @workshop_facilitator = WorkshopFacilitator.new(workshop_facilitator_params) + + if @workshop_facilitator.save + redirect_to @workshop_facilitator, notice: 'Workshop facilitator was successfully created.' + else + render action: 'new' + end + end + + # PATCH/PUT /workshop_facilitators/1 + def update + if @workshop_facilitator.update(workshop_facilitator_params) + redirect_to @workshop_facilitator, notice: 'Workshop facilitator was successfully updated.' + else + render action: 'edit' + end + end + + # DELETE /workshop_facilitators/1 + def destroy + @workshop_facilitator.destroy + redirect_to workshop_facilitators_url, notice: 'Workshop facilitator was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_workshop_facilitator + @workshop_facilitator = WorkshopFacilitator.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def workshop_facilitator_params + params.require(:workshop_facilitator).permit(:user_id, :workshop_id, :role) + end +end diff --git a/app/controllers/workshop_requested_resources_controller.rb b/app/controllers/workshop_requested_resources_controller.rb new file mode 100644 index 0000000..24a3beb --- /dev/null +++ b/app/controllers/workshop_requested_resources_controller.rb @@ -0,0 +1,58 @@ +class WorkshopRequestedResourcesController < ApplicationController + before_action :set_workshop_requested_resource, only: [:show, :edit, :update, :destroy] + + # GET /workshop_requested_resources + def index + @workshop_requested_resources = WorkshopRequestedResource.all + end + + # GET /workshop_requested_resources/1 + def show + end + + # GET /workshop_requested_resources/new + def new + @workshop_requested_resource = WorkshopRequestedResource.new + end + + # GET /workshop_requested_resources/1/edit + def edit + end + + # POST /workshop_requested_resources + def create + @workshop_requested_resource = WorkshopRequestedResource.new(workshop_requested_resource_params) + + if @workshop_requested_resource.save + redirect_to @workshop_requested_resource, notice: 'Workshop requested resource was successfully created.' + else + render action: 'new' + end + end + + # PATCH/PUT /workshop_requested_resources/1 + def update + if @workshop_requested_resource.update(workshop_requested_resource_params) + redirect_to @workshop_requested_resource, notice: 'Workshop requested resource was successfully updated.' + else + render action: 'edit' + end + end + + # DELETE /workshop_requested_resources/1 + def destroy + @workshop_requested_resource.destroy + redirect_to workshop_requested_resources_url, notice: 'Workshop requested resource was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_workshop_requested_resource + @workshop_requested_resource = WorkshopRequestedResource.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def workshop_requested_resource_params + params.require(:workshop_requested_resource).permit(:workshop_id, :workshop_resource_id, :status) + end +end diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb new file mode 100644 index 0000000..ef4611d --- /dev/null +++ b/app/controllers/workshops_controller.rb @@ -0,0 +1,69 @@ +class WorkshopsController < ApplicationController + before_action :set_workshop, only: [:show, :edit, :update, :destroy] + + # GET /workshops + def index + set_conference + @workshops = Workshop.where(['conference_id = ?', @conference.id]) + end + + # GET /workshops/1 + def show + set_workshop + set_conference + end + + # GET /workshops/new + def new + set_conference + @workshop = Workshop.new + end + + # GET /workshops/1/edit + def edit + set_conference + end + + # POST /workshops + def create + set_conference + @workshop = Workshop.new(workshop_params) + + if @workshop.save + redirect_to conference_workshop_path(@conference, @workshop), notice: 'Workshop was successfully created.' + else + render action: 'new' + end + end + + # PATCH/PUT /workshops/1 + def update + set_conference + if @workshop.update(workshop_params) + redirect_to conference_workshop_path(@conference, @workshop), notice: 'Workshop was successfully updated.' + else + render action: 'edit' + end + end + + # DELETE /workshops/1 + def destroy + @workshop.destroy + redirect_to workshops_url, notice: 'Workshop was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_workshop + @workshop = Workshop.find_by(slug: params[:workshop_slug] || params[:slug]) + end + + def set_conference + @conference = Conference.find_by(slug: params[:conference_slug] || params[:slug]) + end + + # Only allow a trusted parameter "white list" through. + def workshop_params + params.require(:workshop).permit(:title, :slug, :info, :conference_id, :workshop_stream_id, :workshop_presentation_style, :min_facilitators, :location_id, :start_time, :end_time) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8e73304..08fcbe0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -90,7 +90,7 @@ module ApplicationHelper return nil end - def _(key, behavior = nil, behavior_size = nil, fake: nil, vars: {}, html: nil, blockData: {}, &block) + def _(key, behavior = nil, behavior_size = nil, vars: {}, html: nil, blockData: {}, &block) queued_keys = nil result = nil @@ -201,7 +201,7 @@ module ApplicationHelper end end - def field(form, name, type = nil, param = nil, html: nil, help: false, attrs: [], classes: nil, label: nil, placeholder: nil) + def field(form, name, type = nil, param = nil, html: nil, help: false, attrs: [], classes: nil, label: nil, placeholder: nil, value: nil, checked: nil, required: false) if form.is_a?(Symbol) || form.is_a?(String) param = type @@ -226,20 +226,26 @@ module ApplicationHelper end select_prompt = nil - show_label = true + show_label = !(/^hidden_field/.match(type.to_s)) label_after = true + value_attribute = !form if /select(_tag)?$/.match(type.to_s) - placeholder = nil if !label - select_prompt = 'Select a ' + name.to_s + select_prompt = placeholder || (form ? 'Select a ' + name.to_s : 'Select one') label_html = '' show_label = false end - label_after = false - if param && param.is_a?(Array) - param = options_for_select(param) + placeholder = nil + label_after = false + if param + if param.is_a?(Array) + param = options_for_select(param, value) + elsif param.is_a?(Hash) + param = options_from_collection_for_select(param, :first, :last, value) + end end + value_attribute = false elsif type.to_s == 'image_field' || type.to_s == 'user_select_field' || type.to_s == 'organization_select_field' placeholder = nil label_html = '' @@ -256,7 +262,7 @@ module ApplicationHelper label_html = eval("(" + (form ? 'form.label' : 'label_tag') + " name, '#{label ? CGI.escapeHTML(label) : name}'.html_safe)") end - if label === false + if label === false || !show_label label_html = '' end @@ -316,14 +322,29 @@ module ApplicationHelper end else ph = '' + va = '' + if value_attribute + if /^(check_box|radio_button)/.match(type.to_s) + if checked === nil + checked = value == "on" || value.to_s == "1" + end + if /^(radio_button)/.match(type.to_s) + va = ', "' + value + '", checked' + else + va = ', "1", checked' + end + else + va = ', value' + end + end if placeholder if form ph = ", :placeholder => '#{placeholder}'" else - ph = ", nil, placeholder: '#{placeholder}'" + ph = ", placeholder: '#{placeholder}'" end end - form_html = (form ? "form.#{type} :#{name}" : "#{type} :#{name}") + ph + (param ? ', param' : '') + form_html = (form ? "form.#{type} :#{name}" : "#{type} :#{name}") + va + ph + (param ? ', param' : '') attrs.each_index { |i| form_html += (i >= attrs_used ? ', attrs[' + i.to_s + ']' : '') } if select_prompt if form @@ -333,7 +354,9 @@ module ApplicationHelper end end form_html += (html_options || '') - puts "\n\t" + form_html + "\n" + if required + form_html += ', :required => true' + end form_html = eval(form_html) if root form_html = "<#{root}>" + form_html + "" @@ -383,7 +406,18 @@ module ApplicationHelper if params[:action] == tab.to_s c << 'current' end - tab_list += link_to tab, link || object, :class => c + link_html = '' + if tab.is_a?(Hash) + func = tab.keys[0] + val = tab[func] + args = val ? (val.is_a?(Array) ? (val.collect { |v| object[v] } ) : [object[val]] ) : nil + + link_html = link_to func.to_s.gsub(/_path$/, ''), args ? self.send(func, args) : self.send(func), :class => c + else + #x + link_html = link_to tab, link || object, :class => c + end + tab_list += link_html end ('