total.php
266 lines
| 1 | <?php |
| 2 | namespace ElementorPro\Modules\Forms\Fields; |
| 3 | use Elementor\Widget_Base; |
| 4 | use ElementorPro\Modules\Forms\Classes; |
| 5 | use Elementor\Controls_Manager; |
| 6 | use ElementorPro\Plugin; |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | exit; // Exit if accessed directly |
| 9 | } |
| 10 | class Cost_Calculator extends Field_Base { |
| 11 | public function get_type() { |
| 12 | return 'calculator'; |
| 13 | } |
| 14 | public function get_name() { |
| 15 | return esc_html__( 'Calculator', 'cost-calculator-for-elementor' ); |
| 16 | } |
| 17 | public function __construct() { |
| 18 | parent::__construct(); |
| 19 | add_action( 'elementor/preview/init', array( $this, 'editor_preview_footer' ) ); |
| 20 | } |
| 21 | public function editor_preview_footer() { |
| 22 | add_action( 'wp_footer', array($this,"field_template_script")); |
| 23 | } |
| 24 | function field_template_script(){ |
| 25 | ?> |
| 26 | <script> |
| 27 | jQuery( document ).ready( () => { |
| 28 | elementor.hooks.addFilter( |
| 29 | 'elementor_pro/forms/content_template/field/calculator', |
| 30 | function ( inputField, item, i ) { |
| 31 | const fieldId = `form_field_${i}`; |
| 32 | const fieldClass = `elementor-field elementor-size-sm elementor-field-textual ${item.css_classes}`; |
| 33 | const size = '1'; |
| 34 | return `<input placeholder="Total" type="text" id="${fieldId}" class="${fieldClass}">`; |
| 35 | }, 10, 3 |
| 36 | ); |
| 37 | }); |
| 38 | </script> |
| 39 | <?php |
| 40 | } |
| 41 | public function render( $item, $item_index, $form ) { |
| 42 | $form->remove_render_attribute( 'input' . $item_index, 'type' ); |
| 43 | $form->add_render_attribute( 'input' . $item_index, 'type', 'text' ); |
| 44 | $form->add_render_attribute( 'input' . $item_index, 'readonly', 'readonly' ); |
| 45 | $form->add_render_attribute( 'input' . $item_index, 'class', 'elementor-field-textual elementor-field-calculator' ); |
| 46 | if ( isset( $item['formula'] ) ) { |
| 47 | $form->add_render_attribute( 'input' . $item_index, 'data-formula', esc_attr( $item['formula'] ) ); |
| 48 | } |
| 49 | if ( isset( $item['number_format'] ) && $item['number_format'] =="yes" ) { |
| 50 | $form->add_render_attribute( 'input' . $item_index, 'class', 'elementor-number-format' ); |
| 51 | $form->add_render_attribute( 'input' . $item_index, 'data-a-sign', esc_attr( $item['number_format_symbols'] ) ); |
| 52 | $form->add_render_attribute( 'input' . $item_index, 'data-a-dec', esc_attr( $item['number_format_decimal_sep'] ) ); |
| 53 | $form->add_render_attribute( 'input' . $item_index, 'data-a-sep', esc_attr( $item['number_format_thousand_sep'] ) ); |
| 54 | $form->add_render_attribute( 'input' . $item_index, 'data-m-dec', esc_attr( $item['number_format_num_decimals'] ) ); |
| 55 | if( $item['number_format_symbols_position'] == "right" ){ |
| 56 | $form->add_render_attribute( 'input' . $item_index, 'data-p-sign', 's'); |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | ?> |
| 61 | <input <?php $form->print_render_attribute_string( 'input' . $item_index ); ?> > |
| 62 | <?php |
| 63 | } |
| 64 | /** |
| 65 | * @param Widget_Base $widget |
| 66 | */ |
| 67 | public function update_controls( $widget ) { |
| 68 | $elementor = Plugin::elementor(); |
| 69 | $control_data = $elementor->controls_manager->get_control_from_stack( $widget->get_unique_name(), 'form_fields' ); |
| 70 | if ( is_wp_error( $control_data ) ) { |
| 71 | return; |
| 72 | } |
| 73 | $check = get_option( '_redmuber_item_1529'); |
| 74 | if($check == "ok") { |
| 75 | $field_controls = [ |
| 76 | 'formula' => [ |
| 77 | 'name' => 'formula', |
| 78 | 'label' => esc_html__( 'Formula', 'cost-calculator-for-elementor' ), |
| 79 | 'type' => Controls_Manager::TEXTAREA, |
| 80 | 'condition' => [ |
| 81 | 'field_type' => $this->get_type(), |
| 82 | ], |
| 83 | 'tab' => 'content', |
| 84 | 'inner_tab' => 'form_fields_content_tab', |
| 85 | 'tabs_wrapper' => 'form_fields_tabs', |
| 86 | ], |
| 87 | 'number_format' => [ |
| 88 | 'name' => 'number_format', |
| 89 | 'label' => esc_html__( 'Number Format', 'cost-calculator-for-elementor' ), |
| 90 | 'type' => Controls_Manager::SWITCHER, |
| 91 | 'condition' => [ |
| 92 | 'field_type' => $this->get_type(), |
| 93 | ], |
| 94 | 'tab' => 'content', |
| 95 | 'inner_tab' => 'form_fields_content_tab', |
| 96 | 'tabs_wrapper' => 'form_fields_tabs', |
| 97 | ], |
| 98 | 'number_format_symbols' => [ |
| 99 | 'name' => 'number_format_symbols', |
| 100 | 'label' => esc_html__( 'Symbols', 'cost-calculator-for-elementor' ), |
| 101 | 'type' => Controls_Manager::TEXT, |
| 102 | 'condition' => [ |
| 103 | 'field_type' => $this->get_type(), |
| 104 | 'number_format' => 'yes' |
| 105 | ], |
| 106 | 'dynamic' => [ |
| 107 | 'active' => true, |
| 108 | ], |
| 109 | 'tab' => 'content', |
| 110 | 'inner_tab' => 'form_fields_content_tab', |
| 111 | 'tabs_wrapper' => 'form_fields_tabs', |
| 112 | ], |
| 113 | 'number_format_symbols_position' => [ |
| 114 | 'name' => 'number_format_symbols_position', |
| 115 | 'label' => esc_html__( 'Symbols Position', 'cost-calculator-for-elementor' ), |
| 116 | 'type' => Controls_Manager::SELECT, |
| 117 | 'options'=> array("left"=>"Left","right"=>"Right"), |
| 118 | 'default' => 'left', |
| 119 | 'condition' => [ |
| 120 | 'field_type' => $this->get_type(), |
| 121 | 'number_format' => 'yes' |
| 122 | ], |
| 123 | 'tab' => 'content', |
| 124 | 'inner_tab' => 'form_fields_content_tab', |
| 125 | 'tabs_wrapper' => 'form_fields_tabs', |
| 126 | ], |
| 127 | 'number_format_thousand_sep' => [ |
| 128 | 'name' => 'number_format_thousand_sep', |
| 129 | 'label' => esc_html__( 'Thousand separator', 'cost-calculator-for-elementor' ), |
| 130 | 'type' => Controls_Manager::TEXT, |
| 131 | 'default' => ',', |
| 132 | 'condition' => [ |
| 133 | 'field_type' => $this->get_type(), |
| 134 | 'number_format' => 'yes' |
| 135 | ], |
| 136 | 'tab' => 'content', |
| 137 | 'inner_tab' => 'form_fields_content_tab', |
| 138 | 'tabs_wrapper' => 'form_fields_tabs', |
| 139 | ], |
| 140 | 'number_format_decimal_sep' => [ |
| 141 | 'name' => 'number_format_decimal_sep', |
| 142 | 'label' => esc_html__( 'Decimal separator', 'cost-calculator-for-elementor' ), |
| 143 | 'type' => Controls_Manager::TEXT, |
| 144 | 'default' => '.', |
| 145 | 'condition' => [ |
| 146 | 'field_type' => $this->get_type(), |
| 147 | 'number_format' => 'yes' |
| 148 | ], |
| 149 | 'tab' => 'content', |
| 150 | 'inner_tab' => 'form_fields_content_tab', |
| 151 | 'tabs_wrapper' => 'form_fields_tabs', |
| 152 | ], |
| 153 | 'number_format_num_decimals' => [ |
| 154 | 'name' => 'number_format_num_decimals', |
| 155 | 'label' => esc_html__( 'Number Decimals', 'cost-calculator-for-elementor' ), |
| 156 | 'type' => Controls_Manager::NUMBER, |
| 157 | 'default' => 2, |
| 158 | 'condition' => [ |
| 159 | 'field_type' => $this->get_type(), |
| 160 | 'number_format' => 'yes' |
| 161 | ], |
| 162 | 'tab' => 'content', |
| 163 | 'inner_tab' => 'form_fields_content_tab', |
| 164 | 'tabs_wrapper' => 'form_fields_tabs', |
| 165 | ], |
| 166 | ]; |
| 167 | }else{ |
| 168 | $field_controls = [ |
| 169 | 'formula' => [ |
| 170 | 'name' => 'formula', |
| 171 | 'label' => esc_html__( 'Formula', 'cost-calculator-for-elementor' ), |
| 172 | 'type' => Controls_Manager::TEXTAREA, |
| 173 | 'condition' => [ |
| 174 | 'field_type' => $this->get_type(), |
| 175 | ], |
| 176 | 'tab' => 'content', |
| 177 | 'inner_tab' => 'form_fields_content_tab', |
| 178 | 'tabs_wrapper' => 'form_fields_tabs', |
| 179 | ], |
| 180 | 'number_format' => [ |
| 181 | 'name' => 'number_format', |
| 182 | 'label' => esc_html__( 'Number Format', 'cost-calculator-for-elementor' ), |
| 183 | 'type' => Controls_Manager::SWITCHER, |
| 184 | 'condition' => [ |
| 185 | 'field_type' => $this->get_type(), |
| 186 | ], |
| 187 | 'tab' => 'content', |
| 188 | 'inner_tab' => 'form_fields_content_tab', |
| 189 | 'tabs_wrapper' => 'form_fields_tabs', |
| 190 | ], |
| 191 | 'number_format_symbols_disable' => [ |
| 192 | 'name' => 'number_format_symbols_disable', |
| 193 | 'label' => esc_html__( 'Symbols (pro)', 'cost-calculator-for-elementor' ), |
| 194 | 'type' => Controls_Manager::TEXT, |
| 195 | 'class' => 'd', |
| 196 | 'condition' => [ |
| 197 | 'field_type' => $this->get_type(), |
| 198 | 'number_format' => 'yes' |
| 199 | ], |
| 200 | 'dynamic' => [ |
| 201 | 'active' => true, |
| 202 | ], |
| 203 | 'tab' => 'content', |
| 204 | 'inner_tab' => 'form_fields_content_tab', |
| 205 | 'tabs_wrapper' => 'form_fields_tabs', |
| 206 | ], |
| 207 | 'number_format_symbols_position_disable' => [ |
| 208 | 'name' => 'number_format_symbols_position_disable', |
| 209 | 'label' => esc_html__( 'Symbols Position (pro)', 'cost-calculator-for-elementor' ), |
| 210 | 'type' => Controls_Manager::SELECT, |
| 211 | 'options'=> array("left"=>"Left","right"=>"Right"), |
| 212 | 'default' => 'left', |
| 213 | 'condition' => [ |
| 214 | 'field_type' => $this->get_type(), |
| 215 | 'number_format' => 'yes' |
| 216 | ], |
| 217 | 'tab' => 'content', |
| 218 | 'inner_tab' => 'form_fields_content_tab', |
| 219 | 'tabs_wrapper' => 'form_fields_tabs', |
| 220 | ], |
| 221 | 'number_format_thousand_sep_disable' => [ |
| 222 | 'name' => 'number_format_thousand_sep_disable', |
| 223 | 'label' => esc_html__( 'Thousand separator (pro)', 'cost-calculator-for-elementor' ), |
| 224 | 'type' => Controls_Manager::TEXT, |
| 225 | 'default' => ',', |
| 226 | 'condition' => [ |
| 227 | 'field_type' => $this->get_type(), |
| 228 | 'number_format' => 'yes' |
| 229 | ], |
| 230 | 'tab' => 'content', |
| 231 | 'inner_tab' => 'form_fields_content_tab', |
| 232 | 'tabs_wrapper' => 'form_fields_tabs', |
| 233 | ], |
| 234 | 'number_format_decimal_sep_disable' => [ |
| 235 | 'name' => 'number_format_decimal_sep_disable', |
| 236 | 'label' => esc_html__( 'Decimal separator (pro)', 'cost-calculator-for-elementor' ), |
| 237 | 'type' => Controls_Manager::TEXT, |
| 238 | 'default' => '.', |
| 239 | 'condition' => [ |
| 240 | 'field_type' => $this->get_type(), |
| 241 | 'number_format' => 'yes' |
| 242 | ], |
| 243 | 'tab' => 'content', |
| 244 | 'inner_tab' => 'form_fields_content_tab', |
| 245 | 'tabs_wrapper' => 'form_fields_tabs', |
| 246 | ], |
| 247 | 'number_format_num_decimals_disable' => [ |
| 248 | 'name' => 'number_format_num_decimals_disable', |
| 249 | 'label' => esc_html__( 'Number Decimals (pro)', 'cost-calculator-for-elementor' ), |
| 250 | 'type' => Controls_Manager::NUMBER, |
| 251 | 'default' => 2, |
| 252 | 'condition' => [ |
| 253 | 'field_type' => $this->get_type(), |
| 254 | 'number_format' => 'yes' |
| 255 | ], |
| 256 | 'tab' => 'content', |
| 257 | 'inner_tab' => 'form_fields_content_tab', |
| 258 | 'tabs_wrapper' => 'form_fields_tabs', |
| 259 | ], |
| 260 | ]; |
| 261 | } |
| 262 | $control_data['fields'] = $this->inject_field_controls( $control_data['fields'], $field_controls ); |
| 263 | $widget->update_control( 'form_fields', $control_data ); |
| 264 | } |
| 265 | } |
| 266 | new Cost_Calculator; |