Add "allow contact info choice" support for new custorder batch

This commit is contained in:
Lance Edgar 2021-10-06 12:43:38 -04:00
parent 0237d8c31a
commit 2fa7857daf
2 changed files with 254 additions and 235 deletions

View file

@ -155,74 +155,76 @@
<div class="level-item">
{{ orderPhoneNumber }}
</div>
<div class="level-item"
v-if="contactPhones.length &gt; 1">
<b-button type="is-primary"
@click="editPhoneNumberInit()"
icon-pack="fas"
icon-left="edit">
Edit
</b-button>
% if allow_contact_info_choice:
<div class="level-item"
v-if="contactPhones.length &gt; 1">
<b-button type="is-primary"
@click="editPhoneNumberInit()"
icon-pack="fas"
icon-left="edit">
Edit
</b-button>
<b-modal has-modal-card
:active.sync="editPhoneNumberShowDialog">
<div class="modal-card">
<b-modal has-modal-card
:active.sync="editPhoneNumberShowDialog">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Edit Phone Number</p>
</header>
<header class="modal-card-head">
<p class="modal-card-title">Edit Phone Number</p>
</header>
<section class="modal-card-body">
<section class="modal-card-body">
<b-field v-for="phone in contactPhones"
:key="phone.uuid">
<b-radio v-model="existingPhoneUUID"
:native-value="phone.uuid">
{{ phone.type }} {{ phone.number }}
<span v-if="phone.preferred"
class="is-italic">
(preferred)
</span>
</b-radio>
</b-field>
% if not restrict_contact_info:
<b-field>
<b-field v-for="phone in contactPhones"
:key="phone.uuid">
<b-radio v-model="existingPhoneUUID"
:native-value="null">
other
:native-value="phone.uuid">
{{ phone.type }} {{ phone.number }}
<span v-if="phone.preferred"
class="is-italic">
(preferred)
</span>
</b-radio>
</b-field>
<b-field v-if="!existingPhoneUUID"
grouped>
<b-input v-model="otherPhoneNumber">
</b-input>
<b-checkbox v-model="addOtherPhoneNumber"
disabled>
add this phone number to customer record
</b-checkbox>
</b-field>
% endif
% if not restrict_contact_info:
<b-field>
<b-radio v-model="existingPhoneUUID"
:native-value="null">
other
</b-radio>
</b-field>
</section>
<b-field v-if="!existingPhoneUUID"
grouped>
<b-input v-model="otherPhoneNumber">
</b-input>
<b-checkbox v-model="addOtherPhoneNumber"
disabled>
add this phone number to customer record
</b-checkbox>
</b-field>
% endif
</section>
<footer class="modal-card-foot">
<b-button type="is-primary"
icon-pack="fas"
icon-left="save"
:disabled="editPhoneNumberSaveDisabled"
@click="editPhoneNumberSave()">
{{ editPhoneNumberSaveText }}
</b-button>
<b-button @click="editPhoneNumberShowDialog = false">
Cancel
</b-button>
</footer>
</div>
</b-modal>
<footer class="modal-card-foot">
<b-button type="is-primary"
icon-pack="fas"
icon-left="save"
:disabled="editPhoneNumberSaveDisabled"
@click="editPhoneNumberSave()">
{{ editPhoneNumberSaveText }}
</b-button>
<b-button @click="editPhoneNumberShowDialog = false">
Cancel
</b-button>
</footer>
</div>
</b-modal>
</div>
% endif
</div>
</div>
</b-field>
@ -239,72 +241,74 @@
(no valid email on file)
</span>
</div>
<div class="level-item"
v-if="contactEmails.length &gt; 1">
<b-button type="is-primary"
@click="editEmailAddressInit()"
icon-pack="fas"
icon-left="edit">
Edit
</b-button>
<b-modal has-modal-card
:active.sync="editEmailAddressShowDialog">
<div class="modal-card">
% if allow_contact_info_choice:
<div class="level-item"
v-if="contactEmails.length &gt; 1">
<b-button type="is-primary"
@click="editEmailAddressInit()"
icon-pack="fas"
icon-left="edit">
Edit
</b-button>
<b-modal has-modal-card
:active.sync="editEmailAddressShowDialog">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Edit Email Address</p>
</header>
<header class="modal-card-head">
<p class="modal-card-title">Edit Email Address</p>
</header>
<section class="modal-card-body">
<section class="modal-card-body">
<b-field v-for="email in contactEmails"
:key="email.uuid">
<b-radio v-model="existingEmailUUID"
:native-value="email.uuid">
{{ email.type }} {{ email.address }}
<span v-if="email.preferred"
class="is-italic">
(preferred)
</span>
</b-radio>
</b-field>
% if not restrict_contact_info:
<b-field>
<b-field v-for="email in contactEmails"
:key="email.uuid">
<b-radio v-model="existingEmailUUID"
:native-value="null">
other
:native-value="email.uuid">
{{ email.type }} {{ email.address }}
<span v-if="email.preferred"
class="is-italic">
(preferred)
</span>
</b-radio>
</b-field>
<b-field v-if="!existingEmailUUID"
grouped>
<b-input v-model="otherEmailAddress">
</b-input>
<b-checkbox v-model="addOtherEmailAddress"
disabled>
add this email address to customer record
</b-checkbox>
</b-field>
% endif
% if not restrict_contact_info:
<b-field>
<b-radio v-model="existingEmailUUID"
:native-value="null">
other
</b-radio>
</b-field>
</section>
<b-field v-if="!existingEmailUUID"
grouped>
<b-input v-model="otherEmailAddress">
</b-input>
<b-checkbox v-model="addOtherEmailAddress"
disabled>
add this email address to customer record
</b-checkbox>
</b-field>
% endif
<footer class="modal-card-foot">
<b-button type="is-primary"
icon-pack="fas"
icon-left="save"
:disabled="editEmailAddressSaveDisabled"
@click="editEmailAddressSave()">
{{ editEmailAddressSaveText }}
</b-button>
<b-button @click="editEmailAddressShowDialog = false">
Cancel
</b-button>
</footer>
</section>
<footer class="modal-card-foot">
<b-button type="is-primary"
icon-pack="fas"
icon-left="save"
:disabled="editEmailAddressSaveDisabled"
@click="editEmailAddressSave()">
{{ editEmailAddressSaveText }}
</b-button>
<b-button @click="editEmailAddressShowDialog = false">
Cancel
</b-button>
</footer>
</div>
</b-modal>
</div>
</b-modal>
</div>
% endif
</div>
</div>
</b-field>
@ -581,19 +585,25 @@
orderPhoneNumber: ${json.dumps(batch.phone_number)|n},
contactPhones: ${json.dumps(contact_phones)|n},
existingPhoneUUID: null,
otherPhoneNumber: null,
addOtherPhoneNumber: false,
editPhoneNumberShowDialog: false,
editPhoneNumberSaving: false,
orderEmailAddress: ${json.dumps(batch.email_address)|n},
contactEmails: ${json.dumps(contact_emails)|n},
existingEmailUUID: null,
otherEmailAddress: null,
addOtherEmailAddress: false,
editEmailAddressShowDialog: false,
editEmailAddressSaving: false,
% if allow_contact_info_choice:
existingPhoneUUID: null,
otherPhoneNumber: null,
addOtherPhoneNumber: false,
editPhoneNumberShowDialog: false,
editPhoneNumberSaving: false,
existingEmailUUID: null,
otherEmailAddress: null,
addOtherEmailAddress: false,
editEmailAddressShowDialog: false,
editEmailAddressSaving: false,
% endif
customerName: null,
phoneNumber: null,
@ -722,39 +732,43 @@
}
},
editPhoneNumberSaveDisabled() {
if (this.editPhoneNumberSaving) {
return true
}
if (!this.existingPhoneUUID && !this.otherPhoneNumber) {
return true
}
return false
},
% if allow_contact_info_choice:
editPhoneNumberSaveText() {
if (this.editPhoneNumberSaving) {
return "Working, please wait..."
}
return "Save"
},
editPhoneNumberSaveDisabled() {
if (this.editPhoneNumberSaving) {
return true
}
if (!this.existingPhoneUUID && !this.otherPhoneNumber) {
return true
}
return false
},
editEmailAddressSaveDisabled() {
if (this.editEmailAddressSaving) {
return true
}
if (!this.existingEmailUUID && !this.otherEmailAddress) {
return true
}
return false
},
editPhoneNumberSaveText() {
if (this.editPhoneNumberSaving) {
return "Working, please wait..."
}
return "Save"
},
editEmailAddressSaveText() {
if (this.editEmailAddressSaving) {
return "Working, please wait..."
}
return "Save"
},
editEmailAddressSaveDisabled() {
if (this.editEmailAddressSaving) {
return true
}
if (!this.existingEmailUUID && !this.otherEmailAddress) {
return true
}
return false
},
editEmailAddressSaveText() {
if (this.editEmailAddressSaving) {
return "Working, please wait..."
}
return "Save"
},
% endif
itemsPanelHeader() {
let text = "Items"
@ -912,109 +926,113 @@
this.contactChanged(this.contactUUID)
},
editPhoneNumberInit() {
this.existingPhoneUUID = null
let normalOrderPhone = this.orderPhoneNumber.replace(/\D/g, '')
for (let phone of this.contactPhones) {
let normal = phone.number.replace(/\D/g, '')
if (normal == normalOrderPhone) {
this.existingPhoneUUID = phone.uuid
break
}
}
this.otherPhoneNumber = this.existingPhoneUUID ? null : this.orderPhoneNumber
this.editPhoneNumberShowDialog = true
},
% if allow_contact_info_choice:
editPhoneNumberSave() {
this.editPhoneNumberSaving = true
let params = {
action: 'update_phone_number',
phone_number: null,
}
if (this.existingPhoneUUID) {
editPhoneNumberInit() {
this.existingPhoneUUID = null
let normalOrderPhone = this.orderPhoneNumber.replace(/\D/g, '')
for (let phone of this.contactPhones) {
if (phone.uuid == this.existingPhoneUUID) {
params.phone_number = phone.number
let normal = phone.number.replace(/\D/g, '')
if (normal == normalOrderPhone) {
this.existingPhoneUUID = phone.uuid
break
}
}
}
this.otherPhoneNumber = this.existingPhoneUUID ? null : this.orderPhoneNumber
this.editPhoneNumberShowDialog = true
},
if (!params.phone_number) {
params.phone_number = this.otherPhoneNumber
// params.add_phone_number = this.addOtherPhoneNumber
}
editPhoneNumberSave() {
this.editPhoneNumberSaving = true
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
})
let params = {
action: 'update_phone_number',
phone_number: null,
}
this.editPhoneNumberSaving = false
})
},
editEmailAddressInit() {
this.existingEmailUUID = null
let normalOrderEmail = (this.orderEmailAddress || '').toLowerCase()
for (let email of this.contactEmails) {
let normal = email.address.toLowerCase()
if (normal == normalOrderEmail) {
this.existingEmailUUID = email.uuid
break
if (this.existingPhoneUUID) {
for (let phone of this.contactPhones) {
if (phone.uuid == this.existingPhoneUUID) {
params.phone_number = phone.number
break
}
}
}
}
this.otherEmailAddress = this.existingEmailUUID ? null : this.orderEmailAddress
this.editEmailAddressShowDialog = true
},
if (!params.phone_number) {
params.phone_number = this.otherPhoneNumber
// params.add_phone_number = this.addOtherPhoneNumber
}
editEmailAddressSave() {
this.editEmailAddressSaving = true
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
})
let params = {
action: 'update_email_address',
email_address: null,
}
},
if (this.existingEmailUUID) {
editEmailAddressInit() {
this.existingEmailUUID = null
let normalOrderEmail = (this.orderEmailAddress || '').toLowerCase()
for (let email of this.contactEmails) {
if (email.uuid == this.existingEmailUUID) {
params.email_address = email.address
let normal = email.address.toLowerCase()
if (normal == normalOrderEmail) {
this.existingEmailUUID = email.uuid
break
}
}
}
this.otherEmailAddress = this.existingEmailUUID ? null : this.orderEmailAddress
this.editEmailAddressShowDialog = true
if (!params.email_address) {
params.email_address = this.otherEmailAddress
// params.add_email_address = this.addOtherEmailAddress
}
},
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
})
editEmailAddressSave() {
this.editEmailAddressSaving = true
let params = {
action: 'update_email_address',
email_address: null,
}
this.editEmailAddressSaving = false
})
},
if (this.existingEmailUUID) {
for (let email of this.contactEmails) {
if (email.uuid == this.existingEmailUUID) {
params.email_address = email.address
break
}
}
}
if (!params.email_address) {
params.email_address = this.otherEmailAddress
// params.add_email_address = this.addOtherEmailAddress
}
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
})
},
% endif
showAddItemDialog() {
this.customerPanelOpen = false

View file

@ -255,6 +255,7 @@ class CustomerOrderView(MasterView):
context = {'batch': batch,
'normalized_batch': self.normalize_batch(batch),
'new_order_requires_customer': self.handler.new_order_requires_customer(),
'allow_contact_info_choice': self.handler.allow_contact_info_choice(),
'restrict_contact_info': self.handler.should_restrict_contact_info(),
'contact_display': self.handler.get_contact_display(batch),
'contact_phones': self.handler.get_contact_phones(batch),