From ad6562558df85b6f42a8f5ba355c5f1dbc2497fd Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 27 Sep 2021 18:04:07 -0400 Subject: [PATCH] Improve phone/email handling when making new custorder still needs more improvement, but this is a start --- tailbone/templates/custorders/create.mako | 289 ++++++++++++++++++---- tailbone/views/custorders/orders.py | 40 +-- 2 files changed, 259 insertions(+), 70 deletions(-) diff --git a/tailbone/templates/custorders/create.mako b/tailbone/templates/custorders/create.mako index f1ecfb9f..0d4576bb 100644 --- a/tailbone/templates/custorders/create.mako +++ b/tailbone/templates/custorders/create.mako @@ -107,19 +107,24 @@ -
- - - +
+ + + + + + - - {{ phoneNumberEntry }} -## -## -## -## Please save when finished editing -## -## -## -## + + + + +
+
+
+ {{ orderPhoneNumber }} +
+
+ + Edit + + + + + + +
+
+
+
+ + +
+
+
+ {{ orderEmailAddress }} +
+
+ + Edit + + + + +
+
+
+
+
@@ -400,10 +493,20 @@ contactDisplay: ${json.dumps(six.text_type(batch.customer or ''))|n}, customerEntry: null, contactProfileURL: ${json.dumps(contact_profile_url)|n}, - phoneNumberEntry: ${json.dumps(batch.phone_number)|n}, + ## phoneNumberEntry: ${json.dumps(batch.phone_number)|n}, + orderPhoneNumber: ${json.dumps(batch.phone_number)|n}, phoneNumberSaved: true, customerName: null, phoneNumber: null, + orderEmailAddress: ${json.dumps(batch.email_address)|n}, + + editPhoneNumberShowDialog: false, + editPhoneNumberValue: null, + editPhoneNumberSaving: false, + + editEmailAddressShowDialog: false, + editEmailAddressValue: null, + editEmailAddressSaving: false, items: ${json.dumps(order_items)|n}, editingItem: null, @@ -478,13 +581,13 @@ text: "Please identify the customer.", } } - if (!this.phoneNumberEntry) { + if (!this.orderPhoneNumber) { return { type: 'is-warning', text: "Please provide a phone number for the customer.", } } - phoneNumber = this.phoneNumberEntry + phoneNumber = this.orderPhoneNumber } else { // customer is not known if (!this.customerName) { return { @@ -522,6 +625,40 @@ } }, + editPhoneNumberSaveDisabled() { + if (this.editPhoneNumberSaving) { + return true + } + if (!this.editPhoneNumberValue) { + return true + } + return false + }, + + editPhoneNumberSaveText() { + if (this.editPhoneNumberSaving) { + return "Working, please wait..." + } + return "Save" + }, + + editEmailAddressSaveDisabled() { + if (this.editEmailAddressSaving) { + return true + } + if (!this.editEmailAddressValue) { + return true + } + return false + }, + + editEmailAddressSaveText() { + if (this.editEmailAddressSaving) { + return "Working, please wait..." + } + return "Save" + }, + itemsPanelHeader() { let text = "Items" @@ -621,18 +758,6 @@ }) }, - // setContactData() { - // let params = { - // action: 'set_customer_data', - // customer_uuid: this.contactUUID, - // phone_number: this.phoneNumberEntry, - // } - // let that = this - // this.submitBatchData(params, function(response) { - // that.phoneNumberSaved = true - // }) - // }, - submitOrder() { this.submittingOrder = true @@ -678,22 +803,78 @@ % else: that.contactUUID = response.data.person_uuid % endif - that.phoneNumberEntry = response.data.phone_number + that.orderPhoneNumber = response.data.phone_number + that.orderEmailAddress = response.data.email_address that.contactProfileURL = response.data.contact_profile_url }) }, - // phoneNumberChanged(value) { - // this.phoneNumberSaved = false - // }, + editPhoneNumberInit() { + this.editPhoneNumberValue = this.orderPhoneNumber + this.editPhoneNumberShowDialog = true + this.$nextTick(() => { + this.$refs.editPhoneNumberInput.focus() + }) + }, - // phoneNumberKeyDown(event) { - // if (event.which == 13) { // Enter - // this.setContactData() - // } - // }, + editPhoneNumberSave() { + this.editPhoneNumberSaving = true + + let params = { + action: 'update_phone_number', + phone_number: this.editPhoneNumberValue, + } + + this.submitBatchData(params, response => { + if (response.data.success) { + this.orderPhoneNumber = response.data.phone_number + this.editPhoneNumberShowDialog = false + } else { + this.$buefy.toast.open({ + message: "Save failed: " + response.data.error, + type: 'is-danger', + duration: 2000, // 2 seconds + }) + } + this.editPhoneNumberSaving = false + }) + + }, + + editEmailAddressInit() { + this.editEmailAddressValue = this.orderEmailAddress + this.editEmailAddressShowDialog = true + this.$nextTick(() => { + this.$refs.editEmailAddressInput.focus() + }) + }, + + editEmailAddressSave() { + this.editEmailAddressSaving = true + + let params = { + action: 'update_email_address', + email_address: this.editEmailAddressValue, + } + + this.submitBatchData(params, response => { + if (response.data.success) { + this.orderEmailAddress = response.data.email_address + this.editEmailAddressShowDialog = false + } else { + this.$buefy.toast.open({ + message: "Save failed: " + response.data.error, + type: 'is-danger', + duration: 2000, // 2 seconds + }) + } + this.editEmailAddressSaving = false + }) + + }, showAddItemDialog() { + this.customerPanelOpen = false this.editingItem = null this.productIsKnown = true this.productUUID = null diff --git a/tailbone/views/custorders/orders.py b/tailbone/views/custorders/orders.py index 4ae9666f..151f4572 100644 --- a/tailbone/views/custorders/orders.py +++ b/tailbone/views/custorders/orders.py @@ -228,6 +228,8 @@ class CustomerOrderView(MasterView): json_actions = [ 'assign_contact', 'unassign_contact', + 'update_phone_number', + 'update_email_address', 'get_customer_info', # 'set_customer_data', 'find_product_by_upc', @@ -413,22 +415,28 @@ class CustomerOrderView(MasterView): return context - # def set_customer_data(self, batch, data): - # if 'customer_uuid' in data: - # batch.customer_uuid = data['customer_uuid'] - # if 'person_uuid' in data: - # batch.person_uuid = data['person_uuid'] - # elif batch.customer_uuid: - # self.Session.flush() - # batch.person = batch.customer.first_person() - # else: # no customer set - # batch.person_uuid = None - # if 'phone_number' in data: - # batch.phone_number = data['phone_number'] - # if 'email_address' in data: - # batch.email_address = data['email_address'] - # self.Session.flush() - # return {'success': True} + def update_phone_number(self, batch, data): + app = self.get_rattail_app() + + batch.phone_number = app.format_phone_number(data['phone_number']) + self.Session.flush() + self.Session.refresh(batch) + + return { + 'success': True, + 'phone_number': batch.phone_number, + } + + def update_email_address(self, batch, data): + + batch.email_address = data['email_address'] + self.Session.flush() + self.Session.refresh(batch) + + return { + 'success': True, + 'email_address': batch.email_address, + } def product_autocomplete(self): """