bookyt 0.0.1
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.
- data/app/assets/images/16x16/add.png +0 -0
- data/app/assets/images/16x16/alert.png +0 -0
- data/app/assets/images/16x16/combolink.png +0 -0
- data/app/assets/images/16x16/copy.png +0 -0
- data/app/assets/images/16x16/delete.png +0 -0
- data/app/assets/images/16x16/edit.png +0 -0
- data/app/assets/images/16x16/filter.png +0 -0
- data/app/assets/images/16x16/index.png +0 -0
- data/app/assets/images/16x16/notice.png +0 -0
- data/app/assets/images/16x16/pdf.png +0 -0
- data/app/assets/images/16x16/print.png +0 -0
- data/app/assets/images/16x16/show.png +0 -0
- data/app/assets/images/22x22/arrow-right.png +0 -0
- data/app/assets/images/22x22/edit.png +0 -0
- data/app/assets/images/22x22/insert_booking.png +0 -0
- data/app/assets/images/22x22/remove.png +0 -0
- data/app/assets/images/32x32/edit.png +0 -0
- data/app/assets/images/32x32/remove.png +0 -0
- data/app/assets/images/48x48/accounting.png +0 -0
- data/app/assets/images/48x48/basic_claims_data.png +0 -0
- data/app/assets/images/48x48/contacts.png +0 -0
- data/app/assets/images/48x48/invoicing.png +0 -0
- data/app/assets/images/48x48/nav_users.png +0 -0
- data/app/assets/images/48x48/settings.png +0 -0
- data/app/assets/images/48x48/store.png +0 -0
- data/app/assets/images/button_bg.png +0 -0
- data/app/assets/images/crystal-icons/16x16/filter.png +0 -0
- data/app/assets/images/down.png +0 -0
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/images/flavour-extended/48x48/invoice.png +0 -0
- data/app/assets/images/free-business-desktop-icons/48x48/business.png +0 -0
- data/app/assets/images/gnome-web-icons/48x48/Gnome-X-Office-Address-Book-48.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_flat_55_fbec88_40x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_glass_75_759fcf_1x400.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_glass_85_aeb9cf_1x400.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_gloss-wave_55_aeb9cf_500x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_inset-hard_100_759fcf_1x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_inset-hard_100_f6f6f6_1x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_217bc0_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_2e83ff_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_469bdd_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_6da8d5_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_cd0a0a_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_d8e7f3_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_f9bd01_256x240.png +0 -0
- data/app/assets/images/jquery/tooltip/black_arrow.png +0 -0
- data/app/assets/images/letter-logo.alpha.png +0 -0
- data/app/assets/images/letter-logo.big.png +0 -0
- data/app/assets/images/letter-logo.orig.png +0 -0
- data/app/assets/images/letter-logo.png +0 -0
- data/app/assets/images/loading.gif +0 -0
- data/app/assets/images/logo.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/application-pdf.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/document-preview.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/document-print.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/edit-copy.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/go-next.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/mail-mark-notjunk.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/status_unknown.png +0 -0
- data/app/assets/images/oxygen-icons/48x48/system-users.png +0 -0
- data/app/assets/images/rails.png +0 -0
- data/app/assets/images/up.png +0 -0
- data/app/assets/javascripts/application.js +49 -0
- data/app/assets/javascripts/cyt.js +86 -0
- data/app/assets/javascripts/jquery-ui.js +11437 -0
- data/app/assets/javascripts/jquery.dirtyform.js +242 -0
- data/app/assets/javascripts/jquery.form.js +785 -0
- data/app/assets/javascripts/jquery.js +8936 -0
- data/app/assets/javascripts/jquery.meio.mask.js +683 -0
- data/app/assets/javascripts/jquery.remotipart.js +46 -0
- data/app/assets/javascripts/jquery.ui.combobox.js +77 -0
- data/app/assets/javascripts/jquery_ujs.js +316 -0
- data/app/assets/javascripts/nested_form.js +51 -0
- data/app/assets/javascripts/tooltip.js +343 -0
- data/app/assets/stylesheets/.gitkeep +0 -0
- data/app/assets/stylesheets/ie.scss +16 -0
- data/app/assets/stylesheets/ie6.scss +4 -0
- data/app/assets/stylesheets/partials/_base.sass +39 -0
- data/app/assets/stylesheets/partials/_content.sass +60 -0
- data/app/assets/stylesheets/partials/_jquery.sass +2 -0
- data/app/assets/stylesheets/partials/_layout.sass +21 -0
- data/app/assets/stylesheets/partials/_sidebar.sass +5 -0
- data/app/assets/stylesheets/partials/content/_accounting.sass +41 -0
- data/app/assets/stylesheets/partials/content/_ajax_indicator.sass +28 -0
- data/app/assets/stylesheets/partials/content/_app.sass +43 -0
- data/app/assets/stylesheets/partials/content/_combobox.sass +8 -0
- data/app/assets/stylesheets/partials/content/_cyt.sass +200 -0
- data/app/assets/stylesheets/partials/content/_fancy_buttons.sass +10 -0
- data/app/assets/stylesheets/partials/content/_flash_errors.sass +46 -0
- data/app/assets/stylesheets/partials/content/_form_view.sass +20 -0
- data/app/assets/stylesheets/partials/content/_icons.sass +35 -0
- data/app/assets/stylesheets/partials/content/_invoice.sass +6 -0
- data/app/assets/stylesheets/partials/content/_overview.sass +40 -0
- data/app/assets/stylesheets/partials/content/_pagination.sass +61 -0
- data/app/assets/stylesheets/partials/content/_person.sass +5 -0
- data/app/assets/stylesheets/partials/content/_scaffold.sass +67 -0
- data/app/assets/stylesheets/partials/content/_table_list.sass +26 -0
- data/app/assets/stylesheets/partials/content/formtastic/_formtastic.sass +201 -0
- data/app/assets/stylesheets/partials/content/formtastic/_formtastic_cyt.sass +90 -0
- data/app/assets/stylesheets/partials/formtastic/_custom_fields.sass +2 -0
- data/app/assets/stylesheets/partials/formtastic/_formtastic_base.sass +652 -0
- data/app/assets/stylesheets/partials/jquery/_jquery_ui.sass +1461 -0
- data/app/assets/stylesheets/partials/jquery/_tooltip.sass +21 -0
- data/app/assets/stylesheets/partials/layout/_header.sass +29 -0
- data/app/assets/stylesheets/partials/layout/_navigation.sass +2 -0
- data/app/assets/stylesheets/partials/layout/navigation/_main.sass +34 -0
- data/app/assets/stylesheets/partials/layout/navigation/_sidebar.sass +18 -0
- data/app/assets/stylesheets/partials/print/_app.sass +21 -0
- data/app/assets/stylesheets/partials/print/_layout.sass +24 -0
- data/app/assets/stylesheets/print.scss +5 -0
- data/app/assets/stylesheets/screen.scss +12 -0
- data/app/controllers/account_types_controller.rb +2 -0
- data/app/controllers/accounts_controller.rb +30 -0
- data/app/controllers/application_controller.rb +12 -0
- data/app/controllers/attachments_controller.rb +15 -0
- data/app/controllers/authorized_controller.rb +24 -0
- data/app/controllers/bank_accounts_controller.rb +2 -0
- data/app/controllers/booking_imports_controller.rb +2 -0
- data/app/controllers/booking_templates_controller.rb +8 -0
- data/app/controllers/bookings_controller.rb +64 -0
- data/app/controllers/charge_booking_templates_controller.rb +2 -0
- data/app/controllers/charge_rates_controller.rb +2 -0
- data/app/controllers/companies_controller.rb +8 -0
- data/app/controllers/credit_invoices_controller.rb +29 -0
- data/app/controllers/customers_controller.rb +12 -0
- data/app/controllers/debit_invoices_controller.rb +43 -0
- data/app/controllers/direct_bookings_controller.rb +17 -0
- data/app/controllers/employees_controller.rb +3 -0
- data/app/controllers/employments_controller.rb +2 -0
- data/app/controllers/invoices_controller.rb +21 -0
- data/app/controllers/notes_controller.rb +34 -0
- data/app/controllers/overview_controller.rb +6 -0
- data/app/controllers/people_controller.rb +13 -0
- data/app/controllers/salaries_controller.rb +46 -0
- data/app/controllers/tenants_controller.rb +39 -0
- data/app/controllers/users_controller.rb +26 -0
- data/app/helpers/application_helper.rb +52 -0
- data/app/helpers/booking_helper.rb +10 -0
- data/app/helpers/booking_template_helper.rb +17 -0
- data/app/helpers/charge_rate_helper.rb +5 -0
- data/app/helpers/invoice_helper.rb +9 -0
- data/app/helpers/vat_rate_helper.rb +10 -0
- data/app/inputs/combobox_input.rb +23 -0
- data/app/inputs/date_field_input.rb +5 -0
- data/app/inputs/hour_field_input.rb +5 -0
- data/app/models/ability.rb +34 -0
- data/app/models/attachment.rb +13 -0
- data/app/models/booking_import.rb +8 -0
- data/app/models/booking_import_observer.rb +7 -0
- data/app/models/booking_reference.rb +4 -0
- data/app/models/booking_template.rb +92 -0
- data/app/models/charge_booking_template.rb +57 -0
- data/app/models/charge_rate.rb +30 -0
- data/app/models/civil_status.rb +5 -0
- data/app/models/company.rb +5 -0
- data/app/models/credit_invoice.rb +32 -0
- data/app/models/customer.rb +4 -0
- data/app/models/debit_invoice.rb +24 -0
- data/app/models/employee.rb +6 -0
- data/app/models/employment.rb +28 -0
- data/app/models/invoice.rb +145 -0
- data/app/models/line_item.rb +22 -0
- data/app/models/note.rb +8 -0
- data/app/models/person.rb +65 -0
- data/app/models/product.rb +2 -0
- data/app/models/profit.rb +9 -0
- data/app/models/religion.rb +5 -0
- data/app/models/role.rb +9 -0
- data/app/models/salary.rb +93 -0
- data/app/models/tenant.rb +43 -0
- data/app/models/user.rb +44 -0
- data/app/models/vat_rate.rb +11 -0
- data/app/uploaders/attachment_uploader.rb +12 -0
- data/app/views/account_types/_account_type.html.haml +6 -0
- data/app/views/account_types/_form.html.haml +7 -0
- data/app/views/account_types/_list.html.haml +7 -0
- data/app/views/account_types/index.html.haml +6 -0
- data/app/views/account_types/show.html.haml +6 -0
- data/app/views/accounts/_account.html.haml +12 -0
- data/app/views/accounts/_booking_item.html.haml +15 -0
- data/app/views/accounts/_booking_list.html.haml +19 -0
- data/app/views/accounts/_booking_list_footer.html.haml +2 -0
- data/app/views/accounts/_booking_list_header.html.haml +8 -0
- data/app/views/accounts/_booking_list_paginate.html.haml +5 -0
- data/app/views/accounts/_booking_list_saldo.html.haml +8 -0
- data/app/views/accounts/_booking_list_turnover.html.haml +9 -0
- data/app/views/accounts/_carry_booking.html.haml +9 -0
- data/app/views/accounts/_form.html.haml +10 -0
- data/app/views/accounts/_list_footer.html.haml +2 -0
- data/app/views/accounts/_list_header.html.haml +5 -0
- data/app/views/accounts/index.html.haml +8 -0
- data/app/views/accounts/show.html.haml +10 -0
- data/app/views/application/_form.html.haml +7 -0
- data/app/views/application/_list.html.haml +15 -0
- data/app/views/application/_search_form.html.haml +5 -0
- data/app/views/application/_show.html.haml +2 -0
- data/app/views/application/create.js.erb +3 -0
- data/app/views/application/destroy.js.erb +2 -0
- data/app/views/application/edit.html.haml +5 -0
- data/app/views/application/edit.js.erb +3 -0
- data/app/views/application/index.html.haml +7 -0
- data/app/views/application/new.html.haml +5 -0
- data/app/views/application/new.js.erb +3 -0
- data/app/views/application/show.html.haml +5 -0
- data/app/views/application/update.js.erb +3 -0
- data/app/views/attachments/_attachment.html.haml +5 -0
- data/app/views/attachments/_form.html.haml +15 -0
- data/app/views/attachments/_list.html.haml +6 -0
- data/app/views/bank_accounts/_bank_account.html.haml +1 -0
- data/app/views/booking_imports/_booking_import.html.haml +5 -0
- data/app/views/booking_imports/_form.html.haml +6 -0
- data/app/views/booking_imports/_list.html.haml +7 -0
- data/app/views/booking_imports/create.js.erb +4 -0
- data/app/views/booking_imports/index.html.haml +6 -0
- data/app/views/booking_imports/show.html.haml +6 -0
- data/app/views/booking_templates/_booking_template.html.haml +16 -0
- data/app/views/booking_templates/_form.html.haml +12 -0
- data/app/views/booking_templates/_list.html.haml +10 -0
- data/app/views/booking_templates/index.html.haml +6 -0
- data/app/views/bookings/_booking.html.haml +17 -0
- data/app/views/bookings/_form.html.haml +14 -0
- data/app/views/bookings/_list.html.haml +11 -0
- data/app/views/bookings/_new_form.html.haml +8 -0
- data/app/views/bookings/_sidebar.html.haml +7 -0
- data/app/views/bookings/_simple_form.html.haml +12 -0
- data/app/views/bookings/index.html.haml +9 -0
- data/app/views/bookings/new.html.haml +8 -0
- data/app/views/bookings/select.html.haml +11 -0
- data/app/views/bookings/show.html.haml +27 -0
- data/app/views/bookings/simple_edit.html.haml +4 -0
- data/app/views/charge_booking_templates/_charge_booking_template.html.haml +15 -0
- data/app/views/charge_booking_templates/_form.html.haml +12 -0
- data/app/views/charge_booking_templates/_list.html.haml +10 -0
- data/app/views/charge_rates/_form.html.haml +14 -0
- data/app/views/companies/_company.html.haml +5 -0
- data/app/views/companies/_form.html.haml +8 -0
- data/app/views/companies/_list.html.haml +6 -0
- data/app/views/companies/index.html.haml +6 -0
- data/app/views/companies/show.html.haml +27 -0
- data/app/views/credit_invoices/_credit_invoice.html.haml +9 -0
- data/app/views/credit_invoices/_form.html.haml +41 -0
- data/app/views/credit_invoices/_list.html.haml +20 -0
- data/app/views/credit_invoices/index.html.haml +7 -0
- data/app/views/credit_invoices/show.html.haml +56 -0
- data/app/views/customers/_customer.html.haml +5 -0
- data/app/views/customers/_form.html.haml +8 -0
- data/app/views/customers/_list.html.haml +6 -0
- data/app/views/customers/index.html.haml +6 -0
- data/app/views/customers/show.html.haml +22 -0
- data/app/views/debit_invoices/_debit_invoice.html.haml +9 -0
- data/app/views/debit_invoices/_form.html.haml +38 -0
- data/app/views/debit_invoices/_invoice_body.html.haml +8 -0
- data/app/views/debit_invoices/_invoice_info.html.haml +10 -0
- data/app/views/debit_invoices/_invoice_parties.html.haml +9 -0
- data/app/views/debit_invoices/_list.html.haml +21 -0
- data/app/views/debit_invoices/index.html.haml +7 -0
- data/app/views/debit_invoices/letter.html.haml +9 -0
- data/app/views/debit_invoices/letter.pdf.prawn +57 -0
- data/app/views/debit_invoices/show.html.haml +56 -0
- data/app/views/devise/confirmations/new.html.haml +10 -0
- data/app/views/devise/mailer/confirmation_instructions.html.haml +6 -0
- data/app/views/devise/mailer/reset_password_instructions.html.haml +10 -0
- data/app/views/devise/mailer/unlock_instructions.html.haml +8 -0
- data/app/views/devise/passwords/edit.html.haml +15 -0
- data/app/views/devise/passwords/new.html.haml +11 -0
- data/app/views/devise/sessions/new.html.haml +13 -0
- data/app/views/devise/shared/_links.haml +15 -0
- data/app/views/devise/unlocks/new.html.haml +11 -0
- data/app/views/direct_bookings/_form.html.haml +12 -0
- data/app/views/direct_bookings/_item.html.haml +17 -0
- data/app/views/direct_bookings/_list.html.haml +10 -0
- data/app/views/direct_bookings/_list_footer.html.haml +6 -0
- data/app/views/direct_bookings/_show.html.haml +3 -0
- data/app/views/direct_bookings/_show_all.html.haml +8 -0
- data/app/views/direct_bookings/list.js.erb +2 -0
- data/app/views/direct_bookings/new.js.erb +2 -0
- data/app/views/employees/_employee.html.haml +5 -0
- data/app/views/employees/_form.html.haml +19 -0
- data/app/views/employees/_list.html.haml +6 -0
- data/app/views/employees/index.html.haml +6 -0
- data/app/views/employees/show.html.haml +31 -0
- data/app/views/employments/_employment.html.haml +10 -0
- data/app/views/employments/_form.html.haml +24 -0
- data/app/views/employments/_list.html.haml +11 -0
- data/app/views/employments/_show.html.haml +9 -0
- data/app/views/employments/index.html.haml +5 -0
- data/app/views/invoices/_form.html.haml +13 -0
- data/app/views/invoices/_invoice.html.haml +7 -0
- data/app/views/invoices/_list.html.haml +20 -0
- data/app/views/invoices/_sidebar.html.haml +11 -0
- data/app/views/invoices/index.html.haml +17 -0
- data/app/views/invoices/show.html.haml +56 -0
- data/app/views/layouts/_flash_new.html.haml +1 -0
- data/app/views/layouts/_list_item_actions_for.html.haml +3 -0
- data/app/views/layouts/application.html.haml +46 -0
- data/app/views/line_items/_form.html.haml +6 -0
- data/app/views/line_items/_line_item.html.haml +7 -0
- data/app/views/line_items/_list_footer.html.haml +7 -0
- data/app/views/notes/_form.html.haml +10 -0
- data/app/views/notes/_list.html.haml +15 -0
- data/app/views/notes/index.html.haml +9 -0
- data/app/views/notes/show.html.haml +12 -0
- data/app/views/overview/index.html.haml +14 -0
- data/app/views/people/_form.html.haml +8 -0
- data/app/views/people/_list.html.haml +7 -0
- data/app/views/people/_person.html.haml +6 -0
- data/app/views/people/_show.html.haml +6 -0
- data/app/views/people/show.html.haml +21 -0
- data/app/views/persons/_civil.html.haml +5 -0
- data/app/views/persons/_show.html.haml +6 -0
- data/app/views/salaries/_form.html.haml +14 -0
- data/app/views/salaries/_list.html.haml +12 -0
- data/app/views/salaries/_salary.html.haml +10 -0
- data/app/views/salaries/_salary_certificate.html.haml +25 -0
- data/app/views/salaries/payslip.html.haml +40 -0
- data/app/views/salaries/show.html.haml +30 -0
- data/app/views/salaries/statistics.html.haml +6 -0
- data/app/views/tenants/_account.html.haml +7 -0
- data/app/views/tenants/_account_group_sheet.html.haml +8 -0
- data/app/views/tenants/_form.html.haml +17 -0
- data/app/views/tenants/_list.html.haml +7 -0
- data/app/views/tenants/_tenant.html.haml +7 -0
- data/app/views/tenants/balance_sheet.html.haml +43 -0
- data/app/views/tenants/index.html.haml +6 -0
- data/app/views/tenants/new.js.erb +1 -0
- data/app/views/tenants/profit_sheet.html.haml +26 -0
- data/app/views/tenants/show.html.haml +18 -0
- data/app/views/users/_demo.de-CH.html.haml +7 -0
- data/app/views/users/_demo.de.html.haml +7 -0
- data/app/views/users/_demo.html.haml +7 -0
- data/app/views/users/_form.html.haml +17 -0
- data/app/views/users/_list.html.haml +9 -0
- data/app/views/users/_show.html.haml +13 -0
- data/app/views/users/_user.html.haml +7 -0
- data/app/views/users/index.html.haml +6 -0
- data/app/views/users/new.js.erb +1 -0
- data/app/views/users/show.html.haml +14 -0
- data/lib/acts_as_csv.rb +113 -0
- data/lib/bookyt/engine.rb +18 -0
- data/lib/bookyt/version.rb +3 -0
- data/lib/float.rb +17 -0
- data/lib/pagination_list_link_renderer.rb +63 -0
- data/lib/parse_date.rb +27 -0
- data/lib/prawn/letter_document.rb +136 -0
- data/lib/raiffeisen_importer.rb +15 -0
- data/lib/recipes/bookyt.rb +15 -0
- data/lib/simple_navigation/renderer/list.rb +20 -0
- data/lib/simple_navigation/renderer/overview.rb +46 -0
- data/lib/sqlite3_extensions.rb +45 -0
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/bookyt.rake +15 -0
- data/lib/tasks/cucumber.rake +53 -0
- data/lib/tasks/environment_seeds.rake +7 -0
- data/lib/tasks/users.rake +46 -0
- metadata +423 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// Copyright 2009 Asa Wilson
|
|
2
|
+
// Available under both the GPL and MIT licenses, see license files for more details.
|
|
3
|
+
|
|
4
|
+
if (typeof jQuery == 'undefined') throw("jQuery could not be found.");
|
|
5
|
+
|
|
6
|
+
(function($){
|
|
7
|
+
|
|
8
|
+
$.extend({
|
|
9
|
+
DirtyForm: {
|
|
10
|
+
debug : false, // print out debug info? works best with firebug.
|
|
11
|
+
changedClass : 'changed',
|
|
12
|
+
addClassOn : new Function,
|
|
13
|
+
hasFirebug : "console" in window && "firebug" in window.console,
|
|
14
|
+
includeHidden : false,
|
|
15
|
+
monitorEvent : 'blur',
|
|
16
|
+
logger : function(msg){
|
|
17
|
+
if(this.debug){
|
|
18
|
+
msg = "DirtyForm: " + msg;
|
|
19
|
+
this.hasFirebug ? console.log(msg) : alert(msg);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
input_value : function(input){
|
|
23
|
+
if(input.is(':radio,:checkbox')){
|
|
24
|
+
return typeof(input.attr("checked")) == "undefined" ? false : input.attr("checked");
|
|
25
|
+
} else {
|
|
26
|
+
return input.val();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
input_reset : function(input){
|
|
30
|
+
if(input.is(':radio,:checkbox')){
|
|
31
|
+
input.attr('checked', input.data('initial'));
|
|
32
|
+
} else {
|
|
33
|
+
input.val(input.data('initial'));
|
|
34
|
+
}
|
|
35
|
+
input.trigger($.DirtyForm.monitorEvent + '.dirty_form')
|
|
36
|
+
},
|
|
37
|
+
input_checker : function(event){
|
|
38
|
+
var npt = $(event.target), form = npt.parents('.dirtyform'), initial = npt.data("initial"), current = $.DirtyForm.input_value(npt), inputs = event.data.inputs, settings = event.data.settings
|
|
39
|
+
|
|
40
|
+
if(initial != current) {
|
|
41
|
+
$.DirtyForm.logger("Form "+form.attr('class')+" is dirty. Changed from \""+initial+"\" to \""+current+"\"");
|
|
42
|
+
$.DirtyForm.logger("Class: "+settings.changedClass);
|
|
43
|
+
form
|
|
44
|
+
.data("dirty", true) //TODO: check if we can use an expando property here
|
|
45
|
+
.trigger("dirty", {target: npt, from: initial, to: current, preventDefault: function(){return false}, stopPropagation: function(){return false}, bubbles: true, cancelable: true});
|
|
46
|
+
npt
|
|
47
|
+
.add(settings.addClassOn.apply(npt))
|
|
48
|
+
.addClass(settings.changedClass); // TODO: maybe we need to check if the class exists already?
|
|
49
|
+
|
|
50
|
+
} else {
|
|
51
|
+
npt
|
|
52
|
+
.add(settings.addClassOn.apply(npt))
|
|
53
|
+
.removeClass(settings.changedClass)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if(!inputs.filter('.' + settings.changedClass).size()){
|
|
57
|
+
form
|
|
58
|
+
.data("dirty",false)
|
|
59
|
+
.trigger("clean", {target: npt, preventDefault: function(){return false}, stopPropagation: function(){return false}, bubbles: true, cancelable: true});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
$.fn.clean_form = function(){
|
|
67
|
+
return this.each(function(){
|
|
68
|
+
var dirtyform = $(this)
|
|
69
|
+
if(dirtyform.is('form')) {
|
|
70
|
+
dirtyform.reset().find('.changed:input').each(function(){
|
|
71
|
+
$(this).trigger($.DirtyForm.monitorEvent + '.dirty_form');
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
var selectorFilters = ':submit,:password,:button';
|
|
75
|
+
if (!settings.includeHidden) {
|
|
76
|
+
selectorFilters = ':hidden,' + selectorFilters;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
$(':input:not(' + selectorFilters + ')', dirtyform).each(function(){
|
|
80
|
+
$.DirtyForm.input_reset($(this));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// will flag a form as dirty if something is changed on the form.
|
|
87
|
+
$.fn.dirty_form = function(){
|
|
88
|
+
var defaults = {
|
|
89
|
+
changedClass : $.DirtyForm.changedClass,
|
|
90
|
+
addClassOn : $.DirtyForm.addClassOn,
|
|
91
|
+
dynamic : $.isFunction($.livequery)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var settings = $.extend(defaults, arguments.length != 0 ? arguments[0] : {});
|
|
95
|
+
|
|
96
|
+
return this.each(function(){
|
|
97
|
+
var form = $(this);
|
|
98
|
+
|
|
99
|
+
var selectorFilters = ':submit,:password,:button';
|
|
100
|
+
if (!settings.includeHidden) {
|
|
101
|
+
selectorFilters = ':hidden,' + selectorFilters;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var inputs = $(':input:not(' + selectorFilters + ')', form);
|
|
105
|
+
|
|
106
|
+
if( form.hasClass('dirtyform') ){
|
|
107
|
+
// unbind all DirtyForms specific events, then proceed to re-add them
|
|
108
|
+
form.unbind("dirty").unbind("clean");
|
|
109
|
+
inputs.unbind($.DirtyForm.monitorEvent + ".dirty_form");
|
|
110
|
+
}else{
|
|
111
|
+
// mark it as a dirtyform
|
|
112
|
+
$(this).addClass('dirtyform')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
$.DirtyForm.logger('Storing initial data for form ' + form.get(0));
|
|
116
|
+
|
|
117
|
+
if (settings.dynamic) {
|
|
118
|
+
inputs.livequery(function(){ // use livequery to perform these functions on the new elements added to the form
|
|
119
|
+
$(this)
|
|
120
|
+
.bind($.DirtyForm.monitorEvent + ".dirty_form", {inputs: inputs, settings: settings}, $.DirtyForm.input_checker)
|
|
121
|
+
.data('initial', $.DirtyForm.input_value($(this)))
|
|
122
|
+
});
|
|
123
|
+
}else {
|
|
124
|
+
inputs.each(function(){
|
|
125
|
+
$(this)
|
|
126
|
+
.bind($.DirtyForm.monitorEvent + ".dirty_form", {inputs: inputs, settings: settings}, $.DirtyForm.input_checker)
|
|
127
|
+
.data("initial", $.DirtyForm.input_value($(this)));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
// this is meant for selecting links that will warn about proceeding if there are any dirty forms on the page
|
|
135
|
+
$.fn.dirty_stopper = function(){
|
|
136
|
+
var defaults = {
|
|
137
|
+
dialog : {
|
|
138
|
+
title: "Warning: Unsaved Changes!",
|
|
139
|
+
height: 300,
|
|
140
|
+
width: 500,
|
|
141
|
+
modal: true,
|
|
142
|
+
resizeable: false,
|
|
143
|
+
autoResize: false,
|
|
144
|
+
overlay: {backgroundColor: "black", opacity: 0.5}
|
|
145
|
+
},
|
|
146
|
+
message : '<br/><p>You have changed form data without saving. All of your changes will be lost.</p><p>Are you sure you want to proceed?</p>'
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
var settings = $.extend(true, defaults, arguments.length != 0 ? arguments[0] : {});
|
|
150
|
+
|
|
151
|
+
$.DirtyForm.logger("Setting dirty stoppers")
|
|
152
|
+
|
|
153
|
+
return this.each(function(){
|
|
154
|
+
var stopper = $(this);
|
|
155
|
+
|
|
156
|
+
if ($(this).parents('.ui-tabs-nav').length > 0){
|
|
157
|
+
// FIXME: not sure what the comment below is actually saying. "Unchaining ... made it NOT work"?? (dvd, 03-02-2009)
|
|
158
|
+
// Unchaining these tabs calls made the tab links not work
|
|
159
|
+
var tabs = $(this).parents('.ui-tabs-nav')
|
|
160
|
+
tabs.find('a').unbind('click.dirty_form')
|
|
161
|
+
tabs.unbind('tabsselect.dirty_form')
|
|
162
|
+
tabs.bind('tabsselect.dirty_form', function(event, ui){
|
|
163
|
+
if($('.dirtyform').are_dirty()) {
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
var div = $("<div id='dirty_stopper_dialog'/>").appendTo(document.body)
|
|
166
|
+
var href = $(this).attr('href')
|
|
167
|
+
div.dialog($.extend(settings.dialog, {
|
|
168
|
+
buttons: {
|
|
169
|
+
Proceed: function(){
|
|
170
|
+
var selected_id = $(ui.tab).parent().siblings('.ui-tabs-selected').find('a').attr('href');
|
|
171
|
+
// reset the form in the selected tab and make sure it cleans up after itself
|
|
172
|
+
$('.dirtyform', selected_id).clean_form();
|
|
173
|
+
|
|
174
|
+
// select the tab now that the old tab is clean
|
|
175
|
+
tabs.tabs('select', $(ui.tab).attr('href'));
|
|
176
|
+
|
|
177
|
+
// close the dialog with fire
|
|
178
|
+
$(this).dialog('destroy').remove()
|
|
179
|
+
},
|
|
180
|
+
Cancel: function(){$(this).dialog('destroy').remove()}
|
|
181
|
+
}
|
|
182
|
+
})).dialog("moveToTop").append(settings.message);
|
|
183
|
+
// div.append(settings.message);
|
|
184
|
+
return false
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
} else {
|
|
188
|
+
stopper.unbind('click.dirty_form')
|
|
189
|
+
stopper.bind('click.dirty_form', function(event){
|
|
190
|
+
if($('.dirtyform').are_dirty()) {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
var div = $("<div id='dirty_stopper_dialog'/>").appendTo(document.body),
|
|
193
|
+
href = $(this).attr('href');
|
|
194
|
+
div.dialog($.extend({buttons: {
|
|
195
|
+
Proceed:function(){window.location = href},
|
|
196
|
+
Cancel:function(){$(this).dialog('destroy').remove(); return false}
|
|
197
|
+
}
|
|
198
|
+
}, settings.dialog)).dialog("moveToTop").append(settings.message);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// not chainable
|
|
206
|
+
// returns false if any of the forms on the page are dirty
|
|
207
|
+
$.fn.are_dirty = function (){
|
|
208
|
+
var dirty = false
|
|
209
|
+
this.each(function(){
|
|
210
|
+
if($(this).data('dirty')) {
|
|
211
|
+
dirty = true;
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
return dirty
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// This is just for testing purposes...
|
|
218
|
+
$.fn.dirty_checker = function(){
|
|
219
|
+
$.DirtyForm.logger("Setting dirty checkers!")
|
|
220
|
+
|
|
221
|
+
return this.each(function(){
|
|
222
|
+
checker = $(this);
|
|
223
|
+
checker.click(function(){
|
|
224
|
+
if($("form").are_dirty()) {
|
|
225
|
+
alert("Dirty Form!!");
|
|
226
|
+
} else {
|
|
227
|
+
alert("Clean Form ...phew!");
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Shortcut to bind a handler to the "ondirty" event
|
|
234
|
+
$.fn.extend({
|
|
235
|
+
dirty: function(fn) {
|
|
236
|
+
return this.bind('dirty', fn);
|
|
237
|
+
},
|
|
238
|
+
clean: function(fn) {
|
|
239
|
+
return this.bind('clean', fn);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
})(jQuery);
|
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* jQuery Form Plugin
|
|
3
|
+
* version: 2.49 (18-OCT-2010)
|
|
4
|
+
* @requires jQuery v1.3.2 or later
|
|
5
|
+
*
|
|
6
|
+
* Examples and documentation at: http://malsup.com/jquery/form/
|
|
7
|
+
* Dual licensed under the MIT and GPL licenses:
|
|
8
|
+
* http://www.opensource.org/licenses/mit-license.php
|
|
9
|
+
* http://www.gnu.org/licenses/gpl.html
|
|
10
|
+
*/
|
|
11
|
+
;(function($) {
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
Usage Note:
|
|
15
|
+
-----------
|
|
16
|
+
Do not use both ajaxSubmit and ajaxForm on the same form. These
|
|
17
|
+
functions are intended to be exclusive. Use ajaxSubmit if you want
|
|
18
|
+
to bind your own submit handler to the form. For example,
|
|
19
|
+
|
|
20
|
+
$(document).ready(function() {
|
|
21
|
+
$('#myForm').bind('submit', function(e) {
|
|
22
|
+
e.preventDefault(); // <-- important
|
|
23
|
+
$(this).ajaxSubmit({
|
|
24
|
+
target: '#output'
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
Use ajaxForm when you want the plugin to manage all the event binding
|
|
30
|
+
for you. For example,
|
|
31
|
+
|
|
32
|
+
$(document).ready(function() {
|
|
33
|
+
$('#myForm').ajaxForm({
|
|
34
|
+
target: '#output'
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
When using ajaxForm, the ajaxSubmit function will be invoked for you
|
|
39
|
+
at the appropriate time.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* ajaxSubmit() provides a mechanism for immediately submitting
|
|
44
|
+
* an HTML form using AJAX.
|
|
45
|
+
*/
|
|
46
|
+
$.fn.ajaxSubmit = function(options) {
|
|
47
|
+
// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
|
|
48
|
+
if (!this.length) {
|
|
49
|
+
log('ajaxSubmit: skipping submit process - no element selected');
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof options == 'function') {
|
|
54
|
+
options = { success: options };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var url = $.trim(this.attr('action'));
|
|
58
|
+
if (url) {
|
|
59
|
+
// clean url (don't include hash vaue)
|
|
60
|
+
url = (url.match(/^([^#]+)/)||[])[1];
|
|
61
|
+
}
|
|
62
|
+
url = url || window.location.href || '';
|
|
63
|
+
|
|
64
|
+
options = $.extend(true, {
|
|
65
|
+
url: url,
|
|
66
|
+
type: this.attr('method') || 'GET',
|
|
67
|
+
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
|
|
68
|
+
}, options);
|
|
69
|
+
|
|
70
|
+
// hook for manipulating the form data before it is extracted;
|
|
71
|
+
// convenient for use with rich editors like tinyMCE or FCKEditor
|
|
72
|
+
var veto = {};
|
|
73
|
+
this.trigger('form-pre-serialize', [this, options, veto]);
|
|
74
|
+
if (veto.veto) {
|
|
75
|
+
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// provide opportunity to alter form data before it is serialized
|
|
80
|
+
if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
|
|
81
|
+
log('ajaxSubmit: submit aborted via beforeSerialize callback');
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var n,v,a = this.formToArray(options.semantic);
|
|
86
|
+
if (options.data) {
|
|
87
|
+
options.extraData = options.data;
|
|
88
|
+
for (n in options.data) {
|
|
89
|
+
if(options.data[n] instanceof Array) {
|
|
90
|
+
for (var k in options.data[n]) {
|
|
91
|
+
a.push( { name: n, value: options.data[n][k] } );
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
v = options.data[n];
|
|
96
|
+
v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
|
|
97
|
+
a.push( { name: n, value: v } );
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// give pre-submit callback an opportunity to abort the submit
|
|
103
|
+
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
|
|
104
|
+
log('ajaxSubmit: submit aborted via beforeSubmit callback');
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// fire vetoable 'validate' event
|
|
109
|
+
this.trigger('form-submit-validate', [a, this, options, veto]);
|
|
110
|
+
if (veto.veto) {
|
|
111
|
+
log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
var q = $.param(a);
|
|
116
|
+
|
|
117
|
+
if (options.type.toUpperCase() == 'GET') {
|
|
118
|
+
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
|
|
119
|
+
options.data = null; // data is null for 'get'
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
options.data = q; // data is the query string for 'post'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
var $form = this, callbacks = [];
|
|
126
|
+
if (options.resetForm) {
|
|
127
|
+
callbacks.push(function() { $form.resetForm(); });
|
|
128
|
+
}
|
|
129
|
+
if (options.clearForm) {
|
|
130
|
+
callbacks.push(function() { $form.clearForm(); });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// perform a load on the target only if dataType is not provided
|
|
134
|
+
if (!options.dataType && options.target) {
|
|
135
|
+
var oldSuccess = options.success || function(){};
|
|
136
|
+
callbacks.push(function(data) {
|
|
137
|
+
var fn = options.replaceTarget ? 'replaceWith' : 'html';
|
|
138
|
+
$(options.target)[fn](data).each(oldSuccess, arguments);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if (options.success) {
|
|
142
|
+
callbacks.push(options.success);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
|
|
146
|
+
var context = options.context || options; // jQuery 1.4+ supports scope context
|
|
147
|
+
for (var i=0, max=callbacks.length; i < max; i++) {
|
|
148
|
+
callbacks[i].apply(context, [data, status, xhr || $form, $form]);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// are there files to upload?
|
|
153
|
+
var fileInputs = $('input:file', this).length > 0;
|
|
154
|
+
var mp = 'multipart/form-data';
|
|
155
|
+
var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
|
|
156
|
+
|
|
157
|
+
// options.iframe allows user to force iframe mode
|
|
158
|
+
// 06-NOV-09: now defaulting to iframe mode if file input is detected
|
|
159
|
+
if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
|
|
160
|
+
// hack to fix Safari hang (thanks to Tim Molendijk for this)
|
|
161
|
+
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
|
|
162
|
+
if (options.closeKeepAlive) {
|
|
163
|
+
$.get(options.closeKeepAlive, fileUpload);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
fileUpload();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
$.ajax(options);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// fire 'notify' event
|
|
174
|
+
this.trigger('form-submit-notify', [this, options]);
|
|
175
|
+
return this;
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
// private function for handling file uploads (hat tip to YAHOO!)
|
|
179
|
+
function fileUpload() {
|
|
180
|
+
var form = $form[0];
|
|
181
|
+
|
|
182
|
+
if ($(':input[name=submit],:input[id=submit]', form).length) {
|
|
183
|
+
// if there is an input with a name or id of 'submit' then we won't be
|
|
184
|
+
// able to invoke the submit fn on the form (at least not x-browser)
|
|
185
|
+
alert('Error: Form elements must not have name or id of "submit".');
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
var s = $.extend(true, {}, $.ajaxSettings, options);
|
|
190
|
+
s.context = s.context || s;
|
|
191
|
+
var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id;
|
|
192
|
+
window[fn] = function() {
|
|
193
|
+
var f = $io.data('form-plugin-onload');
|
|
194
|
+
if (f) {
|
|
195
|
+
f();
|
|
196
|
+
window[fn] = undefined;
|
|
197
|
+
try { delete window[fn]; } catch(e){}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" onload="window[\'_\'+this.id]()" />');
|
|
201
|
+
var io = $io[0];
|
|
202
|
+
|
|
203
|
+
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
|
|
204
|
+
|
|
205
|
+
var xhr = { // mock object
|
|
206
|
+
aborted: 0,
|
|
207
|
+
responseText: null,
|
|
208
|
+
responseXML: null,
|
|
209
|
+
status: 0,
|
|
210
|
+
statusText: 'n/a',
|
|
211
|
+
getAllResponseHeaders: function() {},
|
|
212
|
+
getResponseHeader: function() {},
|
|
213
|
+
setRequestHeader: function() {},
|
|
214
|
+
abort: function() {
|
|
215
|
+
this.aborted = 1;
|
|
216
|
+
$io.attr('src', s.iframeSrc); // abort op in progress
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
var g = s.global;
|
|
221
|
+
// trigger ajax global events so that activity/block indicators work like normal
|
|
222
|
+
if (g && ! $.active++) {
|
|
223
|
+
$.event.trigger("ajaxStart");
|
|
224
|
+
}
|
|
225
|
+
if (g) {
|
|
226
|
+
$.event.trigger("ajaxSend", [xhr, s]);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
|
|
230
|
+
if (s.global) {
|
|
231
|
+
$.active--;
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (xhr.aborted) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
var cbInvoked = false;
|
|
240
|
+
var timedOut = 0;
|
|
241
|
+
|
|
242
|
+
// add submitting element to data if we know it
|
|
243
|
+
var sub = form.clk;
|
|
244
|
+
if (sub) {
|
|
245
|
+
var n = sub.name;
|
|
246
|
+
if (n && !sub.disabled) {
|
|
247
|
+
s.extraData = s.extraData || {};
|
|
248
|
+
s.extraData[n] = sub.value;
|
|
249
|
+
if (sub.type == "image") {
|
|
250
|
+
s.extraData[n+'.x'] = form.clk_x;
|
|
251
|
+
s.extraData[n+'.y'] = form.clk_y;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// take a breath so that pending repaints get some cpu time before the upload starts
|
|
257
|
+
function doSubmit() {
|
|
258
|
+
// make sure form attrs are set
|
|
259
|
+
var t = $form.attr('target'), a = $form.attr('action');
|
|
260
|
+
|
|
261
|
+
// update form attrs in IE friendly way
|
|
262
|
+
form.setAttribute('target',id);
|
|
263
|
+
if (form.getAttribute('method') != 'POST') {
|
|
264
|
+
form.setAttribute('method', 'POST');
|
|
265
|
+
}
|
|
266
|
+
if (form.getAttribute('action') != s.url) {
|
|
267
|
+
form.setAttribute('action', s.url);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ie borks in some cases when setting encoding
|
|
271
|
+
if (! s.skipEncodingOverride) {
|
|
272
|
+
$form.attr({
|
|
273
|
+
encoding: 'multipart/form-data',
|
|
274
|
+
enctype: 'multipart/form-data'
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// support timout
|
|
279
|
+
if (s.timeout) {
|
|
280
|
+
setTimeout(function() { timedOut = true; cb(); }, s.timeout);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// add "extra" data to form if provided in options
|
|
284
|
+
var extraInputs = [];
|
|
285
|
+
try {
|
|
286
|
+
if (s.extraData) {
|
|
287
|
+
for (var n in s.extraData) {
|
|
288
|
+
extraInputs.push(
|
|
289
|
+
$('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
|
|
290
|
+
.appendTo(form)[0]);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// add iframe to doc and submit the form
|
|
295
|
+
$io.appendTo('body');
|
|
296
|
+
$io.data('form-plugin-onload', cb);
|
|
297
|
+
form.submit();
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
// reset attrs and remove "extra" input elements
|
|
301
|
+
form.setAttribute('action',a);
|
|
302
|
+
if(t) {
|
|
303
|
+
form.setAttribute('target', t);
|
|
304
|
+
} else {
|
|
305
|
+
$form.removeAttr('target');
|
|
306
|
+
}
|
|
307
|
+
$(extraInputs).remove();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (s.forceSync) {
|
|
312
|
+
doSubmit();
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
setTimeout(doSubmit, 10); // this lets dom updates render
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
var data, doc, domCheckCount = 50;
|
|
319
|
+
|
|
320
|
+
function cb() {
|
|
321
|
+
if (cbInvoked) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
$io.removeData('form-plugin-onload');
|
|
326
|
+
|
|
327
|
+
var ok = true;
|
|
328
|
+
try {
|
|
329
|
+
if (timedOut) {
|
|
330
|
+
throw 'timeout';
|
|
331
|
+
}
|
|
332
|
+
// extract the server response from the iframe
|
|
333
|
+
doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
|
|
334
|
+
|
|
335
|
+
var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
|
|
336
|
+
log('isXml='+isXml);
|
|
337
|
+
if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
|
|
338
|
+
if (--domCheckCount) {
|
|
339
|
+
// in some browsers (Opera) the iframe DOM is not always traversable when
|
|
340
|
+
// the onload callback fires, so we loop a bit to accommodate
|
|
341
|
+
log('requeing onLoad callback, DOM not available');
|
|
342
|
+
setTimeout(cb, 250);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
// let this fall through because server response could be an empty document
|
|
346
|
+
//log('Could not access iframe DOM after mutiple tries.');
|
|
347
|
+
//throw 'DOMException: not available';
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
//log('response detected');
|
|
351
|
+
cbInvoked = true;
|
|
352
|
+
xhr.responseText = doc.documentElement ? doc.documentElement.innerHTML : null;
|
|
353
|
+
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
|
354
|
+
xhr.getResponseHeader = function(header){
|
|
355
|
+
var headers = {'content-type': s.dataType};
|
|
356
|
+
return headers[header];
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
var scr = /(json|script)/.test(s.dataType);
|
|
360
|
+
if (scr || s.textarea) {
|
|
361
|
+
// see if user embedded response in textarea
|
|
362
|
+
var ta = doc.getElementsByTagName('textarea')[0];
|
|
363
|
+
if (ta) {
|
|
364
|
+
xhr.responseText = ta.value;
|
|
365
|
+
}
|
|
366
|
+
else if (scr) {
|
|
367
|
+
// account for browsers injecting pre around json response
|
|
368
|
+
var pre = doc.getElementsByTagName('pre')[0];
|
|
369
|
+
var b = doc.getElementsByTagName('body')[0];
|
|
370
|
+
if (pre) {
|
|
371
|
+
xhr.responseText = pre.innerHTML;
|
|
372
|
+
}
|
|
373
|
+
else if (b) {
|
|
374
|
+
xhr.responseText = b.innerHTML;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
|
|
379
|
+
xhr.responseXML = toXml(xhr.responseText);
|
|
380
|
+
}
|
|
381
|
+
data = $.httpData(xhr, s.dataType);
|
|
382
|
+
}
|
|
383
|
+
catch(e){
|
|
384
|
+
log('error caught:',e);
|
|
385
|
+
ok = false;
|
|
386
|
+
xhr.error = e;
|
|
387
|
+
$.handleError(s, xhr, 'error', e);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
|
391
|
+
if (ok) {
|
|
392
|
+
s.success.call(s.context, data, 'success', xhr);
|
|
393
|
+
if (g) {
|
|
394
|
+
$.event.trigger("ajaxSuccess", [xhr, s]);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (g) {
|
|
398
|
+
$.event.trigger("ajaxComplete", [xhr, s]);
|
|
399
|
+
}
|
|
400
|
+
if (g && ! --$.active) {
|
|
401
|
+
$.event.trigger("ajaxStop");
|
|
402
|
+
}
|
|
403
|
+
if (s.complete) {
|
|
404
|
+
s.complete.call(s.context, xhr, ok ? 'success' : 'error');
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// clean up
|
|
408
|
+
setTimeout(function() {
|
|
409
|
+
$io.removeData('form-plugin-onload');
|
|
410
|
+
$io.remove();
|
|
411
|
+
xhr.responseXML = null;
|
|
412
|
+
}, 100);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function toXml(s, doc) {
|
|
416
|
+
if (window.ActiveXObject) {
|
|
417
|
+
doc = new ActiveXObject('Microsoft.XMLDOM');
|
|
418
|
+
doc.async = 'false';
|
|
419
|
+
doc.loadXML(s);
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
|
423
|
+
}
|
|
424
|
+
return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* ajaxForm() provides a mechanism for fully automating form submission.
|
|
431
|
+
*
|
|
432
|
+
* The advantages of using this method instead of ajaxSubmit() are:
|
|
433
|
+
*
|
|
434
|
+
* 1: This method will include coordinates for <input type="image" /> elements (if the element
|
|
435
|
+
* is used to submit the form).
|
|
436
|
+
* 2. This method will include the submit element's name/value data (for the element that was
|
|
437
|
+
* used to submit the form).
|
|
438
|
+
* 3. This method binds the submit() method to the form for you.
|
|
439
|
+
*
|
|
440
|
+
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
|
|
441
|
+
* passes the options argument along after properly binding events for submit elements and
|
|
442
|
+
* the form itself.
|
|
443
|
+
*/
|
|
444
|
+
$.fn.ajaxForm = function(options) {
|
|
445
|
+
// in jQuery 1.3+ we can fix mistakes with the ready state
|
|
446
|
+
if (this.length === 0) {
|
|
447
|
+
var o = { s: this.selector, c: this.context };
|
|
448
|
+
if (!$.isReady && o.s) {
|
|
449
|
+
log('DOM not ready, queuing ajaxForm');
|
|
450
|
+
$(function() {
|
|
451
|
+
$(o.s,o.c).ajaxForm(options);
|
|
452
|
+
});
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
// is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
|
|
456
|
+
log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
|
|
457
|
+
return this;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
|
|
461
|
+
if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
|
|
462
|
+
e.preventDefault();
|
|
463
|
+
$(this).ajaxSubmit(options);
|
|
464
|
+
}
|
|
465
|
+
}).bind('click.form-plugin', function(e) {
|
|
466
|
+
var target = e.target;
|
|
467
|
+
var $el = $(target);
|
|
468
|
+
if (!($el.is(":submit,input:image"))) {
|
|
469
|
+
// is this a child element of the submit el? (ex: a span within a button)
|
|
470
|
+
var t = $el.closest(':submit');
|
|
471
|
+
if (t.length == 0) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
target = t[0];
|
|
475
|
+
}
|
|
476
|
+
var form = this;
|
|
477
|
+
form.clk = target;
|
|
478
|
+
if (target.type == 'image') {
|
|
479
|
+
if (e.offsetX != undefined) {
|
|
480
|
+
form.clk_x = e.offsetX;
|
|
481
|
+
form.clk_y = e.offsetY;
|
|
482
|
+
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
|
|
483
|
+
var offset = $el.offset();
|
|
484
|
+
form.clk_x = e.pageX - offset.left;
|
|
485
|
+
form.clk_y = e.pageY - offset.top;
|
|
486
|
+
} else {
|
|
487
|
+
form.clk_x = e.pageX - target.offsetLeft;
|
|
488
|
+
form.clk_y = e.pageY - target.offsetTop;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// clear form vars
|
|
492
|
+
setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
|
|
493
|
+
});
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
|
|
497
|
+
$.fn.ajaxFormUnbind = function() {
|
|
498
|
+
return this.unbind('submit.form-plugin click.form-plugin');
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* formToArray() gathers form element data into an array of objects that can
|
|
503
|
+
* be passed to any of the following ajax functions: $.get, $.post, or load.
|
|
504
|
+
* Each object in the array has both a 'name' and 'value' property. An example of
|
|
505
|
+
* an array for a simple login form might be:
|
|
506
|
+
*
|
|
507
|
+
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
|
|
508
|
+
*
|
|
509
|
+
* It is this array that is passed to pre-submit callback functions provided to the
|
|
510
|
+
* ajaxSubmit() and ajaxForm() methods.
|
|
511
|
+
*/
|
|
512
|
+
$.fn.formToArray = function(semantic) {
|
|
513
|
+
var a = [];
|
|
514
|
+
if (this.length === 0) {
|
|
515
|
+
return a;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
var form = this[0];
|
|
519
|
+
var els = semantic ? form.getElementsByTagName('*') : form.elements;
|
|
520
|
+
if (!els) {
|
|
521
|
+
return a;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
var i,j,n,v,el,max,jmax;
|
|
525
|
+
for(i=0, max=els.length; i < max; i++) {
|
|
526
|
+
el = els[i];
|
|
527
|
+
n = el.name;
|
|
528
|
+
if (!n) {
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if (semantic && form.clk && el.type == "image") {
|
|
533
|
+
// handle image inputs on the fly when semantic == true
|
|
534
|
+
if(!el.disabled && form.clk == el) {
|
|
535
|
+
a.push({name: n, value: $(el).val()});
|
|
536
|
+
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
|
537
|
+
}
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
v = $.fieldValue(el, true);
|
|
542
|
+
if (v && v.constructor == Array) {
|
|
543
|
+
for(j=0, jmax=v.length; j < jmax; j++) {
|
|
544
|
+
a.push({name: n, value: v[j]});
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
else if (v !== null && typeof v != 'undefined') {
|
|
548
|
+
a.push({name: n, value: v});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (!semantic && form.clk) {
|
|
553
|
+
// input type=='image' are not found in elements array! handle it here
|
|
554
|
+
var $input = $(form.clk), input = $input[0];
|
|
555
|
+
n = input.name;
|
|
556
|
+
if (n && !input.disabled && input.type == 'image') {
|
|
557
|
+
a.push({name: n, value: $input.val()});
|
|
558
|
+
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return a;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Serializes form data into a 'submittable' string. This method will return a string
|
|
566
|
+
* in the format: name1=value1&name2=value2
|
|
567
|
+
*/
|
|
568
|
+
$.fn.formSerialize = function(semantic) {
|
|
569
|
+
//hand off to jQuery.param for proper encoding
|
|
570
|
+
return $.param(this.formToArray(semantic));
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Serializes all field elements in the jQuery object into a query string.
|
|
575
|
+
* This method will return a string in the format: name1=value1&name2=value2
|
|
576
|
+
*/
|
|
577
|
+
$.fn.fieldSerialize = function(successful) {
|
|
578
|
+
var a = [];
|
|
579
|
+
this.each(function() {
|
|
580
|
+
var n = this.name;
|
|
581
|
+
if (!n) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
var v = $.fieldValue(this, successful);
|
|
585
|
+
if (v && v.constructor == Array) {
|
|
586
|
+
for (var i=0,max=v.length; i < max; i++) {
|
|
587
|
+
a.push({name: n, value: v[i]});
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
else if (v !== null && typeof v != 'undefined') {
|
|
591
|
+
a.push({name: this.name, value: v});
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
//hand off to jQuery.param for proper encoding
|
|
595
|
+
return $.param(a);
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Returns the value(s) of the element in the matched set. For example, consider the following form:
|
|
600
|
+
*
|
|
601
|
+
* <form><fieldset>
|
|
602
|
+
* <input name="A" type="text" />
|
|
603
|
+
* <input name="A" type="text" />
|
|
604
|
+
* <input name="B" type="checkbox" value="B1" />
|
|
605
|
+
* <input name="B" type="checkbox" value="B2"/>
|
|
606
|
+
* <input name="C" type="radio" value="C1" />
|
|
607
|
+
* <input name="C" type="radio" value="C2" />
|
|
608
|
+
* </fieldset></form>
|
|
609
|
+
*
|
|
610
|
+
* var v = $(':text').fieldValue();
|
|
611
|
+
* // if no values are entered into the text inputs
|
|
612
|
+
* v == ['','']
|
|
613
|
+
* // if values entered into the text inputs are 'foo' and 'bar'
|
|
614
|
+
* v == ['foo','bar']
|
|
615
|
+
*
|
|
616
|
+
* var v = $(':checkbox').fieldValue();
|
|
617
|
+
* // if neither checkbox is checked
|
|
618
|
+
* v === undefined
|
|
619
|
+
* // if both checkboxes are checked
|
|
620
|
+
* v == ['B1', 'B2']
|
|
621
|
+
*
|
|
622
|
+
* var v = $(':radio').fieldValue();
|
|
623
|
+
* // if neither radio is checked
|
|
624
|
+
* v === undefined
|
|
625
|
+
* // if first radio is checked
|
|
626
|
+
* v == ['C1']
|
|
627
|
+
*
|
|
628
|
+
* The successful argument controls whether or not the field element must be 'successful'
|
|
629
|
+
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
|
630
|
+
* The default value of the successful argument is true. If this value is false the value(s)
|
|
631
|
+
* for each element is returned.
|
|
632
|
+
*
|
|
633
|
+
* Note: This method *always* returns an array. If no valid value can be determined the
|
|
634
|
+
* array will be empty, otherwise it will contain one or more values.
|
|
635
|
+
*/
|
|
636
|
+
$.fn.fieldValue = function(successful) {
|
|
637
|
+
for (var val=[], i=0, max=this.length; i < max; i++) {
|
|
638
|
+
var el = this[i];
|
|
639
|
+
var v = $.fieldValue(el, successful);
|
|
640
|
+
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
v.constructor == Array ? $.merge(val, v) : val.push(v);
|
|
644
|
+
}
|
|
645
|
+
return val;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Returns the value of the field element.
|
|
650
|
+
*/
|
|
651
|
+
$.fieldValue = function(el, successful) {
|
|
652
|
+
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
|
|
653
|
+
if (successful === undefined) {
|
|
654
|
+
successful = true;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
|
|
658
|
+
(t == 'checkbox' || t == 'radio') && !el.checked ||
|
|
659
|
+
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
|
|
660
|
+
tag == 'select' && el.selectedIndex == -1)) {
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
if (tag == 'select') {
|
|
665
|
+
var index = el.selectedIndex;
|
|
666
|
+
if (index < 0) {
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
var a = [], ops = el.options;
|
|
670
|
+
var one = (t == 'select-one');
|
|
671
|
+
var max = (one ? index+1 : ops.length);
|
|
672
|
+
for(var i=(one ? index : 0); i < max; i++) {
|
|
673
|
+
var op = ops[i];
|
|
674
|
+
if (op.selected) {
|
|
675
|
+
var v = op.value;
|
|
676
|
+
if (!v) { // extra pain for IE...
|
|
677
|
+
v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
|
|
678
|
+
}
|
|
679
|
+
if (one) {
|
|
680
|
+
return v;
|
|
681
|
+
}
|
|
682
|
+
a.push(v);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return a;
|
|
686
|
+
}
|
|
687
|
+
return $(el).val();
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Clears the form data. Takes the following actions on the form's input fields:
|
|
692
|
+
* - input text fields will have their 'value' property set to the empty string
|
|
693
|
+
* - select elements will have their 'selectedIndex' property set to -1
|
|
694
|
+
* - checkbox and radio inputs will have their 'checked' property set to false
|
|
695
|
+
* - inputs of type submit, button, reset, and hidden will *not* be effected
|
|
696
|
+
* - button elements will *not* be effected
|
|
697
|
+
*/
|
|
698
|
+
$.fn.clearForm = function() {
|
|
699
|
+
return this.each(function() {
|
|
700
|
+
$('input,select,textarea', this).clearFields();
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Clears the selected form elements.
|
|
706
|
+
*/
|
|
707
|
+
$.fn.clearFields = $.fn.clearInputs = function() {
|
|
708
|
+
return this.each(function() {
|
|
709
|
+
var t = this.type, tag = this.tagName.toLowerCase();
|
|
710
|
+
if (t == 'text' || t == 'password' || tag == 'textarea') {
|
|
711
|
+
this.value = '';
|
|
712
|
+
}
|
|
713
|
+
else if (t == 'checkbox' || t == 'radio') {
|
|
714
|
+
this.checked = false;
|
|
715
|
+
}
|
|
716
|
+
else if (tag == 'select') {
|
|
717
|
+
this.selectedIndex = -1;
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Resets the form data. Causes all form elements to be reset to their original value.
|
|
724
|
+
*/
|
|
725
|
+
$.fn.resetForm = function() {
|
|
726
|
+
return this.each(function() {
|
|
727
|
+
// guard against an input with the name of 'reset'
|
|
728
|
+
// note that IE reports the reset function as an 'object'
|
|
729
|
+
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
|
|
730
|
+
this.reset();
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Enables or disables any matching elements.
|
|
737
|
+
*/
|
|
738
|
+
$.fn.enable = function(b) {
|
|
739
|
+
if (b === undefined) {
|
|
740
|
+
b = true;
|
|
741
|
+
}
|
|
742
|
+
return this.each(function() {
|
|
743
|
+
this.disabled = !b;
|
|
744
|
+
});
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Checks/unchecks any matching checkboxes or radio buttons and
|
|
749
|
+
* selects/deselects and matching option elements.
|
|
750
|
+
*/
|
|
751
|
+
$.fn.selected = function(select) {
|
|
752
|
+
if (select === undefined) {
|
|
753
|
+
select = true;
|
|
754
|
+
}
|
|
755
|
+
return this.each(function() {
|
|
756
|
+
var t = this.type;
|
|
757
|
+
if (t == 'checkbox' || t == 'radio') {
|
|
758
|
+
this.checked = select;
|
|
759
|
+
}
|
|
760
|
+
else if (this.tagName.toLowerCase() == 'option') {
|
|
761
|
+
var $sel = $(this).parent('select');
|
|
762
|
+
if (select && $sel[0] && $sel[0].type == 'select-one') {
|
|
763
|
+
// deselect all other options
|
|
764
|
+
$sel.find('option').selected(false);
|
|
765
|
+
}
|
|
766
|
+
this.selected = select;
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
// helper fn for console logging
|
|
772
|
+
// set $.fn.ajaxSubmit.debug to true to enable debug logging
|
|
773
|
+
function log() {
|
|
774
|
+
if ($.fn.ajaxSubmit.debug) {
|
|
775
|
+
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
|
|
776
|
+
if (window.console && window.console.log) {
|
|
777
|
+
window.console.log(msg);
|
|
778
|
+
}
|
|
779
|
+
else if (window.opera && window.opera.postError) {
|
|
780
|
+
window.opera.postError(msg);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
})(jQuery);
|