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

View file

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