This repository has been archived by the owner on Sep 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import stock_transfer files with history from solidus
- Loading branch information
Showing
48 changed files
with
2,980 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
app/assets/javascripts/spree/backend/stock_transfers/count_update_forms.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class CountUpdateForms | ||
@beginListening: (isReceiving) -> | ||
# Edit | ||
$('body').on 'click', '#listing_transfer_items [data-action="edit"]', (ev) => | ||
ev.preventDefault() | ||
transferItemId = $(ev.currentTarget).data('id') | ||
Spree.NumberFieldUpdater.hideReadOnly(transferItemId) | ||
Spree.NumberFieldUpdater.showForm(transferItemId) | ||
|
||
# Cancel | ||
$('body').on 'click', '#listing_transfer_items [data-action="cancel"]', (ev) => | ||
ev.preventDefault() | ||
transferItemId = $(ev.currentTarget).data('id') | ||
Spree.NumberFieldUpdater.hideForm(transferItemId) | ||
Spree.NumberFieldUpdater.showReadOnly(transferItemId) | ||
|
||
# Submit | ||
$('body').on 'click', '#listing_transfer_items [data-action="save"]', (ev) => | ||
ev.preventDefault() | ||
transferItemId = $(ev.currentTarget).data('id') | ||
stockTransferNumber = $("#stock_transfer_number").val() | ||
quantity = parseInt($("#number-update-#{transferItemId} input[type='number']").val(), 10) | ||
|
||
itemAttributes = | ||
id: transferItemId | ||
stockTransferNumber: stockTransferNumber | ||
quantityKey = if isReceiving then 'receivedQuantity' else 'expectedQuantity' | ||
itemAttributes[quantityKey] = quantity | ||
transferItem = new Spree.TransferItem(itemAttributes) | ||
transferItem.update(successHandler, errorHandler) | ||
|
||
successHandler = (transferItem) => | ||
if $('#received-transfer-items').length > 0 | ||
Spree.NumberFieldUpdater.successHandler(transferItem.id, transferItem.received_quantity) | ||
Spree.StockTransfers.ReceivedCounter.updateTotal() | ||
else | ||
Spree.NumberFieldUpdater.successHandler(transferItem.id, transferItem.expected_quantity) | ||
show_flash("success", Spree.translations.updated_successfully) | ||
|
||
errorHandler = (errorData) => | ||
show_flash("error", errorData.responseText) | ||
|
||
Spree.StockTransfers ?= {} | ||
Spree.StockTransfers.CountUpdateForms = CountUpdateForms |
6 changes: 6 additions & 0 deletions
6
app/assets/javascripts/spree/backend/stock_transfers/edit.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Spree.ready -> | ||
if $('#stock-transfer-transfer-items').length > 0 | ||
Spree.StockTransfers.VariantForm.initializeForm(true) | ||
Spree.StockTransfers.VariantForm.beginListeningForAdd() | ||
Spree.StockTransfers.CountUpdateForms.beginListening(false) | ||
Spree.StockTransfers.TransferItemDeleting.beginListening() |
5 changes: 5 additions & 0 deletions
5
app/assets/javascripts/spree/backend/stock_transfers/receive.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Spree.ready -> | ||
if $('#received-transfer-items').length > 0 | ||
Spree.StockTransfers.VariantForm.initializeForm(false) | ||
Spree.StockTransfers.VariantForm.beginListeningForReceive() | ||
Spree.StockTransfers.CountUpdateForms.beginListening(true) |
9 changes: 9 additions & 0 deletions
9
app/assets/javascripts/spree/backend/stock_transfers/received_counter.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class ReceivedCounter | ||
@updateTotal: -> | ||
newTotal = _.reduce($('.js-number-update-text'), (memo, el) -> | ||
memo + parseInt($(el).text().trim(), 10) | ||
, 0) | ||
$('#total-received-quantity').text(newTotal) | ||
|
||
Spree.StockTransfers ?= {} | ||
Spree.StockTransfers.ReceivedCounter = ReceivedCounter |
17 changes: 17 additions & 0 deletions
17
app/assets/javascripts/spree/backend/stock_transfers/stock_transfer.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class StockTransfer | ||
constructor: (options = {}) -> | ||
@number = options.number | ||
@transferItems = options.transferItems | ||
|
||
receive: (variantId, successHandler, errorHandler) -> | ||
Spree.ajax | ||
url: Spree.routes.receive_stock_transfer_api(@number) | ||
type: "POST" | ||
data: | ||
variant_id: variantId | ||
success: (stockTransfer) => | ||
successHandler(stockTransfer, variantId) | ||
error: (errorData) -> | ||
errorHandler(errorData) | ||
|
||
Spree.StockTransfer = StockTransfer |
48 changes: 48 additions & 0 deletions
48
app/assets/javascripts/spree/backend/stock_transfers/transfer_item.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class TransferItem | ||
constructor: (options = {}) -> | ||
@id = options.id | ||
@variantId = options.variantId | ||
@receivedQuantity = options.receivedQuantity | ||
@expectedQuantity = options.expectedQuantity | ||
@stockTransferNumber = options.stockTransferNumber | ||
|
||
create: (successHandler, errorHandler) -> | ||
Spree.ajax | ||
url: Spree.routes.create_transfer_items_api(@stockTransferNumber) | ||
type: "POST" | ||
data: | ||
transfer_item: | ||
variant_id: @variantId | ||
expected_quantity: @expectedQuantity | ||
success: (transferItem) -> | ||
successHandler(transferItem) | ||
error: (errorData) -> | ||
errorHandler(errorData) | ||
|
||
update: (successHandler, errorHandler) -> | ||
itemAttrs = if @receivedQuantity? | ||
{ received_quantity: @receivedQuantity } | ||
else if @expectedQuantity? | ||
{ expected_quantity: @expectedQuantity } | ||
else | ||
{} | ||
Spree.ajax | ||
url: Spree.routes.update_transfer_items_api(@stockTransferNumber, @id) | ||
type: "PUT" | ||
data: | ||
transfer_item: itemAttrs | ||
success: (transferItem) -> | ||
successHandler(transferItem) | ||
error: (errorData) -> | ||
errorHandler(errorData) | ||
|
||
destroy: (successHandler, errorHandler) -> | ||
Spree.ajax | ||
url: Spree.routes.update_transfer_items_api(@stockTransferNumber, @id) | ||
type: "DELETE" | ||
success: (transferItem) -> | ||
successHandler(transferItem) | ||
error: (errorData) -> | ||
errorHandler(errorData) | ||
|
||
Spree.TransferItem = TransferItem |
22 changes: 22 additions & 0 deletions
22
app/assets/javascripts/spree/backend/stock_transfers/transfer_item_deleting.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class TransferItemDeleting | ||
@beginListening: -> | ||
$('body').on 'click', '#listing_transfer_items [data-action="remove"]', (ev) => | ||
ev.preventDefault() | ||
if confirm(Spree.translations.are_you_sure_delete) | ||
transferItemId = $(ev.currentTarget).data('id') | ||
stockTransferNumber = $("#stock_transfer_number").val() | ||
|
||
transferItem = new Spree.TransferItem | ||
id: transferItemId | ||
stockTransferNumber: stockTransferNumber | ||
transferItem.destroy(successHandler, errorHandler) | ||
|
||
successHandler = (transferItem) => | ||
$("[data-transfer-item-id='#{transferItem.id}']").remove() | ||
show_flash("success", Spree.translations.deleted_successfully) | ||
|
||
errorHandler = (errorData) => | ||
show_flash("error", errorData.responseText) | ||
|
||
Spree.StockTransfers ?= {} | ||
Spree.StockTransfers.TransferItemDeleting = TransferItemDeleting |
128 changes: 128 additions & 0 deletions
128
app/assets/javascripts/spree/backend/stock_transfers/variant_form.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
class VariantForm | ||
@initializeForm: (isBuilding) -> | ||
autoCompleteEl().variantAutocomplete({ in_stock_only: isBuilding }) | ||
resetVariantAutocomplete() | ||
|
||
@beginListeningForReceive: -> | ||
variantSelector = autoCompleteEl() | ||
# Search result selected | ||
variantSelector.on 'select2-selecting', (ev) => | ||
ev.preventDefault() | ||
receiveTransferItem(ev.val) | ||
# Search results came back from the server | ||
variantSelector.on 'select2-loaded', (ev) => | ||
if ev.items.results.length == 1 | ||
receiveTransferItem(ev.items.results[0].id) | ||
|
||
@beginListeningForAdd: -> | ||
variantSelector = autoCompleteEl() | ||
# Search result selected | ||
variantSelector.on 'select2-selecting', (ev) => | ||
ev.preventDefault() | ||
createTransferItem(ev.val) | ||
# Search results came back from the server | ||
variantSelector.on 'select2-loaded', (ev) => | ||
if ev.items.results.length == 1 | ||
createTransferItem(ev.items.results[0].id) | ||
|
||
autoCompleteEl = -> | ||
@variantAutocomplete ?= $('[data-hook="transfer_item_selection"]').find('.variant_autocomplete') | ||
@variantAutocomplete | ||
|
||
resetVariantAutocomplete = -> | ||
autoCompleteEl().select2('val', '').trigger('change') | ||
|
||
createTransferItem = (variantId) -> | ||
stockTransferNumber = $("#stock_transfer_number").val() | ||
$(".select2-results").html("<li class='select2-no-results'>#{Spree.translations.adding_match}</li>") | ||
transferItemRow = $("[data-variant-id='#{variantId}']") | ||
if transferItemRow.length > 0 | ||
transferItemId = transferItemRow.parents('tr:first').data('transfer-item-id') | ||
expectedQuantity = parseInt($("#number-update-#{transferItemId}").find('.js-number-update-text').text().trim(), 10) | ||
transferItem = new Spree.TransferItem | ||
id: transferItemId | ||
stockTransferNumber: stockTransferNumber | ||
expectedQuantity: expectedQuantity + 1 | ||
transferItem.update(updateSuccessHandler, errorHandler) | ||
else | ||
transferItem = new Spree.TransferItem | ||
stockTransferNumber: stockTransferNumber | ||
variantId: variantId | ||
expectedQuantity: 1 | ||
transferItem.create(createSuccessHandler, errorHandler) | ||
|
||
receiveTransferItem = (variantId) -> | ||
stockTransferNumber = $("#stock_transfer_number").val() | ||
$(".select2-results").html("<li class='select2-no-results'>#{Spree.translations.receiving_match}</li>") | ||
stockTransfer = new Spree.StockTransfer | ||
number: stockTransferNumber | ||
stockTransfer.receive(variantId, receiveSuccessHandler, errorHandler) | ||
|
||
createSuccessHandler = (transferItem) => | ||
successHandler(transferItem, false) | ||
show_flash('success', Spree.translations.created_successfully) | ||
|
||
updateSuccessHandler = (transferItem) => | ||
successHandler(transferItem, false) | ||
show_flash('success', Spree.translations.updated_successfully) | ||
|
||
receiveSuccessHandler = (stockTransfer, variantId) => | ||
receivedItem = | ||
id: stockTransfer.received_item.id | ||
variant: stockTransfer.received_item.variant | ||
received_quantity: stockTransfer.received_item.received_quantity | ||
successHandler(receivedItem, true) | ||
Spree.StockTransfers.ReceivedCounter.updateTotal() | ||
show_flash('success', Spree.translations.received_successfully) | ||
|
||
successHandler = (transferItem, isReceiving) => | ||
resetVariantAutocomplete() | ||
rowTemplate = HandlebarsTemplates['stock_transfers/transfer_item'] | ||
templateAttributes = | ||
id: transferItem.id | ||
isReceiving: isReceiving | ||
variantId: transferItem.variant.id | ||
variantDisplayAttributes: formatVariantDisplayAttributes(transferItem.variant) | ||
variantOptions: formatVariantOptionValues(transferItem.variant) | ||
variantImage: transferItem.variant.images[0] | ||
|
||
if isReceiving | ||
templateAttributes["receivedQuantity"] = transferItem.received_quantity | ||
else | ||
templateAttributes["expectedQuantity"] = transferItem.expected_quantity | ||
|
||
htmlOutput = rowTemplate(templateAttributes) | ||
$("tr[data-transfer-item-id='#{transferItem.id}']").remove() | ||
if $("#listing_transfer_items tbody tr:first").length > 0 | ||
$("#listing_transfer_items tbody tr:first").before(htmlOutput) | ||
else | ||
$("#listing_transfer_items tbody").html(htmlOutput) | ||
$("#listing_transfer_items").prop('hidden', false) | ||
$(".no-objects-found").prop('hidden', true) | ||
$("tr[data-transfer-item-id='#{transferItem.id}']").fadeIn() | ||
|
||
errorHandler = (errorData) -> | ||
resetVariantAutocomplete() | ||
errorMessage = if errorData.responseJSON?.error? and !errorData.responseJSON.errors? | ||
errorData.responseJSON.error | ||
else | ||
errorData.responseText | ||
show_flash('error', errorMessage) | ||
|
||
formatVariantDisplayAttributes = (variant) -> | ||
displayAttributes = JSON.parse($("#variant_display_attributes").val()) | ||
_.map(displayAttributes, (attribute) => | ||
label: Spree.translations[attribute.translation_key] | ||
value: variant[attribute.attr_name] | ||
) | ||
|
||
formatVariantOptionValues = (variant) -> | ||
optionValues = variant.option_values | ||
optionValues = _.sortBy(optionValues, 'option_type_presentation') | ||
_.map(optionValues, (optionValue) -> | ||
option_type: optionValue.option_type_presentation | ||
option_value: optionValue.presentation | ||
) | ||
|
||
Spree.StockTransfers ?= {} | ||
Spree.StockTransfers.VariantForm = VariantForm |
48 changes: 48 additions & 0 deletions
48
app/assets/javascripts/spree/backend/templates/stock_transfers/transfer_item.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<tr class='new-row' data-transfer-item-id="{{id}}"> | ||
<td class="no-padding"> | ||
<div class='variant-container' data-variant-id="{{variantId}}"> | ||
<div class='variant-image'> | ||
{{> _image image=variantImage size="small" alt=variantName }} | ||
</div> | ||
<div class='variant-details'> | ||
<table class='stock-variant-field-table'> | ||
<tbody> | ||
{{#each variantDisplayAttributes}} | ||
<tr> | ||
<td>{{this.label}}</td> | ||
<td class="fullwidth">{{this.value}}</td> | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</td> | ||
<td> | ||
<table class='stock-variant-field-table'> | ||
{{#each variantOptions}} | ||
<tr> | ||
<td>{{this.option_type}}</td> | ||
<td>{{this.option_value}}</td> | ||
</tr> | ||
{{/each}} | ||
</table> | ||
</td> | ||
<td id="number-update-{{id}}"> | ||
{{#if isReceiving }} | ||
<span class='js-number-update-text'>{{receivedQuantity}}</span> | ||
<input class="fullwidth js-number-update-input" name="received_quantity" type="number" value=""> | ||
{{ else }} | ||
<span class='js-number-update-text'>{{expectedQuantity}}</span> | ||
<input class="fullwidth js-number-update-input" name="expected_quantity" type="number" value=""> | ||
{{/if}} | ||
</td> | ||
<td class="actions"> | ||
<a class="fa fa-edit icon_link with-tip no-text" data-action="edit" data-id="{{id}}" href="#"></a> | ||
<a class="fa fa-check icon_link with-tip no-text" data-action="save" data-id="{{id}}" href="#"></a> | ||
<a class="fa fa-cancel icon_link with-tip no-text" data-action="cancel" data-id="{{id}}" href="#"></a> | ||
{{#unless isReceiving }} | ||
<a class="fa fa-trash icon_link with-tip no-text" data-action="remove" data-id="{{id}}" href="#"></a> | ||
{{/unless}} | ||
</td> | ||
</tr> |
7 changes: 7 additions & 0 deletions
7
app/assets/stylesheets/spree/backend/sections/_stock_transfers.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#stock-transfer-edit-variants { | ||
margin-top: 60px; | ||
} | ||
|
||
#stock-transfer-transfer-items { | ||
margin-top: 80px; | ||
} |
49 changes: 49 additions & 0 deletions
49
app/assets/stylesheets/spree/backend/sections/_transfer_items.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#stock_transfer_summary { | ||
margin: 20px 0px; | ||
display: inline-block; | ||
|
||
.location, | ||
.count-summary { | ||
float: left; | ||
font-size: 15px; | ||
} | ||
.location { | ||
width: 70%; | ||
} | ||
.count-summary { | ||
width: 30%; | ||
text-align: right; | ||
&:after { | ||
content: ""; | ||
clear: both; | ||
display: table; | ||
} | ||
} | ||
.summary-field { | ||
font-weight: 600; | ||
font-size: 105%; | ||
} | ||
.arrow { | ||
margin: 0px 5px; | ||
} | ||
} | ||
|
||
#received-transfer-items, | ||
#stock-transfer-transfer-items { | ||
margin-top: 70px; | ||
.new-row { | ||
display: none; | ||
} | ||
} | ||
|
||
#listing_transfer_items { | ||
> tbody { | ||
tr { | ||
&:hover { | ||
td { | ||
background-color: $color-1; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.