| Total Complexity | 74 |
| Total Lines | 1560 |
| Duplicated Lines | 0 % |
| Changes | 19 | ||
| Bugs | 0 | Features | 2 |
Complex classes like WPInv_Payment_Form_Elements often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WPInv_Payment_Form_Elements, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class WPInv_Payment_Form_Elements { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @param array payment form elements |
||
| 11 | */ |
||
| 12 | protected $elements; |
||
| 13 | |||
| 14 | public function __construct() { |
||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | } |
||
| 29 | |||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Returns all the elements that can be added to a form. |
||
| 34 | */ |
||
| 35 | public function get_elements() { |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Returns the restrict markup. |
||
| 49 | */ |
||
| 50 | public function get_restrict_markup( $field, $field_type ) { |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Renders the gateway select element template. |
||
| 57 | */ |
||
| 58 | public function render_gateway_select_template( $field ) { |
||
| 59 | $restrict = $this->get_restrict_markup( $field, 'gateway_select' ); |
||
| 60 | $text = __( 'The gateway select box will appear hear', 'invoicing' ); |
||
| 61 | echo " |
||
| 62 | <div $restrict class='alert alert-info' role='alert'> |
||
| 63 | <span>$text</span> |
||
| 64 | </div> |
||
| 65 | "; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Renders the edit gateway select element template. |
||
| 70 | */ |
||
| 71 | public function edit_gateway_select_template( $field ) { |
||
| 72 | $restrict = $this->get_restrict_markup( $field, 'gateway_select' ); |
||
| 73 | $label = __( 'The gateway select text', 'invoicing' ); |
||
| 74 | $id = $field . '.id + "_edit"'; |
||
| 75 | echo " |
||
| 76 | <div $restrict> |
||
| 77 | <div class='form-group'> |
||
| 78 | <label :for='$id'>$label</label> |
||
| 79 | <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
| 80 | </div> |
||
| 81 | </div> |
||
| 82 | "; |
||
| 83 | |||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Renders the total payable element template. |
||
| 88 | */ |
||
| 89 | public function render_total_payable_template( $field ) { |
||
| 90 | $restrict = $this->get_restrict_markup( $field, 'total_payable' ); |
||
| 91 | $text = __( 'The total payable amount will appear here', 'invoicing' ); |
||
| 92 | echo " |
||
| 93 | <div $restrict class='alert alert-info' role='alert'> |
||
| 94 | <span>$text</span> |
||
| 95 | </div> |
||
| 96 | "; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Renders the edit total payable element template. |
||
| 101 | */ |
||
| 102 | public function edit_total_payable_template( $field ) { |
||
| 103 | $restrict = $this->get_restrict_markup( $field, 'total_payable' ); |
||
| 104 | $label = __( 'The total payable text', 'invoicing' ); |
||
| 105 | $id = $field . '.id + "_edit"'; |
||
| 106 | echo " |
||
| 107 | <div $restrict> |
||
| 108 | <div class='form-group'> |
||
| 109 | <label :for='$id'>$label</label> |
||
| 110 | <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
| 111 | </div> |
||
| 112 | </div> |
||
| 113 | "; |
||
| 114 | |||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Renders the title element template. |
||
| 119 | */ |
||
| 120 | public function render_heading_template( $field ) { |
||
| 121 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
| 122 | echo "<component :is='$field.level' $restrict v-html='$field.text'></component>"; |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Renders the edit title element template. |
||
| 127 | */ |
||
| 128 | public function edit_heading_template( $field ) { |
||
| 129 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
| 130 | $label = __( 'Heading', 'invoicing' ); |
||
| 131 | $label2 = __( 'Select Heading Level', 'invoicing' ); |
||
| 132 | $id = $field . '.id + "_edit"'; |
||
| 133 | $id2 = $field . '.id + "_edit2"'; |
||
| 134 | |||
| 135 | echo " |
||
| 136 | <div $restrict> |
||
| 137 | <div class='form-group'> |
||
| 138 | <label :for='$id'>$label</label> |
||
| 139 | <input class='form-control' :id='$id' v-model='$field.text' type='text' /> |
||
| 140 | </div> |
||
| 141 | |||
| 142 | <div class='form-group'> |
||
| 143 | <label :for='$id2'>$label2</label> |
||
| 144 | |||
| 145 | <select class='form-control custom-select' :id='$id2' v-model='$field.level'> |
||
| 146 | <option value='h1'>H1</option> |
||
| 147 | <option value='h2'>H2</option> |
||
| 148 | <option value='h3'>H3</option> |
||
| 149 | <option value='h4'>H4</option> |
||
| 150 | <option value='h5'>H5</option> |
||
| 151 | <option value='h6'>H6</option> |
||
| 152 | <option value='h7'>H7</option> |
||
| 153 | </select> |
||
| 154 | </div> |
||
| 155 | </div> |
||
| 156 | "; |
||
| 157 | |||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Renders a paragraph element template. |
||
| 162 | */ |
||
| 163 | public function render_paragraph_template( $field ) { |
||
| 164 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
| 165 | $label = "$field.text"; |
||
| 166 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Renders the edit paragraph element template. |
||
| 171 | */ |
||
| 172 | public function edit_paragraph_template( $field ) { |
||
| 173 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
| 174 | $label = __( 'Enter your text', 'invoicing' ); |
||
| 175 | $id = $field . '.id + "_edit"'; |
||
| 176 | echo " |
||
| 177 | <div $restrict> |
||
| 178 | <div class='form-group'> |
||
| 179 | <label :for='$id'>$label</label> |
||
| 180 | <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
| 181 | </div> |
||
| 182 | </div> |
||
| 183 | "; |
||
| 184 | |||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Renders the text element template. |
||
| 189 | */ |
||
| 190 | public function render_text_template( $field ) { |
||
| 191 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
| 192 | $label = "$field.label"; |
||
| 193 | echo " |
||
| 194 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 195 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 196 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 197 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'> |
||
| 198 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 199 | </div> |
||
| 200 | "; |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Renders the edit price select element template. |
||
| 205 | */ |
||
| 206 | public function edit_price_select_template( $field ) { |
||
| 207 | $restrict = $this->get_restrict_markup( $field, 'price_select' ); |
||
| 208 | |||
| 209 | $label3 = __( 'Help text', 'invoicing' ); |
||
|
|
|||
| 210 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 211 | $id3 = $field . '.id + "_edit3"'; |
||
| 212 | $label6 = __( 'Options', 'invoicing' ); |
||
| 213 | $id6 = $field . '.id + "_edit5"'; |
||
| 214 | ?> |
||
| 215 | <div <?php echo $restrict; ?>> |
||
| 216 | <small class='form-text text-muted mb-2'><?php _e( 'This amount will be added to the total amount for this form', 'invoicing' ); ?></small> |
||
| 217 | <div class='form-group'> |
||
| 218 | <label class="d-block"> |
||
| 219 | <span><?php _e( 'Field Label', 'invoicing' ); ?></span> |
||
| 220 | <input v-model='<?php echo $field; ?>.label' class='form-control' /> |
||
| 221 | </label> |
||
| 222 | </div> |
||
| 223 | |||
| 224 | <div class='form-group' v-if="<?php echo $field; ?>.select_type=='select'"> |
||
| 225 | <label class="d-block"> |
||
| 226 | <span><?php _e( 'Placeholder text', 'invoicing' ); ?></span> |
||
| 227 | <input v-model='<?php echo $field; ?>.placeholder' class='form-control' /> |
||
| 228 | </label> |
||
| 229 | </div> |
||
| 230 | |||
| 231 | <div class='form-group'> |
||
| 232 | <label class="d-block"> |
||
| 233 | <span><?php _e( 'Select Type', 'invoicing' ); ?></span> |
||
| 234 | <select class='form-control custom-select' v-model='<?php echo $field; ?>.select_type'> |
||
| 235 | <option value='select'><?php _e( 'Dropdown', 'invoicing' ) ?></option> |
||
| 236 | <option value='checkboxes'><?php _e( 'Checkboxes', 'invoicing' ) ?></option> |
||
| 237 | <option value='radios'><?php _e( 'Radio Buttons', 'invoicing' ) ?></option> |
||
| 238 | <option value='buttons'><?php _e( 'Buttons', 'invoicing' ) ?></option> |
||
| 239 | <option value='circles'><?php _e( 'Circles', 'invoicing' ) ?></option> |
||
| 240 | </select> |
||
| 241 | </label> |
||
| 242 | </div> |
||
| 243 | |||
| 244 | <div class='form-group'> |
||
| 245 | <label class="d-block"> |
||
| 246 | <span><?php _e( 'Options', 'invoicing' ); ?></span> |
||
| 247 | <textarea placeholder='Basic|10,Pro|99,Business|199' v-model='<?php echo $field; ?>.options' class='form-control' rows='3'></textarea> |
||
| 248 | <small class='form-text text-muted mb-2'><?php _e( 'Use commas to separate options and pipes to separate a label and its price. Do not include a currency symbol in the price.', 'invoicing' ); ?></small> |
||
| 249 | </label> |
||
| 250 | </div> |
||
| 251 | |||
| 252 | <div class='form-group'> |
||
| 253 | <label class="d-block"> |
||
| 254 | <span><?php _e( 'Help Text', 'invoicing' ); ?></span> |
||
| 255 | <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea> |
||
| 256 | </label> |
||
| 257 | </div> |
||
| 258 | </div> |
||
| 259 | <?php |
||
| 260 | |||
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Renders the price select element template. |
||
| 265 | */ |
||
| 266 | public function render_price_select_template( $field ) { |
||
| 267 | $restrict = $this->get_restrict_markup( $field, 'price_select' ); |
||
| 268 | ?> |
||
| 269 | <div <?php echo $restrict; ?> class='wpinv-payment-form-field-preview'> |
||
| 270 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 271 | |||
| 272 | <label>{{<?php echo $field; ?>.label}}</label> |
||
| 273 | |||
| 274 | <!-- Buttons --> |
||
| 275 | <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="buttons"' class="getpaid-price-buttons"> |
||
| 276 | <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
||
| 277 | <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" /> |
||
| 278 | <label :for="<?php echo esc_attr( $field ); ?>.id + index" class="rounded">{{option | optionize}}</label> |
||
| 279 | </span> |
||
| 280 | </div> |
||
| 281 | |||
| 282 | <!-- Circles --> |
||
| 283 | <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="circles"' class="getpaid-price-buttons getpaid-price-circles"> |
||
| 284 | <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
||
| 285 | <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" /> |
||
| 286 | <label :for="<?php echo esc_attr( $field ); ?>.id + index"><span>{{option | optionize}}</span></label> |
||
| 287 | </span> |
||
| 288 | </div> |
||
| 289 | |||
| 290 | <!-- Radios --> |
||
| 291 | <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="radios"'> |
||
| 292 | <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
||
| 293 | <label> |
||
| 294 | <input type="radio" :checked="index==0" /> |
||
| 295 | <span>{{option | optionize}}</span> |
||
| 296 | </label> |
||
| 297 | </div> |
||
| 298 | </div> |
||
| 299 | |||
| 300 | <!-- Checkboxes --> |
||
| 301 | <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="checkboxes"'> |
||
| 302 | <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
||
| 303 | <label> |
||
| 304 | <input type="checkbox" :checked="index==0" /> |
||
| 305 | <span>{{option | optionize}}</span> |
||
| 306 | </label> |
||
| 307 | </div> |
||
| 308 | </div> |
||
| 309 | |||
| 310 | <!-- Select --> |
||
| 311 | <select v-if='<?php echo esc_attr( $field ); ?>.select_type=="select"' class='form-control custom-select'> |
||
| 312 | <option v-if="<?php echo esc_attr( $field ); ?>.placeholder" selected="selected"> |
||
| 313 | {{<?php echo esc_attr( $field ); ?>.placeholder}} |
||
| 314 | </option> |
||
| 315 | <option v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
||
| 316 | {{option | optionize}} |
||
| 317 | </option> |
||
| 318 | </select> |
||
| 319 | <small v-if='<?php echo esc_attr( $field ); ?>.description' class='form-text text-muted' v-html='<?php echo esc_attr( $field ); ?>.description'></small> |
||
| 320 | </div> |
||
| 321 | |||
| 322 | <?php |
||
| 323 | } |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Renders the edit price input element template. |
||
| 327 | */ |
||
| 328 | public function edit_price_input_template( $field ) { |
||
| 329 | $restrict = $this->get_restrict_markup( $field, 'price_input' ); |
||
| 330 | $label = __( 'Field Label', 'invoicing' ); |
||
| 331 | $id = $field . '.id + "_edit"'; |
||
| 332 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 333 | $id2 = $field . '.id + "_edit2"'; |
||
| 334 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 335 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 336 | $id3 = $field . '.id + "_edit3"'; |
||
| 337 | $label5 = __( 'The amount that users add to this field will be added to the total amount', 'invoicing' ); |
||
| 338 | $label6 = __( 'Default Amount', 'invoicing' ); |
||
| 339 | $id6 = $field . '.id + "_edit5"'; |
||
| 340 | echo " |
||
| 341 | <div $restrict> |
||
| 342 | <small class='form-text text-muted mb-2'>$label5</small> |
||
| 343 | <div class='form-group'> |
||
| 344 | <label :for='$id'>$label</label> |
||
| 345 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 346 | </div> |
||
| 347 | <div class='form-group'> |
||
| 348 | <label :for='$id6'>$label6</label> |
||
| 349 | <input :id='$id6' v-model='$field.value' class='form-control' /> |
||
| 350 | </div> |
||
| 351 | <div class='form-group'> |
||
| 352 | <label :for='$id2'>$label2</label> |
||
| 353 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 354 | </div> |
||
| 355 | <div class='form-group'> |
||
| 356 | <label :for='$id3'>$label3</label> |
||
| 357 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 358 | </div> |
||
| 359 | </div> |
||
| 360 | "; |
||
| 361 | } |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Renders the edit text element template. |
||
| 365 | */ |
||
| 366 | public function edit_text_template( $field ) { |
||
| 367 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
| 368 | $label = __( 'Field Label', 'invoicing' ); |
||
| 369 | $id = $field . '.id + "_edit"'; |
||
| 370 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 371 | $id2 = $field . '.id + "_edit2"'; |
||
| 372 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 373 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 374 | $id3 = $field . '.id + "_edit3"'; |
||
| 375 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 376 | $id4 = $field . '.id + "_edit4"'; |
||
| 377 | echo " |
||
| 378 | <div $restrict> |
||
| 379 | <div class='form-group'> |
||
| 380 | <label :for='$id'>$label</label> |
||
| 381 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 382 | </div> |
||
| 383 | <div class='form-group'> |
||
| 384 | <label :for='$id2'>$label2</label> |
||
| 385 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 386 | </div> |
||
| 387 | <div class='form-group'> |
||
| 388 | <label :for='$id3'>$label3</label> |
||
| 389 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 390 | </div> |
||
| 391 | <div class='form-group form-check'> |
||
| 392 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 393 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 394 | </div> |
||
| 395 | </div> |
||
| 396 | "; |
||
| 397 | |||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Renders the textarea element template. |
||
| 402 | */ |
||
| 403 | public function render_textarea_template( $field ) { |
||
| 404 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
| 405 | $label = "$field.label"; |
||
| 406 | echo " |
||
| 407 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 408 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 409 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 410 | <textarea :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea> |
||
| 411 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 412 | </div> |
||
| 413 | "; |
||
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Renders the edit textarea element template. |
||
| 418 | */ |
||
| 419 | public function edit_textarea_template( $field ) { |
||
| 420 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
| 421 | $label = __( 'Field Label', 'invoicing' ); |
||
| 422 | $id = $field . '.id + "_edit"'; |
||
| 423 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 424 | $id2 = $field . '.id + "_edit2"'; |
||
| 425 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 426 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 427 | $id3 = $field . '.id + "_edit3"'; |
||
| 428 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 429 | $id4 = $field . '.id + "_edit4"'; |
||
| 430 | echo " |
||
| 431 | <div $restrict> |
||
| 432 | <div class='form-group'> |
||
| 433 | <label :for='$id'>$label</label> |
||
| 434 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 435 | </div> |
||
| 436 | <div class='form-group'> |
||
| 437 | <label :for='$id2'>$label2</label> |
||
| 438 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 439 | </div> |
||
| 440 | <div class='form-group'> |
||
| 441 | <label :for='$id3'>$label3</label> |
||
| 442 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 443 | </div> |
||
| 444 | <div class='form-group form-check'> |
||
| 445 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 446 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 447 | </div> |
||
| 448 | </div> |
||
| 449 | "; |
||
| 450 | |||
| 451 | } |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Renders the select element template. |
||
| 455 | */ |
||
| 456 | public function render_select_template( $field ) { |
||
| 457 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
| 458 | $label = "$field.label"; |
||
| 459 | $placeholder = "$field.placeholder"; |
||
| 460 | $id = $field . '.id'; |
||
| 461 | echo " |
||
| 462 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 463 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 464 | <label :for='$id'>{{" . $label . "}}</label> |
||
| 465 | <select id='$id' class='form-control custom-select' v-model='$field.value'> |
||
| 466 | <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option> |
||
| 467 | <option v-for='option in $field.options' value='option'>{{option}}</option> |
||
| 468 | </select> |
||
| 469 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 470 | </div> |
||
| 471 | "; |
||
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Renders the edit select element template. |
||
| 476 | */ |
||
| 477 | public function edit_select_template( $field ) { |
||
| 478 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
| 479 | $label = __( 'Field Label', 'invoicing' ); |
||
| 480 | $id = $field . '.id + "_edit"'; |
||
| 481 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 482 | $id2 = $field . '.id + "_edit2"'; |
||
| 483 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 484 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 485 | $id3 = $field . '.id + "_edit3"'; |
||
| 486 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 487 | $id4 = $field . '.id + "_edit4"'; |
||
| 488 | $label6 = __( 'Available Options', 'invoicing' ); |
||
| 489 | echo " |
||
| 490 | <div $restrict> |
||
| 491 | <div class='form-group'> |
||
| 492 | <label :for='$id'>$label</label> |
||
| 493 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 494 | </div> |
||
| 495 | <div class='form-group'> |
||
| 496 | <label :for='$id2'>$label2</label> |
||
| 497 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 498 | </div> |
||
| 499 | <div class='form-group'> |
||
| 500 | <label :for='$id3'>$label3</label> |
||
| 501 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 502 | </div> |
||
| 503 | <div class='form-group form-check'> |
||
| 504 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 505 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 506 | </div> |
||
| 507 | <hr class='featurette-divider mt-4'> |
||
| 508 | <h5>$label6</h5> |
||
| 509 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
| 510 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
| 511 | <div class='input-group-append'> |
||
| 512 | <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
| 513 | </div> |
||
| 514 | </div> |
||
| 515 | <div class='form-group'> |
||
| 516 | <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
| 517 | </div> |
||
| 518 | </div> |
||
| 519 | "; |
||
| 520 | |||
| 521 | } |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Renders the checkbox element template. |
||
| 525 | */ |
||
| 526 | public function render_checkbox_template( $field ) { |
||
| 527 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
| 528 | echo " |
||
| 529 | <div class='form-check' $restrict> |
||
| 530 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 531 | <input :id='$field.id' class='form-check-input' type='checkbox' /> |
||
| 532 | <label class='form-check-label' :for='$field.id' v-html='$field.label'></label> |
||
| 533 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 534 | </div> |
||
| 535 | "; |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Renders the edit checkbox element template. |
||
| 540 | */ |
||
| 541 | public function edit_checkbox_template( $field ) { |
||
| 542 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
| 543 | $label = __( 'Field Label', 'invoicing' ); |
||
| 544 | $id = $field . '.id + "_edit"'; |
||
| 545 | $label2 = __( 'Help text', 'invoicing' ); |
||
| 546 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 547 | $id2 = $field . '.id + "_edit2"'; |
||
| 548 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
| 549 | $id3 = $field . '.id + "_edit3"'; |
||
| 550 | echo " |
||
| 551 | <div $restrict> |
||
| 552 | <div class='form-group'> |
||
| 553 | <label :for='$id'>$label</label> |
||
| 554 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 555 | </div> |
||
| 556 | <div class='form-group'> |
||
| 557 | <label :for='$id2'>$label2</label> |
||
| 558 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 559 | </div> |
||
| 560 | <div class='form-group form-check'> |
||
| 561 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 562 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
| 563 | </div> |
||
| 564 | </div> |
||
| 565 | "; |
||
| 566 | |||
| 567 | } |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Renders the radio element template. |
||
| 571 | */ |
||
| 572 | public function render_radio_template( $field ) { |
||
| 573 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
| 574 | $label = "$field.label"; |
||
| 575 | $id = $field . '.id'; |
||
| 576 | echo " |
||
| 577 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 578 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 579 | <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend> |
||
| 580 | <div class='form-check' v-for='(option, index) in $field.options'> |
||
| 581 | <input class='form-check-input' type='radio' :id='$id + index'> |
||
| 582 | <label class='form-check-label' :for='$id + index'>{{option}}</label> |
||
| 583 | </div> |
||
| 584 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 585 | </div> |
||
| 586 | "; |
||
| 587 | } |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Renders the edit radio element template. |
||
| 591 | */ |
||
| 592 | public function edit_radio_template( $field ) { |
||
| 593 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
| 594 | $label = __( 'Field Label', 'invoicing' ); |
||
| 595 | $id = $field . '.id + "_edit"'; |
||
| 596 | $label2 = __( 'Help text', 'invoicing' ); |
||
| 597 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 598 | $id2 = $field . '.id + "_edit3"'; |
||
| 599 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
| 600 | $id3 = $field . '.id + "_edit4"'; |
||
| 601 | $label5 = __( 'Available Options', 'invoicing' ); |
||
| 602 | echo " |
||
| 603 | <div $restrict> |
||
| 604 | <div class='form-group'> |
||
| 605 | <label :for='$id'>$label</label> |
||
| 606 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 607 | </div> |
||
| 608 | <div class='form-group'> |
||
| 609 | <label :for='$id2'>$label2</label> |
||
| 610 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 611 | </div> |
||
| 612 | <div class='form-group form-check'> |
||
| 613 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 614 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
| 615 | </div> |
||
| 616 | <hr class='featurette-divider mt-4'> |
||
| 617 | <h5>$label5</h5> |
||
| 618 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
| 619 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
| 620 | <div class='input-group-append'> |
||
| 621 | <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
| 622 | </div> |
||
| 623 | </div> |
||
| 624 | <div class='form-group'> |
||
| 625 | <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
| 626 | </div> |
||
| 627 | </div> |
||
| 628 | "; |
||
| 629 | |||
| 630 | } |
||
| 631 | |||
| 632 | /** |
||
| 633 | * Renders the address element template. |
||
| 634 | */ |
||
| 635 | public function render_address_template( $field ) { |
||
| 636 | $restrict = $this->get_restrict_markup( $field, 'address' ); |
||
| 637 | |||
| 638 | echo " |
||
| 639 | <div class='wpinv-address-wrapper' $restrict> |
||
| 640 | <draggable v-model='$field.fields' group='address_fields_preview'> |
||
| 641 | <div class='form-group address-field-preview wpinv-payment-form-field-preview' v-for='(field, index) in $field.fields' :key='field.name' v-show='field.visible'> |
||
| 642 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 643 | <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label> |
||
| 644 | <input v-if='field.name !== \"wpinv_country\" && field.name !== \"wpinv_state\"' class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'> |
||
| 645 | <select v-else class='form-control' :id='field.name'> |
||
| 646 | <option v-if='field.placeholder'>{{field.placeholder}}</option> |
||
| 647 | </select> |
||
| 648 | <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small> |
||
| 649 | </div> |
||
| 650 | </draggable> |
||
| 651 | </div> |
||
| 652 | "; |
||
| 653 | } |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Renders the edit address element template. |
||
| 657 | */ |
||
| 658 | public function edit_address_template( $field ) { |
||
| 659 | $restrict = $this->get_restrict_markup( $field, 'address' ); |
||
| 660 | $label = __( 'Field Label', 'invoicing' ); |
||
| 661 | $label2 = __( 'Placeholder', 'invoicing' ); |
||
| 662 | $label3 = __( 'Description', 'invoicing' ); |
||
| 663 | $label4 = __( 'Is required', 'invoicing' ); |
||
| 664 | $label5 = __( 'Is visible', 'invoicing' ); |
||
| 665 | $id = $field . '.id + "_edit_label"'; |
||
| 666 | $id2 = $field . '.id + "_edit_placeholder"'; |
||
| 667 | $id3 = $field . '.id + "_edit_description"'; |
||
| 668 | $id4 = $field . '.id + "_edit_required"'; |
||
| 669 | $id5 = $field . '.id + "_edit_visible"'; |
||
| 670 | $id5 = $field . '.id + "_edit_visible"'; |
||
| 671 | $id_main = $field . '.id'; |
||
| 672 | |||
| 673 | echo " |
||
| 674 | <div $restrict :id='$id_main'> |
||
| 675 | <draggable v-model='$field.fields' group='address_fields'> |
||
| 676 | <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'> |
||
| 677 | |||
| 678 | <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'> |
||
| 679 | <span class='label'>{{field.label}}</span> |
||
| 680 | <span class='toggle-visibility-icon' @click.stop='field.visible = !field.visible;'> |
||
| 681 | <span class='dashicons dashicons-hidden'></span> |
||
| 682 | <span class='dashicons dashicons-visibility'></span> |
||
| 683 | </span> |
||
| 684 | <span class='toggle-icon'> |
||
| 685 | <span class='dashicons dashicons-arrow-down'></span> |
||
| 686 | <span class='dashicons dashicons-arrow-up' style='display:none'></span> |
||
| 687 | </span> |
||
| 688 | </div> |
||
| 689 | |||
| 690 | <div class='wpinv-form-address-field-editor-editor-body'> |
||
| 691 | <div class='p-2'> |
||
| 692 | |||
| 693 | <div class='form-group'> |
||
| 694 | <label :for='$id + index'>$label</label> |
||
| 695 | <input :id='$id + index' v-model='field.label' class='form-control' /> |
||
| 696 | </div> |
||
| 697 | |||
| 698 | <div class='form-group'> |
||
| 699 | <label :for='$id2 + index'>$label2</label> |
||
| 700 | <input :id='$id2 + index' v-model='field.placeholder' class='form-control' /> |
||
| 701 | </div> |
||
| 702 | |||
| 703 | <div class='form-group'> |
||
| 704 | <label :for='$id3 + index'>$label3</label> |
||
| 705 | <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea> |
||
| 706 | </div> |
||
| 707 | |||
| 708 | <div class='form-group form-check'> |
||
| 709 | <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' /> |
||
| 710 | <label class='form-check-label' :for='$id4 + index'>$label4</label> |
||
| 711 | </div> |
||
| 712 | |||
| 713 | <div class='form-group form-check'> |
||
| 714 | <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' /> |
||
| 715 | <label class='form-check-label' :for='$id5 + index'>$label5</label> |
||
| 716 | </div> |
||
| 717 | |||
| 718 | </div> |
||
| 719 | </div> |
||
| 720 | |||
| 721 | </div> |
||
| 722 | </draggable> |
||
| 723 | |||
| 724 | </div> |
||
| 725 | "; |
||
| 726 | |||
| 727 | } |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Renders the email element template. |
||
| 731 | */ |
||
| 732 | public function render_email_template( $field ) { |
||
| 733 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
| 734 | $label = "$field.label"; |
||
| 735 | echo " |
||
| 736 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 737 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 738 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 739 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
| 740 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 741 | </div> |
||
| 742 | "; |
||
| 743 | } |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Renders the billing_email element template. |
||
| 747 | */ |
||
| 748 | public function render_billing_email_template( $field ) { |
||
| 749 | $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
||
| 750 | $label = "$field.label"; |
||
| 751 | echo " |
||
| 752 | <div $restrict> |
||
| 753 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 754 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
| 755 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 756 | </div> |
||
| 757 | "; |
||
| 758 | } |
||
| 759 | |||
| 760 | /** |
||
| 761 | * Renders the edit email element template. |
||
| 762 | */ |
||
| 763 | public function edit_email_template( $field ) { |
||
| 764 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
| 765 | $label = __( 'Field Label', 'invoicing' ); |
||
| 766 | $id = $field . '.id + "_edit"'; |
||
| 767 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 768 | $id2 = $field . '.id + "_edit2"'; |
||
| 769 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 770 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 771 | $id3 = $field . '.id + "_edit3"'; |
||
| 772 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 773 | $id4 = $field . '.id + "_edit4"'; |
||
| 774 | echo " |
||
| 775 | <div $restrict> |
||
| 776 | <div class='form-group'> |
||
| 777 | <label :for='$id'>$label</label> |
||
| 778 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 779 | </div> |
||
| 780 | <div class='form-group'> |
||
| 781 | <label :for='$id2'>$label2</label> |
||
| 782 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 783 | </div> |
||
| 784 | <div class='form-group'> |
||
| 785 | <label :for='$id3'>$label3</label> |
||
| 786 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 787 | </div> |
||
| 788 | <div class='form-group form-check'> |
||
| 789 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 790 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 791 | </div> |
||
| 792 | </div> |
||
| 793 | "; |
||
| 794 | |||
| 795 | } |
||
| 796 | |||
| 797 | /** |
||
| 798 | * Renders the edit billing_email element template. |
||
| 799 | */ |
||
| 800 | public function edit_billing_email_template( $field ) { |
||
| 801 | $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
||
| 802 | $label = __( 'Field Label', 'invoicing' ); |
||
| 803 | $id = $field . '.id + "_edit"'; |
||
| 804 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 805 | $id2 = $field . '.id + "_edit2"'; |
||
| 806 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 807 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 808 | $id3 = $field . '.id + "_edit3"'; |
||
| 809 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 810 | $id4 = $field . '.id + "_edit4"'; |
||
| 811 | echo " |
||
| 812 | <div $restrict> |
||
| 813 | <div class='form-group'> |
||
| 814 | <label :for='$id'>$label</label> |
||
| 815 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 816 | </div> |
||
| 817 | <div class='form-group'> |
||
| 818 | <label :for='$id2'>$label2</label> |
||
| 819 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 820 | </div> |
||
| 821 | <div class='form-group'> |
||
| 822 | <label :for='$id3'>$label3</label> |
||
| 823 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 824 | </div> |
||
| 825 | </div> |
||
| 826 | "; |
||
| 827 | |||
| 828 | } |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Renders the website element template. |
||
| 832 | */ |
||
| 833 | public function render_website_template( $field ) { |
||
| 834 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
| 835 | $label = "$field.label"; |
||
| 836 | echo " |
||
| 837 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 838 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 839 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 840 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'> |
||
| 841 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 842 | </div> |
||
| 843 | "; |
||
| 844 | } |
||
| 845 | |||
| 846 | /** |
||
| 847 | * Renders the edit website element template. |
||
| 848 | */ |
||
| 849 | public function edit_website_template( $field ) { |
||
| 850 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
| 851 | $label = __( 'Field Label', 'invoicing' ); |
||
| 852 | $id = $field . '.id + "_edit"'; |
||
| 853 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 854 | $id2 = $field . '.id + "_edit2"'; |
||
| 855 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 856 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 857 | $id3 = $field . '.id + "_edit3"'; |
||
| 858 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 859 | $id4 = $field . '.id + "_edit4"'; |
||
| 860 | echo " |
||
| 861 | <div $restrict> |
||
| 862 | <div class='form-group'> |
||
| 863 | <label :for='$id'>$label</label> |
||
| 864 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 865 | </div> |
||
| 866 | <div class='form-group'> |
||
| 867 | <label :for='$id2'>$label2</label> |
||
| 868 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 869 | </div> |
||
| 870 | <div class='form-group'> |
||
| 871 | <label :for='$id3'>$label3</label> |
||
| 872 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 873 | </div> |
||
| 874 | <div class='form-group form-check'> |
||
| 875 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 876 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 877 | </div> |
||
| 878 | </div> |
||
| 879 | "; |
||
| 880 | |||
| 881 | } |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Renders the date element template. |
||
| 885 | */ |
||
| 886 | public function render_date_template( $field ) { |
||
| 887 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
| 888 | $label = "$field.label"; |
||
| 889 | echo " |
||
| 890 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 891 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 892 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 893 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'> |
||
| 894 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 895 | </div> |
||
| 896 | "; |
||
| 897 | } |
||
| 898 | |||
| 899 | /** |
||
| 900 | * Renders the edit date element template. |
||
| 901 | */ |
||
| 902 | public function edit_date_template( $field ) { |
||
| 903 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
| 904 | $label = __( 'Field Label', 'invoicing' ); |
||
| 905 | $id = $field . '.id + "_edit"'; |
||
| 906 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 907 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 908 | $id3 = $field . '.id + "_edit3"'; |
||
| 909 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 910 | $id4 = $field . '.id + "_edit4"'; |
||
| 911 | echo " |
||
| 912 | <div $restrict> |
||
| 913 | <div class='form-group'> |
||
| 914 | <label :for='$id'>$label</label> |
||
| 915 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 916 | </div> |
||
| 917 | <div class='form-group'> |
||
| 918 | <label :for='$id3'>$label3</label> |
||
| 919 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 920 | </div> |
||
| 921 | <div class='form-group form-check'> |
||
| 922 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 923 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 924 | </div> |
||
| 925 | </div> |
||
| 926 | "; |
||
| 927 | |||
| 928 | } |
||
| 929 | |||
| 930 | /** |
||
| 931 | * Renders the time element template. |
||
| 932 | */ |
||
| 933 | public function render_time_template( $field ) { |
||
| 934 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
| 935 | $label = "$field.label"; |
||
| 936 | echo " |
||
| 937 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 938 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 939 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 940 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'> |
||
| 941 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 942 | </div> |
||
| 943 | "; |
||
| 944 | } |
||
| 945 | |||
| 946 | /** |
||
| 947 | * Renders the edit time element template. |
||
| 948 | */ |
||
| 949 | public function edit_time_template( $field ) { |
||
| 950 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
| 951 | $label = __( 'Field Label', 'invoicing' ); |
||
| 952 | $id = $field . '.id + "_edit"'; |
||
| 953 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 954 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 955 | $id3 = $field . '.id + "_edit3"'; |
||
| 956 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 957 | $id4 = $field . '.id + "_edit4"'; |
||
| 958 | echo " |
||
| 959 | <div $restrict> |
||
| 960 | <div class='form-group'> |
||
| 961 | <label :for='$id'>$label</label> |
||
| 962 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 963 | </div> |
||
| 964 | <div class='form-group'> |
||
| 965 | <label :for='$id3'>$label3</label> |
||
| 966 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 967 | </div> |
||
| 968 | <div class='form-group form-check'> |
||
| 969 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 970 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 971 | </div> |
||
| 972 | </div> |
||
| 973 | "; |
||
| 974 | |||
| 975 | } |
||
| 976 | |||
| 977 | /** |
||
| 978 | * Renders the number element template. |
||
| 979 | */ |
||
| 980 | public function render_number_template( $field ) { |
||
| 981 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
| 982 | $label = "$field.label"; |
||
| 983 | echo " |
||
| 984 | <div $restrict class='wpinv-payment-form-field-preview'> |
||
| 985 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 986 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
| 987 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'> |
||
| 988 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 989 | </div> |
||
| 990 | "; |
||
| 991 | } |
||
| 992 | |||
| 993 | /** |
||
| 994 | * Renders the edit number element template. |
||
| 995 | */ |
||
| 996 | public function edit_number_template( $field ) { |
||
| 997 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
| 998 | $label = __( 'Field Label', 'invoicing' ); |
||
| 999 | $id = $field . '.id + "_edit"'; |
||
| 1000 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
| 1001 | $id2 = $field . '.id + "_edit2"'; |
||
| 1002 | $label3 = __( 'Help text', 'invoicing' ); |
||
| 1003 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 1004 | $id3 = $field . '.id + "_edit3"'; |
||
| 1005 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
| 1006 | $id4 = $field . '.id + "_edit4"'; |
||
| 1007 | echo " |
||
| 1008 | <div $restrict> |
||
| 1009 | <div class='form-group'> |
||
| 1010 | <label :for='$id'>$label</label> |
||
| 1011 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 1012 | </div> |
||
| 1013 | <div class='form-group'> |
||
| 1014 | <label :for='$id2'>$label2</label> |
||
| 1015 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
| 1016 | </div> |
||
| 1017 | <div class='form-group'> |
||
| 1018 | <label :for='$id3'>$label3</label> |
||
| 1019 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 1020 | </div> |
||
| 1021 | <div class='form-group form-check'> |
||
| 1022 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
| 1023 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
| 1024 | </div> |
||
| 1025 | </div> |
||
| 1026 | "; |
||
| 1027 | |||
| 1028 | } |
||
| 1029 | |||
| 1030 | /** |
||
| 1031 | * Renders the separator element template. |
||
| 1032 | */ |
||
| 1033 | public function render_separator_template( $field ) { |
||
| 1036 | } |
||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * Renders the pay button element template. |
||
| 1040 | */ |
||
| 1041 | public function render_pay_button_template( $field ) { |
||
| 1042 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
| 1043 | $label = "$field.label"; |
||
| 1044 | echo " |
||
| 1045 | <div $restrict> |
||
| 1046 | <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button> |
||
| 1047 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
| 1048 | </div> |
||
| 1049 | "; |
||
| 1050 | } |
||
| 1051 | |||
| 1052 | /** |
||
| 1053 | * Renders the pay button element template. |
||
| 1054 | */ |
||
| 1055 | public function edit_pay_button_template( $field ) { |
||
| 1056 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
| 1057 | $label = __( 'Button Text', 'invoicing' ); |
||
| 1058 | $id = $field . '.id + "_edit"'; |
||
| 1059 | $label2 = __( 'Help text', 'invoicing' ); |
||
| 1060 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 1061 | $id2 = $field . '.id + "_edit2"'; |
||
| 1062 | $label4 = esc_attr__( 'Button Type', 'invoicing' ); |
||
| 1063 | $id3 = $field . '.id + "_edit3"'; |
||
| 1064 | |||
| 1065 | echo " |
||
| 1066 | <div $restrict> |
||
| 1067 | <div class='form-group'> |
||
| 1068 | <label :for='$id'>$label</label> |
||
| 1069 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
| 1070 | </div> |
||
| 1071 | <div class='form-group'> |
||
| 1072 | <label :for='$id2'>$label2</label> |
||
| 1073 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 1074 | </div> |
||
| 1075 | <div class='form-group'> |
||
| 1076 | <label :for='$id3'>$label4</label> |
||
| 1077 | |||
| 1078 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
| 1079 | <option value='btn-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
| 1080 | <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
| 1081 | <option value='btn-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
| 1082 | <option value='btn-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
| 1083 | <option value='btn-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
| 1084 | <option value='btn-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
| 1085 | <option value='btn-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
| 1086 | <option value='btn-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
| 1087 | <option value='btn-link'>" . __( 'Link', 'invoicing' ) ."</option> |
||
| 1088 | </select> |
||
| 1089 | </div> |
||
| 1090 | </div> |
||
| 1091 | "; |
||
| 1092 | |||
| 1093 | } |
||
| 1094 | |||
| 1095 | /** |
||
| 1096 | * Renders the alert element template. |
||
| 1097 | */ |
||
| 1098 | public function render_alert_template( $field ) { |
||
| 1099 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
| 1100 | $text = "$field.text"; |
||
| 1101 | echo " |
||
| 1102 | <div $restrict class='alert' :class='$field.class' role='alert'> |
||
| 1103 | <span v-html='$text'></span> |
||
| 1104 | <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''> |
||
| 1105 | <span aria-hidden='true'>×</span> |
||
| 1106 | </button> |
||
| 1107 | </div> |
||
| 1108 | "; |
||
| 1109 | } |
||
| 1110 | |||
| 1111 | /** |
||
| 1112 | * Renders the alert element template. |
||
| 1113 | */ |
||
| 1114 | public function edit_alert_template( $field ) { |
||
| 1115 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
| 1116 | $label = __( 'Alert Text', 'invoicing' ); |
||
| 1117 | $label2 = esc_attr__( 'Enter your alert text here', 'invoicing' ); |
||
| 1118 | $id = $field . '.id + "_edit"'; |
||
| 1119 | $label3 = __( 'Is Dismissible?', 'invoicing' ); |
||
| 1120 | $id2 = $field . '.id + "_edit2"'; |
||
| 1121 | $label4 = esc_attr__( 'Alert Type', 'invoicing' ); |
||
| 1122 | $id3 = $field . '.id + "_edit3"'; |
||
| 1123 | echo " |
||
| 1124 | <div $restrict> |
||
| 1125 | <div class='form-group'> |
||
| 1126 | <label :for='$id'>$label</label> |
||
| 1127 | <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
| 1128 | </div> |
||
| 1129 | <div class='form-group form-check'> |
||
| 1130 | <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' /> |
||
| 1131 | <label class='form-check-label' :for='$id2'>$label3</label> |
||
| 1132 | </div> |
||
| 1133 | <div class='form-group'> |
||
| 1134 | <label :for='$id3'>$label4</label> |
||
| 1135 | |||
| 1136 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
| 1137 | <option value='alert-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
| 1138 | <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
| 1139 | <option value='alert-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
| 1140 | <option value='alert-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
| 1141 | <option value='alert-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
| 1142 | <option value='alert-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
| 1143 | <option value='alert-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
| 1144 | <option value='alert-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
| 1145 | </select> |
||
| 1146 | </div> |
||
| 1147 | </div> |
||
| 1148 | "; |
||
| 1149 | |||
| 1150 | } |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Renders the discount element template. |
||
| 1154 | */ |
||
| 1155 | public function render_discount_template( $field ) { |
||
| 1156 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
| 1157 | ?> |
||
| 1158 | |||
| 1159 | <div <?php echo $restrict; ?> class="discount_field border rounded p-3 wpinv-payment-form-field-preview"> |
||
| 1160 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
||
| 1161 | <div class="discount_field_inner d-flex flex-column flex-md-row"> |
||
| 1162 | <input :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text"> |
||
| 1163 | <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button> |
||
| 1164 | </div> |
||
| 1165 | <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small> |
||
| 1166 | </div> |
||
| 1167 | |||
| 1168 | <?php |
||
| 1169 | } |
||
| 1170 | |||
| 1171 | /** |
||
| 1172 | * Renders the discount element template. |
||
| 1173 | */ |
||
| 1174 | public function edit_discount_template( $field ) { |
||
| 1175 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
| 1176 | $label = __( 'Discount Input Placeholder', 'invoicing' ); |
||
| 1177 | $label2 = __( 'Help Text', 'invoicing' ); |
||
| 1178 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
| 1179 | $label4 = __( 'Button Text', 'invoicing' ); |
||
| 1180 | $id = $field . '.id + "_edit"'; |
||
| 1181 | $id2 = $field . '.id + "_edit2"'; |
||
| 1182 | $id3 = $field . '.id + "_edit3"'; |
||
| 1183 | echo " |
||
| 1184 | <div $restrict> |
||
| 1185 | <div class='form-group'> |
||
| 1186 | <label :for='$id'>$label</label> |
||
| 1187 | <input :id='$id' v-model='$field.input_label' class='form-control' /> |
||
| 1188 | </div> |
||
| 1189 | |||
| 1190 | <div class='form-group'> |
||
| 1191 | <label :for='$id2'>$label4</label> |
||
| 1192 | <input :id='$id2' v-model='$field.button_label' class='form-control' /> |
||
| 1193 | </div> |
||
| 1194 | |||
| 1195 | <div class='form-group'> |
||
| 1196 | <label :for='$id3'>$label2</label> |
||
| 1197 | <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
| 1198 | </div> |
||
| 1199 | |||
| 1200 | </div> |
||
| 1201 | "; |
||
| 1202 | |||
| 1203 | } |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Renders the items element template. |
||
| 1207 | */ |
||
| 1208 | public function render_items_template( $field ) { |
||
| 1219 | </div> |
||
| 1220 | </div> |
||
| 1221 | |||
| 1222 | <?php |
||
| 1223 | } |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Renders the items element template. |
||
| 1227 | */ |
||
| 1228 | public function edit_items_template( $field ) { |
||
| 1229 | global $wpinv_euvat, $post; |
||
| 1230 | |||
| 1231 | $restrict = $this->get_restrict_markup( $field, 'items' ); |
||
| 1232 | $id2 = $field . '.id + "_edit2"'; |
||
| 1233 | $id3 = $field . '.id + "_edit3"'; |
||
| 1234 | |||
| 1235 | // Item types. |
||
| 1236 | $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
||
| 1237 | |||
| 1238 | ?> |
||
| 1239 | <div <?php echo $restrict; ?>> |
||
| 1240 | <div v-if="!is_default"> |
||
| 1241 | <label class='form-group'> |
||
| 1242 | <input v-model='<?php echo $field; ?>.hide_cart' type='checkbox' /> |
||
| 1243 | <span class='form-check-label'><?php _e( 'Hide cart details', 'invoicing' ); ?></span> |
||
| 1244 | </label> |
||
| 1245 | |||
| 1246 | <div class="mb-1"><?php _e( 'Form Items', 'invoicing' ); ?></div> |
||
| 1247 | <draggable v-model='form_items' group='selectable_form_items'> |
||
| 1248 | <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class="'item_' + item.id" :key="item.id"> |
||
| 1249 | |||
| 1250 | <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'> |
||
| 1251 | <span class='label'>{{item.title}}</span> |
||
| 1252 | <span class='price'>({{formatPrice(item.price)}})</span> |
||
| 1253 | <span class='toggle-icon'> |
||
| 1254 | <span class='dashicons dashicons-arrow-down'></span> |
||
| 1255 | <span class='dashicons dashicons-arrow-up' style='display:none'></span> |
||
| 1256 | </span> |
||
| 1257 | </div> |
||
| 1258 | |||
| 1259 | <div class='wpinv-available-items-editor-body'> |
||
| 1260 | <div class='p-3'> |
||
| 1261 | |||
| 1262 | <div class="form-group" v-if="! item.new"> |
||
| 1263 | <span class='form-text'> |
||
| 1264 | <a target="_blank" :href="'<?php echo esc_url( admin_url( '/post.php?action=edit&post' ) ) ?>=' + item.id"> |
||
| 1265 | <?php _e( 'Edit the item name, price and other details', 'invoicing' ); ?> |
||
| 1266 | </a> |
||
| 1267 | </span> |
||
| 1268 | </div> |
||
| 1269 | |||
| 1270 | <div class='form-group' v-if="item.new"> |
||
| 1271 | <label class='mb-0 w-100'> |
||
| 1272 | <span><?php _e( 'Item Name', 'invoicing' ); ?></span> |
||
| 1273 | <input v-model='item.title' type='text' class='w-100'/> |
||
| 1274 | </label> |
||
| 1275 | </div> |
||
| 1276 | |||
| 1277 | <div class='form-group' v-if="item.new"> |
||
| 1278 | <label class='mb-0 w-100'> |
||
| 1279 | <span v-if='!item.custom_price'><?php _e( 'Item Price', 'invoicing' ); ?></span> |
||
| 1280 | <span v-if='item.custom_price'><?php _e( 'Recommended Price', 'invoicing' ); ?></span> |
||
| 1281 | <input v-model='item.price' type='text' class='w-100'/> |
||
| 1282 | </label> |
||
| 1283 | </div> |
||
| 1284 | |||
| 1285 | <div class='form-group' v-if='item.new'> |
||
| 1286 | <label :for="'edit_item_type' + item.id" class='mb-0 w-100'> |
||
| 1287 | <span><?php _e( 'Item Type', 'invoicing' ); ?></span> |
||
| 1288 | <select class='w-100' v-model='item.type'> |
||
| 1289 | <?php |
||
| 1290 | foreach ( $item_types as $type => $_label ) { |
||
| 1291 | $type = esc_attr( $type ); |
||
| 1292 | $_label = esc_html( $_label ); |
||
| 1293 | echo "<option value='$type'>$_label</type>"; |
||
| 1294 | } |
||
| 1295 | ?> |
||
| 1296 | </select> |
||
| 1297 | </label> |
||
| 1298 | </div> |
||
| 1299 | |||
| 1300 | <div v-if='item.new'> |
||
| 1301 | <?php if ( $wpinv_euvat->allow_vat_rules() ) : ?> |
||
| 1302 | <div class='form-group'> |
||
| 1303 | <label class='w-100 mb-0'><?php _e( 'VAT Rule', 'invoicing' ) ; ?> |
||
| 1304 | <select class='w-100' v-model='item.rule'> |
||
| 1305 | <?php |
||
| 1306 | foreach ( $wpinv_euvat->get_rules() as $type => $_label ) { |
||
| 1307 | $type = esc_attr( $type ); |
||
| 1308 | $_label = esc_html( $_label ); |
||
| 1309 | echo "<option value='$type'>$_label</type>"; |
||
| 1310 | } |
||
| 1311 | ?> |
||
| 1312 | </select> |
||
| 1313 | </label> |
||
| 1314 | </div> |
||
| 1315 | <?php endif;?> |
||
| 1316 | |||
| 1317 | <?php if ( $wpinv_euvat->allow_vat_classes() ) : ?> |
||
| 1318 | <div class='form-group'> |
||
| 1319 | <label class='w-100 mb-0'><?php _e( 'VAT class', 'invoicing' ) ; ?> |
||
| 1320 | <select class='w-100' v-model='item.class'> |
||
| 1321 | <?php |
||
| 1322 | foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) { |
||
| 1323 | $type = esc_attr( $type ); |
||
| 1324 | $_label = esc_html( $_label ); |
||
| 1325 | echo "<option value='$type'>$_label</type>"; |
||
| 1326 | } |
||
| 1327 | ?> |
||
| 1328 | </select> |
||
| 1329 | </label> |
||
| 1330 | </div> |
||
| 1331 | <?php endif;?> |
||
| 1332 | |||
| 1333 | </div> |
||
| 1334 | |||
| 1335 | <label v-if='item.new' class='form-group'> |
||
| 1336 | <input v-model='item.custom_price' type='checkbox' /> |
||
| 1337 | <span class='form-check-label'><?php _e( 'Allow users to pay what they want', 'invoicing' ); ?></span> |
||
| 1338 | </label> |
||
| 1339 | |||
| 1340 | <div class='form-group' v-if='item.new && item.custom_price'> |
||
| 1341 | <label class='mb-0 w-100'> |
||
| 1342 | <span><?php _e( 'Minimum Price', 'invoicing' ); ?></span> |
||
| 1343 | <input placeholder='0.00' v-model='item.minimum_price' class='w-100' /> |
||
| 1344 | <small class='form-text text-muted'><?php _e( 'Enter the minimum price that a user can pay', 'invoicing' ); ?></small> |
||
| 1345 | </label> |
||
| 1346 | </div> |
||
| 1347 | |||
| 1348 | <label class='form-group'> |
||
| 1349 | <input v-model='item.allow_quantities' type='checkbox' /> |
||
| 1350 | <span><?php _e( 'Allow users to buy several quantities', 'invoicing' ); ?></span> |
||
| 1351 | </label> |
||
| 1352 | |||
| 1353 | <label class='form-group'> |
||
| 1354 | <input v-model='item.required' type='checkbox' /> |
||
| 1355 | <span><?php _e( 'This item is required', 'invoicing' ); ?></span> |
||
| 1356 | </label> |
||
| 1357 | |||
| 1358 | <div class='form-group'> |
||
| 1359 | <label class="mb-0 w-100"> |
||
| 1360 | <span><?php _e( 'Item Description', 'invoicing' ); ?></span> |
||
| 1361 | <textarea v-model='item.description' class='w-100'></textarea> |
||
| 1362 | </label> |
||
| 1363 | </div> |
||
| 1364 | |||
| 1365 | <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'><?php _e( 'Delete Item', 'invoicing' ); ?></button> |
||
| 1366 | |||
| 1367 | </div> |
||
| 1368 | </div> |
||
| 1369 | |||
| 1370 | </div> |
||
| 1371 | </draggable> |
||
| 1372 | |||
| 1373 | <small v-if='! form_items.length' class='form-text text-danger'><?php _e( 'You have not set up any items. Please select an item below or create a new item.', 'invoicing' ); ?></small> |
||
| 1374 | |||
| 1375 | <div class='form-group mt-2'> |
||
| 1376 | |||
| 1377 | <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" v-model='selected_item' @change='addSelectedItem'> |
||
| 1378 | <option value=''><?php _e( 'Select an item to add...', 'invoicing' ) ?></option> |
||
| 1379 | <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option> |
||
| 1380 | </select> |
||
| 1381 | |||
| 1382 | </div> |
||
| 1383 | |||
| 1384 | <div class='form-group'> |
||
| 1385 | <button @click.prevent='addNewItem' class="button button-link"><?php _e( 'Or create a new item.', 'invoicing' ) ?></button> |
||
| 1386 | </div> |
||
| 1387 | |||
| 1388 | <div class='form-group mt-5'> |
||
| 1389 | <label :for='<?php echo $id2; ?>'><?php _e( 'Let customers...', 'invoicing' ) ?></label> |
||
| 1390 | |||
| 1391 | <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" :id='<?php echo $id2; ?>' v-model='<?php echo $field; ?>.items_type'> |
||
| 1392 | <option value='total' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Buy all items on the list', 'invoicing' ); ?></option> |
||
| 1393 | <option value='radio'><?php _e( 'Select a single item from the list', 'invoicing' ); ?></option> |
||
| 1394 | <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Select one or more items on the list', 'invoicing' ) ;?></option> |
||
| 1395 | <option value='select'><?php _e( 'Select a single item from a dropdown', 'invoicing' ); ?></option> |
||
| 1396 | </select> |
||
| 1397 | |||
| 1398 | </div> |
||
| 1399 | </div> |
||
| 1400 | <div class='form-group'> |
||
| 1401 | <label :for='<?php echo $id3; ?>'><?php _e( 'Help Text', 'invoicing' ); ?></label> |
||
| 1402 | <textarea placeholder='<?php esc_attr_e( 'Add some help text for this element', 'invoicing' ); ?>' :id='<?php echo $id3; ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea> |
||
| 1403 | </div> |
||
| 1404 | |||
| 1405 | </div> |
||
| 1406 | |||
| 1407 | <?php |
||
| 1408 | |||
| 1409 | } |
||
| 1410 | |||
| 1411 | /** |
||
| 1412 | * Returns an array of all published items. |
||
| 1413 | */ |
||
| 1414 | public function get_published_items() { |
||
| 1415 | |||
| 1416 | $item_args = array( |
||
| 1417 | 'post_type' => 'wpi_item', |
||
| 1418 | 'orderby' => 'title', |
||
| 1419 | 'order' => 'ASC', |
||
| 1420 | 'posts_per_page' => -1, |
||
| 1421 | 'post_status' => array( 'publish' ), |
||
| 1422 | 'meta_query' => array( |
||
| 1423 | array( |
||
| 1424 | 'key' => '_wpinv_type', |
||
| 1425 | 'compare' => '!=', |
||
| 1426 | 'value' => 'package' |
||
| 1427 | ) |
||
| 1428 | ) |
||
| 1429 | ); |
||
| 1430 | |||
| 1431 | $items = get_posts( apply_filters( 'getpaid_payment_form_item_dropdown_query_args', $item_args ) ); |
||
| 1432 | |||
| 1433 | if ( empty( $items ) ) { |
||
| 1434 | return array(); |
||
| 1435 | } |
||
| 1436 | |||
| 1437 | $options = array(); |
||
| 1438 | foreach ( $items as $item ) { |
||
| 1439 | $item = new GetPaid_Form_Item( $item ); |
||
| 1440 | $options[] = $item->prepare_data_for_use(); |
||
| 1441 | } |
||
| 1442 | return $options; |
||
| 1443 | |||
| 1444 | } |
||
| 1445 | |||
| 1446 | /** |
||
| 1447 | * Returns an array of items for the currently being edited form. |
||
| 1448 | */ |
||
| 1449 | public function get_form_items( $id = false ) { |
||
| 1450 | $form = new GetPaid_Payment_Form( $id ); |
||
| 1451 | |||
| 1452 | // Is this a default form? |
||
| 1453 | if ( $form->is_default() ) { |
||
| 1454 | return array(); |
||
| 1455 | } |
||
| 1456 | |||
| 1457 | return $form->get_items( 'view', 'arrays' ); |
||
| 1458 | } |
||
| 1459 | |||
| 1460 | /** |
||
| 1461 | * Converts form items for use. |
||
| 1462 | */ |
||
| 1463 | public function convert_checkout_items( $items, $invoice ) { |
||
| 1464 | |||
| 1465 | $converted = array(); |
||
| 1466 | foreach ( $items as $item ) { |
||
| 1467 | |||
| 1468 | $item_id = $item['id']; |
||
| 1469 | $_item = new WPInv_Item( $item_id ); |
||
| 1470 | |||
| 1471 | if( ! $_item ) { |
||
| 1472 | continue; |
||
| 1473 | } |
||
| 1474 | |||
| 1475 | $converted[] = array( |
||
| 1476 | 'title' => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ), |
||
| 1477 | 'id' => $item['id'], |
||
| 1478 | 'price' => $item['subtotal'], |
||
| 1479 | 'custom_price' => $_item->get_is_dynamic_pricing(), |
||
| 1480 | 'recurring' => $_item->is_recurring(), |
||
| 1481 | 'description' => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ), |
||
| 1482 | 'minimum_price' => $_item->get_minimum_price(), |
||
| 1483 | 'allow_quantities' => false, |
||
| 1484 | 'quantity' => $item['quantity'], |
||
| 1485 | 'required' => true, |
||
| 1486 | ); |
||
| 1487 | } |
||
| 1488 | return $converted; |
||
| 1489 | |||
| 1490 | } |
||
| 1491 | |||
| 1492 | /** |
||
| 1493 | * Converts an array of id => quantity for use. |
||
| 1494 | */ |
||
| 1495 | public function convert_normal_items( $items ) { |
||
| 1522 | |||
| 1523 | } |
||
| 1524 | |||
| 1525 | /** |
||
| 1526 | * Returns an array of elements for the currently being edited form. |
||
| 1527 | */ |
||
| 1528 | public function get_form_elements( $id = false ) { |
||
| 1541 | } |
||
| 1542 | |||
| 1543 | /** |
||
| 1544 | * Sends a redrect response to payment details. |
||
| 1545 | * |
||
| 1546 | */ |
||
| 1547 | public function send_redirect_response( $url ) { |
||
| 1548 | $url = urlencode( $url ); |
||
| 1549 | wp_send_json_success( $url ); |
||
| 1550 | } |
||
| 1551 | |||
| 1552 | /** |
||
| 1553 | * Fired when a checkout error occurs |
||
| 1554 | * |
||
| 1555 | */ |
||
| 1556 | public function checkout_error() { |
||
| 1567 | |||
| 1568 | } |
||
| 1569 | |||
| 1570 | } |
||
| 1571 |