Skip to content

Commit

Permalink
Merge pull request #1764 from jhawthorn/handlebars_image_partial
Browse files Browse the repository at this point in the history
Add image partial to handlebars
  • Loading branch information
jhawthorn authored Mar 15, 2017
2 parents 3c1c9e8 + 10508c1 commit 1412e87
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 35 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//= require handlebars
//= require spree/backend/translation

Handlebars.registerHelper("t", function(key, options) {
return Spree.t(key, options.hash);
});

Handlebars.registerHelper("human_attribute_name", function(model, attr) {
return Spree.human_attribute_name(model, attr);
});

Handlebars.registerHelper("admin_url", function() {
return Spree.pathFor("admin")
});

Handlebars.registerHelper("concat", function() {
return Array.prototype.slice.call(arguments, 0, -1).join('');
});
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class VariantForm
variantId: transferItem.variant.id
variantDisplayAttributes: formatVariantDisplayAttributes(transferItem.variant)
variantOptions: formatVariantOptionValues(transferItem.variant)
variantImageURL: transferItem.variant.images[0]?.small_url
variantImage: transferItem.variant.images[0]

if isReceiving
templateAttributes["receivedQuantity"] = transferItem.received_quantity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#if image }}
<img src='{{ lookup image (concat size "_url") }}' alt="{{ alt }}" />
{{ else }}
<span class="image-placeholder {{ size }}"></span>
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//= require spree/backend/templates/_image
//= require spree/backend/templates/orders/customer_details/autocomplete
//= require spree/backend/templates/orders/details_adjustment_row
//= require spree/backend/templates/orders/line_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
</td>
{{else}}
<td class="line-item-image">
{{#if image }}
<img src="{{ image.mini_url }}">
{{else}}
<span class="image-placeholder mini"></span>
{{/if}}
{{> _image image=line_item.variant.images.[0] size="mini" }}
</td>
<td class="line-item-name">
{{ line_item.variant.name }}<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<td class="align-center no-padding">
<div class='variant-container' data-variant-id="{{variantId}}">
<div class='variant-image'>
{{#if variantImageURL }}
<img alt="{{variantName}}" src="{{variantImageURL}}">
{{ else }}
<span class="image-placeholder small"></span>
{{/if}}
{{> _image image=variantImage size="small" alt=variantName }}
</div>
<div class='variant-details'>
<table class='stock-variant-field-table'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<div class="variant-autocomplete-item media">
<div class="media-left">
{{#if image }}
<img class="media-object" src='{{variant.image}}' />
{{ else }}
<span class="image-placeholder mini"></span>
{{/if}}
{{> _image image=variant.images.[0] size="mini" }}
</div>

<div class="media-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
variantTemplate = HandlebarsTemplates["variants/autocomplete"]

formatVariantResult = (variant) ->
image = variant.images[0].mini_url if variant["images"][0] isnt undefined and variant["images"][0].mini_url isnt undefined
variantTemplate(
variant: variant
image: image
)

$.fn.variantAutocomplete = (searchOptions = {}) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ Spree.Views.Cart.LineItemRow = Backbone.View.extend({
},

render: function() {
var line_item = this.model.attributes
var image = line_item.variant && line_item.variant.images[0]
var html = HandlebarsTemplates['orders/line_item']({
line_item: line_item,
image: image,
line_item: this.model.toJSON(),
editing: this.editing,
isNew: this.model.isNew(),
noCancel: this.model.isNew() && this.model.collection.length == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
padding: 0px 5px;
}
.variant-image,
.variant-details,
.variant-container {
.variant-details {
float: left;
}
.variant-container {
Expand Down

0 comments on commit 1412e87

Please sign in to comment.