spree_mobility 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.hound.yml +21 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +7 -0
  6. data/.travis.yml +45 -0
  7. data/Appraisals +8 -0
  8. data/CONTRIBUTING.md +81 -0
  9. data/Gemfile +8 -0
  10. data/Guardfile +12 -0
  11. data/LICENSE.md +26 -0
  12. data/README.md +92 -0
  13. data/Rakefile +24 -0
  14. data/app/assets/javascripts/spree/backend/spree_mobility.js +2 -0
  15. data/app/assets/javascripts/spree/backend/taxon_tree_menu.js +49 -0
  16. data/app/assets/javascripts/spree/backend/translations.js +50 -0
  17. data/app/controllers/concerns/spree_mobility/controller_mobility_helper.rb +18 -0
  18. data/app/controllers/spree/admin/option_values_controller_decorator.rb +23 -0
  19. data/app/controllers/spree/admin/product_properties_controller_decorator.rb +22 -0
  20. data/app/controllers/spree/admin/shipping_methods_controller_decorator.rb +18 -0
  21. data/app/controllers/spree/admin/translations_controller.rb +53 -0
  22. data/app/controllers/spree/api/base_controller_decorator.rb +5 -0
  23. data/app/controllers/spree/base_controller_decorator.rb +5 -0
  24. data/app/helpers/spree_mobility/locale_helper.rb +11 -0
  25. data/app/models/concerns/spree_mobility/translatable.rb +63 -0
  26. data/app/overrides/spree/admin/option_types/_option_value_fields/add_translation.rb +10 -0
  27. data/app/overrides/spree/admin/option_types/index/add_translation.rb +8 -0
  28. data/app/overrides/spree/admin/product_properties/_product_property_fields/add_translation.rb +10 -0
  29. data/app/overrides/spree/admin/products/index/search_by_name_or_sku.rb +21 -0
  30. data/app/overrides/spree/admin/promotions/index/add_translation_link.rb +8 -0
  31. data/app/overrides/spree/admin/properties/index/add_translation.rb +8 -0
  32. data/app/overrides/spree/admin/shared/_product_tabs/add_translations.rb +10 -0
  33. data/app/overrides/spree/admin/shared/_translations/translation.rb +8 -0
  34. data/app/overrides/spree/admin/shared/sub_menu/_configuration/store_translations.rb +8 -0
  35. data/app/overrides/spree/admin/shipping_methods/index/add_translation.rb +8 -0
  36. data/app/overrides/spree/admin/taxonomies/_list/add_translations.rb +8 -0
  37. data/app/views/spree/admin/translations/_fields.html.erb +12 -0
  38. data/app/views/spree/admin/translations/_form.html.erb +13 -0
  39. data/app/views/spree/admin/translations/_form_fields.html.erb +38 -0
  40. data/app/views/spree/admin/translations/_settings.html.erb +22 -0
  41. data/app/views/spree/admin/translations/option_type.html.erb +9 -0
  42. data/app/views/spree/admin/translations/option_value.html.erb +25 -0
  43. data/app/views/spree/admin/translations/product.html.erb +7 -0
  44. data/app/views/spree/admin/translations/product_property.html.erb +23 -0
  45. data/app/views/spree/admin/translations/promotion.html.erb +9 -0
  46. data/app/views/spree/admin/translations/property.html.erb +9 -0
  47. data/app/views/spree/admin/translations/shipping_method.html.erb +9 -0
  48. data/app/views/spree/admin/translations/store.html.erb +25 -0
  49. data/app/views/spree/admin/translations/taxon.html.erb +25 -0
  50. data/app/views/spree/admin/translations/taxonomy.html.erb +9 -0
  51. data/bin/rails +7 -0
  52. data/config/initializers/enable_extensions.rb +27 -0
  53. data/config/initializers/form_builder_mobility_patch.rb +53 -0
  54. data/config/initializers/mobility.rb +118 -0
  55. data/config/initializers/spree_ransack.rb +31 -0
  56. data/config/locales/be.yml +6 -0
  57. data/config/locales/bg.yml +6 -0
  58. data/config/locales/en.yml +6 -0
  59. data/config/locales/it.yml +6 -0
  60. data/config/locales/ru.yml +6 -0
  61. data/config/locales/zh-TW.yml +6 -0
  62. data/config/routes.rb +7 -0
  63. data/db/migrate/20220411041407_add_translations_to_main_models.rb +83 -0
  64. data/db/migrate/20220412095648_remove_null_constraints_from_spree_tables.rb +13 -0
  65. data/db/migrate/20220413095648_migrate_translation_data.rb +53 -0
  66. data/gemfiles/spree_4_2.gemfile +8 -0
  67. data/gemfiles/spree_master.gemfile +10 -0
  68. data/lib/generators/spree_mobility/install/install_generator.rb +23 -0
  69. data/lib/spree_mobility/configuration.rb +12 -0
  70. data/lib/spree_mobility/core_ext/mobility/backends/active_record/table/mobility_acts_as_paranoid_decorator.rb +31 -0
  71. data/lib/spree_mobility/core_ext/spree/option_type_decorator.rb +11 -0
  72. data/lib/spree_mobility/core_ext/spree/option_value_decorator.rb +30 -0
  73. data/lib/spree_mobility/core_ext/spree/product_decorator.rb +87 -0
  74. data/lib/spree_mobility/core_ext/spree/product_property_decorator.rb +6 -0
  75. data/lib/spree_mobility/core_ext/spree/product_scopes_with_mobility_decorator.rb +16 -0
  76. data/lib/spree_mobility/core_ext/spree/products/find_with_mobility_decorator.rb +12 -0
  77. data/lib/spree_mobility/core_ext/spree/promotion_decorator.rb +11 -0
  78. data/lib/spree_mobility/core_ext/spree/property_decorator.rb +26 -0
  79. data/lib/spree_mobility/core_ext/spree/shipping_method_decorator.rb +10 -0
  80. data/lib/spree_mobility/core_ext/spree/store_decorator.rb +12 -0
  81. data/lib/spree_mobility/core_ext/spree/taxon_decorator.rb +54 -0
  82. data/lib/spree_mobility/core_ext/spree/taxonomy_decorator.rb +29 -0
  83. data/lib/spree_mobility/core_ext/spree/variant_decorator.rb +19 -0
  84. data/lib/spree_mobility/engine.rb +33 -0
  85. data/lib/spree_mobility/fallbacks.rb +45 -0
  86. data/lib/spree_mobility/translation_query.rb +36 -0
  87. data/lib/spree_mobility/version.rb +18 -0
  88. data/lib/spree_mobility.rb +47 -0
  89. data/spec/features/admin/products_spec.rb +15 -0
  90. data/spec/features/admin/translations_spec.rb +259 -0
  91. data/spec/features/translations_spec.rb +35 -0
  92. data/spec/models/product_spec.rb +77 -0
  93. data/spec/models/taxon_spec.rb +16 -0
  94. data/spec/models/translated_models_spec.rb +33 -0
  95. data/spec/models/variant_spec.rb +33 -0
  96. data/spec/spec_helper.rb +10 -0
  97. data/spec/support/i18n.rb +5 -0
  98. data/spec/support/matchers/be_a_thorough_translation_of_matcher.rb +21 -0
  99. data/spec/support/matchers/have_text_like.rb +3 -0
  100. data/spec/support/shared_contexts/translatable_context.rb +63 -0
  101. data/spree_mobility.gemspec +37 -0
  102. metadata +316 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 022505f406f3f9336ed07f01f2e991a46d04d21fb8c6a8320dc4b3c79093b227
