mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Keyboard estimate entry: Tab picks the product; Tab selects the text
- In a line's product box, Tab picks the product the typed text points to: an exact name, else the only
match, else the only name starting with it ("lab" -> Labor). Tabbing before the search comes back
fills the line when it does; ambiguous text is left as typed; an item highlighted in the list still wins.
- Tabbing into a line's description, quantity or rate selects its text so typing replaces it (a click
still places the cursor).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
2 files changed
+72
-16
No files matched your search
@@ -103,6 +103,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
|
|
||||||
* **New estimate** from the customer page: Create Estimate opens the Redmine editor. The customer page no longer links to QuickBooks' estimate or payment screens; the customer's name still opens their QuickBooks account page as a fallback.
|
* **New estimate** from the customer page: Create Estimate opens the Redmine editor. The customer page no longer links to QuickBooks' estimate or payment screens; the customer's name still opens their QuickBooks account page as a fallback.
|
||||||
* **Edit** any estimate from the Edit link next to it on the customer page or the issue page.
|
* **Edit** any estimate from the Edit link next to it on the customer page or the issue page.
|
||||||
|
* **Keyboard entry**: in a line's product box, Tab picks the product the text points to (an exact name, the only match, or the only name starting with it, e.g. "lab" → Labor) and fills the line. Tabbing into the description, quantity or rate selects it, so typing replaces it.
|
||||||
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, custom fields and messages, dated today, with the current user as sales person.
|
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, custom fields and messages, dated today, with the current user as sales person.
|
||||||
* **Read-only once linked to an issue**: an estimate that an issue is linked to can be viewed, emailed and duplicated, but not changed, so the work doesn't drift from what was quoted. The list shows a View link for these instead of Edit.
|
* **Read-only once linked to an issue**: an estimate that an issue is linked to can be viewed, emailed and duplicated, but not changed, so the work doesn't drift from what was quoted. The list shows a View link for these instead of Edit.
|
||||||
* **Read-only once billed**: an estimate that's Converted or Closed in QuickBooks, or linked to an invoice, can't be changed here either (including redmine_qbo_lineitems' estimates once they're invoiced). Its page lists the invoices it's on; it can still be viewed, emailed and duplicated, and it shows View instead of Edit in lists.
|
* **Read-only once billed**: an estimate that's Converted or Closed in QuickBooks, or linked to an invoice, can't be changed here either (including redmine_qbo_lineitems' estimates once they're invoiced). Its page lists the invoices it's on; it can still be viewed, emailed and duplicated, and it shows View instead of Edit in lists.
|
||||||
|
|||||||
@@ -135,23 +135,11 @@ $(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---- product/service search ----
|
// ---- product/service search ----
|
||||||
function setupItemSearch($input) {
|
|
||||||
$input.autocomplete({
|
// Fills a line from a product/service: name, id, description (unless the user typed their own), rate,
|
||||||
appendTo: 'body',
|
// quantity 1 if empty, taxable
|
||||||
minLength: 0,
|
function applyItem($input, item) {
|
||||||
delay: 150,
|
|
||||||
source: function (request, response) {
|
|
||||||
$.getJSON($form.data('itemsUrl'), { q: request.term })
|
|
||||||
.done(function (items) {
|
|
||||||
response(items.map(function (item) {
|
|
||||||
return { label: item.name, value: item.name, item: item };
|
|
||||||
}));
|
|
||||||
})
|
|
||||||
.fail(function () { response([]); });
|
|
||||||
},
|
|
||||||
select: function (event, ui) {
|
|
||||||
var $row = $input.closest('tr');
|
var $row = $input.closest('tr');
|
||||||
var item = ui.item.item;
|
|
||||||
var $description = $row.find('.qbo-line-description-input');
|
var $description = $row.find('.qbo-line-description-input');
|
||||||
var previous = $row.data('itemDescription');
|
var previous = $row.data('itemDescription');
|
||||||
|
|
||||||
@@ -162,6 +150,8 @@ $(function () {
|
|||||||
if (!$description.val().trim() || $description.val() === previous) {
|
if (!$description.val().trim() || $description.val() === previous) {
|
||||||
$description.val(item.description || '');
|
$description.val(item.description || '');
|
||||||
autoGrow($description[0]);
|
autoGrow($description[0]);
|
||||||
|
// Tabbed into it already (the product was filled in after the search came back): keep it selected
|
||||||
|
if (document.activeElement === $description[0]) $description[0].select();
|
||||||
}
|
}
|
||||||
$row.data('itemDescription', item.description || '');
|
$row.data('itemDescription', item.description || '');
|
||||||
if (item.price !== null && item.price !== undefined && item.price !== '') {
|
if (item.price !== null && item.price !== undefined && item.price !== '') {
|
||||||
@@ -171,10 +161,64 @@ $(function () {
|
|||||||
if (!$row.find('.qbo-line-qty-input').val().trim()) $row.find('.qbo-line-qty-input').val('1');
|
if (!$row.find('.qbo-line-qty-input').val().trim()) $row.find('.qbo-line-qty-input').val('1');
|
||||||
$row.find('.qbo-line-taxable').prop('checked', item.taxable !== false);
|
$row.find('.qbo-line-taxable').prop('checked', item.taxable !== false);
|
||||||
changed();
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// The product typed text points to: an exact name match, else the only result, else the only one whose name
|
||||||
|
// starts with the text (e.g. "lab" -> Labor). Nothing when it's ambiguous.
|
||||||
|
function bestItem(term, items) {
|
||||||
|
var t = term.trim().toLowerCase();
|
||||||
|
if (!t || !items || !items.length) return null;
|
||||||
|
var exact = items.filter(function (i) { return String(i.name).toLowerCase() === t; });
|
||||||
|
if (exact.length === 1) return exact[0];
|
||||||
|
if (items.length === 1) return items[0];
|
||||||
|
var starts = items.filter(function (i) { return String(i.name).toLowerCase().indexOf(t) === 0; });
|
||||||
|
return starts.length === 1 ? starts[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupItemSearch($input) {
|
||||||
|
$input.autocomplete({
|
||||||
|
appendTo: 'body',
|
||||||
|
minLength: 0,
|
||||||
|
delay: 150,
|
||||||
|
source: function (request, response) {
|
||||||
|
$.getJSON($form.data('itemsUrl'), { q: request.term })
|
||||||
|
.done(function (items) {
|
||||||
|
$input.data('qboResults', { term: request.term, items: items });
|
||||||
|
response(items.map(function (item) {
|
||||||
|
return { label: item.name, value: item.name, item: item };
|
||||||
|
}));
|
||||||
|
})
|
||||||
|
.fail(function () { response([]); });
|
||||||
|
},
|
||||||
|
select: function (event, ui) {
|
||||||
|
applyItem($input, ui.item.item);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tab picks the product the text points to (an item highlighted in the list is picked by the
|
||||||
|
// autocomplete itself). If the search hasn't come back yet, the line is filled in when it does.
|
||||||
|
$input.on('keydown', function (event) {
|
||||||
|
if (event.key !== 'Tab' || event.shiftKey) return;
|
||||||
|
var menu = $input.autocomplete('instance').menu;
|
||||||
|
if (menu && menu.active) return;
|
||||||
|
var $row = $input.closest('tr');
|
||||||
|
var term = $input.val();
|
||||||
|
if ($row.find('.qbo-line-item-id').val() || !term.trim()) return;
|
||||||
|
|
||||||
|
var known = $input.data('qboResults');
|
||||||
|
if (known && known.term.trim().toLowerCase() === term.trim().toLowerCase()) {
|
||||||
|
var pick = bestItem(term, known.items);
|
||||||
|
if (pick) applyItem($input, pick);
|
||||||
|
$input.autocomplete('close');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.getJSON($form.data('itemsUrl'), { q: term }).done(function (items) {
|
||||||
|
var pick = bestItem(term, items);
|
||||||
|
if (pick && $input.val() === term && !$row.find('.qbo-line-item-id').val()) applyItem($input, pick);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$input.autocomplete('instance')._renderItem = function (ul, entry) {
|
$input.autocomplete('instance')._renderItem = function (ul, entry) {
|
||||||
var item = entry.item;
|
var item = entry.item;
|
||||||
var $div = $('<div>');
|
var $div = $('<div>');
|
||||||
@@ -214,6 +258,17 @@ $(function () {
|
|||||||
ensureSpareRow();
|
ensureSpareRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- keyboard ----
|
||||||
|
// Tabbing into a line's description, quantity or rate selects what's there, so typing replaces it (a click
|
||||||
|
// still places the cursor)
|
||||||
|
var tabbedAt = 0;
|
||||||
|
$(document).on('keydown', function (event) { if (event.key === 'Tab') tabbedAt = Date.now(); });
|
||||||
|
$tbody.on('focus', '.qbo-line-description-input, .qbo-line-qty-input, .qbo-line-rate-input', function () {
|
||||||
|
if (Date.now() - tabbedAt > 500) return;
|
||||||
|
var box = this;
|
||||||
|
setTimeout(function () { if (document.activeElement === box) box.select(); }, 0);
|
||||||
|
});
|
||||||
|
|
||||||
// ---- line events ----
|
// ---- line events ----
|
||||||
$tbody.on('input', '.qbo-line-qty-input, .qbo-line-rate-input, .qbo-line-description-input, .qbo-line-item-name', changed);
|
$tbody.on('input', '.qbo-line-qty-input, .qbo-line-rate-input, .qbo-line-description-input, .qbo-line-item-name', changed);
|
||||||
$tbody.on('change', '.qbo-line-taxable', changed);
|
$tbody.on('change', '.qbo-line-taxable', changed);
|
||||||
|
|||||||
Reference in new issue
Block a user