workarea-reviews 3.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintignore +2 -0
  4. data/.eslintrc +24 -0
  5. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  6. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/.gitignore +16 -0
  9. data/.scss-lint.yml +188 -0
  10. data/.yardopts +1 -0
  11. data/CHANGELOG.md +763 -0
  12. data/CODE_OF_CONDUCT.md +3 -0
  13. data/CONTRIBUTING.md +3 -0
  14. data/Gemfile +6 -0
  15. data/LICENSE +52 -0
  16. data/README.md +107 -0
  17. data/Rakefile +54 -0
  18. data/app/assets/images/workarea/admin/icons/star.svg +1 -0
  19. data/app/assets/images/workarea/storefront/icons/empty_star.svg +1 -0
  20. data/app/assets/images/workarea/storefront/icons/half_star.svg +1 -0
  21. data/app/assets/images/workarea/storefront/icons/star.svg +1 -0
  22. data/app/assets/javascripts/workarea/storefront/reviews/modules/product_review_ajax_submit.js +39 -0
  23. data/app/assets/javascripts/workarea/storefront/reviews/modules/product_reviews_sort_menus.js +82 -0
  24. data/app/assets/javascripts/workarea/storefront/reviews/modules/rating_buttons.js +103 -0
  25. data/app/assets/javascripts/workarea/storefront/reviews/templates/sort_by_property.jst.ejs +11 -0
  26. data/app/assets/stylesheets/workarea/storefront/reviews/components/_rating.scss +28 -0
  27. data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews.scss +59 -0
  28. data/app/assets/stylesheets/workarea/storefront/reviews/components/_reviews_aggregate.scss +38 -0
  29. data/app/assets/stylesheets/workarea/storefront/reviews/components/_write_review.scss +63 -0
  30. data/app/controllers/workarea/admin/catalog_products_controller.decorator +9 -0
  31. data/app/controllers/workarea/admin/import_reviews_controller.rb +35 -0
  32. data/app/controllers/workarea/admin/reviews_controller.rb +51 -0
  33. data/app/controllers/workarea/storefront/review_requests_controller.rb +50 -0
  34. data/app/controllers/workarea/storefront/reviews_controller.rb +53 -0
  35. data/app/helpers/workarea/admin/reviews_helper.rb +12 -0
  36. data/app/helpers/workarea/storefront/reviews_helper.rb +24 -0
  37. data/app/mailers/workarea/admin/status_report_mailer.decorator +8 -0
  38. data/app/mailers/workarea/storefront/review_mailer.rb +23 -0
  39. data/app/models/workarea/catalog/product.decorator +15 -0
  40. data/app/models/workarea/fulfillment.decorator +11 -0
  41. data/app/models/workarea/review.rb +135 -0
  42. data/app/models/workarea/review/request.rb +62 -0
  43. data/app/models/workarea/search/admin/review.rb +72 -0
  44. data/app/models/workarea/search/storefront/product.decorator +9 -0
  45. data/app/models/workarea/sort.decorator +17 -0
  46. data/app/queries/workarea/review_request_params.rb +47 -0
  47. data/app/queries/workarea/review_summary.rb +11 -0
  48. data/app/queries/workarea/search/admin_reviews.rb +40 -0
  49. data/app/queries/workarea/search/category_browse.decorator +9 -0
  50. data/app/queries/workarea/search/product_search.decorator +9 -0
  51. data/app/seeds/review_seeds.rb +49 -0
  52. data/app/services/workarea/create_review.rb +99 -0
  53. data/app/view_models/workarea/admin/product_view_model.decorator +7 -0
  54. data/app/view_models/workarea/admin/review_view_model.rb +23 -0
  55. data/app/view_models/workarea/admin/reviews_search_view_model.rb +46 -0
  56. data/app/view_models/workarea/storefront/product_view_model.decorator +13 -0
  57. data/app/view_models/workarea/storefront/review_view_model.rb +14 -0
  58. data/app/views/workarea/admin/activities/_review_create.html.haml +12 -0
  59. data/app/views/workarea/admin/activities/_review_destroy.html.haml +10 -0
  60. data/app/views/workarea/admin/activities/_review_update.html.haml +10 -0
  61. data/app/views/workarea/admin/reviews/_aux_navigation.html.haml +5 -0
  62. data/app/views/workarea/admin/reviews/_catalog_products_aux_link.html.haml +5 -0
  63. data/app/views/workarea/admin/reviews/_dashboard_navigation.html.haml +1 -0
  64. data/app/views/workarea/admin/reviews/_menu.html.haml +3 -0
  65. data/app/views/workarea/admin/reviews/_summary.html.haml +12 -0
  66. data/app/views/workarea/admin/reviews/edit.html.haml +77 -0
  67. data/app/views/workarea/admin/reviews/index.html.haml +74 -0
  68. data/app/views/workarea/admin/status_report_mailer/_reviews.html.haml +5 -0
  69. data/app/views/workarea/storefront/products/_rating.html.haml +10 -0
  70. data/app/views/workarea/storefront/products/_reviews.html.haml +23 -0
  71. data/app/views/workarea/storefront/products/_reviews_aggregate.html.haml +22 -0
  72. data/app/views/workarea/storefront/products/_reviews_summary.html.haml +2 -0
  73. data/app/views/workarea/storefront/review_mailer/review_request.html.haml +22 -0
  74. data/app/views/workarea/storefront/review_requests/show.html.haml +44 -0
  75. data/app/views/workarea/storefront/reviews/new.html.haml +68 -0
  76. data/app/views/workarea/storefront/style_guides/_reviews_product_summary_docs.html.haml +13 -0
  77. data/app/views/workarea/storefront/style_guides/components/_reviews.html.haml +17 -0
  78. data/app/workers/workarea/create_review_requests.rb +33 -0
  79. data/app/workers/workarea/schedule_review_requests.rb +44 -0
  80. data/app/workers/workarea/send_review_requests.rb +12 -0
  81. data/app/workers/workarea/update_product_review_data.rb +26 -0
  82. data/bin/rails +18 -0
  83. data/config/initializers/append_points.rb +70 -0
  84. data/config/initializers/assets.rb +1 -0
  85. data/config/initializers/configuration.rb +29 -0
  86. data/config/initializers/rack_attack.rb +11 -0
  87. data/config/initializers/recaptcha.rb +19 -0
  88. data/config/initializers/scheduled_jobs.rb +8 -0
  89. data/config/locales/en.yml +104 -0
  90. data/config/routes.rb +21 -0
  91. data/lib/tasks/verify.rake +16 -0
  92. data/lib/workarea/mailer_previews/storefront/review_mailer_preview.rb +10 -0
  93. data/lib/workarea/reviews.rb +13 -0
  94. data/lib/workarea/reviews/engine.rb +12 -0
  95. data/lib/workarea/reviews/version.rb +5 -0
  96. data/test/dummy/Rakefile +6 -0
  97. data/test/dummy/app/assets/config/manifest.js +4 -0
  98. data/test/dummy/app/assets/images/.keep +0 -0
  99. data/test/dummy/app/assets/javascripts/application.js +13 -0
  100. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  101. data/test/dummy/app/controllers/application_controller.rb +3 -0
  102. data/test/dummy/app/controllers/concerns/.keep +0 -0
  103. data/test/dummy/app/helpers/application_helper.rb +2 -0
  104. data/test/dummy/app/jobs/application_job.rb +2 -0
  105. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  106. data/test/dummy/app/models/concerns/.keep +0 -0
  107. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  108. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  109. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  110. data/test/dummy/bin/bundle +3 -0
  111. data/test/dummy/bin/rails +4 -0
  112. data/test/dummy/bin/rake +4 -0
  113. data/test/dummy/bin/setup +34 -0
  114. data/test/dummy/bin/update +29 -0
  115. data/test/dummy/config.ru +5 -0
  116. data/test/dummy/config/application.rb +25 -0
  117. data/test/dummy/config/boot.rb +5 -0
  118. data/test/dummy/config/cable.yml +9 -0
  119. data/test/dummy/config/environment.rb +5 -0
  120. data/test/dummy/config/environments/development.rb +55 -0
  121. data/test/dummy/config/environments/production.rb +86 -0
  122. data/test/dummy/config/environments/test.rb +43 -0
  123. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  124. data/test/dummy/config/initializers/assets.rb +11 -0
  125. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  126. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  127. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  128. data/test/dummy/config/initializers/inflections.rb +16 -0
  129. data/test/dummy/config/initializers/mime_types.rb +4 -0
  130. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  131. data/test/dummy/config/initializers/session_store.rb +3 -0
  132. data/test/dummy/config/initializers/workarea.rb +5 -0
  133. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  134. data/test/dummy/config/locales/en.yml +23 -0
  135. data/test/dummy/config/puma.rb +47 -0
  136. data/test/dummy/config/routes.rb +5 -0
  137. data/test/dummy/config/secrets.yml +22 -0
  138. data/test/dummy/config/spring.rb +6 -0
  139. data/test/dummy/db/seeds.rb +2 -0
  140. data/test/dummy/lib/assets/.keep +0 -0
  141. data/test/dummy/log/.keep +0 -0
  142. data/test/factories/reviews.rb +32 -0
  143. data/test/fixtures/reviews.csv +5 -0
  144. data/test/helpers/workarea/admin/reviews_helper_test.rb +17 -0
  145. data/test/helpers/workarea/storefront/reviews_helper_test.rb +19 -0
  146. data/test/integration/workarea/admin/reviews_integration_test.rb +33 -0
  147. data/test/integration/workarea/storefront/review_requests_integration_test.rb +63 -0
  148. data/test/integration/workarea/storefront/reviews_integration_test.rb +82 -0
  149. data/test/javascripts/fixtures/product_review_ajax_submit.html.haml +4 -0
  150. data/test/javascripts/product_review_ajax_submit_spec.js +28 -0
  151. data/test/javascripts/spec_helper.js +23 -0
  152. data/test/models/workarea/review/request_test.rb +18 -0
  153. data/test/models/workarea/review_test.rb +94 -0
  154. data/test/models/workarea/search/storefront/product_test.decorator +14 -0
  155. data/test/queries/workarea/review_request_params_test.rb +64 -0
  156. data/test/services/workarea/create_review_test.rb +131 -0
  157. data/test/system/workarea/admin/review_system_test.rb +96 -0
  158. data/test/system/workarea/storefront/review_request_system_test.rb +34 -0
  159. data/test/system/workarea/storefront/review_system_test.rb +113 -0
  160. data/test/teaspoon_env.rb +10 -0
  161. data/test/test_helper.rb +11 -0
  162. data/test/workers/workarea/create_review_requests_test.rb +38 -0
  163. data/test/workers/workarea/schedule_review_requests_test.rb +115 -0
  164. data/test/workers/workarea/send_review_requests_test.rb +30 -0
  165. data/workarea-reviews.gemspec +22 -0
  166. metadata +241 -0
