mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Refactorin'
This commit is contained in:
		@@ -309,13 +309,13 @@ function constructInput(name, parameters, options={}) {
 | 
				
			|||||||
            // TODO - email input
 | 
					            // TODO - email input
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case 'integer':
 | 
					        case 'integer':
 | 
				
			||||||
            // TODO: integer field
 | 
					            func = constructNumberInput;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case 'float':
 | 
					        case 'float':
 | 
				
			||||||
            // TODO: floating point field
 | 
					            func = constructNumberInput;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case 'decimal':
 | 
					        case 'decimal':
 | 
				
			||||||
            // TODO: decimal field
 | 
					            func = constructNumberInput;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case 'choice':
 | 
					        case 'choice':
 | 
				
			||||||
            // TODO: choice field
 | 
					            // TODO: choice field
 | 
				
			||||||
@@ -338,35 +338,87 @@ function constructInput(name, parameters, options={}) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Construct a set of default input options which apply to all input types
 | 
				
			||||||
 | 
					function constructInputOptions(name, classes, type, parameters) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var opts = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    opts.push(`id='id_${name}'`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    opts.push(`class='${classes}'`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    opts.push(`name='${name}'`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    opts.push(`type='${type}'`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Maximum input length
 | 
				
			||||||
 | 
					    if (parameters.max_length) {
 | 
				
			||||||
 | 
					        opts.push(`maxlength='${parameters.max_length}'`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Minimum input length
 | 
				
			||||||
 | 
					    if (parameters.min_length) {
 | 
				
			||||||
 | 
					        opts.push(`minlength='${parameters.min_length}'`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Maximum value
 | 
				
			||||||
 | 
					    if (parameters.max_value != null) {
 | 
				
			||||||
 | 
					        opts.push(`max='${parameters.max_value}'`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Minimum value
 | 
				
			||||||
 | 
					    if (parameters.min_value != null) {
 | 
				
			||||||
 | 
					        opts.push(`min='${parameters.min_value}'`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Field is required?
 | 
				
			||||||
 | 
					    if (parameters.required) {
 | 
				
			||||||
 | 
					        opts.push(`required=''`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Placeholder?
 | 
				
			||||||
 | 
					    if (parameters.placeholder) {
 | 
				
			||||||
 | 
					        opts.push(`placeholder='${parameters.placeholder}'`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return `<input ${opts.join(' ')}>`;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Construct a "checkbox" input
 | 
					// Construct a "checkbox" input
 | 
				
			||||||
function constructCheckboxInput(name, parameters, options={}) {
 | 
					function constructCheckboxInput(name, parameters, options={}) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var html = `<input id='id_${name}' class='checkboxinput' type='checkbox' name='${name}'>`;
 | 
					    return constructInputOptions(
 | 
				
			||||||
 | 
					        name,
 | 
				
			||||||
 | 
					        'checkboxinput',
 | 
				
			||||||
 | 
					        'checkbox',
 | 
				
			||||||
 | 
					        parameters
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return html;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Construct a "text" input
 | 
					// Construct a "text" input
 | 
				
			||||||
function constructTextInput(name, parameters, options={}) {
 | 
					function constructTextInput(name, parameters, options={}) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var html = `<input id='id_${name}' class='textinput textInput form-control' type='text' name='${name}'`;
 | 
					    return constructInputOptions(
 | 
				
			||||||
 | 
					        name,
 | 
				
			||||||
    // TODO: placeholder?
 | 
					        'textinput textInput form-control',
 | 
				
			||||||
 | 
					        'text',
 | 
				
			||||||
    // TODO: value?
 | 
					        parameters
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
    if (parameters.max_length) {
 | 
					 | 
				
			||||||
        html += ` maxlength='${parameters.max_length}'`;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (parameters.required) {
 | 
					 | 
				
			||||||
        html += ` required=''`;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    html += `>`;
 | 
					// Construct a "number" field
 | 
				
			||||||
 | 
					function constructNumberInput(name, parameters, options={}) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return html;
 | 
					    return constructInputOptions(
 | 
				
			||||||
 | 
					        name,
 | 
				
			||||||
 | 
					        'numberinput form-control',
 | 
				
			||||||
 | 
					        'number',
 | 
				
			||||||
 | 
					        parameters
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user