-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactor/address-fields' into beta
- Loading branch information
Showing
46 changed files
with
2,109 additions
and
1,250 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.* @seebeen @oblakbot |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.vscode | ||
dist | ||
languages/*backup* | ||
languages/*.php | ||
node_modules | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import _ from 'lodash'; | ||
|
||
declare global { | ||
const _: typeof _; | ||
const Backbone: typeof Backbone; | ||
const _: _.UnderscoreStatic; | ||
|
||
interface Window { | ||
wc_address_i18n_params: any; | ||
wp: { | ||
template: (id: string) => _.CompiledTemplate; | ||
}; | ||
} | ||
} | ||
|
||
export {}; |
41 changes: 20 additions & 21 deletions
41
assets/scripts/admin/controllers/company-settings.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 61 additions & 9 deletions
70
assets/scripts/frontend/controllers/address-page.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,77 @@ | ||
const $ = jQuery; | ||
|
||
export default class AddressPageController { | ||
private $inputs: JQuery<HTMLInputElement>; | ||
private selector = '.entity-type-control input'; | ||
private locale: Record<string, string>; | ||
|
||
public init(): void { | ||
this.$inputs = $('.entity-type-control input[type="radio"]'); | ||
this.locale = JSON.parse(window.wc_address_i18n_params.locale_fields); | ||
} | ||
|
||
public finalize(): void { | ||
this.$inputs.on('click', ({ currentTarget }) => | ||
this.toggleFields($(currentTarget)), | ||
$(document.body).on('change refresh', this.selector, (e) => { | ||
console.log('change refresh'); | ||
this.toggleEntityType($(e.target)); | ||
}); | ||
|
||
$(document.body).on('country_to_state_changing', () => { | ||
window.setTimeout( | ||
() => this.toggleEntityType($(`${this.selector}:checked`)), | ||
100, | ||
); | ||
console.log('country_to_state_changing'); | ||
}); | ||
} | ||
|
||
private toggleEntityType($input: JQuery<HTMLInputElement>): void { | ||
const isCompany = $input.val() === 'company'; | ||
|
||
console.log($input.is(':checked'), $input.val()); | ||
|
||
this.isRequired($<HTMLParagraphElement>('.entity-type-toggle'), isCompany); | ||
} | ||
|
||
private isRequired( | ||
$field: JQuery<HTMLParagraphElement>, | ||
required: boolean, | ||
): void { | ||
$field.find('input').prop({ | ||
'aria-required': required, | ||
disabled: !required, | ||
}); | ||
|
||
if (required) { | ||
$field.find('label .optional').remove(); | ||
$field.addClass('shown validate-required'); | ||
|
||
if ($field.find('label .required').length === 0) { | ||
$field | ||
.find('label') | ||
.append( | ||
`<abbr class="required" title="${window.wc_address_i18n_params.i18n_required_text}">*</abbr>`, | ||
); | ||
} | ||
|
||
return; | ||
} | ||
|
||
$field.find('label .required').remove(); | ||
$field.removeClass( | ||
'shown validate-required woocommerce-invalid woocommerce-invalid-required-field', | ||
); | ||
this.toggleFields(this.$inputs.filter(':checked')); | ||
|
||
if ($field.find('label .optional').length === 0) { | ||
$field | ||
.find('label') | ||
.append( | ||
`<abbr class="optional" title="${window.wc_address_i18n_params.i18n_optional_text}">${window.wc_address_i18n_params.i18n_optional_text}</abbr>`, | ||
); | ||
} | ||
} | ||
|
||
private toggleFields($toggle: JQuery<HTMLInputElement>): void { | ||
const isPerson = $toggle.attr('value') === 'person'; | ||
|
||
$('.hide-if-person').toggleClass('shown', !isPerson).find('input').prop({ | ||
required: isPerson, | ||
disabled: isPerson, | ||
}); | ||
$('.hide-if-person').toggleClass('shown', !isPerson); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.