@@ -0,0 +1,3 @@
1
+ View this plugin's code of conduct here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CODE_OF_CONDUCT.md>
@@ -0,0 +1,3 @@
1
+ View this plugin's contribution guidelines here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CONTRIBUTING.md>
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
+
4
+ gemspec
5
+
6
+ gem 'workarea'
data/LICENSE ADDED
@@ -0,0 +1,52 @@
1
+ WebLinc
2
+ Business Source License
3
+
4
+ Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
5
+
6
+ Licensed Work: Workarea Commerce Platform
7
+ The Licensed Work is (c) 2019 WebLinc Corporation
8
+
9
+ Additional Use Grant:
10
+ You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
11
+
12
+ A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
13
+
14
+ For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
15
+
16
+ Change Date: 2019-08-20
17
+
18
+ Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
19
+
20
+ Terms
21
+
22
+ The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
25
+
26
+ If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
27
+
28
+ All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
29
+
30
+ You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
31
+
32
+ Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
33
+
34
+ This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
35
+
36
+ Covenants of Licensor
37
+ In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
38
+
39
+ To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
40
+
41
+ To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
42
+
43
+ To specify a Change Date.
44
+
45
+ Not to modify this License in any other way.
46
+
47
+ Notice
48
+ The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
49
+
50
+ For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
51
+
52
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
@@ -0,0 +1,107 @@
1
+ Workarea Reviews
2
+ ================================================================================
3
+
4
+ A Workarea Commerce plugin that enables product reviews.
5
+
6
+
7
+ Overview
8
+ --------------------------------------------------------------------------------
9
+
10
+ * Consumers can write product reviews in the Storefront
11
+ * Admins can edit those reviews in the Admin, which includes approving them
12
+ * Approved reviews are reflected in product summaries and displayed on product detail pages
13
+ * Consumers can sort products by rating in the Storefront
14
+ * Admins can list, show, edit, and delete reviews in the Admin
15
+ * Admins can view and navigate to a product's reviews when administrating a product in the Admin
16
+ * The Admin daily status report email includes a summary of reviews
17
+ * The system emails consumers who place orders to request they write reviews
18
+ * Developers can seed reviews for all products
19
+ * Developers can preview review-related emails
20
+ * Admins can view a reviews by product report
21
+ * The system generates top rated and most reviewed product insights
22
+ * The system generates most active reviewers insight
23
+
24
+ Getting Started
25
+ --------------------------------------------------------------------------------
26
+
27
+ Add the gem to your application's Gemfile:
28
+
29
+ ```ruby
30
+ # ...
31
+ gem 'workarea-reviews'
32
+ # ...
33
+ ```
34
+
35
+ Update your application's bundle.
36
+
37
+ ```bash
38
+ cd path/to/application
39
+ bundle
40
+ ```
41
+
42
+ Features
43
+ --------------------------------------------------------------------------------
44
+
45
+
46
+ ### Writing Reviews
47
+
48
+ * Reviews are written in the Storefront; users may be logged in or anonymous (requires reCAPTCHA)
49
+ * Developers can set `Workarea.config.require_purchase_to_write_review` to `true` to require the reviewer to have a `total_spent` greater than zero for the review to be valid
50
+ * The "write review" form is presented as a dialog, which closes after the review is submitted
51
+ * The reviewer uses a rating star UI (with underlying values of 1 through 5) to select a rating
52
+ * The reviewer may also provide a title and body, along with their first name, last name, and email
53
+ * The reviewer receives an email to confirm the review was submitted and is awaiting admin approval
54
+
55
+
56
+ ### Displaying Reviews
57
+
58
+ * In the Storefront, reviews are presented without pagination
59
+ * Reviews can be sorted, which is handled client-side (values are oldest, newest, and highest)
60
+ * Each review may include a title, a body, and the following metadata: author, date, verified
61
+ * A review is considered verified if the reviewer was logged in and has the ID of the reviewed product in their order history
62
+
63
+
64
+ ### Administrating Reviews
65
+
66
+ * Admins with marketing permission may access the reviews admin
67
+ * The reviews admin is accessible from the Marketing section of the primary navigation and from the Marketing dashboard
68
+ * Admins can also jump to the reviews admin by searching for "Product Reviews"
69
+ * Products and reviews are cross referenced within the auxillary navigation of each
70
+ * Admins can list, show, edit, and delete reviews, which includes approving them (Admins can edit a review before approving)
71
+
72
+
73
+ ### Requesting Reviews
74
+
75
+ * For each order, the system will send up to _n_ review requests (Workarea.config.review_requests_per_order)
76
+ * Each request is for a different order item (selected by most expensive)
77
+ * Each request expires after a configurable duration (Workarea.config.review_request_ttl)
78
+ * The first request is sent after a configurable duration has passed (Workarea.config.review_request_initial_delivery_delay)
79
+ * Each consecutive request is sent at a configurable duration (Workarea.config.review_request_secondary_delivery_delay)
80
+
81
+ reCAPTCHA Configuration
82
+ --------------------------------------------------------------------------------
83
+
84
+ Workarea Reviews utilizes [reCAPTCHA](https://github.com/ambethia/recaptcha) in the review form to prevent abuse. You'll need to configure each environment's secrets file to provide recaptcha keys. For testing and development, the plugin will use the [google provided](https://developers.google.com/recaptcha/docs/faq) testing keys if none are specified in your secrets.
85
+
86
+ ```yaml
87
+ production:
88
+ recaptcha:
89
+ site_key: YOUR_SITE_KEY
90
+ secret_key: YOUR_SECRET_KEY
91
+ ```
92
+
93
+ reCAPTCHA sends its HTTP requests through the proxy automatically if the
94
+ `$HTTP_PROXY` environment variable is set. This is set for you in hosted
95
+ environments.
96
+
97
+ [Obtain your keys from the reCAPTCHA site](https://www.google.com/recaptcha/admin)
98
+
99
+ Workarea Commerce Documentation
100
+ --------------------------------------------------------------------------------
101
+
102
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.
103
+
104
+ License
105
+ --------------------------------------------------------------------------------
106
+
107
+ Workarea Reviews is released under the [Business Software License](LICENSE)
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
9
+ load 'rails/tasks/engine.rake'
10
+ load 'rails/tasks/statistics.rake'
11
+ load 'workarea/changelog.rake'
12
+
13
+ require 'rake/testtask'
14
+
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << 'lib'
17
+ t.libs << 'test'
18
+ t.pattern = 'test/**/*_test.rb'
19
+ t.verbose = false
20
+ end
21
+
22
+ task default: :test
23
+
24
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
25
+ require 'workarea/reviews/version'
26
+
27
+ desc "Release version #{Workarea::Reviews::VERSION} of the gem"
28
+ task :release do
29
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
30
+
31
+ #Rake::Task['workarea:changelog'].execute
32
+ #system 'git add CHANGELOG.md'
33
+ #system 'git commit -m "Update CHANGELOG"'
34
+ #system 'git push origin HEAD'
35
+
36
+ system "git tag -a v#{Workarea::Reviews::VERSION} -m 'Tagging #{Workarea::Reviews::VERSION}'"
37
+ system 'git push --tags'
38
+
39
+ system 'gem build workarea-reviews.gemspec'
40
+ system "gem push workarea-reviews-#{Workarea::Reviews::VERSION}.gem"
41
+ system "gem push workarea-reviews-#{Workarea::Reviews::VERSION}.gem --host #{host}"
42
+ system "rm workarea-reviews-#{Workarea::Reviews::VERSION}.gem"
43
+ end
44
+
45
+ desc 'Run the JavaScript tests'
46
+ ENV['TEASPOON_RAILS_ENV'] = File.expand_path('../test/dummy/config/environment', __FILE__)
47
+ task teaspoon: 'app:teaspoon'
48
+
49
+ desc 'Start a server at http://localhost:3000/teaspoon for JavaScript tests'
50
+ task :teaspoon_server do
51
+ Dir.chdir('test/dummy')
52
+ teaspoon_env = File.expand_path('../test/teaspoon_env.rb', __FILE__)
53
+ system "RAILS_ENV=test TEASPOON_ENV=#{teaspoon_env} rails s"
54
+ end
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>star</title><path d="M12 19.41l-7.33 3.84 1.43-8.13L.17 9.36l8.18-1.2L12 .75l3.65 7.41 8.19 1.2-5.94 5.76 1.42 8.13L12 19.41z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>empty_star</title><path d="M12 3l2.75 5.6.23.47.52.08 6.18.91-4.48 4.34-.38.37.09.52L18 21.42l-5.52-2.9-.48-.24-.46.24L6 21.42l1.08-6.13.09-.52-.37-.37-4.48-4.34 6.18-.91.5-.08.23-.47L12 3m0-2.25L8.35 8.16.17 9.36l5.93 5.76-1.43 8.13L12 19.41l7.32 3.84-1.42-8.13 5.94-5.76-8.19-1.2L12 .75z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>half_star</title><path d="M12 19.41V.75L8.35 8.16.17 9.36l5.93 5.76-1.43 8.13L12 19.41z"/><path d="M12 3l2.75 5.6.23.47.52.08 6.18.91-4.48 4.34-.38.37.09.52L18 21.42l-5.52-2.9-.48-.24-.46.24L6 21.42l1.08-6.13.09-.52-.37-.37-4.48-4.34 6.18-.91.5-.08.23-.47L12 3m0-2.25L8.35 8.16.17 9.36l5.93 5.76-1.43 8.13L12 19.41l7.32 3.84-1.42-8.13 5.94-5.76-8.19-1.2L12 .75z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>star</title><path d="M12 19.41l-7.33 3.84 1.43-8.13L.17 9.36l8.18-1.2L12 .75l3.65 7.41 8.19 1.2-5.94 5.76 1.42 8.13L12 19.41z"/></svg>
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @namespace WORKAREA.productReviewAjaxSubmit
3
+ */
4
+ WORKAREA.registerModule('productReviewAjaxSubmit', (function () {
5
+ 'use strict';
6
+
7
+ var submitForm = function ($form, event) {
8
+ if ($form.valid() === false) { return; }
9
+
10
+ event.preventDefault();
11
+
12
+ $.ajax({
13
+ url: $form.attr('action'),
14
+ type: $form.attr('method'),
15
+ data: $form.serialize()
16
+ }).done(_.partial(WORKAREA.dialog.closeClosest, $form));
17
+ },
18
+
19
+ formNotInDialog = function ($form) {
20
+ return _.isEmpty($form.closest('.ui-dialog'));
21
+ },
22
+
23
+ /**
24
+ * @method
25
+ * @name init
26
+ * @memberof WORKAREA.productReviewAjaxSubmit
27
+ */
28
+ init = function ($scope) {
29
+ var $form = $('[data-product-review-ajax-submit]', $scope);
30
+
31
+ if (formNotInDialog($form)) { return; }
32
+
33
+ $form.on('submit', _.partial(submitForm, $form));
34
+ };
35
+
36
+ return {
37
+ init: init
38
+ };
39
+ }()));
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @namespace WORKAREA.productReviewsSortMenus
3
+ */
4
+ WORKAREA.registerModule('productReviewsSortMenus', (function () {
5
+ 'use strict';
6
+
7
+ var insertSortSelectBox = function (index, section) {
8
+ $('.reviews__header', section).after(
9
+ JST['workarea/storefront/reviews/templates/sort_by_property']()
10
+ );
11
+ },
12
+
13
+ sortNewToOld = function ($reviews) {
14
+ return _.sortBy($reviews, function (review) {
15
+ return -($(review).data('productReviewSectionEntry').createdAt);
16
+ });
17
+ },
18
+
19
+ sortOldToNew = function ($reviews) {
20
+ return _.sortBy($reviews, function (review) {
21
+ return $(review).data('productReviewSectionEntry').createdAt;
22
+ });
23
+ },
24
+
25
+
26
+ sortHighToLow = function ($reviews) {
27
+ return _.sortBy($reviews, function (review) {
28
+ return -($(review).data('productReviewSectionEntry').rating);
29
+ });
30
+ },
31
+
32
+ sortLowToHigh = function ($reviews) {
33
+ return _.sortBy($reviews, function (review) {
34
+ return $(review).data('productReviewSectionEntry').rating;
35
+ });
36
+ },
37
+
38
+ handleSortSelectChange = function (event) {
39
+ var $reviews = $(
40
+ '[data-product-review-section-entry]', event.delegateTarget
41
+ ),
42
+
43
+ action = $(event.currentTarget).val(),
44
+
45
+ actions = {
46
+ oldest: function () {
47
+ return sortOldToNew($reviews);
48
+ },
49
+ newest: function () {
50
+ return sortNewToOld($reviews);
51
+ },
52
+ lowest: function () {
53
+ return sortLowToHigh($reviews);
54
+ },
55
+ highest: function () {
56
+ return sortHighToLow($reviews);
57
+ }
58
+ };
59
+
60
+ $('.reviews__review-group', event.delegateTarget)
61
+ .html(actions[action]());
62
+ },
63
+
64
+ /**
65
+ * @method
66
+ * @name init
67
+ * @memberof WORKAREA.productReviewsSortMenus
68
+ */
69
+ init = function ($scope) {
70
+ $('.reviews', $scope)
71
+ .each(insertSortSelectBox)
72
+ .on(
73
+ 'change',
74
+ '[data-product-reviews-sort-menu]',
75
+ handleSortSelectChange
76
+ );
77
+ };
78
+
79
+ return {
80
+ init: init
81
+ };
82
+ }()));
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @namespace WORKAREA.ratingButtons
3
+ */
4
+ WORKAREA.registerModule('ratingButtons', (function () {
5
+ 'use strict';
6
+
7
+ var activateLabels = function (radioButton, originalIndex, $scope) {
8
+ var $allButtons = getAllRatingButtons($(document)),
9
+
10
+ updateState = function (index, button) {
11
+ var $label = getAssociatedLabel(button, $scope);
12
+
13
+ $label.removeClass('write-review__star--hovered write-review__star--active');
14
+
15
+ if ($label.data('index') <= originalIndex) {
16
+ $label.addClass('write-review__star--active');
17
+ }
18
+ };
19
+
20
+ if ($(radioButton).is(':checked')) {
21
+ $allButtons.each(updateState);
22
+ }
23
+ },
24
+
25
+ getAllRatingButtons = function ($scope) {
26
+ return $('[data-rating-button]', $scope);
27
+ },
28
+
29
+ getAssociatedLabel = function (button, $scope) {
30
+ return $('label[for=' + $(button).attr('id') + ']', $scope);
31
+ },
32
+
33
+ removeHoverClass = function ($label) {
34
+ $label.removeClass('write-review__star--hovered');
35
+ },
36
+
37
+ addHoverClass = function ($label) {
38
+ $label.addClass('write-review__star--hovered');
39
+ },
40
+
41
+ removeHoverStateFromLabel = function ($scope) {
42
+ var $buttons = getAllRatingButtons($scope),
43
+
44
+ removeState = function (index, button) {
45
+ var $label = getAssociatedLabel(button, $scope);
46
+
47
+ removeHoverClass($label);
48
+ };
49
+
50
+ $buttons.each(removeState);
51
+ },
52
+
53
+ addHoverStateToLabels = function ($scope, originalIndex) {
54
+ var $buttons = getAllRatingButtons($scope),
55
+
56
+ addState = function (index, button) {
57
+ var $label = getAssociatedLabel(button, $scope);
58
+
59
+ if ($label.data('index') <= originalIndex) {
60
+ addHoverClass($label);
61
+ }
62
+ };
63
+
64
+ $buttons.each(addState);
65
+ },
66
+
67
+ setupLabels = function ($scope, index, button) {
68
+ var $label = getAssociatedLabel(button, $scope),
69
+ labelTitle = $('.write-review__star-text', $label).text();
70
+
71
+ /**
72
+ * 1. per http://www.workarea.com/labs/touching-on-html-labels/
73
+ */
74
+
75
+ $label
76
+ .attr('title', labelTitle)
77
+ .data('index', index)
78
+ .on('click', $.noop) /* [1] */
79
+ .on('mouseenter', _.partial(addHoverStateToLabels, $scope, index))
80
+ .on('mouseleave', _.partial(removeHoverStateFromLabel, $scope));
81
+
82
+ activateLabels(button, index, $scope);
83
+
84
+ $(button)
85
+ .on('click', _.partial(activateLabels, button, index, $scope))
86
+ .on('focus', _.partial(addHoverClass, $label))
87
+ .on('blur', _.partial(removeHoverClass, $label));
88
+ },
89
+
90
+ /**
91
+ * @method
92
+ * @name init
93
+ * @memberof WORKAREA.ratingButtons
94
+ */
95
+ init = function ($scope) {
96
+ $('[data-rating-button]', $scope)
97
+ .each(_.partial(setupLabels, $scope));
98
+ };
99
+
100
+ return {
101
+ init: init
102
+ };
103
+ }()));