<%# Inline so the page never depends on precompiled plugin assets %> <%= javascript_tag do %> $(function () { var $form = $('#qbo-estimate-form'); if (!$form.length) return; // For other plugins' editor scripts (added through the view_qbo_estimate_form_bottom hook). The form also // triggers these events (listen with $(document).on('qbo:imported', '#qbo-estimate-form', fn)): // qbo:customer-changed (event, { customer_id, info }) info includes field_options // qbo:imported (event, { issue_ids, estimates, issue_values }) after time/estimates are // imported into an invoice; issue_values is { issue_id => { field_id => value } } // and each estimate has its own custom_fields { field_id => value } window.qboEditor = { form: $form, document: $form.data('document'), // A QuickBooks custom field's box, by field id or by a name pattern (RegExp) field: function (id) { return $('#qbo_custom_field_' + id); }, fieldNamed: function (pattern) { var $box = $(); $form.find('.qbo-field-custom').each(function () { if (!$box.length && pattern.test(String($(this).data('qboFieldName')))) $box = $(this).find('input.qbo-custom-field'); }); return $box; }, fieldId: function ($box) { return $box.closest('.qbo-field-custom').data('qboFieldId'); }, // Replaces a box's suggestion list: [{ value, label }] setFieldOptions: function (id, options) { var $list = $('#qbo-custom-field-options-' + id).empty(); (options || []).forEach(function (o) { $('