mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Refactor DisplayManager for admin field display rules centralization.
This commit is contained in:
parent
93f7e5dca6
commit
e31e09f0c7
20 changed files with 619 additions and 273 deletions
|
@ -0,0 +1,19 @@
|
|||
|
||||
class BaseCondition {
|
||||
|
||||
constructor(config, triggerUpdate) {
|
||||
this.config = config;
|
||||
this.status = false;
|
||||
this.triggerUpdate = triggerUpdate;
|
||||
}
|
||||
|
||||
get key() {
|
||||
return this.config.key;
|
||||
}
|
||||
|
||||
register() {
|
||||
// To override.
|
||||
}
|
||||
}
|
||||
|
||||
export default BaseCondition;
|
|
@ -0,0 +1,15 @@
|
|||
import BaseCondition from "./BaseCondition";
|
||||
|
||||
class BoolCondition extends BaseCondition {
|
||||
|
||||
register() {
|
||||
this.status = this.check();
|
||||
}
|
||||
|
||||
check() {
|
||||
return !! this.config.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default BoolCondition;
|
|
@ -0,0 +1,27 @@
|
|||
import BaseCondition from "./BaseCondition";
|
||||
import {inputValue} from "../../../helper/form";
|
||||
|
||||
class ElementCondition extends BaseCondition {
|
||||
|
||||
register() {
|
||||
jQuery(document).on('change', this.config.selector, () => {
|
||||
const status = this.check();
|
||||
if (status !== this.status) {
|
||||
this.status = status;
|
||||
this.triggerUpdate();
|
||||
}
|
||||
});
|
||||
|
||||
this.status = this.check();
|
||||
}
|
||||
|
||||
check() {
|
||||
let value = inputValue(this.config.selector);
|
||||
value = (value !== null ? value.toString() : value);
|
||||
|
||||
return this.config.value === value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ElementCondition;
|
Loading…
Add table
Add a link
Reference in a new issue