4
+ data.tar.gz: 4bd438df89aad4b7be914cf0e8e40b128b67ac70409d99bc5a775d0841d95a0a
5
+ SHA512:
6
+ metadata.gz: db5144c00d20a57c15a5ce19de8b507d8cf56195ca5c1de4dcb554fb21f4127713fefbb4ed3e2817aa3be5b2335916c7b544e7d363929d5042e9c37622bf2313
7
+ data.tar.gz: 0cd224a84e281656efd79977715d2c688fa068ff846cea76b84f9a9506e77fb6adc1b09bc6ecf86d6e0ca51e92bbb5ce466a4c0e162745de2816e355b67dc9b2
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .localeapp/locales
7
+ .project
8
+ coverage
9
+ default
10
+ Gemfile.lock
11
+ tmp
12
+ nbproject
13
+ pkg
14
+ *.sw?
15
+ spec/dummy
16
+ .rvmrc
17
+ .sass-cache
18
+ public/spree
19
+ .ruby-version
20
+ .ruby-gemset
21
+ .bundle
22
+ gemfiles/*.gemfile.lock
data/.hound.yml ADDED
@@ -0,0 +1,21 @@
1
+ ---
2
+ # Too picky.
3
+ LineLength:
4
+ Enabled: false
5
+
6
+ # This should truly be on for well documented gems.
7
+ Documentation:
8
+ Enabled: false
9
+
10
+ # Neatly aligned code is too swell.
11
+ SingleSpaceBeforeFirstArg:
12
+ Enabled: false
13
+
14
+ # Don't mess with RSpec DSL.
15
+ Blocks:
16
+ Exclude:
17
+ - 'spec/**/*'
18
+
19
+ # Avoid contradictory style rules by enforce single quotes.
20
+ StringLiterals:
21
+ EnforcedStyle: single_quotes
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -r spec_helper
3
+ -f documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ inherit_from: .hound.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - spec/dummy/**/*
7
+ - bin/*
data/.travis.yml ADDED
@@ -0,0 +1,45 @@
1
+ os: linux
2
+ dist: bionic
3
+
4
+ addons:
5
+ apt:
6
+ sources:
7
+ - google-chrome
8
+ packages:
9
+ - google-chrome-stable
10
+
11
+ services:
12
+ - mysql
13
+ - postgresql
14
+
15
+ language: ruby
16
+
17
+ rvm:
18
+ - 2.7
19
+
20
+ env:
21
+ - DB=mysql
22
+ - DB=postgres
23
+
24
+ gemfile:
25
+ - gemfiles/spree_4_2.gemfile
26
+ - gemfiles/spree_master.gemfile
27
+
28
+ jobs:
29
+ allow_failures:
30
+ - gemfile: gemfiles/spree_master.gemfile
31
+
32
+ before_script:
33
+ - CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'`
34
+ - CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"`
35
+ - curl "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O
36
+ - unzip chromedriver_linux64.zip -d ~/bin
37
+ - nvm install 14
38
+
39
+ script:
40
+ - bundle exec rake test_app
41
+ - bundle exec rake spec
42
+
43
+
44
+ before_install:
45
+ - mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
data/Appraisals ADDED
@@ -0,0 +1,8 @@
1
+ appraise 'spree-4-2' do
2
+ gem 'spree', '~> 4.2.0.rc4'
3
+ gem 'spree_i18n', github: 'spree-contrib/spree_i18n'
4
+ end
5
+
6
+ appraise 'spree-master' do
7
+ gem 'spree', github: 'spree/spree', branch: 'master'
8
+ end
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,81 @@
1
+ # Contributing
2
+
3
+ Spree mobility is an open source project and we encourage contributions. Please see the [contributors guidelines](http://spreecommerce.com/documentation/contributing_to_spree.html) for more information before contributing.
4
+
5
+ In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
6
+
7
+ Here are some ways *you* can contribute:
8
+
9
+ * by using prerelease versions
10
+ * by reporting [bugs][2]
11
+ * by suggesting new features
12
+ * by writing [translations][3] (e.g. use branch 2-4-stable for Spree v2.4.x)
13
+ * by writing or editing documentation
14
+ * by writing specifications
15
+ * by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
16
+ * by refactoring code
17
+ * by resolving [issues][2]
18
+ * by reviewing patches
19
+
20
+ ---
21
+
22
+ ## Filing an issue
23
+
24
+ When filing an issue on this extension, please first do these things:
25
+
26
+ * Verify you can reproduce this issue in a brand new application.
27
+ * Run through the steps to reproduce the issue again.
28
+
29
+ In the issue itself please provide:
30
+
31
+ * A comprehensive list of steps to reproduce the issue.
32
+ * What you're *expecting* to happen compared with what's *actually* happening.
33
+ * The version of Spree *and* the version of Rails.
34
+ * A list of all extensions.
35
+ * Any relevant stack traces ("Full trace" preferred)
36
+ * Your `Gemfile`
37
+
38
+ In 99% of cases, this information is enough to determine the cause and solution to the problem that is being described.
39
+
40
+ ---
41
+
42
+ ## Pull requests
43
+
44
+ We gladly accept pull requests to fix bugs and, in some circumstances, add new features to this extension.
45
+
46
+ Here's a quick guide:
47
+
48
+ 1. Fork the repo.
49
+
50
+ 2. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate.
51
+
52
+ 3. Create new branch then make changes and add tests for your changes. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need tests!
53
+
54
+ 4. Push to your fork and submit a pull request. If the changes will apply cleanly to the latest stable branches and master branch, you will only need to submit one pull request.
55
+
56
+ At this point you're waiting on us. We may suggest some changes or improvements or alternatives.
57
+
58
+ Some things that will increase the chance that your pull request is accepted, taken straight from the Ruby on Rails guide:
59
+
60
+ * Use Rails idioms and helpers.
61
+ * Include tests that fail without your code, and pass with it.
62
+ * Update the documentation, the surrounding one, examples elsewhere, guides, whatever is affected by your contribution.
63
+
64
+ ---
65
+
66
+ ## TL;DR
67
+
68
+ * Fork the repo
69
+ * Clone your repo
70
+ * Run `bundle install`
71
+ * Run `bundle exec rake test_app` to create the test application in `spec/dummy`
72
+ * Make your changes
73
+ * Ensure specs pass by running `bundle exec rspec spec`
74
+ * Ensure all syntax ok by running `rubocop .`
75
+ * Submit your pull request
76
+
77
+ And in case we didn't emphasize it enough: **we love tests!**
78
+
79
+ [1]: http://www.fsf.org/licensing/essays/free-sw.html
80
+ [2]: https://github.com/spree-contrib/spree_mobility/issues
81
+ [3]: https://github.com/spree-contrib/spree_mobility/tree/master/config/locales
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'spree', '~> 4.3.1'
4
+ gem 'spree_frontend', '~> 4.3.1'
5
+ gem 'spree_backend', '~> 4.3.1'
6
+ gem 'spree_i18n', github: 'spree-contrib/spree_i18n', branch: 'main'
7
+
8
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ group :red_green_refactor, halt_on_fail: true do
2
+
3
+ guard 'rspec', cmd: 'bundle exec rspec' do
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ watch('config/routes.rb') { 'spec/controllers' }
6
+ watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb"}
7
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
9
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
10
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
11
+ end
12
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2011-2015 Spree Commerce Inc., and other contributors.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Spree Mobility
2
+
3
+ This is a Spree model translation gem based on `spree_globalize` for [Spree Commerce][1] version 4.3+.
4
+ It uses `mobility` instead of `globalize`, since `globalize` is not actively developed anymore.
5
+ It is a drop-in replacement for `spree_globalize` and will use your existing translations.
6
+
7
+ ## Improvements
8
+
9
+ This gem offers several improvements over `spree_globalize`:
10
+
11
+ * Proper translation fallbacks support (if a translation for the current locale is missing, it will fallback to other locales, strictly based on configured fallbacks):
12
+ * for finders (slug/permalink)
13
+ * when searching by product name (frontend & admin search)
14
+ * Proper validations on translation models (e.g. slug presence validation), also meaning uniqueness validations will now work correctly per-locale
15
+ * Better support for future versions of Rails as `mobility` is more actively maintained
16
+
17
+ Admin:
18
+
19
+ * Rich-text editor for product description translations in admin (if enabled)
20
+ * Searching by product SKU in admin
21
+ * Admin product search will no longer return duplicate results
22
+ * Works correctly if using custom Spree.admin_path config
23
+
24
+ ## Installation
25
+
26
+ Add the following to your `Gemfile`:
27
+
28
+ ```ruby
29
+ gem 'spree_i18n', '~> 5.0'
30
+ gem 'friendly_id-mobility', github: 'mrbrdo/friendly_id-mobility', branch: 'master'
31
+ gem 'spree_mobility'
32
+ ```
33
+
34
+ Run `bundle install`
35
+
36
+ You can use the generator to install migrations and append spree_mobility assets to
37
+ your app spree manifest file.
38
+
39
+ rails g spree_mobility:install
40
+
41
+ This will insert these lines into your spree manifest files:
42
+
43
+ ```
44
+ vendor/assets/javascripts/spree/backend/all.js
45
+ //= require spree/backend/spree_mobility
46
+ ```
47
+
48
+ It is also recommended to configure Mobility fallback locales, especially if your admin locale is not the same as your Store's default_locale. For example if you have en and de locale:
49
+
50
+ ```
51
+ # config/initializers/mobility.rb
52
+ Mobility.configure do
53
+ plugins do
54
+ fallbacks({ :en => [:de], :de => [:en] })
55
+ end
56
+ end
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Model Translations
62
+
63
+ This feature uses the [Mobility][3] gem to localize model data.
64
+ So far the following models are translatable:
65
+
66
+ Product, Promotion, OptionType, Taxonomy, Taxon, Property, Store and ShippingMethod.
67
+
68
+ Start your server and you should see a TRANSLATIONS link or a flag icon on each
69
+ admin section that supports this feature.
70
+
71
+ *Every record needs to have a translation. If by any chance you remove `spree_mobility`
72
+ from your Gemfile, add some records and then add `spree_mobility` gem back you might get
73
+ errors like ``undefined method for nilClass`` because Mobility will try fetch
74
+ translations that do not exist.*
75
+
76
+ ---
77
+
78
+ ## Contributing
79
+
80
+ [See corresponding guidelines][7]
81
+
82
+ ---
83
+
84
+ Copyright (c) 2010-2022 MrBrdo. released under the [New BSD License][6]
85
+
86
+ [1]: http://spreecommerce.org
87
+ [2]: http://guides.spreecommerce.org/developer/i18n.html
88
+ [3]: https://github.com/shioyama/mobility
89
+ [5]: https://github.com/spree-contrib/spree_globalize/graphs/contributors
90
+ [6]: https://github.com/mrbrdo/spree_mobility/blob/master/LICENSE.md
91
+ [7]: https://github.com/mrbrdo/spree_mobility/blob/master/CONTRIBUTING.md
92
+ [8]: https://github.com/spree-contrib/spree_i18n
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/packagetask'
5
+ require 'rubygems/package_task'
6
+ require 'rspec/core/rake_task'
7
+ require 'spree/testing_support/extension_rake'
8
+
9
+ Bundler::GemHelper.install_tasks
10
+ RSpec::Core::RakeTask.new
11
+
12
+ task default: :spec
13
+
14
+ spec = eval(File.read('spree_mobility.gemspec'))
15
+
16
+ Gem::PackageTask.new(spec) do |p|
17
+ p.gem_spec = spec
18
+ end
19
+
20
+ desc 'Generates a dummy app for testing'
21
+ task :test_app do
22
+ ENV['LIB_NAME'] = 'spree_mobility'
23
+ Rake::Task['extension:test_app'].invoke
24
+ end
@@ -0,0 +1,2 @@
1
+ //= require spree/backend
2
+ //= require_tree .
@@ -0,0 +1,49 @@
1
+ (function() {
2
+ var root;
3
+
4
+ root = typeof exports !== "undefined" && exports !== null ? exports : this;
5
+
6
+ root.taxon_tree_menu = function(obj, context) {
7
+ var admin_base_url, edit_url, id, translation_base_path, translation_url;
8
+ id = obj.attr("id");
9
+ admin_base_url = Spree.url(Spree.routes.admin_taxonomy_taxons_path);
10
+ edit_url = admin_base_url.clone();
11
+ edit_url.setPath(edit_url.path() + '/' + id + "/edit");
12
+ translation_url = Spree.url(admin_base_url.path().replace(/\/taxonomies\/\d.+$/, '') + '/taxons/' + id + '/translations');
13
+ return {
14
+ create: {
15
+ label: "<span class='icon icon-plus'></span> " + Spree.translations.add,
16
+ action: function(obj) {
17
+ return context.create(obj);
18
+ }
19
+ },
20
+ rename: {
21
+ label: "<span class='icon icon-pencil'></span> " + Spree.translations.rename,
22
+ action: function(obj) {
23
+ return context.rename(obj);
24
+ }
25
+ },
26
+ remove: {
27
+ label: "<span class='icon icon-trash'></span> " + Spree.translations.remove,
28
+ action: function(obj) {
29
+ return context.remove(obj);
30
+ }
31
+ },
32
+ edit: {
33
+ separator_before: true,
34
+ label: "<span class='icon icon-cog'></span> " + Spree.translations.edit,
35
+ action: function(obj) {
36
+ return window.location = edit_url.toString();
37
+ }
38
+ },
39
+ translate: {
40
+ separator_before: true,
41
+ label: "<span class='icon icon-flag'></span> " + Spree.translations.translations,
42
+ action: function(obj) {
43
+ return window.location = translation_url.toString();
44
+ }
45
+ }
46
+ };
47
+ };
48
+
49
+ }).call(this);
@@ -0,0 +1,50 @@
1
+ (function() {
2
+ var display_locale_fields;
3
+
4
+ display_locale_fields = function() {
5
+ var attr, locale, locales, show, _fn, _i, _len;
6
+ attr = $('#attr_list a.active').data('attr');
7
+ locale = $('#locale').val();
8
+ available_locales = $('#available_locales').val().split(',');
9
+ show = $("select[name='show-only']").val();
10
+ $('#attr_fields .panel').hide();
11
+ _fn = function(locale) {
12
+ var display, value;
13
+ value = $('#attr_fields .panel.' + attr + '.' + locale + ' :input').val().replace(/^\s+|\s+$/g, "");
14
+ if (show === 'incomplete') {
15
+ display = value === '';
16
+ } else if (show === 'complete') {
17
+ display = value !== '';
18
+ } else {
19
+ display = true;
20
+ }
21
+ if (display) {
22
+ return $('#attr_fields .panel.' + attr + '.' + locale).show();
23
+ }
24
+ };
25
+ if (locale === '') {
26
+ available_locales.forEach(function(locale) { _fn(locale) });
27
+ } else {
28
+ _fn(locale);
29
+ }
30
+ if ($('#attr_fields .panel:visible').length === 0 && show !== 'all') {
31
+ return $('#attr_fields .no-translations').show();
32
+ }
33
+ };
34
+
35
+ $(function() {
36
+ $('#attr_list a').click(function() {
37
+ $('#attr_list a').removeClass('active');
38
+ $(this).addClass('active');
39
+ display_locale_fields();
40
+ return false;
41
+ });
42
+ $('#locale').change(function() {
43
+ return display_locale_fields();
44
+ });
45
+ return $("select[name='show-only']").change(function() {
46
+ return display_locale_fields();
47
+ });
48
+ });
49
+
50
+ }).call(this);
@@ -0,0 +1,18 @@
1
+ module SpreeMobility
2
+ # The fact this logic is in a single module also helps to apply a custom
3
+ # locale on the spree/api context since api base controller inherits from
4
+ # MetalController instead of Spree::BaseController
5
+ module ControllerMobilityHelper
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ prepend_before_action :mobility_fallbacks
10
+
11
+ private
12
+
13
+ def mobility_fallbacks
14
+ SpreeMobility::Fallbacks.config!
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ module Admin
3
+ module OptionValuesControllerDecorator
4
+ def update
5
+ option_value = Spree::OptionValue.find(params[:id])
6
+ option_value.update update_option_value_attribute
7
+ redirect_to spree.edit_admin_option_type_path(option_value.option_type)
8
+ end
9
+
10
+ private
11
+
12
+ def update_option_value_attribute
13
+ params.require(:option_value).permit(permitted_params)
14
+ end
15
+
16
+ def permitted_params
17
+ Spree::PermittedAttributes.option_value_attributes
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ SpreeMobility.prepend_once(::Spree::Admin::OptionValuesController, Spree::Admin::OptionValuesControllerDecorator)
@@ -0,0 +1,22 @@
1
+ module Spree
2
+ module Admin
3
+ module ProductPropertiesControllerDecorator
4
+ def translate
5
+ product_property = Spree::ProductProperty.find(params[:id])
6
+ product_property.update update_product_property_attribute
7
+ redirect_to spree.admin_product_product_properties_path(product_property.product)
8
+ end
9
+
10
+ private
11
+ def update_product_property_attribute
12
+ params.require(:product_property).permit(permitted_params)
13
+ end
14
+
15
+ def permitted_params
16
+ [translations_attributes: [:id, :locale, :value]]
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ SpreeMobility.prepend_once(::Spree::Admin::ProductPropertiesController, Spree::Admin::ProductPropertiesControllerDecorator)
@@ -0,0 +1,18 @@
1
+ module Spree
2
+ module Admin
3
+ module ShippingMethodsControllerDecorator
4
+ private
5
+ # We have to override those filters since they break proper PATCH behaviour.
6
+
7
+ def set_shipping_category
8
+ super unless params['shipping_method'][:translations_attributes]
9
+ end
10
+
11
+ def set_zones
12
+ super unless params['shipping_method'][:translations_attributes]
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ SpreeMobility.prepend_once(::Spree::Admin::ShippingMethodsController, Spree::Admin::ShippingMethodsControllerDecorator)
@@ -0,0 +1,53 @@
1
+ module Spree
2
+ class Admin::TranslationsController < Admin::BaseController
3
+ before_action :load_parent
4
+
5
+ if defined?(SpreeI18n::ControllerLocaleHelper)
6
+ helper 'spree_i18n/locale'
7
+ end
8
+ helper 'spree_mobility/locale'
9
+
10
+ helper_method :collection_url
11
+
12
+ def index
13
+ render resource_name
14
+ end
15
+
16
+ private
17
+
18
+ def load_parent
19
+ set_resource_ivar(resource)
20
+ end
21
+
22
+ def resource_name
23
+ params[:resource].singularize
24
+ end
25
+
26
+ def set_resource_ivar(resource)
27
+ instance_variable_set("@#{resource_name}", resource)
28
+ end
29
+
30
+ def klass
31
+ @klass ||= "Spree::#{params[:resource].classify}".constantize
32
+ end
33
+
34
+ def resource
35
+ @resource ||= if slugged_models.include? klass.name
36
+ klass.friendly.find(params[:resource_id])
37
+ else
38
+ klass.find(params[:resource_id])
39
+ end
40
+ end
41
+
42
+ def collection_url
43
+ ActionController::Routing::Routes.recognize_path("admin_#{resource_name}_url", @resource)
44
+ send "admin_#{resource_name}_url", @resource
45
+ rescue
46
+ send "edit_admin_#{resource_name}_url", @resource
47
+ end
48
+
49
+ def slugged_models
50
+ ["Spree::Product"]
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ module Spree::Api::BaseControllerDecorator
2
+ Spree::Api::BaseController.include(SpreeMobility::ControllerMobilityHelper)
3
+ end
4
+
5
+ SpreeMobility.prepend_once(::Spree::Api::BaseController, Spree::Api::BaseControllerDecorator)
@@ -0,0 +1,5 @@
1
+ module Spree::BaseControllerDecorator
2
+ Spree::BaseController.include(SpreeMobility::ControllerMobilityHelper)
3
+ end
4
+
5
+ SpreeMobility.prepend_once(::Spree::BaseController, Spree::BaseControllerDecorator)
@@ -0,0 +1,11 @@
1
+ module SpreeMobility
2
+ module LocaleHelper
3
+ def select_available_locales_fields
4
+ select_tag(
5
+ 'locale',
6
+ options_for_select(available_locales_options, nil),
7
+ { include_blank: Spree.t(:all), class: 'select2' }
8
+ )
9
+ end
10
+ end
11
+ end