diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 0f11355a..aaf38423 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -173,6 +173,35 @@ class Homs cache: true language: I18n.locale) + enableOrderAttributePicker: (allowClear) => + $('.order_attribute-picker').select2( + width: '100%' + allowClear: allowClear + theme: 'bootstrap' + formatSelection: -> (node) node.id + cache: true + language: I18n.locale) + + currentOrderType = $('.order_type-picker option:selected').val() + if currentOrderType + @setAttributePickerOptions(currentOrderType) + + setAttributePickerOptions: (orderType) => + $.ajax '/orders/order_type_attributes/' + orderType, + method: 'GET' + success: (data) => + if Object.keys(data.options).length > 0 + $orderAttributePicker = $('.order_attribute-picker') + $orderAttributePicker.empty() + + $.each(data.options, (key, value) => + $orderAttributePicker + .append( + $('