solidus_backend 2.2.2 → 2.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_backend might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree/backend.js +1 -2
- data/app/assets/javascripts/spree/backend/address_states.js +1 -1
- data/app/assets/javascripts/spree/backend/adjustments.js.coffee +1 -1
- data/app/assets/javascripts/spree/backend/admin.js +37 -41
- data/app/assets/javascripts/spree/backend/components/editable_table.js.coffee +3 -0
- data/app/assets/javascripts/spree/backend/images/index.js.coffee +1 -1
- data/app/assets/javascripts/spree/backend/images/upload.js +13 -189
- data/app/assets/javascripts/spree/backend/models/image_upload.js +76 -0
- data/app/assets/javascripts/spree/backend/models/index.js +2 -0
- data/app/assets/javascripts/spree/backend/models/taxonomy.js +3 -0
- data/app/assets/javascripts/spree/backend/namespaces.js +3 -1
- data/app/assets/javascripts/spree/backend/payments/new.js +8 -36
- data/app/assets/javascripts/spree/backend/promotions.js.coffee +1 -1
- data/app/assets/javascripts/spree/backend/select_payments.js.coffee +0 -12
- data/app/assets/javascripts/spree/backend/shipments.js +1 -1
- data/app/assets/javascripts/spree/backend/spree-select2.js +1 -1
- data/app/assets/javascripts/spree/backend/taxonomy.js.coffee +101 -95
- data/app/assets/javascripts/spree/backend/templates/products/upload_progress.hbs +5 -3
- data/app/assets/javascripts/spree/backend/views/images/upload_progress.js +48 -0
- data/app/assets/javascripts/spree/backend/views/images/upload_zone.js +39 -0
- data/app/assets/javascripts/spree/backend/views/index.js +6 -0
- data/app/assets/javascripts/spree/backend/views/order/address.js +1 -5
- data/app/assets/javascripts/spree/backend/views/payment/edit_credit_card.js +23 -0
- data/app/assets/javascripts/spree/backend/views/payment/new.js +25 -0
- data/app/assets/javascripts/spree/backend/views/state_select.js +4 -4
- data/app/assets/javascripts/spree/backend/views/tables/editable_table.js.coffee +14 -0
- data/app/assets/javascripts/spree/backend/views/tables/editable_table_row.js.coffee +45 -0
- data/app/assets/stylesheets/spree/backend/components/_date-picker.scss +0 -1
- data/app/assets/stylesheets/spree/backend/components/_editable_table.scss +37 -0
- data/app/assets/stylesheets/spree/backend/plugins/_bootstrap_tooltip.scss +2 -2
- data/app/assets/stylesheets/spree/backend/sections/_products.scss +0 -8
- data/app/assets/stylesheets/spree/backend/sections/_style_guide.scss +15 -9
- data/app/assets/stylesheets/spree/backend/shared/_icons.scss +14 -14
- data/app/assets/stylesheets/spree/backend/shared/_tables.scss +1 -2
- data/app/assets/stylesheets/spree/backend/shared/_utilities.scss +13 -0
- data/app/assets/stylesheets/spree/backend/spree_admin.scss +1 -1
- data/app/controllers/spree/admin/cancellations_controller.rb +1 -1
- data/app/controllers/spree/admin/orders/customer_details_controller.rb +1 -1
- data/app/controllers/spree/admin/orders_controller.rb +3 -10
- data/app/controllers/spree/admin/payment_methods_controller.rb +19 -6
- data/app/controllers/spree/admin/payments_controller.rb +2 -2
- data/app/controllers/spree/admin/products_controller.rb +3 -9
- data/app/controllers/spree/admin/promotion_rules_controller.rb +5 -1
- data/app/controllers/spree/admin/promotions_controller.rb +1 -1
- data/app/controllers/spree/admin/properties_controller.rb +1 -1
- data/app/controllers/spree/admin/reports_controller.rb +24 -21
- data/app/controllers/spree/admin/resource_controller.rb +25 -14
- data/app/controllers/spree/admin/style_guide_controller.rb +4 -0
- data/app/controllers/spree/admin/users_controller.rb +1 -1
- data/app/controllers/spree/admin/variants_controller.rb +5 -0
- data/app/helpers/spree/admin/navigation_helper.rb +6 -2
- data/app/helpers/spree/promotion_rules_helper.rb +2 -2
- data/app/models/spree/backend_configuration.rb +1 -0
- data/app/views/spree/admin/adjustments/_form.html.erb +1 -1
- data/app/views/spree/admin/customer_returns/_return_item_selection.html.erb +2 -2
- data/app/views/spree/admin/customer_returns/new.html.erb +1 -1
- data/app/views/spree/admin/images/_form.html.erb +1 -1
- data/app/views/spree/admin/images/_image_row.html.erb +22 -4
- data/app/views/spree/admin/images/create.js.erb +8 -5
- data/app/views/spree/admin/images/index.html.erb +4 -8
- data/app/views/spree/admin/orders/_risk_analysis.html.erb +6 -7
- data/app/views/spree/admin/orders/_shipment.html.erb +1 -1
- data/app/views/spree/admin/orders/confirm/_customer_details.html.erb +1 -1
- data/app/views/spree/admin/orders/confirm/_payments.html.erb +1 -1
- data/app/views/spree/admin/orders/index.html.erb +3 -3
- data/app/views/spree/admin/payment_methods/_form.html.erb +5 -5
- data/app/views/spree/admin/payments/_form.html.erb +2 -2
- data/app/views/spree/admin/payments/_list.html.erb +1 -1
- data/app/views/spree/admin/payments/show.html.erb +1 -1
- data/app/views/spree/admin/payments/source_forms/_gateway.html.erb +2 -7
- data/app/views/spree/admin/prices/_form.html.erb +2 -2
- data/app/views/spree/admin/prices/edit.html.erb +2 -0
- data/app/views/spree/admin/prices/index.html.erb +5 -4
- data/app/views/spree/admin/prices/new.html.erb +4 -0
- data/app/views/spree/admin/product_properties/index.html.erb +1 -1
- data/app/views/spree/admin/products/_form.html.erb +4 -3
- data/app/views/spree/admin/products/index.html.erb +3 -3
- data/app/views/spree/admin/products/new.html.erb +2 -2
- data/app/views/spree/admin/products/new.js.erb +0 -3
- data/app/views/spree/admin/promotion_actions/create.js.erb +2 -6
- data/app/views/spree/admin/promotion_rules/create.js.erb +0 -8
- data/app/views/spree/admin/promotions/_actions.html.erb +2 -2
- data/app/views/spree/admin/promotions/_form.html.erb +1 -1
- data/app/views/spree/admin/promotions/_promotion_action.html.erb +3 -4
- data/app/views/spree/admin/promotions/_promotion_rule.html.erb +3 -3
- data/app/views/spree/admin/promotions/_rules.html.erb +1 -1
- data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +6 -2
- data/app/views/spree/admin/promotions/actions/_promotion_calculators_with_custom_fields.html.erb +1 -1
- data/app/views/spree/admin/promotions/calculators/distributed_amount/_fields.html.erb +54 -0
- data/app/views/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb +33 -14
- data/app/views/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb +33 -14
- data/app/views/spree/admin/promotions/index.html.erb +1 -1
- data/app/views/spree/admin/promotions/rules/_first_repeat_purchase_since.html.erb +1 -1
- data/app/views/spree/admin/promotions/rules/_item_total.html.erb +1 -1
- data/app/views/spree/admin/promotions/rules/_landing_page.html.erb +1 -1
- data/app/views/spree/admin/promotions/rules/_nth_order.html.erb +1 -1
- data/app/views/spree/admin/promotions/rules/_product.html.erb +1 -1
- data/app/views/spree/admin/promotions/rules/_taxon.html.erb +1 -1
- data/app/views/spree/admin/promotions/rules/_user_role.html.erb +2 -2
- data/app/views/spree/admin/refunds/edit.html.erb +1 -1
- data/app/views/spree/admin/refunds/new.html.erb +1 -1
- data/app/views/spree/admin/reimbursements/edit.html.erb +2 -2
- data/app/views/spree/admin/reports/sales_total.html.erb +1 -1
- data/app/views/spree/admin/return_authorizations/_form.html.erb +4 -4
- data/app/views/spree/admin/shared/_address_form.html.erb +2 -2
- data/app/views/spree/admin/shared/_calculator_fields.html.erb +1 -1
- data/app/views/spree/admin/shared/_product_tabs.html.erb +4 -4
- data/app/views/spree/admin/shared/_report_order_criteria.html.erb +1 -1
- data/app/views/spree/admin/shared/_variant_search.html.erb +1 -1
- data/app/views/spree/admin/shipping_methods/_form.html.erb +1 -1
- data/app/views/spree/admin/states/index.html.erb +1 -1
- data/app/views/spree/admin/stock_items/_stock_management.html.erb +1 -1
- data/app/views/spree/admin/stock_locations/_form.html.erb +1 -1
- data/app/views/spree/admin/stock_transfers/edit.html.erb +1 -1
- data/app/views/spree/admin/stock_transfers/index.html.erb +1 -1
- data/app/views/spree/admin/stock_transfers/new.html.erb +1 -1
- data/app/views/spree/admin/store_credits/_form.html.erb +1 -1
- data/app/views/spree/admin/store_credits/_update_reason_field.html.erb +1 -1
- data/app/views/spree/admin/stores/_form.html.erb +1 -1
- data/app/views/spree/admin/style_guide/topics/forms/_building_forms.html.erb +4 -8
- data/app/views/spree/admin/style_guide/topics/forms/_buttons.html.erb +6 -0
- data/app/views/spree/admin/style_guide/topics/forms/_helper_text.html.erb +13 -0
- data/app/views/spree/admin/style_guide/topics/forms/_inputs.html.erb +96 -0
- data/app/views/spree/admin/style_guide/topics/forms/_labels.html.erb +6 -0
- data/app/views/spree/admin/style_guide/topics/forms/_validation.html.erb +8 -1
- data/app/views/spree/admin/style_guide/topics/layout/_full_width_table_layout.html.erb +10 -0
- data/app/views/spree/admin/style_guide/topics/layout/_helpful_layout.html.erb +0 -0
- data/app/views/spree/admin/style_guide/topics/layout/_sidebar_layout.html.erb +4 -0
- data/app/views/spree/admin/style_guide/topics/messaging/_flashes.html.erb +10 -4
- data/app/views/spree/admin/style_guide/topics/messaging/_tooltips.html.erb +45 -0
- data/app/views/spree/admin/style_guide/topics/tables/_forms_in_tables.html.erb +4 -0
- data/app/views/spree/admin/style_guide/topics/typography/_lists.html.erb +1 -1
- data/app/views/spree/admin/tax_rates/_form.html.erb +17 -3
- data/app/views/spree/admin/tax_rates/index.html.erb +12 -3
- data/app/views/spree/admin/taxonomies/edit.erb +1 -8
- data/app/views/spree/admin/taxons/_form.html.erb +6 -4
- data/app/views/spree/admin/taxons/edit.html.erb +0 -15
- data/app/views/spree/admin/taxons/index.html.erb +1 -1
- data/app/views/spree/admin/variants/_form.html.erb +8 -9
- data/app/views/spree/admin/variants/new.js.erb +0 -1
- data/config/routes.rb +1 -1
- data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +1 -1
- data/spec/controllers/spree/admin/orders_controller_spec.rb +16 -4
- data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +2 -2
- data/spec/controllers/spree/admin/payments_controller_spec.rb +1 -1
- data/spec/controllers/spree/admin/products_controller_spec.rb +33 -0
- data/spec/controllers/spree/admin/variants_controller_spec.rb +39 -13
- data/spec/features/admin/configuration/payment_methods_spec.rb +11 -11
- data/spec/features/admin/configuration/shipping_methods_spec.rb +1 -1
- data/spec/features/admin/configuration/states_spec.rb +4 -4
- data/spec/features/admin/configuration/store_spec.rb +3 -3
- data/spec/features/admin/configuration/tax_rates_spec.rb +1 -1
- data/spec/features/admin/orders/adjustments_spec.rb +1 -1
- data/spec/features/admin/orders/customer_details_spec.rb +10 -11
- data/spec/features/admin/orders/listing_spec.rb +1 -1
- data/spec/features/admin/orders/new_order_spec.rb +4 -11
- data/spec/features/admin/orders/order_details_spec.rb +20 -30
- data/spec/features/admin/orders/return_payment_state_spec.rb +60 -0
- data/spec/features/admin/orders/shipments_spec.rb +7 -0
- data/spec/features/admin/products/edit/images_spec.rb +48 -9
- data/spec/features/admin/products/edit/variants_spec.rb +1 -1
- data/spec/features/admin/products/option_types_spec.rb +2 -2
- data/spec/features/admin/products/products_spec.rb +49 -3
- data/spec/features/admin/products/stock_management_spec.rb +1 -3
- data/spec/features/admin/products/variant_spec.rb +20 -0
- data/spec/features/admin/promotion_adjustments_spec.rb +35 -34
- data/spec/features/admin/promotions/option_value_rule_spec.rb +2 -2
- data/spec/features/admin/promotions/product_rule_spec.rb +1 -1
- data/spec/features/admin/promotions/tiered_calculator_spec.rb +2 -2
- data/spec/features/admin/promotions/user_rule_spec.rb +2 -2
- data/spec/features/admin/stock_transfer_spec.rb +11 -8
- data/spec/helpers/admin/navigation_helper_spec.rb +23 -0
- metadata +26 -18
- data/app/assets/javascripts/spree/backend/images/new.js.coffee +0 -7
- data/app/assets/stylesheets/spree/backend/sections/_payments.scss +0 -14
- data/app/helpers/spree/admin/images_helper.rb +0 -17
- data/app/views/spree/admin/orders/_add_line_item.html.erb +0 -15
- data/app/views/spree/admin/prices/new.js.erb +0 -2
- data/app/views/spree/admin/products/_properties_form.erb +0 -10
- data/app/views/spree/admin/promotions/_tab.html.erb +0 -1
- data/app/views/spree/admin/shared/_report_criteria.html.erb +0 -17
- data/app/views/spree/admin/states/_new.html.erb +0 -7
- data/app/views/spree/admin/stock_locations/_transfer_stock_form.html.erb +0 -38
- data/app/views/spree/admin/stock_transfers/_stock_movements.html.erb +0 -27
- data/app/views/spree/admin/taxons/_taxon_table.html.erb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cebe06f697d76eeeeb4f0127598a92a3bac822e1
|
4
|
+
data.tar.gz: f6d8aadac696b01eddbe0eeeb20ebc350b086991
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d66d74dc75f5cd2c9f9cc2e793896e7a938ec3549f4a0d2e92096a8f36041a943a19a10e8c776af35691f33cc325a13d6d50c04a7da8e5842ba53a33ee6638f0
|
7
|
+
data.tar.gz: bd40e9bf6e7e06f667970d34cbb7389b320b0752a68fc7d112acfec8d8d959253eac2fa555e55218aa83e8564a58a4664092fb468dc33111e10746e3fbb89078
|
@@ -32,11 +32,11 @@
|
|
32
32
|
//= require spree/backend/components/number_with_currency
|
33
33
|
//= require spree/backend/components/tabs
|
34
34
|
//= require spree/backend/components/tooltips
|
35
|
+
//= require spree/backend/components/editable_table
|
35
36
|
//= require spree/backend/flash
|
36
37
|
//= require spree/backend/gateway
|
37
38
|
//= require spree/backend/handlebars_extensions
|
38
39
|
//= require spree/backend/images/index
|
39
|
-
//= require spree/backend/images/new
|
40
40
|
//= require spree/backend/images/upload
|
41
41
|
//= require spree/backend/navigation
|
42
42
|
//= require spree/backend/number_field_updater
|
@@ -51,7 +51,6 @@
|
|
51
51
|
//= require spree/backend/promotions/activation
|
52
52
|
//= require spree/backend/returns/return_item_selection
|
53
53
|
//= require spree/backend/routes
|
54
|
-
//= require spree/backend/select_payments
|
55
54
|
//= require spree/backend/shipments
|
56
55
|
//= require spree/backend/spree-select2
|
57
56
|
//= require spree/backend/states
|
@@ -1,7 +1,7 @@
|
|
1
1
|
window.update_state = function (region, done) {
|
2
2
|
'use strict';
|
3
3
|
|
4
|
-
var country = $('span#' + region + 'country .select2').select2('val');
|
4
|
+
var country = $('span#' + region + 'country select.select2').select2('val');
|
5
5
|
var state_select = $('span#' + region + 'state select.select2');
|
6
6
|
var state_input = $('span#' + region + 'state input.state_name');
|
7
7
|
|
@@ -14,7 +14,7 @@ under the spree namespace that do stuff we find helpful.
|
|
14
14
|
Hopefully, this will evolve into a propper class.
|
15
15
|
**/
|
16
16
|
|
17
|
-
|
17
|
+
Spree.ready(function() {
|
18
18
|
// Highlight hovered table column
|
19
19
|
$('table').on("mouseenter", 'td.actions a, td.actions button', function(){
|
20
20
|
var tr = $(this).closest('tr');
|
@@ -159,48 +159,44 @@ $(document).ready(function(){
|
|
159
159
|
return ui;
|
160
160
|
};
|
161
161
|
|
162
|
-
$(
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
positions['positions['+objId+']'] = position+1;
|
179
|
-
}
|
180
|
-
}
|
181
|
-
});
|
182
|
-
Spree.ajax({
|
183
|
-
type: 'POST',
|
184
|
-
dataType: 'script',
|
185
|
-
url: tableEl.data("sortable-link"),
|
186
|
-
data: positions,
|
187
|
-
success: function(data){ $("#progress").hide(); }
|
188
|
-
});
|
189
|
-
},
|
190
|
-
start: function (event, ui) {
|
191
|
-
// Set correct height for placehoder (from dragged tr)
|
192
|
-
ui.placeholder.height(ui.item.height())
|
193
|
-
// Fix placeholder content to make it correct width
|
194
|
-
ui.placeholder.html("<td colspan='"+(td_count-1)+"'></td><td class='actions'></td>")
|
195
|
-
},
|
196
|
-
stop: function (event, ui) {
|
197
|
-
var tableEl = $(ui.item).closest("table.sortable")
|
198
|
-
// Fix odd/even classes after reorder
|
199
|
-
tableEl.find("tr:even").removeClass("odd even").addClass("even");
|
200
|
-
tableEl.find("tr:odd").removeClass("odd even").addClass("odd");
|
162
|
+
var td_count = $(this).find('tbody tr:first-child td').length
|
163
|
+
$('table.sortable tbody').sortable({
|
164
|
+
handle: '.handle',
|
165
|
+
helper: fixHelper,
|
166
|
+
placeholder: 'ui-sortable-placeholder',
|
167
|
+
update: function(event, ui) {
|
168
|
+
$("#progress").show();
|
169
|
+
var tableEl = $(ui.item).closest("table.sortable")
|
170
|
+
var positions = {};
|
171
|
+
$.each(tableEl.find('tbody tr'), function(position, obj){
|
172
|
+
var idAttr = $(obj).prop('id');
|
173
|
+
if (idAttr) {
|
174
|
+
var objId = idAttr.split('_').slice(-1);
|
175
|
+
if (!isNaN(objId)) {
|
176
|
+
positions['positions['+objId+']'] = position+1;
|
177
|
+
}
|
201
178
|
}
|
202
|
-
|
203
179
|
});
|
180
|
+
Spree.ajax({
|
181
|
+
type: 'POST',
|
182
|
+
dataType: 'script',
|
183
|
+
url: tableEl.data("sortable-link"),
|
184
|
+
data: positions,
|
185
|
+
success: function(data){ $("#progress").hide(); }
|
186
|
+
});
|
187
|
+
},
|
188
|
+
start: function (event, ui) {
|
189
|
+
// Set correct height for placehoder (from dragged tr)
|
190
|
+
ui.placeholder.height(ui.item.height())
|
191
|
+
// Fix placeholder content to make it correct width
|
192
|
+
ui.placeholder.html("<td colspan='"+(td_count-1)+"'></td><td class='actions'></td>")
|
193
|
+
},
|
194
|
+
stop: function (event, ui) {
|
195
|
+
var tableEl = $(ui.item).closest("table.sortable")
|
196
|
+
// Fix odd/even classes after reorder
|
197
|
+
tableEl.find("tr:even").removeClass("odd even").addClass("even");
|
198
|
+
tableEl.find("tr:odd").removeClass("odd even").addClass("odd");
|
199
|
+
}
|
204
200
|
});
|
205
201
|
|
206
202
|
window.Spree.advanceOrder = function() {
|
@@ -3,199 +3,23 @@ Spree.prepareImageUploader = function () {
|
|
3
3
|
var uploadZone = document.getElementById('upload-zone');
|
4
4
|
if(!uploadZone) return;
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
"dragover" : "onDragOver",
|
11
|
-
"dragleave" : "onDragLeave",
|
12
|
-
"drop" : "onDrop",
|
13
|
-
'change input[type="file"]' : "onFileBrowserSelect"
|
14
|
-
},
|
15
|
-
|
16
|
-
progressZone: document.getElementById('progress-zone'),
|
17
|
-
|
18
|
-
// Hide or highlight supported browser features
|
19
|
-
initialize: function() {
|
20
|
-
"filereader formdata progress".split(' ').forEach(function (api) {
|
21
|
-
this.support[api].className = (this.tests[api] === false) ? 'red' : 'hidden'
|
22
|
-
}, this);
|
23
|
-
},
|
24
|
-
|
25
|
-
upload: function(file) {
|
26
|
-
if (!FormData) return;
|
27
|
-
|
28
|
-
var progressModel = new ProgressModel({file: file});
|
29
|
-
progressModel.previewFile();
|
30
|
-
progressModel.uploadFile();
|
31
|
-
|
32
|
-
var progressView = new ProgressView({model: progressModel});
|
33
|
-
this.progressZone.appendChild(progressView.render().el);
|
34
|
-
},
|
35
|
-
|
36
|
-
dragClass: 'with-images',
|
37
|
-
|
38
|
-
onDragOver: function(e) {
|
39
|
-
this.el.classList.add(this.dragClass);
|
40
|
-
e.preventDefault();
|
41
|
-
},
|
42
|
-
|
43
|
-
onDragLeave: function() {
|
44
|
-
this.el.classList.remove(this.dragClass);
|
45
|
-
},
|
46
|
-
|
47
|
-
onDrop: function(e) {
|
48
|
-
this.el.classList.remove(this.dragClass);
|
49
|
-
e.preventDefault();
|
50
|
-
|
51
|
-
_.each(e.originalEvent.dataTransfer.files, this.upload, this);
|
52
|
-
},
|
53
|
-
|
54
|
-
onFileBrowserSelect: function(e) {
|
55
|
-
_.each(e.target.files, this.upload, this);
|
56
|
-
},
|
57
|
-
|
58
|
-
tests: {
|
59
|
-
filereader: typeof FileReader != 'undefined',
|
60
|
-
dnd: 'draggable' in document.createElement('span'),
|
61
|
-
formdata: !!window.FormData,
|
62
|
-
progress: "upload" in new XMLHttpRequest
|
63
|
-
},
|
6
|
+
// Kick off by binding the events on the upload zone
|
7
|
+
var imageUploads = new Backbone.Collection();
|
8
|
+
var progressZone = document.getElementById('progress-zone');
|
9
|
+
var variantId = document.querySelector('input[name="image[viewable_id]"]').value;
|
64
10
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
progress: document.getElementById('progress')
|
69
|
-
}
|
11
|
+
new Spree.Views.Images.UploadZone({
|
12
|
+
el: uploadZone,
|
13
|
+
collection: imageUploads
|
70
14
|
});
|
71
15
|
|
72
|
-
|
73
|
-
|
74
|
-
this.set({summary: this.get("file").name});
|
75
|
-
},
|
76
|
-
|
77
|
-
defaults: function() {
|
78
|
-
return {
|
79
|
-
file: null,
|
80
|
-
imgSrc: '',
|
81
|
-
progress: 0,
|
82
|
-
serverError: false,
|
83
|
-
summary: ''
|
84
|
-
}
|
85
|
-
},
|
86
|
-
|
87
|
-
acceptedTypes: {
|
88
|
-
'image/png': true,
|
89
|
-
'image/jpeg': true,
|
90
|
-
'image/gif': true
|
91
|
-
},
|
92
|
-
|
93
|
-
variantId: document.querySelector('input[name="image[viewable_id]"]').value,
|
94
|
-
|
95
|
-
previewFile: function () {
|
96
|
-
var file = this.get('file'),
|
97
|
-
that = this;
|
16
|
+
imageUploads.on('add', function(progressModel) {
|
17
|
+
progressModel.set({variant_id: variantId});
|
98
18
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
};
|
104
|
-
|
105
|
-
reader.readAsDataURL(file);
|
106
|
-
} else {
|
107
|
-
var summary = 'Uploading ' + file.name + ' ' + (file.size ? (file.size/1024|0) + 'K' : '');
|
108
|
-
this.set({summary: summary});
|
109
|
-
}
|
110
|
-
},
|
111
|
-
|
112
|
-
uploadFile: function () {
|
113
|
-
var formData = new FormData(),
|
114
|
-
that = this;
|
115
|
-
|
116
|
-
formData.append('image[attachment]', this.get('file'));
|
117
|
-
formData.append('image[viewable_id]', this.variantId);
|
118
|
-
formData.append('upload_id', this.cid);
|
119
|
-
|
120
|
-
// send the image to the server
|
121
|
-
Spree.ajax({
|
122
|
-
url: window.location.pathname,
|
123
|
-
type: "POST",
|
124
|
-
dataType: 'script',
|
125
|
-
data: formData,
|
126
|
-
processData: false, // tell jQuery not to process the data
|
127
|
-
contentType: false, // tell jQuery not to set contentType
|
128
|
-
xhr: function () {
|
129
|
-
var xhr = $.ajaxSettings.xhr();
|
130
|
-
if (xhr.upload) {
|
131
|
-
xhr.upload.onprogress = function (event) {
|
132
|
-
if (event.lengthComputable) {
|
133
|
-
var complete = (event.loaded / event.total * 100 | 0);
|
134
|
-
that.set({progress: complete})
|
135
|
-
}
|
136
|
-
};
|
137
|
-
}
|
138
|
-
return xhr;
|
139
|
-
}
|
140
|
-
}).done(function() {
|
141
|
-
that.set({progress: 100})
|
142
|
-
}).error(function(jqXHR, textStatus, errorThrown) {
|
143
|
-
that.set({serverError: true});
|
144
|
-
});
|
145
|
-
}
|
146
|
-
}); // end ProgressModel
|
147
|
-
|
148
|
-
|
149
|
-
var ProgressView = Backbone.View.extend({
|
150
|
-
tagName: "div",
|
151
|
-
|
152
|
-
// Cache the template function for a single item.
|
153
|
-
template: HandlebarsTemplates["products/upload_progress"],
|
154
|
-
|
155
|
-
initialize: function() {
|
156
|
-
this.listenTo(this.model, 'change:progress', this.updateProgressBar);
|
157
|
-
this.listenTo(this.model, 'change', this.render);
|
158
|
-
this.listenTo(this.model, 'destroy', this.remove);
|
159
|
-
},
|
160
|
-
|
161
|
-
events: {
|
162
|
-
"clear" : "clear"
|
163
|
-
},
|
164
|
-
|
165
|
-
className: 'col-sm-6 col-md-4 margin-bottom-one',
|
166
|
-
|
167
|
-
attributes: function() {
|
168
|
-
return {
|
169
|
-
"data-upload-id": this.model.cid
|
170
|
-
}
|
171
|
-
},
|
172
|
-
|
173
|
-
render: function() {
|
174
|
-
// Skip progress bar update for better performance
|
175
|
-
var changedAttrs = Object.keys(this.model.changed);
|
176
|
-
if(changedAttrs.length === 1 && changedAttrs[0] == 'progress') return this;
|
177
|
-
|
178
|
-
this.el.innerHTML = this.template(this.model.attributes);
|
179
|
-
return this;
|
180
|
-
},
|
181
|
-
|
182
|
-
updateProgressBar: function() {
|
183
|
-
var progressBar = this.el.querySelector('progress');
|
184
|
-
progressBar.value = progressBar.innerHTML = this.model.get('progress');
|
185
|
-
return this;
|
186
|
-
},
|
187
|
-
|
188
|
-
// Remove the item, destroy the model
|
189
|
-
clear: function() {
|
190
|
-
this.model.destroy();
|
191
|
-
}
|
192
|
-
}); // end ProgressView
|
193
|
-
|
194
|
-
|
195
|
-
// Kick off by binding the events on the upload zone
|
196
|
-
new UploadZone();
|
197
|
-
|
198
|
-
}; // end prepareImageUploader
|
19
|
+
var progressView = new Spree.Views.Images.UploadProgress({model: progressModel});
|
20
|
+
progressZone.appendChild(progressView.render().el);
|
21
|
+
});
|
22
|
+
};
|
199
23
|
|
200
24
|
|
201
25
|
Spree.ready(function () {
|
@@ -0,0 +1,76 @@
|
|
1
|
+
Spree.Models.ImageUpload = Backbone.Model.extend({
|
2
|
+
initialize: function() {
|
3
|
+
var file = this.get("file");
|
4
|
+
this.set({
|
5
|
+
filename: file.name,
|
6
|
+
size: file.size ? (file.size/1024|0) + 'K' : ''
|
7
|
+
});
|
8
|
+
},
|
9
|
+
|
10
|
+
defaults: function() {
|
11
|
+
return {
|
12
|
+
file: null,
|
13
|
+
imgSrc: '',
|
14
|
+
progress: 0,
|
15
|
+
serverError: false,
|
16
|
+
filename: '',
|
17
|
+
size: ''
|
18
|
+
}
|
19
|
+
},
|
20
|
+
|
21
|
+
acceptedTypes: {
|
22
|
+
'image/png': true,
|
23
|
+
'image/jpeg': true,
|
24
|
+
'image/gif': true
|
25
|
+
},
|
26
|
+
|
27
|
+
|
28
|
+
previewFile: function () {
|
29
|
+
var file = this.get('file'),
|
30
|
+
that = this;
|
31
|
+
|
32
|
+
if (FileReader && this.acceptedTypes[file.type] === true) {
|
33
|
+
var reader = new FileReader();
|
34
|
+
reader.onload = function (event) {
|
35
|
+
that.set({imgSrc: event.target.result});
|
36
|
+
};
|
37
|
+
|
38
|
+
reader.readAsDataURL(file);
|
39
|
+
}
|
40
|
+
},
|
41
|
+
|
42
|
+
uploadFile: function () {
|
43
|
+
var formData = new FormData(),
|
44
|
+
that = this;
|
45
|
+
|
46
|
+
formData.append('image[attachment]', this.get('file'));
|
47
|
+
formData.append('image[viewable_id]', this.get('variant_id'));
|
48
|
+
formData.append('upload_id', this.cid);
|
49
|
+
|
50
|
+
// send the image to the server
|
51
|
+
Spree.ajax({
|
52
|
+
url: window.location.pathname,
|
53
|
+
type: "POST",
|
54
|
+
dataType: 'script',
|
55
|
+
data: formData,
|
56
|
+
processData: false, // tell jQuery not to process the data
|
57
|
+
contentType: false, // tell jQuery not to set contentType
|
58
|
+
xhr: function () {
|
59
|
+
var xhr = $.ajaxSettings.xhr();
|
60
|
+
if (xhr.upload) {
|
61
|
+
xhr.upload.onprogress = function (event) {
|
62
|
+
if (event.lengthComputable) {
|
63
|
+
var complete = (event.loaded / event.total * 100 | 0);
|
64
|
+
that.set({progress: complete})
|
65
|
+
}
|
66
|
+
};
|
67
|
+
}
|
68
|
+
return xhr;
|
69
|
+
}
|
70
|
+
}).done(function() {
|
71
|
+
that.set({progress: 100})
|
72
|
+
}).error(function(jqXHR, textStatus, errorThrown) {
|
73
|
+
that.set({serverError: true});
|
74
|
+
});
|
75
|
+
}
|
76
|
+
});
|