decidim-admin 0.24.2 → 0.25.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim-admin might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/cells/decidim/admin/content_block/show.erb +2 -2
- data/app/commands/decidim/admin/block_user.rb +6 -0
- data/app/commands/decidim/admin/create_attachment.rb +2 -1
- data/app/commands/decidim/admin/hide_resource.rb +1 -0
- data/app/commands/decidim/admin/process_participatory_space_private_user_import_csv.rb +1 -1
- data/app/commands/decidim/admin/update_attachment.rb +5 -1
- data/app/commands/decidim/admin/update_content_block.rb +1 -1
- data/app/commands/decidim/admin/update_external_domain_whitelist.rb +32 -0
- data/app/commands/decidim/admin/update_organization.rb +2 -1
- data/app/commands/decidim/admin/update_organization_appearance.rb +4 -14
- data/app/controllers/concerns/decidim/admin/filterable.rb +1 -3
- data/app/controllers/concerns/decidim/participatory_space_private_users/admin/filterable.rb +34 -0
- data/app/controllers/decidim/admin/concerns/has_attachments.rb +1 -4
- data/app/controllers/decidim/admin/concerns/has_private_users.rb +6 -3
- data/app/controllers/decidim/admin/imports_controller.rb +1 -0
- data/app/controllers/decidim/admin/moderated_users_controller.rb +6 -2
- data/app/controllers/decidim/admin/organization_controller.rb +11 -1
- data/app/controllers/decidim/admin/organization_external_domain_whitelist_controller.rb +38 -0
- data/app/controllers/decidim/admin/users_controller.rb +7 -1
- data/app/forms/decidim/admin/external_domain_form.rb +19 -0
- data/app/forms/decidim/admin/import_form.rb +1 -0
- data/app/forms/decidim/admin/organization_appearance_form.rb +7 -7
- data/app/forms/decidim/admin/organization_external_domain_whitelist_form.rb +23 -0
- data/app/forms/decidim/admin/organization_form.rb +1 -0
- data/app/forms/decidim/admin/participatory_space_private_user_csv_import_form.rb +2 -0
- data/app/forms/decidim/admin/user_group_csv_verification_form.rb +2 -0
- data/app/helpers/decidim/admin/filterable_helper.rb +1 -1
- data/app/helpers/decidim/admin/menu_helper.rb +7 -7
- data/app/helpers/decidim/admin/uploader_image_dimensions_helper.rb +2 -1
- data/app/jobs/decidim/admin/expire_impersonation_job.rb +1 -2
- data/app/jobs/decidim/admin/import_participatory_space_private_user_csv_job.rb +1 -1
- data/app/packs/entrypoints/decidim_admin.js +43 -0
- data/app/packs/entrypoints/decidim_admin.scss +1 -0
- data/app/packs/src/decidim/admin/application.js +68 -0
- data/app/packs/src/decidim/admin/auto_buttons_by_position.component.js +37 -0
- data/app/packs/src/decidim/admin/auto_label_by_position.component.js +28 -0
- data/app/packs/src/decidim/admin/autocomplete.component.js +146 -0
- data/app/{frontend/components/autocomplete.component.test.tsx → packs/src/decidim/admin/autocomplete.component.test.js} +1 -2
- data/app/packs/src/decidim/admin/budget_rule_toggler.component.js +50 -0
- data/app/{assets/javascripts → packs/src}/decidim/admin/choose_language.js +0 -0
- data/app/packs/src/decidim/admin/draggable-list.js +30 -0
- data/app/packs/src/decidim/admin/dynamic_fields.component.js +230 -0
- data/app/packs/src/decidim/admin/external_domain_whitelist.js +100 -0
- data/app/packs/src/decidim/admin/field_dependent_inputs.component.js +37 -0
- data/app/{assets/javascripts/decidim/admin/form.js.es6 → packs/src/decidim/admin/form.js} +6 -9
- data/app/{assets/javascripts/decidim/admin/import_guidance.js.es6 → packs/src/decidim/admin/import_guidance.js} +2 -3
- data/app/{assets/javascripts/decidim/admin/managed_users.js.es6 → packs/src/decidim/admin/managed_users.js} +4 -4
- data/app/packs/src/decidim/admin/moderations.js +20 -0
- data/app/{assets/javascripts/decidim/admin/newsletters.js.es6 → packs/src/decidim/admin/newsletters.js} +0 -0
- data/app/{assets/javascripts/decidim/admin/officializations.js.es6 → packs/src/decidim/admin/officializations.js} +0 -0
- data/app/{assets/javascripts/decidim/admin/proposal_infinite_edit.js.es6 → packs/src/decidim/admin/proposal_infinite_edit.js} +0 -0
- data/app/{assets/javascripts/decidim/admin/resources_permissions.js.es6 → packs/src/decidim/admin/resources_permissions.js} +3 -5
- data/app/packs/src/decidim/admin/scope_picker_enabler.component.js +12 -0
- data/app/packs/src/decidim/admin/sort_list.component.js +31 -0
- data/app/packs/src/decidim/admin/sortable.js +21 -0
- data/app/packs/src/decidim/admin/subform_multi_toggler.component.js +38 -0
- data/app/packs/src/decidim/admin/subform_toggler.component.js +38 -0
- data/app/{assets/javascripts/decidim/admin/tab_focus.js.es6 → packs/src/decidim/admin/tab_focus.js} +0 -2
- data/app/packs/src/decidim/admin/toggle_nav.js +14 -0
- data/app/{assets/javascripts/decidim/admin/welcome_notification.js.es6 → packs/src/decidim/admin/welcome_notification.js} +2 -2
- data/app/packs/stylesheets/decidim/admin/_decidim.scss +24 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/_variables.scss +0 -0
- data/app/packs/stylesheets/decidim/admin/application.scss +22 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/bundle.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/components/_accordion.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/components/_autocomplete_select.component.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/components/_dropdown-menu.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/components/_sortable.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_action-icon.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_block_user.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_cards.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_categories.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_dropdown_inverted.scss +0 -0
- data/app/packs/stylesheets/decidim/admin/extra/_editor.scss +1 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_email_preview.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_label-required.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_login.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_logs.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_newsletter-templates-gallery.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_organization-appearance.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_quill.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_select_multiple.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_show_email.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_sort.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/extra/_title_bar.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_action-icon.scss +1 -1
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_agenda.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_buttons.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_callouts.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_card-grid.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_cards.scss +1 -1
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_char-counter.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_component-counter.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_draggable-list.scss +2 -2
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_dropdown.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_filters.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_forms.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_icons.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_import_result.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_layout.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_loading-spinner.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_main-nav.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_moderations.scss +0 -0
- data/app/packs/stylesheets/decidim/admin/modules/_modules.scss +43 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_pics.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_process-header.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_reveal.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_secondary-nav.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_table-list.scss +13 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_tabs.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_title-bar.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_typography.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_user-login.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/modules/_users_statistics.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/plugins/_foundation-datepicker.scss +0 -0
- data/{vendor/assets/stylesheets → app/packs/stylesheets/decidim/admin}/plugins/jquery.auto-complete.css +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/user_moderations.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/utils/_flex.scss +2 -2
- data/app/{assets → packs}/stylesheets/decidim/admin/utils/_helpers.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/utils/_keyframes.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/utils/_mixins.scss +30 -3
- data/app/{assets → packs}/stylesheets/decidim/admin/utils/_settings.scss +11 -3
- data/app/{assets → packs}/stylesheets/decidim/admin/utils/_toggle-expand.scss +0 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/vendor/mathsass/_constants.scss +1 -1
- data/app/{assets → packs}/stylesheets/decidim/admin/vendor/mathsass/_math.scss +0 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_acos.scss +14 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_asin.scss +16 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_atan.scss +36 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_atan2.scss +46 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_cos.scss +17 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/vendor/mathsass/functions/_cot.scss +6 -3
- data/app/{assets → packs}/stylesheets/decidim/admin/vendor/mathsass/functions/_csc.scss +6 -3
- data/app/{assets → packs}/stylesheets/decidim/admin/vendor/mathsass/functions/_exp.scss +10 -6
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_fact.scss +21 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_frexp.scss +25 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_ldexp.scss +20 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_log.scss +39 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_pow.scss +34 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/vendor/mathsass/functions/_sec.scss +6 -3
- data/app/{assets → packs}/stylesheets/decidim/admin/vendor/mathsass/functions/_sin.scss +4 -3
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/functions/_sqrt.scss +21 -0
- data/app/{assets → packs}/stylesheets/decidim/admin/vendor/mathsass/functions/_tan.scss +6 -3
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/helpers/_deg-to-rad.scss +6 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/helpers/_rad-to-deg.scss +6 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/helpers/_strip-unit.scss +11 -0
- data/app/packs/stylesheets/decidim/admin/vendor/mathsass/helpers/_unitless-rad.scss +19 -0
- data/app/presenters/decidim/admin/simple_menu_presenter.rb +11 -0
- data/app/queries/decidim/admin/newsletter_recipients.rb +3 -1
- data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
- data/app/views/decidim/admin/categories/index.html.erb +1 -1
- data/app/views/decidim/admin/components/_form.html.erb +0 -2
- data/app/views/decidim/admin/impersonations/_form.html.erb +3 -1
- data/app/views/decidim/admin/imports/new.html.erb +1 -9
- data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +0 -2
- data/app/views/decidim/admin/officializations/index.html.erb +3 -3
- data/app/views/decidim/admin/organization/_form.html.erb +6 -2
- data/app/views/decidim/admin/organization_appearance/_form.html.erb +0 -2
- data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +20 -4
- data/app/views/decidim/admin/organization_appearance/form/_minimap.html.erb +7 -7
- data/app/views/decidim/admin/organization_external_domain_whitelist/_external_domain.html.erb +31 -0
- data/app/views/decidim/admin/organization_external_domain_whitelist/_form.html.erb +37 -0
- data/app/views/decidim/admin/organization_external_domain_whitelist/edit.html.erb +6 -0
- data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +4 -4
- data/app/views/decidim/admin/resource_permissions/edit.html.erb +0 -2
- data/app/views/decidim/admin/scope_types/index.html.erb +3 -3
- data/app/views/decidim/admin/shared/_gallery.html.erb +1 -1
- data/app/views/decidim/admin/static_pages/_form.html.erb +0 -1
- data/app/views/decidim/admin/user_groups/index.html.erb +2 -2
- data/app/views/decidim/admin/users/index.html.erb +8 -7
- data/app/views/layouts/decidim/admin/_application.html.erb +1 -1
- data/app/views/layouts/decidim/admin/_header.html.erb +2 -3
- data/app/views/layouts/decidim/admin/_js_configuration.html.erb +1 -1
- data/app/views/layouts/decidim/admin/_title_bar.html.erb +1 -1
- data/app/views/layouts/decidim/admin/global_moderations.html.erb +1 -1
- data/app/views/layouts/decidim/admin/settings.html.erb +1 -1
- data/app/views/layouts/decidim/admin/users.html.erb +2 -52
- data/config/assets.rb +8 -0
- data/config/locales/ar.yml +0 -4
- data/config/locales/bg.yml +0 -3
- data/config/locales/ca.yml +36 -6
- data/config/locales/cs.yml +48 -6
- data/config/locales/de.yml +18 -6
- data/config/locales/el.yml +0 -4
- data/config/locales/en.yml +58 -16
- data/config/locales/eo.yml +0 -1
- data/config/locales/es-MX.yml +19 -7
- data/config/locales/es-PY.yml +19 -7
- data/config/locales/es.yml +19 -7
- data/config/locales/eu.yml +0 -4
- data/config/locales/fi-plain.yml +48 -6
- data/config/locales/fi.yml +48 -6
- data/config/locales/fr-CA.yml +46 -6
- data/config/locales/fr-LU.yml +1029 -0
- data/config/locales/fr.yml +46 -6
- data/config/locales/gl.yml +71 -6
- data/config/locales/hu.yml +70 -4
- data/config/locales/id-ID.yml +0 -4
- data/config/locales/is-IS.yml +0 -4
- data/config/locales/it.yml +161 -10
- data/config/locales/ja.yml +139 -5
- data/config/locales/lb-LU.yml +1 -0
- data/config/locales/lv.yml +0 -4
- data/config/locales/nl.yml +17 -6
- data/config/locales/no.yml +6 -4
- data/config/locales/pl.yml +45 -24
- data/config/locales/pt-BR.yml +346 -4
- data/config/locales/pt.yml +6 -4
- data/config/locales/ro-RO.yml +112 -4
- data/config/locales/ru.yml +0 -4
- data/config/locales/sk.yml +0 -4
- data/config/locales/sl.yml +0 -4
- data/config/locales/sr-CS.yml +0 -4
- data/config/locales/sv.yml +45 -2
- data/config/locales/tr-TR.yml +0 -4
- data/config/locales/uk.yml +0 -2
- data/config/locales/zh-CN.yml +0 -4
- data/config/routes.rb +2 -0
- data/lib/decidim/admin/engine.rb +210 -137
- data/lib/decidim/admin/import/readers/xlsx.rb +25 -0
- data/lib/decidim/admin/import/readers.rb +3 -3
- data/lib/decidim/admin/test/filters_participatory_space_users_examples.rb +73 -0
- data/lib/decidim/admin/test/manage_attachment_collections_examples.rb +1 -1
- data/lib/decidim/admin/test/manage_attachments_examples.rb +1 -1
- data/lib/decidim/admin/test.rb +1 -0
- data/lib/decidim/admin/version.rb +1 -1
- metadata +141 -180
- data/app/assets/config/decidim_admin_manifest.js +0 -8
- data/app/assets/javascripts/decidim/admin/application.js.es6 +0 -78
- data/app/assets/javascripts/decidim/admin/auto_buttons_by_position.component.js.es6 +0 -42
- data/app/assets/javascripts/decidim/admin/auto_label_by_position.component.js.es6 +0 -33
- data/app/assets/javascripts/decidim/admin/budget_rule_toggler.component.js.es6 +0 -55
- data/app/assets/javascripts/decidim/admin/bundle.js +0 -34
- data/app/assets/javascripts/decidim/admin/bundle.js.map +0 -1
- data/app/assets/javascripts/decidim/admin/draggable-list.js.es6 +0 -30
- data/app/assets/javascripts/decidim/admin/dynamic_fields.component.js.es6 +0 -233
- data/app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6 +0 -39
- data/app/assets/javascripts/decidim/admin/moderations.js.es6 +0 -24
- data/app/assets/javascripts/decidim/admin/scope_picker_enabler.component.js.es6 +0 -14
- data/app/assets/javascripts/decidim/admin/sort_list.component.js.es6 +0 -35
- data/app/assets/javascripts/decidim/admin/sortable.js.es6 +0 -22
- data/app/assets/javascripts/decidim/admin/subform_multi_toggler.component.js.es6 +0 -43
- data/app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6 +0 -42
- data/app/assets/javascripts/decidim/admin/toggle_nav.js.es6 +0 -17
- data/app/assets/javascripts/decidim/admin/user_moderations.js +0 -2
- data/app/assets/stylesheets/decidim/admin/_decidim.scss +0 -20
- data/app/assets/stylesheets/decidim/admin/application.scss.erb +0 -6
- data/app/assets/stylesheets/decidim/admin/extra/_editor.scss +0 -1
- data/app/assets/stylesheets/decidim/admin/modules/_modules.scss +0 -43
- data/app/assets/stylesheets/decidim/admin/utils/_fontface.scss +0 -29
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_acos.scss +0 -12
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_asin.scss +0 -12
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_atan.scss +0 -28
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_atan2.scss +0 -37
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_cos.scss +0 -13
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_fact.scss +0 -18
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_frexp.scss +0 -21
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_ldexp.scss +0 -17
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_log.scss +0 -34
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_pow.scss +0 -28
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/functions/_sqrt.scss +0 -16
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/helpers/_deg-to-rad.scss +0 -4
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/helpers/_rad-to-deg.scss +0 -4
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/helpers/_strip-unit.scss +0 -8
- data/app/assets/stylesheets/decidim/admin/vendor/mathsass/helpers/_unitless-rad.scss +0 -13
- data/app/frontend/components/autocomplete.component.tsx +0 -198
- data/app/frontend/entry.ts +0 -17
- data/app/frontend/entry_test.ts +0 -4
- data/app/helpers/decidim/admin/sidebar_menu_helper.rb +0 -13
- data/config/locales/ja-JP.yml +0 -855
- data/lib/decidim/admin/import/readers/xls.rb +0 -25
- data/vendor/assets/javascripts/html.sortable.js +0 -691
- data/vendor/assets/javascripts/jquery.auto-complete.js +0 -171
- data/vendor/assets/javascripts/jquery.serializejson.js +0 -344
- data/vendor/assets/javascripts/moment.min.js +0 -1
@@ -1,171 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
jQuery autoComplete v1.0.7
|
3
|
-
Copyright (c) 2014 Simon Steinberger / Pixabay
|
4
|
-
GitHub: https://github.com/Pixabay/jQuery-autoComplete
|
5
|
-
License: http://www.opensource.org/licenses/mit-license.php
|
6
|
-
*/
|
7
|
-
|
8
|
-
(function($){
|
9
|
-
$.fn.autoComplete = function(options){
|
10
|
-
var o = $.extend({}, $.fn.autoComplete.defaults, options);
|
11
|
-
|
12
|
-
// public methods
|
13
|
-
if (typeof options == 'string') {
|
14
|
-
this.each(function(){
|
15
|
-
var that = $(this);
|
16
|
-
if (options == 'destroy') {
|
17
|
-
$(window).off('resize.autocomplete', that.updateSC);
|
18
|
-
that.off('blur.autocomplete focus.autocomplete keydown.autocomplete keyup.autocomplete');
|
19
|
-
if (that.data('autocomplete'))
|
20
|
-
that.attr('autocomplete', that.data('autocomplete'));
|
21
|
-
else
|
22
|
-
that.removeAttr('autocomplete');
|
23
|
-
$(that.data('sc')).remove();
|
24
|
-
that.removeData('sc').removeData('autocomplete');
|
25
|
-
}
|
26
|
-
});
|
27
|
-
return this;
|
28
|
-
}
|
29
|
-
|
30
|
-
return this.each(function(){
|
31
|
-
var that = $(this);
|
32
|
-
// sc = 'suggestions container'
|
33
|
-
that.sc = $('<div class="autocomplete-suggestions '+o.menuClass+'"></div>');
|
34
|
-
that.data('sc', that.sc).data('autocomplete', that.attr('autocomplete'));
|
35
|
-
that.attr('autocomplete', 'off');
|
36
|
-
that.cache = {};
|
37
|
-
that.last_val = '';
|
38
|
-
|
39
|
-
that.updateSC = function(resize, next){
|
40
|
-
that.sc.css({
|
41
|
-
top: that.offset().top + that.outerHeight(),
|
42
|
-
left: that.offset().left,
|
43
|
-
width: that.outerWidth()
|
44
|
-
});
|
45
|
-
if (!resize) {
|
46
|
-
that.sc.show();
|
47
|
-
if (!that.sc.maxHeight) that.sc.maxHeight = parseInt(that.sc.css('max-height'));
|
48
|
-
if (!that.sc.suggestionHeight) that.sc.suggestionHeight = $('.autocomplete-suggestion', that.sc).first().outerHeight();
|
49
|
-
if (that.sc.suggestionHeight)
|
50
|
-
if (!next) that.sc.scrollTop(0);
|
51
|
-
else {
|
52
|
-
var scrTop = that.sc.scrollTop(), selTop = next.offset().top - that.sc.offset().top;
|
53
|
-
if (selTop + that.sc.suggestionHeight - that.sc.maxHeight > 0)
|
54
|
-
that.sc.scrollTop(selTop + that.sc.suggestionHeight + scrTop - that.sc.maxHeight);
|
55
|
-
else if (selTop < 0)
|
56
|
-
that.sc.scrollTop(selTop + scrTop);
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
$(window).on('resize.autocomplete', that.updateSC);
|
61
|
-
|
62
|
-
that.sc.appendTo('body');
|
63
|
-
|
64
|
-
that.sc.on('mouseleave', '.autocomplete-suggestion', function (){
|
65
|
-
$('.autocomplete-suggestion.selected').removeClass('selected');
|
66
|
-
});
|
67
|
-
|
68
|
-
that.sc.on('mouseenter', '.autocomplete-suggestion', function (){
|
69
|
-
$('.autocomplete-suggestion.selected').removeClass('selected');
|
70
|
-
$(this).addClass('selected');
|
71
|
-
});
|
72
|
-
|
73
|
-
that.sc.on('mousedown click', '.autocomplete-suggestion', function (e){
|
74
|
-
var item = $(this), v = item.data('val');
|
75
|
-
if (v || item.hasClass('autocomplete-suggestion')) { // else outside click
|
76
|
-
that.val(v);
|
77
|
-
o.onSelect(e, v, item);
|
78
|
-
that.sc.hide();
|
79
|
-
}
|
80
|
-
return false;
|
81
|
-
});
|
82
|
-
|
83
|
-
that.on('blur.autocomplete', function(){
|
84
|
-
try { over_sb = $('.autocomplete-suggestions:hover').length; } catch(e){ over_sb = 0; } // IE7 fix :hover
|
85
|
-
if (!over_sb) {
|
86
|
-
that.last_val = that.val();
|
87
|
-
that.sc.hide();
|
88
|
-
setTimeout(function(){ that.sc.hide(); }, 350); // hide suggestions on fast input
|
89
|
-
} else if (!that.is(':focus')) setTimeout(function(){ that.focus(); }, 20);
|
90
|
-
});
|
91
|
-
|
92
|
-
if (!o.minChars) that.on('focus.autocomplete', function(){ that.last_val = '\n'; that.trigger('keyup.autocomplete'); });
|
93
|
-
|
94
|
-
function suggest(data){
|
95
|
-
var val = that.val();
|
96
|
-
that.cache[val] = data;
|
97
|
-
if (data.length && val.length >= o.minChars) {
|
98
|
-
var s = '';
|
99
|
-
for (var i=0;i<data.length;i++) s += o.renderItem(data[i], val);
|
100
|
-
that.sc.html(s);
|
101
|
-
that.updateSC(0);
|
102
|
-
}
|
103
|
-
else
|
104
|
-
that.sc.hide();
|
105
|
-
}
|
106
|
-
|
107
|
-
that.on('keydown.autocomplete', function(e){
|
108
|
-
// down (40), up (38)
|
109
|
-
if ((e.which == 40 || e.which == 38) && that.sc.html()) {
|
110
|
-
var next, sel = $('.autocomplete-suggestion.selected', that.sc);
|
111
|
-
if (!sel.length) {
|
112
|
-
next = (e.which == 40) ? $('.autocomplete-suggestion', that.sc).first() : $('.autocomplete-suggestion', that.sc).last();
|
113
|
-
that.val(next.addClass('selected').data('val'));
|
114
|
-
} else {
|
115
|
-
next = (e.which == 40) ? sel.next('.autocomplete-suggestion') : sel.prev('.autocomplete-suggestion');
|
116
|
-
if (next.length) { sel.removeClass('selected'); that.val(next.addClass('selected').data('val')); }
|
117
|
-
else { sel.removeClass('selected'); that.val(that.last_val); next = 0; }
|
118
|
-
}
|
119
|
-
that.updateSC(0, next);
|
120
|
-
return false;
|
121
|
-
}
|
122
|
-
// esc
|
123
|
-
else if (e.which == 27) that.val(that.last_val).sc.hide();
|
124
|
-
// enter or tab
|
125
|
-
else if (e.which == 13 || e.which == 9) {
|
126
|
-
var sel = $('.autocomplete-suggestion.selected', that.sc);
|
127
|
-
if (sel.length && that.sc.is(':visible')) { o.onSelect(e, sel.data('val'), sel); setTimeout(function(){ that.sc.hide(); }, 20); }
|
128
|
-
}
|
129
|
-
});
|
130
|
-
|
131
|
-
that.on('keyup.autocomplete', function(e){
|
132
|
-
if (!~$.inArray(e.which, [13, 27, 35, 36, 37, 38, 39, 40])) {
|
133
|
-
var val = that.val();
|
134
|
-
if (val.length >= o.minChars) {
|
135
|
-
if (val != that.last_val) {
|
136
|
-
that.last_val = val;
|
137
|
-
clearTimeout(that.timer);
|
138
|
-
if (o.cache) {
|
139
|
-
if (val in that.cache) { suggest(that.cache[val]); return; }
|
140
|
-
// no requests if previous suggestions were empty
|
141
|
-
for (var i=1; i<val.length-o.minChars; i++) {
|
142
|
-
var part = val.slice(0, val.length-i);
|
143
|
-
if (part in that.cache && !that.cache[part].length) { suggest([]); return; }
|
144
|
-
}
|
145
|
-
}
|
146
|
-
that.timer = setTimeout(function(){ o.source(val, suggest) }, o.delay);
|
147
|
-
}
|
148
|
-
} else {
|
149
|
-
that.last_val = val;
|
150
|
-
that.sc.hide();
|
151
|
-
}
|
152
|
-
}
|
153
|
-
});
|
154
|
-
});
|
155
|
-
}
|
156
|
-
|
157
|
-
$.fn.autoComplete.defaults = {
|
158
|
-
source: 0,
|
159
|
-
minChars: 3,
|
160
|
-
delay: 150,
|
161
|
-
cache: 1,
|
162
|
-
menuClass: '',
|
163
|
-
renderItem: function (item, search){
|
164
|
-
// escape special characters
|
165
|
-
search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
166
|
-
var re = new RegExp("(" + search.split(' ').join('|') + ")", "gi");
|
167
|
-
return '<div class="autocomplete-suggestion" data-val="' + item + '">' + item.replace(re, "<b>$1</b>") + '</div>';
|
168
|
-
},
|
169
|
-
onSelect: function(e, term, item){}
|
170
|
-
};
|
171
|
-
}(jQuery));
|
@@ -1,344 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
SerializeJSON jQuery plugin.
|
3
|
-
https://github.com/marioizquierdo/jquery.serializeJSON
|
4
|
-
version 2.9.0 (Jan, 2018)
|
5
|
-
|
6
|
-
Copyright (c) 2012-2018 Mario Izquierdo
|
7
|
-
Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
8
|
-
and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
|
9
|
-
*/
|
10
|
-
(function (factory) {
|
11
|
-
if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module.
|
12
|
-
define(['jquery'], factory);
|
13
|
-
} else if (typeof exports === 'object') { // Node/CommonJS
|
14
|
-
var jQuery = require('jquery');
|
15
|
-
module.exports = factory(jQuery);
|
16
|
-
} else { // Browser globals (zepto supported)
|
17
|
-
factory(window.jQuery || window.Zepto || window.$); // Zepto supported on browsers as well
|
18
|
-
}
|
19
|
-
|
20
|
-
}(function ($) {
|
21
|
-
"use strict";
|
22
|
-
|
23
|
-
// jQuery('form').serializeJSON()
|
24
|
-
$.fn.serializeJSON = function (options) {
|
25
|
-
var f, $form, opts, formAsArray, serializedObject, name, value, parsedValue, _obj, nameWithNoType, type, keys, skipFalsy;
|
26
|
-
f = $.serializeJSON;
|
27
|
-
$form = this; // NOTE: the set of matched elements is most likely a form, but it could also be a group of inputs
|
28
|
-
opts = f.setupOpts(options); // calculate values for options {parseNumbers, parseBoolens, parseNulls, ...} with defaults
|
29
|
-
|
30
|
-
// Use native `serializeArray` function to get an array of {name, value} objects.
|
31
|
-
formAsArray = $form.serializeArray();
|
32
|
-
f.readCheckboxUncheckedValues(formAsArray, opts, $form); // add objects to the array from unchecked checkboxes if needed
|
33
|
-
|
34
|
-
// Convert the formAsArray into a serializedObject with nested keys
|
35
|
-
serializedObject = {};
|
36
|
-
$.each(formAsArray, function (i, obj) {
|
37
|
-
name = obj.name; // original input name
|
38
|
-
value = obj.value; // input value
|
39
|
-
_obj = f.extractTypeAndNameWithNoType(name);
|
40
|
-
nameWithNoType = _obj.nameWithNoType; // input name with no type (i.e. "foo:string" => "foo")
|
41
|
-
type = _obj.type; // type defined from the input name in :type colon notation
|
42
|
-
if (!type) type = f.attrFromInputWithName($form, name, 'data-value-type');
|
43
|
-
f.validateType(name, type, opts); // make sure that the type is one of the valid types if defined
|
44
|
-
|
45
|
-
if (type !== 'skip') { // ignore inputs with type 'skip'
|
46
|
-
keys = f.splitInputNameIntoKeysArray(nameWithNoType);
|
47
|
-
parsedValue = f.parseValue(value, name, type, opts); // convert to string, number, boolean, null or customType
|
48
|
-
|
49
|
-
skipFalsy = !parsedValue && f.shouldSkipFalsy($form, name, nameWithNoType, type, opts); // ignore falsy inputs if specified
|
50
|
-
if (!skipFalsy) {
|
51
|
-
f.deepSet(serializedObject, keys, parsedValue, opts);
|
52
|
-
}
|
53
|
-
}
|
54
|
-
});
|
55
|
-
return serializedObject;
|
56
|
-
};
|
57
|
-
|
58
|
-
// Use $.serializeJSON as namespace for the auxiliar functions
|
59
|
-
// and to define defaults
|
60
|
-
$.serializeJSON = {
|
61
|
-
|
62
|
-
defaultOptions: {
|
63
|
-
checkboxUncheckedValue: undefined, // to include that value for unchecked checkboxes (instead of ignoring them)
|
64
|
-
|
65
|
-
parseNumbers: false, // convert values like "1", "-2.33" to 1, -2.33
|
66
|
-
parseBooleans: false, // convert "true", "false" to true, false
|
67
|
-
parseNulls: false, // convert "null" to null
|
68
|
-
parseAll: false, // all of the above
|
69
|
-
parseWithFunction: null, // to use custom parser, a function like: function(val){ return parsed_val; }
|
70
|
-
|
71
|
-
skipFalsyValuesForTypes: [], // skip serialization of falsy values for listed value types
|
72
|
-
skipFalsyValuesForFields: [], // skip serialization of falsy values for listed field names
|
73
|
-
|
74
|
-
customTypes: {}, // override defaultTypes
|
75
|
-
defaultTypes: {
|
76
|
-
"string": function(str) { return String(str); },
|
77
|
-
"number": function(str) { return Number(str); },
|
78
|
-
"boolean": function(str) { var falses = ["false", "null", "undefined", "", "0"]; return falses.indexOf(str) === -1; },
|
79
|
-
"null": function(str) { var falses = ["false", "null", "undefined", "", "0"]; return falses.indexOf(str) === -1 ? str : null; },
|
80
|
-
"array": function(str) { return JSON.parse(str); },
|
81
|
-
"object": function(str) { return JSON.parse(str); },
|
82
|
-
"auto": function(str) { return $.serializeJSON.parseValue(str, null, null, {parseNumbers: true, parseBooleans: true, parseNulls: true}); }, // try again with something like "parseAll"
|
83
|
-
"skip": null // skip is a special type that makes it easy to ignore elements
|
84
|
-
},
|
85
|
-
|
86
|
-
useIntKeysAsArrayIndex: false // name="foo[2]" value="v" => {foo: [null, null, "v"]}, instead of {foo: ["2": "v"]}
|
87
|
-
},
|
88
|
-
|
89
|
-
// Merge option defaults into the options
|
90
|
-
setupOpts: function(options) {
|
91
|
-
var opt, validOpts, defaultOptions, optWithDefault, parseAll, f;
|
92
|
-
f = $.serializeJSON;
|
93
|
-
|
94
|
-
if (options == null) { options = {}; } // options ||= {}
|
95
|
-
defaultOptions = f.defaultOptions || {}; // defaultOptions
|
96
|
-
|
97
|
-
// Make sure that the user didn't misspell an option
|
98
|
-
validOpts = ['checkboxUncheckedValue', 'parseNumbers', 'parseBooleans', 'parseNulls', 'parseAll', 'parseWithFunction', 'skipFalsyValuesForTypes', 'skipFalsyValuesForFields', 'customTypes', 'defaultTypes', 'useIntKeysAsArrayIndex']; // re-define because the user may override the defaultOptions
|
99
|
-
for (opt in options) {
|
100
|
-
if (validOpts.indexOf(opt) === -1) {
|
101
|
-
throw new Error("serializeJSON ERROR: invalid option '" + opt + "'. Please use one of " + validOpts.join(', '));
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
// Helper to get the default value for this option if none is specified by the user
|
106
|
-
optWithDefault = function(key) { return (options[key] !== false) && (options[key] !== '') && (options[key] || defaultOptions[key]); };
|
107
|
-
|
108
|
-
// Return computed options (opts to be used in the rest of the script)
|
109
|
-
parseAll = optWithDefault('parseAll');
|
110
|
-
return {
|
111
|
-
checkboxUncheckedValue: optWithDefault('checkboxUncheckedValue'),
|
112
|
-
|
113
|
-
parseNumbers: parseAll || optWithDefault('parseNumbers'),
|
114
|
-
parseBooleans: parseAll || optWithDefault('parseBooleans'),
|
115
|
-
parseNulls: parseAll || optWithDefault('parseNulls'),
|
116
|
-
parseWithFunction: optWithDefault('parseWithFunction'),
|
117
|
-
|
118
|
-
skipFalsyValuesForTypes: optWithDefault('skipFalsyValuesForTypes'),
|
119
|
-
skipFalsyValuesForFields: optWithDefault('skipFalsyValuesForFields'),
|
120
|
-
typeFunctions: $.extend({}, optWithDefault('defaultTypes'), optWithDefault('customTypes')),
|
121
|
-
|
122
|
-
useIntKeysAsArrayIndex: optWithDefault('useIntKeysAsArrayIndex')
|
123
|
-
};
|
124
|
-
},
|
125
|
-
|
126
|
-
// Given a string, apply the type or the relevant "parse" options, to return the parsed value
|
127
|
-
parseValue: function(valStr, inputName, type, opts) {
|
128
|
-
var f, parsedVal;
|
129
|
-
f = $.serializeJSON;
|
130
|
-
parsedVal = valStr; // if no parsing is needed, the returned value will be the same
|
131
|
-
|
132
|
-
if (opts.typeFunctions && type && opts.typeFunctions[type]) { // use a type if available
|
133
|
-
parsedVal = opts.typeFunctions[type](valStr);
|
134
|
-
} else if (opts.parseNumbers && f.isNumeric(valStr)) { // auto: number
|
135
|
-
parsedVal = Number(valStr);
|
136
|
-
} else if (opts.parseBooleans && (valStr === "true" || valStr === "false")) { // auto: boolean
|
137
|
-
parsedVal = (valStr === "true");
|
138
|
-
} else if (opts.parseNulls && valStr == "null") { // auto: null
|
139
|
-
parsedVal = null;
|
140
|
-
} else if (opts.typeFunctions && opts.typeFunctions["string"]) { // make sure to apply :string type if it was re-defined
|
141
|
-
parsedVal = opts.typeFunctions["string"](valStr);
|
142
|
-
}
|
143
|
-
|
144
|
-
// Custom parse function: apply after parsing options, unless there's an explicit type.
|
145
|
-
if (opts.parseWithFunction && !type) {
|
146
|
-
parsedVal = opts.parseWithFunction(parsedVal, inputName);
|
147
|
-
}
|
148
|
-
|
149
|
-
return parsedVal;
|
150
|
-
},
|
151
|
-
|
152
|
-
isObject: function(obj) { return obj === Object(obj); }, // is it an Object?
|
153
|
-
isUndefined: function(obj) { return obj === void 0; }, // safe check for undefined values
|
154
|
-
isValidArrayIndex: function(val) { return /^[0-9]+$/.test(String(val)); }, // 1,2,3,4 ... are valid array indexes
|
155
|
-
isNumeric: function(obj) { return obj - parseFloat(obj) >= 0; }, // taken from jQuery.isNumeric implementation. Not using jQuery.isNumeric to support old jQuery and Zepto versions
|
156
|
-
|
157
|
-
optionKeys: function(obj) { if (Object.keys) { return Object.keys(obj); } else { var key, keys = []; for(key in obj){ keys.push(key); } return keys;} }, // polyfill Object.keys to get option keys in IE<9
|
158
|
-
|
159
|
-
|
160
|
-
// Fill the formAsArray object with values for the unchecked checkbox inputs,
|
161
|
-
// using the same format as the jquery.serializeArray function.
|
162
|
-
// The value of the unchecked values is determined from the opts.checkboxUncheckedValue
|
163
|
-
// and/or the data-unchecked-value attribute of the inputs.
|
164
|
-
readCheckboxUncheckedValues: function (formAsArray, opts, $form) {
|
165
|
-
var selector, $uncheckedCheckboxes, $el, uncheckedValue, f, name;
|
166
|
-
if (opts == null) { opts = {}; }
|
167
|
-
f = $.serializeJSON;
|
168
|
-
|
169
|
-
selector = 'input[type=checkbox][name]:not(:checked):not([disabled])';
|
170
|
-
$uncheckedCheckboxes = $form.find(selector).add($form.filter(selector));
|
171
|
-
$uncheckedCheckboxes.each(function (i, el) {
|
172
|
-
// Check data attr first, then the option
|
173
|
-
$el = $(el);
|
174
|
-
uncheckedValue = $el.attr('data-unchecked-value');
|
175
|
-
if (uncheckedValue == null) {
|
176
|
-
uncheckedValue = opts.checkboxUncheckedValue;
|
177
|
-
}
|
178
|
-
|
179
|
-
// If there's an uncheckedValue, push it into the serialized formAsArray
|
180
|
-
if (uncheckedValue != null) {
|
181
|
-
if (el.name && el.name.indexOf("[][") !== -1) { // identify a non-supported
|
182
|
-
throw new Error("serializeJSON ERROR: checkbox unchecked values are not supported on nested arrays of objects like '"+el.name+"'. See https://github.com/marioizquierdo/jquery.serializeJSON/issues/67");
|
183
|
-
}
|
184
|
-
formAsArray.push({name: el.name, value: uncheckedValue});
|
185
|
-
}
|
186
|
-
});
|
187
|
-
},
|
188
|
-
|
189
|
-
// Returns and object with properties {name_without_type, type} from a given name.
|
190
|
-
// The type is null if none specified. Example:
|
191
|
-
// "foo" => {nameWithNoType: "foo", type: null}
|
192
|
-
// "foo:boolean" => {nameWithNoType: "foo", type: "boolean"}
|
193
|
-
// "foo[bar]:null" => {nameWithNoType: "foo[bar]", type: "null"}
|
194
|
-
extractTypeAndNameWithNoType: function(name) {
|
195
|
-
var match;
|
196
|
-
if (match = name.match(/(.*):([^:]+)$/)) {
|
197
|
-
return {nameWithNoType: match[1], type: match[2]};
|
198
|
-
} else {
|
199
|
-
return {nameWithNoType: name, type: null};
|
200
|
-
}
|
201
|
-
},
|
202
|
-
|
203
|
-
|
204
|
-
// Check if this input should be skipped when it has a falsy value,
|
205
|
-
// depending on the options to skip values by name or type, and the data-skip-falsy attribute.
|
206
|
-
shouldSkipFalsy: function($form, name, nameWithNoType, type, opts) {
|
207
|
-
var f = $.serializeJSON;
|
208
|
-
|
209
|
-
var skipFromDataAttr = f.attrFromInputWithName($form, name, 'data-skip-falsy');
|
210
|
-
if (skipFromDataAttr != null) {
|
211
|
-
return skipFromDataAttr !== 'false'; // any value is true, except if explicitly using 'false'
|
212
|
-
}
|
213
|
-
|
214
|
-
var optForFields = opts.skipFalsyValuesForFields;
|
215
|
-
if (optForFields && (optForFields.indexOf(nameWithNoType) !== -1 || optForFields.indexOf(name) !== -1)) {
|
216
|
-
return true;
|
217
|
-
}
|
218
|
-
|
219
|
-
var optForTypes = opts.skipFalsyValuesForTypes;
|
220
|
-
if (type == null) type = 'string'; // assume fields with no type are targeted as string
|
221
|
-
if (optForTypes && optForTypes.indexOf(type) !== -1) {
|
222
|
-
return true
|
223
|
-
}
|
224
|
-
|
225
|
-
return false;
|
226
|
-
},
|
227
|
-
|
228
|
-
// Finds the first input in $form with this name, and get the given attr from it.
|
229
|
-
// Returns undefined if no input or no attribute was found.
|
230
|
-
attrFromInputWithName: function($form, name, attrName) {
|
231
|
-
var escapedName, selector, $input, attrValue;
|
232
|
-
escapedName = name.replace(/(:|\.|\[|\]|\s)/g,'\\$1'); // every non-standard character need to be escaped by \\
|
233
|
-
selector = '[name="' + escapedName + '"]';
|
234
|
-
$input = $form.find(selector).add($form.filter(selector)); // NOTE: this returns only the first $input element if multiple are matched with the same name (i.e. an "array[]"). So, arrays with different element types specified through the data-value-type attr is not supported.
|
235
|
-
return $input.attr(attrName);
|
236
|
-
},
|
237
|
-
|
238
|
-
// Raise an error if the type is not recognized.
|
239
|
-
validateType: function(name, type, opts) {
|
240
|
-
var validTypes, f;
|
241
|
-
f = $.serializeJSON;
|
242
|
-
validTypes = f.optionKeys(opts ? opts.typeFunctions : f.defaultOptions.defaultTypes);
|
243
|
-
if (!type || validTypes.indexOf(type) !== -1) {
|
244
|
-
return true;
|
245
|
-
} else {
|
246
|
-
throw new Error("serializeJSON ERROR: Invalid type " + type + " found in input name '" + name + "', please use one of " + validTypes.join(', '));
|
247
|
-
}
|
248
|
-
},
|
249
|
-
|
250
|
-
|
251
|
-
// Split the input name in programatically readable keys.
|
252
|
-
// Examples:
|
253
|
-
// "foo" => ['foo']
|
254
|
-
// "[foo]" => ['foo']
|
255
|
-
// "foo[inn][bar]" => ['foo', 'inn', 'bar']
|
256
|
-
// "foo[inn[bar]]" => ['foo', 'inn', 'bar']
|
257
|
-
// "foo[inn][arr][0]" => ['foo', 'inn', 'arr', '0']
|
258
|
-
// "arr[][val]" => ['arr', '', 'val']
|
259
|
-
splitInputNameIntoKeysArray: function(nameWithNoType) {
|
260
|
-
var keys, f;
|
261
|
-
f = $.serializeJSON;
|
262
|
-
keys = nameWithNoType.split('['); // split string into array
|
263
|
-
keys = $.map(keys, function (key) { return key.replace(/\]/g, ''); }); // remove closing brackets
|
264
|
-
if (keys[0] === '') { keys.shift(); } // ensure no opening bracket ("[foo][inn]" should be same as "foo[inn]")
|
265
|
-
return keys;
|
266
|
-
},
|
267
|
-
|
268
|
-
// Set a value in an object or array, using multiple keys to set in a nested object or array:
|
269
|
-
//
|
270
|
-
// deepSet(obj, ['foo'], v) // obj['foo'] = v
|
271
|
-
// deepSet(obj, ['foo', 'inn'], v) // obj['foo']['inn'] = v // Create the inner obj['foo'] object, if needed
|
272
|
-
// deepSet(obj, ['foo', 'inn', '123'], v) // obj['foo']['arr']['123'] = v //
|
273
|
-
//
|
274
|
-
// deepSet(obj, ['0'], v) // obj['0'] = v
|
275
|
-
// deepSet(arr, ['0'], v, {useIntKeysAsArrayIndex: true}) // arr[0] = v
|
276
|
-
// deepSet(arr, [''], v) // arr.push(v)
|
277
|
-
// deepSet(obj, ['arr', ''], v) // obj['arr'].push(v)
|
278
|
-
//
|
279
|
-
// arr = [];
|
280
|
-
// deepSet(arr, ['', v] // arr => [v]
|
281
|
-
// deepSet(arr, ['', 'foo'], v) // arr => [v, {foo: v}]
|
282
|
-
// deepSet(arr, ['', 'bar'], v) // arr => [v, {foo: v, bar: v}]
|
283
|
-
// deepSet(arr, ['', 'bar'], v) // arr => [v, {foo: v, bar: v}, {bar: v}]
|
284
|
-
//
|
285
|
-
deepSet: function (o, keys, value, opts) {
|
286
|
-
var key, nextKey, tail, lastIdx, lastVal, f;
|
287
|
-
if (opts == null) { opts = {}; }
|
288
|
-
f = $.serializeJSON;
|
289
|
-
if (f.isUndefined(o)) { throw new Error("ArgumentError: param 'o' expected to be an object or array, found undefined"); }
|
290
|
-
if (!keys || keys.length === 0) { throw new Error("ArgumentError: param 'keys' expected to be an array with least one element"); }
|
291
|
-
|
292
|
-
key = keys[0];
|
293
|
-
|
294
|
-
// Only one key, then it's not a deepSet, just assign the value.
|
295
|
-
if (keys.length === 1) {
|
296
|
-
if (key === '') {
|
297
|
-
o.push(value); // '' is used to push values into the array (assume o is an array)
|
298
|
-
} else {
|
299
|
-
o[key] = value; // other keys can be used as object keys or array indexes
|
300
|
-
}
|
301
|
-
|
302
|
-
// With more keys is a deepSet. Apply recursively.
|
303
|
-
} else {
|
304
|
-
nextKey = keys[1];
|
305
|
-
|
306
|
-
// '' is used to push values into the array,
|
307
|
-
// with nextKey, set the value into the same object, in object[nextKey].
|
308
|
-
// Covers the case of ['', 'foo'] and ['', 'var'] to push the object {foo, var}, and the case of nested arrays.
|
309
|
-
if (key === '') {
|
310
|
-
lastIdx = o.length - 1; // asume o is array
|
311
|
-
lastVal = o[lastIdx];
|
312
|
-
if (f.isObject(lastVal) && (f.isUndefined(lastVal[nextKey]) || keys.length > 2)) { // if nextKey is not present in the last object element, or there are more keys to deep set
|
313
|
-
key = lastIdx; // then set the new value in the same object element
|
314
|
-
} else {
|
315
|
-
key = lastIdx + 1; // otherwise, point to set the next index in the array
|
316
|
-
}
|
317
|
-
}
|
318
|
-
|
319
|
-
// '' is used to push values into the array "array[]"
|
320
|
-
if (nextKey === '') {
|
321
|
-
if (f.isUndefined(o[key]) || !$.isArray(o[key])) {
|
322
|
-
o[key] = []; // define (or override) as array to push values
|
323
|
-
}
|
324
|
-
} else {
|
325
|
-
if (opts.useIntKeysAsArrayIndex && f.isValidArrayIndex(nextKey)) { // if 1, 2, 3 ... then use an array, where nextKey is the index
|
326
|
-
if (f.isUndefined(o[key]) || !$.isArray(o[key])) {
|
327
|
-
o[key] = []; // define (or override) as array, to insert values using int keys as array indexes
|
328
|
-
}
|
329
|
-
} else { // for anything else, use an object, where nextKey is going to be the attribute name
|
330
|
-
if (f.isUndefined(o[key]) || !f.isObject(o[key])) {
|
331
|
-
o[key] = {}; // define (or override) as object, to set nested properties
|
332
|
-
}
|
333
|
-
}
|
334
|
-
}
|
335
|
-
|
336
|
-
// Recursively set the inner object
|
337
|
-
tail = keys.slice(1);
|
338
|
-
f.deepSet(o[key], tail, value, opts);
|
339
|
-
}
|
340
|
-
}
|
341
|
-
|
342
|
-
};
|
343
|
-
|
344
|
-
}));
|