nimbleshop_core 0.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/Rakefile +15 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/american_express.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/authorize_net_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/authorizedotnet_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/discover.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/mastercard.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/visa.png +0 -0
- data/app/assets/images/engines/nimbleshop_cod/cod_small.png +0 -0
- data/app/assets/images/engines/nimbleshop_paypalwp/paypal_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_paypalwp/paypal_small.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable_small.png +0 -0
- data/app/assets/javascripts/admin/products/edit.js.coffee +19 -0
- data/app/assets/javascripts/admin/shipping_methods/edit.js.coffee +6 -0
- data/app/assets/javascripts/admin.js +25 -0
- data/app/assets/javascripts/fadeout_success.js.coffee +2 -0
- data/app/assets/javascripts/payment_method.js.coffee +19 -0
- data/app/assets/javascripts/product-group-condition.js.coffee +33 -0
- data/app/assets/javascripts/remove_deletion_of_product_pictures.js.coffee +5 -0
- data/app/assets/javascripts/shipit.js.coffee +10 -0
- data/app/assets/javascripts/twitter_bootstrap.js.coffee +4 -0
- data/app/assets/stylesheets/admin.css +9 -0
- data/app/assets/stylesheets/admin_bootstrap_and_overrides.css.less +38 -0
- data/app/assets/stylesheets/admin_custom.css +104 -0
- data/app/assets/twitter/bootstrap/glyphicons-halflings-white.png +0 -0
- data/app/assets/twitter/bootstrap/glyphicons-halflings.png +0 -0
- data/app/controllers/admin/custom_fields_controller.rb +56 -0
- data/app/controllers/admin/link_groups_controller.rb +76 -0
- data/app/controllers/admin/main_controller.rb +9 -0
- data/app/controllers/admin/navigations_controller.rb +49 -0
- data/app/controllers/admin/orders_controller.rb +47 -0
- data/app/controllers/admin/payment_methods_controller.rb +26 -0
- data/app/controllers/admin/product_groups_controller.rb +70 -0
- data/app/controllers/admin/products_controller.rb +71 -0
- data/app/controllers/admin/shipments_controller.rb +19 -0
- data/app/controllers/admin/shipping_methods_controller.rb +93 -0
- data/app/controllers/admin/shipping_zones_controller.rb +62 -0
- data/app/controllers/admin/shops_controller.rb +33 -0
- data/app/controllers/admin_controller.rb +38 -0
- data/app/helpers/admin_helper.rb +83 -0
- data/app/helpers/nimbleshop_helper.rb +43 -0
- data/app/helpers/payment_method_helper.rb +52 -0
- data/app/mailers/admin_mailer.rb +22 -0
- data/app/mailers/mailer.rb +31 -0
- data/app/models/address.rb +69 -0
- data/app/models/country_shipping_zone.rb +36 -0
- data/app/models/creditcard.rb +95 -0
- data/app/models/custom_field.rb +8 -0
- data/app/models/custom_field_answer/field.rb +101 -0
- data/app/models/custom_field_answer.rb +17 -0
- data/app/models/line_item.rb +48 -0
- data/app/models/link.rb +3 -0
- data/app/models/link_group.rb +8 -0
- data/app/models/navigation.rb +7 -0
- data/app/models/order.rb +158 -0
- data/app/models/payment_method.rb +20 -0
- data/app/models/payment_transaction.rb +11 -0
- data/app/models/picture.rb +30 -0
- data/app/models/product.rb +76 -0
- data/app/models/product_group.rb +65 -0
- data/app/models/product_group_condition.rb +8 -0
- data/app/models/regional_shipping_zone.rb +25 -0
- data/app/models/shipment.rb +19 -0
- data/app/models/shipment_carrier.rb +3 -0
- data/app/models/shipping_cost_calculator.rb +9 -0
- data/app/models/shipping_method.rb +103 -0
- data/app/models/shipping_zone.rb +9 -0
- data/app/models/shop.rb +26 -0
- data/app/models/tax_calculator.rb +18 -0
- data/app/observers/order_observer.rb +53 -0
- data/app/uploaders/picture_uploader.rb +65 -0
- data/app/views/admin/custom_fields/_form.html.erb +45 -0
- data/app/views/admin/custom_fields/edit.html.erb +7 -0
- data/app/views/admin/custom_fields/index.html.erb +31 -0
- data/app/views/admin/custom_fields/new.html.erb +7 -0
- data/app/views/admin/link_groups/_form.html.erb +31 -0
- data/app/views/admin/link_groups/_link_group.html.erb +50 -0
- data/app/views/admin/link_groups/_link_group_title.html.erb +5 -0
- data/app/views/admin/link_groups/edit.html.erb +8 -0
- data/app/views/admin/link_groups/index.html.erb +29 -0
- data/app/views/admin/link_groups/new.html.erb +9 -0
- data/app/views/admin/mailer/new_order_notification.text.erb +31 -0
- data/app/views/admin/main/index.html.erb +5 -0
- data/app/views/admin/navigations/new.html.erb +29 -0
- data/app/views/admin/orders/_line_item.html.erb +11 -0
- data/app/views/admin/orders/_line_items.html.erb +39 -0
- data/app/views/admin/orders/_payment_info.html.erb +20 -0
- data/app/views/admin/orders/_shipping_info.html.erb +40 -0
- data/app/views/admin/orders/index.html.erb +33 -0
- data/app/views/admin/orders/show.html.erb +40 -0
- data/app/views/admin/payment_methods/index.html.erb +6 -0
- data/app/views/admin/product_groups/_condition.html.mustache +20 -0
- data/app/views/admin/product_groups/_form.html.erb +72 -0
- data/app/views/admin/product_groups/edit.html.erb +7 -0
- data/app/views/admin/product_groups/index.html.erb +30 -0
- data/app/views/admin/product_groups/new.html.erb +7 -0
- data/app/views/admin/product_groups/show.html.erb +9 -0
- data/app/views/admin/products/_custom_field_answer.html.erb +9 -0
- data/app/views/admin/products/_form.html.erb +69 -0
- data/app/views/admin/products/_handle_pictures.html.erb +32 -0
- data/app/views/admin/products/_pictures.html.erb +33 -0
- data/app/views/admin/products/edit.html.erb +26 -0
- data/app/views/admin/products/index.html.erb +34 -0
- data/app/views/admin/products/new.html.erb +9 -0
- data/app/views/admin/shipping_methods/_form.html.erb +58 -0
- data/app/views/admin/shipping_methods/_shipping_method.html.erb +31 -0
- data/app/views/admin/shipping_methods/edit.html.erb +18 -0
- data/app/views/admin/shipping_methods/new.html.erb +7 -0
- data/app/views/admin/shipping_zones/_form.html.erb +31 -0
- data/app/views/admin/shipping_zones/_shipping_method.html.erb +13 -0
- data/app/views/admin/shipping_zones/_shipping_zone.html.erb +47 -0
- data/app/views/admin/shipping_zones/edit.html.erb +8 -0
- data/app/views/admin/shipping_zones/index.html.erb +16 -0
- data/app/views/admin/shipping_zones/new.html.erb +8 -0
- data/app/views/admin/shops/edit.html.erb +119 -0
- data/app/views/layouts/_admin_footer.html.erb +23 -0
- data/app/views/layouts/_admin_sidebar.html.erb +0 -0
- data/app/views/layouts/_container.html.erb +33 -0
- data/app/views/layouts/_top_nav_bar.html.erb +30 -0
- data/app/views/layouts/admin.html.erb +35 -0
- data/app/views/layouts/payment_method.html.erb +12 -0
- data/app/views/mailer/order_notification_to_buyer.text.erb +31 -0
- data/app/views/mailer/shipment_notification_to_buyer.text.erb +34 -0
- data/config/initializers/001_settings_application.rb +10 -0
- data/config/initializers/002_load_core_extensions.rb +8 -0
- data/config/initializers/field_with_error.rb +2 -0
- data/config/initializers/strip_and_nullify.rb +13 -0
- data/config/initializers/time_formats.rb +1 -0
- data/config/locales/en.yml +61 -0
- data/config/routes.rb +56 -0
- data/db/development.sqlite3 +0 -0
- data/db/migrate/20111022144421_create_product_groups.rb +12 -0
- data/db/migrate/20111022144426_create_products.rb +16 -0
- data/db/migrate/20111022144653_create_orders.rb +21 -0
- data/db/migrate/20111022144725_create_line_items.rb +15 -0
- data/db/migrate/20111022234951_create_shops.rb +20 -0
- data/db/migrate/20111026193227_create_link_groups.rb +12 -0
- data/db/migrate/20111026193435_create_navigations.rb +10 -0
- data/db/migrate/20111031135810_create_links.rb +10 -0
- data/db/migrate/20111106193938_create_custom_fields.rb +10 -0
- data/db/migrate/20111106195112_create_custom_field_answers.rb +14 -0
- data/db/migrate/20111106201548_create_product_group_conditions.rb +12 -0
- data/db/migrate/20111107035350_create_creditcard_transactions.rb +15 -0
- data/db/migrate/20111109190754_create_addresses.rb +24 -0
- data/db/migrate/20111125173344_create_pictures.rb +16 -0
- data/db/migrate/20111201024408_create_shipping_methods.rb +16 -0
- data/db/migrate/20111202143154_create_shipping_zones.rb +17 -0
- data/db/migrate/20111203034020_create_payment_methods.rb +14 -0
- data/db/migrate/20111221190000_create_preferences.rb +14 -0
- data/db/migrate/20120105234047_create_shipments.rb +11 -0
- data/db/migrate/20120105234553_create_shipment_carriers.rb +11 -0
- data/db/migrate/20120606165355_create_delayed_jobs.rb +22 -0
- data/db/production.sqlite3 +0 -0
- data/db/schema.rb +265 -0
- data/db/seeds.rb +1 -0
- data/db/test.sqlite3 +0 -0
- data/lib/assets/javascripts/loading_state_for_buttons.js.coffee +3 -0
- data/lib/assets/javascripts/show_help_on_hover.js.coffee +2 -0
- data/lib/assets/javascripts/utils/autoresize.js.coffee +3 -0
- data/lib/assets/javascripts/utils/focus.js.coffee +3 -0
- data/lib/assets/javascripts/utils/formatNumber.js.coffee +25 -0
- data/lib/assets/javascripts/utils/formatPrice.js.coffee +24 -0
- data/lib/generators/nimbleshop/app/app_generator.rb +84 -0
- data/lib/generators/nimbleshop/app/templates/config/application.yml +61 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/airbrake.rb +3 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/cache_images.rb +4 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/carrierwave.rb +36 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/delayed_job.rb +15 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/setup_email.rb +24 -0
- data/lib/nimbleshop/core_ext/activerecord_base.rb +18 -0
- data/lib/nimbleshop/core_ext/filelessio.rb +4 -0
- data/lib/nimbleshop/core_ext/force_ssl.rb +26 -0
- data/lib/nimbleshop/core_ext/mustache_templater_handler.rb +10 -0
- data/lib/nimbleshop/engine.rb +23 -0
- data/lib/nimbleshop/permalink/builder.rb +46 -0
- data/lib/nimbleshop/processor/base.rb +51 -0
- data/lib/nimbleshop/processor.rb +3 -0
- data/lib/nimbleshop/product_group_search/base_field.rb +19 -0
- data/lib/nimbleshop/product_group_search/core_field_strategy.rb +31 -0
- data/lib/nimbleshop/product_group_search/custom_field_strategy.rb +39 -0
- data/lib/nimbleshop/product_group_search/date_field.rb +16 -0
- data/lib/nimbleshop/product_group_search/extension.rb +46 -0
- data/lib/nimbleshop/product_group_search/number_field.rb +17 -0
- data/lib/nimbleshop/product_group_search/text_field.rb +33 -0
- data/lib/nimbleshop/product_group_search.rb +74 -0
- data/lib/nimbleshop/sampledata/data.rb +246 -0
- data/lib/nimbleshop/sampledata/pictures/product1/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product2/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product2/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product4/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product4/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product5/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product5/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic10.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic11.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic12.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic13.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic14.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic15.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic16.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic17.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic6.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic7.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic8.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic9.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic6.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic7.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic8.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product9/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product9/pic2.jpg +0 -0
- data/lib/nimbleshop/util.rb +60 -0
- data/lib/nimbleshop/version.rb +18 -0
- data/lib/nimbleshop_core.rb +23 -0
- data/lib/tasks/localhost2public.rake +8 -0
- data/lib/tasks/setup.rake +26 -0
- data/test/factories/address_factory.rb +31 -0
- data/test/factories/creditcard_factory.rb +30 -0
- data/test/factories/custom_field_answer_factory.rb +6 -0
- data/test/factories/custom_field_factory.rb +21 -0
- data/test/factories/line_item_factory.rb +7 -0
- data/test/factories/link_factory.rb +6 -0
- data/test/factories/link_group_factory.rb +5 -0
- data/test/factories/navigation_factory.rb +6 -0
- data/test/factories/order_factory.rb +49 -0
- data/test/factories/payment_method_factory.rb +6 -0
- data/test/factories/payment_transaction_factory.rb +42 -0
- data/test/factories/picture_factory.rb +11 -0
- data/test/factories/product_group_condition_factory.rb +40 -0
- data/test/factories/product_group_factory.rb +5 -0
- data/test/factories/products_factory.rb +11 -0
- data/test/factories/shipment_carrier_factory.rb +6 -0
- data/test/factories/shipment_factory.rb +6 -0
- data/test/factories/shipping_method_factory.rb +15 -0
- data/test/factories/shipping_zone_factory.rb +5 -0
- data/test/factories/shop_factory.rb +8 -0
- data/test/fixtures/files/avatar.png +0 -0
- data/test/fixtures/link_groups.yml +13 -0
- data/test/fixtures/payment_methods.yml +39 -0
- data/test/fixtures/shops.yml +15 -0
- data/test/helpers/admin_helper_test.rb +37 -0
- data/test/helpers/nimbleshop_helper_test.rb +17 -0
- data/test/integration/admin/link_groups_acceptance_test.rb +39 -0
- data/test/integration/admin/orders_acceptance_test.rb +63 -0
- data/test/integration/admin/payment_methods_acceptance_test.rb +13 -0
- data/test/integration/admin/product_groups_acceptance_test.rb +89 -0
- data/test/integration/admin/products_acceptance_test.rb +105 -0
- data/test/integration/admin/shipping_methods_acceptance_test.rb +63 -0
- data/test/integration/admin/shipping_zones_acceptance_test.rb +16 -0
- data/test/integration/admin/shops_acceptance_test.rb +44 -0
- data/test/integration/checkout/cart_acceptance_test.rb +113 -0
- data/test/integration/checkout/payment_confirmation_acceptance_test.rb +24 -0
- data/test/integration/checkout/paypal_acceptance_test.rb +34 -0
- data/test/integration/checkout/shipping_address_acceptance_test.rb +91 -0
- data/test/integration/checkout/shipping_method_acceptance_test.rb +51 -0
- data/test/integration/homepage_acceptance_test.rb +24 -0
- data/test/integration/products_acceptance_test.rb +12 -0
- data/test/integration/static_pages_acceptance_test.rb +13 -0
- data/test/mailers/mailer_test.rb +25 -0
- data/test/rails_app/Gemfile +27 -0
- data/test/rails_app/Gemfile.lock +218 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/controllers/application_controller.rb +6 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/views/layouts/application.html.erb +10 -0
- data/test/rails_app/config/application.rb +25 -0
- data/test/rails_app/config/application.yml +61 -0
- data/test/rails_app/config/boot.rb +5 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +18 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +10 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/development.sqlite3 +0 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +74 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/log/development.log +94 -0
- data/test/rails_app/log/test.log +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/support/address_test_helper.rb +24 -0
- data/test/support/checkout_test_helper.rb +40 -0
- data/test/support/dbify_sql_helper.rb +12 -0
- data/test/support/images/cookware.jpg +0 -0
- data/test/support/must_be_like.rb +24 -0
- data/test/support/shipping_method_test_helper.rb +5 -0
- data/test/support/wait_for_ajax.rb +4 -0
- data/test/test_helper.rb +65 -0
- data/test/unit/address_test.rb +33 -0
- data/test/unit/country_shipping_zone_test.rb +17 -0
- data/test/unit/creditcard_test.rb +33 -0
- data/test/unit/custom_field_answer/field_test.rb +93 -0
- data/test/unit/order_test.rb +70 -0
- data/test/unit/payment_method/authorizedotnet_test.rb +21 -0
- data/test/unit/payment_method/paypalwp_test.rb +17 -0
- data/test/unit/payment_method/splitable_test.rb +18 -0
- data/test/unit/picture_test.rb +24 -0
- data/test/unit/processor/authorize_net_test.rb +236 -0
- data/test/unit/processor/paypal_test.rb +40 -0
- data/test/unit/processor/splitable_test.rb +123 -0
- data/test/unit/product_group_condition_test.rb +188 -0
- data/test/unit/product_group_test.rb +109 -0
- data/test/unit/product_test.rb +60 -0
- data/test/unit/shipping_cost_calculator_test.rb +19 -0
- data/test/unit/shipping_method_test.rb +197 -0
- data/test/unit/shop_test.rb +11 -0
- data/test/unit/tax_calculator_test.rb +13 -0
- data/test/vcr_cassettes/authorize_net/authorize-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/authorize-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/capture-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/capture-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/purchase-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/purchase-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/refund-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/refund-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-authorize.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-success.yml +38 -0
- data/test/vcr_cassettes/splitable/split-create-failure.yml +48 -0
- data/test/vcr_cassettes/splitable/split-create-success.yml +50 -0
- data/test/vcr_cassettes/splitable/split-draft-create-failure.yml +50 -0
- data/test/vcr_cassettes/splitable/split-draft-create-success.yml +50 -0
- data/vendor/assets/javascripts/accounting.js +406 -0
- data/vendor/assets/javascripts/autoresize.js +275 -0
- data/vendor/assets/javascripts/jquery-1.7.1.js +9267 -0
- data/vendor/assets/javascripts/jquery-form.js +980 -0
- data/vendor/assets/javascripts/jquery-json.js +193 -0
- data/vendor/assets/javascripts/jquery-ui-1.8.16.js +11768 -0
- data/vendor/assets/javascripts/jquery-ujs.js +374 -0
- data/vendor/assets/javascripts/mustache.js +436 -0
- data/vendor/assets/javascripts/nested_form.js +51 -0
- metadata +740 -0
@@ -0,0 +1,374 @@
|
|
1
|
+
(function($, undefined) {
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Unobtrusive scripting adapter for jQuery
|
5
|
+
*
|
6
|
+
* Requires jQuery 1.6.0 or later.
|
7
|
+
* https://github.com/rails/jquery-ujs
|
8
|
+
|
9
|
+
* Uploading file using rails.js
|
10
|
+
* =============================
|
11
|
+
*
|
12
|
+
* By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
|
13
|
+
* in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
|
14
|
+
*
|
15
|
+
* The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
|
16
|
+
*
|
17
|
+
* Ex:
|
18
|
+
* $('form').live('ajax:aborted:file', function(event, elements){
|
19
|
+
* // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
|
20
|
+
* // Returning false in this handler tells rails.js to disallow standard form submission
|
21
|
+
* return false;
|
22
|
+
* });
|
23
|
+
*
|
24
|
+
* The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
|
25
|
+
*
|
26
|
+
* Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
|
27
|
+
* techniques like the iframe method to upload the file instead.
|
28
|
+
*
|
29
|
+
* Required fields in rails.js
|
30
|
+
* ===========================
|
31
|
+
*
|
32
|
+
* If any blank required inputs (required="required") are detected in the remote form, the whole form submission
|
33
|
+
* is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
|
34
|
+
*
|
35
|
+
* The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
|
36
|
+
*
|
37
|
+
* !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
|
38
|
+
* get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
|
39
|
+
*
|
40
|
+
* Ex:
|
41
|
+
* $('form').live('ajax:aborted:required', function(event, elements){
|
42
|
+
* // Returning false in this handler tells rails.js to submit the form anyway.
|
43
|
+
* // The blank required inputs are passed to this function in `elements`.
|
44
|
+
* return ! confirm("Would you like to submit the form with missing info?");
|
45
|
+
* });
|
46
|
+
*/
|
47
|
+
|
48
|
+
// Shorthand to make it a little easier to call public rails functions from within rails.js
|
49
|
+
var rails;
|
50
|
+
|
51
|
+
$.rails = rails = {
|
52
|
+
// Link elements bound by jquery-ujs
|
53
|
+
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
|
54
|
+
|
55
|
+
// Select elements bound by jquery-ujs
|
56
|
+
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
|
57
|
+
|
58
|
+
// Form elements bound by jquery-ujs
|
59
|
+
formSubmitSelector: 'form',
|
60
|
+
|
61
|
+
// Form input elements bound by jquery-ujs
|
62
|
+
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not(button[type])',
|
63
|
+
|
64
|
+
// Form input elements disabled during form submission
|
65
|
+
disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
|
66
|
+
|
67
|
+
// Form input elements re-enabled after form submission
|
68
|
+
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
|
69
|
+
|
70
|
+
// Form required input elements
|
71
|
+
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
|
72
|
+
|
73
|
+
// Form file input elements
|
74
|
+
fileInputSelector: 'input:file',
|
75
|
+
|
76
|
+
// Link onClick disable selector with possible reenable after remote submission
|
77
|
+
linkDisableSelector: 'a[data-disable-with]',
|
78
|
+
|
79
|
+
// Make sure that every Ajax request sends the CSRF token
|
80
|
+
CSRFProtection: function(xhr) {
|
81
|
+
var token = $('meta[name="csrf-token"]').attr('content');
|
82
|
+
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
83
|
+
},
|
84
|
+
|
85
|
+
// Triggers an event on an element and returns false if the event result is false
|
86
|
+
fire: function(obj, name, data) {
|
87
|
+
var event = $.Event(name);
|
88
|
+
obj.trigger(event, data);
|
89
|
+
return event.result !== false;
|
90
|
+
},
|
91
|
+
|
92
|
+
// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
|
93
|
+
confirm: function(message) {
|
94
|
+
return confirm(message);
|
95
|
+
},
|
96
|
+
|
97
|
+
// Default ajax function, may be overridden with custom function in $.rails.ajax
|
98
|
+
ajax: function(options) {
|
99
|
+
return $.ajax(options);
|
100
|
+
},
|
101
|
+
|
102
|
+
// Submits "remote" forms and links with ajax
|
103
|
+
handleRemote: function(element) {
|
104
|
+
var method, url, data,
|
105
|
+
crossDomain = element.data('cross-domain') || null,
|
106
|
+
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
|
107
|
+
options;
|
108
|
+
|
109
|
+
if (rails.fire(element, 'ajax:before')) {
|
110
|
+
|
111
|
+
if (element.is('form')) {
|
112
|
+
method = element.attr('method');
|
113
|
+
url = element.attr('action');
|
114
|
+
data = element.serializeArray();
|
115
|
+
// memoized value from clicked submit button
|
116
|
+
var button = element.data('ujs:submit-button');
|
117
|
+
if (button) {
|
118
|
+
data.push(button);
|
119
|
+
element.data('ujs:submit-button', null);
|
120
|
+
}
|
121
|
+
} else if (element.is(rails.inputChangeSelector)) {
|
122
|
+
method = element.data('method');
|
123
|
+
url = element.data('url');
|
124
|
+
data = element.serialize();
|
125
|
+
if (element.data('params')) data = data + "&" + element.data('params');
|
126
|
+
} else {
|
127
|
+
method = element.data('method');
|
128
|
+
url = element.attr('href');
|
129
|
+
data = element.data('params') || null;
|
130
|
+
}
|
131
|
+
|
132
|
+
options = {
|
133
|
+
type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain,
|
134
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
135
|
+
beforeSend: function(xhr, settings) {
|
136
|
+
if (settings.dataType === undefined) {
|
137
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
138
|
+
}
|
139
|
+
return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
|
140
|
+
},
|
141
|
+
success: function(data, status, xhr) {
|
142
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
143
|
+
},
|
144
|
+
complete: function(xhr, status) {
|
145
|
+
element.trigger('ajax:complete', [xhr, status]);
|
146
|
+
},
|
147
|
+
error: function(xhr, status, error) {
|
148
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
149
|
+
}
|
150
|
+
};
|
151
|
+
// Only pass url to `ajax` options if not blank
|
152
|
+
if (url) { options.url = url; }
|
153
|
+
|
154
|
+
return rails.ajax(options);
|
155
|
+
} else {
|
156
|
+
return false;
|
157
|
+
}
|
158
|
+
},
|
159
|
+
|
160
|
+
// Handles "data-method" on links such as:
|
161
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
162
|
+
handleMethod: function(link) {
|
163
|
+
var href = link.attr('href'),
|
164
|
+
method = link.data('method'),
|
165
|
+
target = link.attr('target'),
|
166
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
167
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
168
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
169
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
170
|
+
|
171
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
172
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
173
|
+
}
|
174
|
+
|
175
|
+
if (target) { form.attr('target', target); }
|
176
|
+
|
177
|
+
form.hide().append(metadata_input).appendTo('body');
|
178
|
+
form.submit();
|
179
|
+
},
|
180
|
+
|
181
|
+
/* Disables form elements:
|
182
|
+
- Caches element value in 'ujs:enable-with' data store
|
183
|
+
- Replaces element text with value of 'data-disable-with' attribute
|
184
|
+
- Sets disabled property to true
|
185
|
+
*/
|
186
|
+
disableFormElements: function(form) {
|
187
|
+
form.find(rails.disableSelector).each(function() {
|
188
|
+
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
189
|
+
element.data('ujs:enable-with', element[method]());
|
190
|
+
element[method](element.data('disable-with'));
|
191
|
+
element.prop('disabled', true);
|
192
|
+
});
|
193
|
+
},
|
194
|
+
|
195
|
+
/* Re-enables disabled form elements:
|
196
|
+
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
|
197
|
+
- Sets disabled property to false
|
198
|
+
*/
|
199
|
+
enableFormElements: function(form) {
|
200
|
+
form.find(rails.enableSelector).each(function() {
|
201
|
+
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
202
|
+
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
|
203
|
+
element.prop('disabled', false);
|
204
|
+
});
|
205
|
+
},
|
206
|
+
|
207
|
+
/* For 'data-confirm' attribute:
|
208
|
+
- Fires `confirm` event
|
209
|
+
- Shows the confirmation dialog
|
210
|
+
- Fires the `confirm:complete` event
|
211
|
+
|
212
|
+
Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
|
213
|
+
Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
|
214
|
+
Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
|
215
|
+
return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
|
216
|
+
*/
|
217
|
+
allowAction: function(element) {
|
218
|
+
var message = element.data('confirm'),
|
219
|
+
answer = false, callback;
|
220
|
+
if (!message) { return true; }
|
221
|
+
|
222
|
+
if (rails.fire(element, 'confirm')) {
|
223
|
+
answer = rails.confirm(message);
|
224
|
+
callback = rails.fire(element, 'confirm:complete', [answer]);
|
225
|
+
}
|
226
|
+
return answer && callback;
|
227
|
+
},
|
228
|
+
|
229
|
+
// Helper function which checks for blank inputs in a form that match the specified CSS selector
|
230
|
+
blankInputs: function(form, specifiedSelector, nonBlank) {
|
231
|
+
var inputs = $(), input,
|
232
|
+
selector = specifiedSelector || 'input,textarea';
|
233
|
+
form.find(selector).each(function() {
|
234
|
+
input = $(this);
|
235
|
+
// Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
|
236
|
+
if (nonBlank ? input.val() : !input.val()) {
|
237
|
+
inputs = inputs.add(input);
|
238
|
+
}
|
239
|
+
});
|
240
|
+
return inputs.length ? inputs : false;
|
241
|
+
},
|
242
|
+
|
243
|
+
// Helper function which checks for non-blank inputs in a form that match the specified CSS selector
|
244
|
+
nonBlankInputs: function(form, specifiedSelector) {
|
245
|
+
return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
|
246
|
+
},
|
247
|
+
|
248
|
+
// Helper function, needed to provide consistent behavior in IE
|
249
|
+
stopEverything: function(e) {
|
250
|
+
$(e.target).trigger('ujs:everythingStopped');
|
251
|
+
e.stopImmediatePropagation();
|
252
|
+
return false;
|
253
|
+
},
|
254
|
+
|
255
|
+
// find all the submit events directly bound to the form and
|
256
|
+
// manually invoke them. If anyone returns false then stop the loop
|
257
|
+
callFormSubmitBindings: function(form, event) {
|
258
|
+
var events = form.data('events'), continuePropagation = true;
|
259
|
+
if (events !== undefined && events['submit'] !== undefined) {
|
260
|
+
$.each(events['submit'], function(i, obj){
|
261
|
+
if (typeof obj.handler === 'function') return continuePropagation = obj.handler(event);
|
262
|
+
});
|
263
|
+
}
|
264
|
+
return continuePropagation;
|
265
|
+
},
|
266
|
+
|
267
|
+
// replace element's html with the 'data-disable-with' after storing original html
|
268
|
+
// and prevent clicking on it
|
269
|
+
disableElement: function(element) {
|
270
|
+
element.data('ujs:enable-with', element.html()); // store enabled state
|
271
|
+
element.html(element.data('disable-with')); // set to disabled state
|
272
|
+
element.bind('click.railsDisable', function(e) { // prevent further clicking
|
273
|
+
return rails.stopEverything(e)
|
274
|
+
});
|
275
|
+
},
|
276
|
+
|
277
|
+
// restore element to its original state which was disabled by 'disableElement' above
|
278
|
+
enableElement: function(element) {
|
279
|
+
if (element.data('ujs:enable-with') !== undefined) {
|
280
|
+
element.html(element.data('ujs:enable-with')); // set to old enabled state
|
281
|
+
// this should be element.removeData('ujs:enable-with')
|
282
|
+
// but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
|
283
|
+
element.data('ujs:enable-with', false); // clean up cache
|
284
|
+
}
|
285
|
+
element.unbind('click.railsDisable'); // enable element
|
286
|
+
}
|
287
|
+
|
288
|
+
};
|
289
|
+
|
290
|
+
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
|
291
|
+
|
292
|
+
$(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
|
293
|
+
rails.enableElement($(this));
|
294
|
+
});
|
295
|
+
|
296
|
+
$(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
|
297
|
+
var link = $(this), method = link.data('method'), data = link.data('params');
|
298
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
299
|
+
|
300
|
+
if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
|
301
|
+
|
302
|
+
if (link.data('remote') !== undefined) {
|
303
|
+
if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
|
304
|
+
|
305
|
+
if (rails.handleRemote(link) === false) { rails.enableElement(link); }
|
306
|
+
return false;
|
307
|
+
|
308
|
+
} else if (link.data('method')) {
|
309
|
+
rails.handleMethod(link);
|
310
|
+
return false;
|
311
|
+
}
|
312
|
+
});
|
313
|
+
|
314
|
+
$(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
|
315
|
+
var link = $(this);
|
316
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
317
|
+
|
318
|
+
rails.handleRemote(link);
|
319
|
+
return false;
|
320
|
+
});
|
321
|
+
|
322
|
+
$(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
|
323
|
+
var form = $(this),
|
324
|
+
remote = form.data('remote') !== undefined,
|
325
|
+
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
|
326
|
+
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
|
327
|
+
|
328
|
+
if (!rails.allowAction(form)) return rails.stopEverything(e);
|
329
|
+
|
330
|
+
// skip other logic when required values are missing or file upload is present
|
331
|
+
if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
|
332
|
+
return rails.stopEverything(e);
|
333
|
+
}
|
334
|
+
|
335
|
+
if (remote) {
|
336
|
+
if (nonBlankFileInputs) {
|
337
|
+
return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
|
338
|
+
}
|
339
|
+
|
340
|
+
// If browser does not support submit bubbling, then this live-binding will be called before direct
|
341
|
+
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
|
342
|
+
if (!$.support.submitBubbles && $().jquery < '1.7' && rails.callFormSubmitBindings(form, e) === false) return rails.stopEverything(e);
|
343
|
+
|
344
|
+
rails.handleRemote(form);
|
345
|
+
return false;
|
346
|
+
|
347
|
+
} else {
|
348
|
+
// slight timeout so that the submit button gets properly serialized
|
349
|
+
setTimeout(function(){ rails.disableFormElements(form); }, 13);
|
350
|
+
}
|
351
|
+
});
|
352
|
+
|
353
|
+
$(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
|
354
|
+
var button = $(this);
|
355
|
+
|
356
|
+
if (!rails.allowAction(button)) return rails.stopEverything(event);
|
357
|
+
|
358
|
+
// register the pressed submit button
|
359
|
+
var name = button.attr('name'),
|
360
|
+
data = name ? {name:name, value:button.val()} : null;
|
361
|
+
|
362
|
+
button.closest('form').data('ujs:submit-button', data);
|
363
|
+
});
|
364
|
+
|
365
|
+
$(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
|
366
|
+
if (this == event.target) rails.disableFormElements($(this));
|
367
|
+
});
|
368
|
+
|
369
|
+
$(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
|
370
|
+
if (this == event.target) rails.enableFormElements($(this));
|
371
|
+
});
|
372
|
+
|
373
|
+
})( jQuery );
|
374
|
+
|