Home Information - Your home, your data, organized.
Python
Have basic new attribute input form plumbing in place. WIP
Anthony Cassandra5a301c88c8de
diff --git a/src/hi/apps/attribute/forms.py b/src/hi/apps/attribute/forms.pyindex 6bfc98cd..8b5f6e9a 100644--- a/src/hi/apps/attribute/forms.py+++ b/src/hi/apps/attribute/forms.py@@ -20,39 +20,11 @@ class AttributeForm(forms.ModelForm):# Access the instance's value_type fieldinstance = kwargs.get('instance')- # Name is not always present and editable- if 'name' in self.fields:- self.fields['name'].widget = forms.TextInput(attrs={'class': 'form-control'})-- # Customize the value field based on the value_type in the instance- if instance and instance.value_type:- value_type = instance.value_type-- if value_type == AttributeValueType.FILE:- # File input for media types- self.fields['value'].widget = forms.FileInput(- attrs={'class': 'form-control'},- )- elif value_type == AttributeValueType.SECRET:- # File input for media types- self.fields['value'].widget = forms.PasswordInput(- attrs={'class': 'form-control'},- )- else:- # Fallback to a simple TextInput- self.fields['value'].widget = forms.TextInput(- attrs={'class': 'form-control'},- )- else:- # If no instance or no value_type, use default TextInput widget- self.fields['value'].widget = forms.TextInput(- attrs={'class': 'form-control'},- )-- if not self._show_as_editable:- for field in self.fields.values():- field.widget.attrs['disabled'] = 'disabled'+ for field in self.fields.values():+ if self._show_as_editable or ( instance and instance.is_editable ):continue+ field.widget.attrs['disabled'] = 'disabled'+ continuereturn@@ -87,5 +59,8 @@ class GeneralAttributeForm( AttributeForm ):choices = AttributeValueType.choices,initial = AttributeValueType.default_value(),required = True,- widget = forms.Select( attrs = { 'class' : 'custom-select' } ),+ widget = forms.Select( attrs = {+ 'class' : 'custom-select',+ 'onchange': 'Hi.changeAttributeValueType( this );',+ } ),)diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form.htmlindex 010d2c79..e35fe162 100644--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html@@ -1,33 +1,23 @@-<div class="hi-attribute">+<div class="hi-attribute-list ">{{ attribute_formset.management_form }}{% for attribute_form in attribute_formset %}- {{ attribute_form.id }}+ <div class="{{ DIVID.ATTRIBUTE_CONTAINER_CLASS }}">+ {{ attribute_form.id }}- {% if attribute_form.non_field_errors %}- <div class="non-field-errors">- {% for err in attribute_form.non_field_errors %}- <p class="form-error">{{ err }}</p>- {% endfor %}- </div>- {% endif %}-- {% if attribute_form.instance.pk %}- <div class="hi-attribute-existing">- {% if attribute_form.instance.is_editable %}- <div class="hi-attribute-editable">- {% include "attribute/panes/attribute_form_existing.html" %}- </div>- {% else %}- <div class="hi-attribute-not-editable">- {% include "attribute/panes/attribute_form_read_only.html" %}+ {% if attribute_form.non_field_errors %}+ <div class="non-field-errors">+ {% for err in attribute_form.non_field_errors %}+ <p class="form-error">{{ err }}</p>+ {% endfor %}</div>{% endif %}- </div>- {% else %}- <div class="hi-attribute-new">++ {% if attribute_form.instance.pk %}+ {% include "attribute/panes/attribute_form_existing.html" %}+ {% else %}{% include "attribute/panes/attribute_form_new.html" %}+ {% endif %}</div>- {% endif %}{% endfor %}</div>diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_existing.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_existing.htmlindex 533f6e73..6b594113 100644--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_existing.html+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_existing.html@@ -1,26 +1,18 @@-EXISTING-<div class="row p-3">- <div class="col-8">- <div class="input-group" >- <div class="input-group-prepend" >- {% if 'name' in attribute_form.fields %}- {{ attribute_form.name }}- {% else %}- <span class="input-group-text" >{{ attribute_form.instance.name }}</span>- {% endif %}- </div>- {{ attribute_form.value }}- </div>- <div class="form-error text-danger" >{{ attribute_form.name.errors }}</div>- <div class="form-error text-danger" >{{ attribute_form.value.errors }}</div>- <div class="form-error text-danger" >{{ attribute_form.file_value.errors }}</div>+<div class="input-group" >+ <div class="input-group-prepend" >+ <span class="input-group-text" >{{ attribute_form.instance.name }}</span></div>+ {{ attribute_form.value }}</div>+<div class="form-error text-danger" >{{ attribute_form.value.errors }}</div>+<div>{{ attribute_form.value_type_str.label }}{{ attribute_form.value_type_str }}{{ attribute_form.value_type_str.errors }}</div>-<div class="col-lg-2 col-12">+{% if attribute_form.show_as_editable and instance.is_editable %}+<div class="">{{ attribute_form.DELETE }} Delete</div>+{% endif %}diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_new.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_new.htmlindex a9b91eba..67deecad 100644--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_new.html+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_new.html@@ -1,19 +1,68 @@-ADD-<div class="row p-3">- <div class="col-8">- <div class="input-group" >- <div class="input-group-prepend" >- {{ attribute_form.name }}- </div>- {{ attribute_form.value }}+<div class="h5">Add</div>++<div>+ {{ attribute_form.value_type_str.label }}+ {{ attribute_form.value_type_str }}+ {{ attribute_form.value_type_str.errors }}+</div>++<div class=""+ {% if attribute_form.value_type_str.value != 'file' %}style="display: none;"{% endif %}+ value-type="file">+ <label for="{{ attribute_form.name.id_for_label }}">{{ attribute_form.name.label }}</label>+ <input type="text"+ id="{{ attribute_form.name.id_for_label }}"+ name="{{ attribute_form.name.html_name }}"+ value="{{ attribute_form.name.value|default_if_none:'' }}">+ <div>+ Choose file:+ {{ attribute_form.file_value }}+ {{ attribute_form.file_value.errors }}+ </div>+</div>++<div class=""+ {% if attribute_form.value_type_str.value != 'secret' %}style="display: none;"{% endif %}+ value-type="secret">+ <div class="input-group" >+ <div>+ <label for="{{ attribute_form.name.id_for_label }}">{{ attribute_form.name.label }}</label>+ <input type="text"+ id="{{ attribute_form.name.id_for_label }}"+ name="{{ attribute_form.name.html_name }}"+ value="{{ attribute_form.name.value|default_if_none:'' }}">+ <input type="checkbox" onclick="Hi.togglePasswordField(this);">Show+ <div class="form-error text-danger" >{{ attribute_form.name.errors }}</div>+ </div>+ <div>+ <label for="{{ attribute_form.value.id_for_label }}">{{ attribute_form.value.label }}</label>+ <input type="password"+ id="{{ attribute_form.value.id_for_label }}"+ name="{{ attribute_form.value.html_name }}"+ value="{{ attribute_form.value.value|default_if_none:'' }}">+ <div class="form-error text-danger" >{{ attribute_form.value.errors }}</div></div>+ </div>+</div>++<div class=""+ {% if attribute_form.value_type_str.value != 'text' %}style="display: none;"{% endif %}+ value-type="text">+ <div class="input-group" >+ <label for="{{ attribute_form.name.id_for_label }}">{{ attribute_form.name.label }}</label>+ <input type="text"+ id="{{ attribute_form.name.id_for_label }}"+ name="{{ attribute_form.name.html_name }}"+ value="{{ attribute_form.name.value|default_if_none:'' }}"><div class="form-error text-danger" >{{ attribute_form.name.errors }}</div>+ </div>+ <div class="input-group">+ <label for="{{ attribute_form.value.id_for_label }}">{{ attribute_form.value.label }}</label>+ <textarea rows="2" cols="40"+ id="{{ attribute_form.value.id_for_label }}"+ name="{{ attribute_form.value.html_name }}"+ value="{{ attribute_form.value.value|default_if_none:'' }}">+ </textarea><div class="form-error text-danger" >{{ attribute_form.value.errors }}</div>- <div class="form-error text-danger" >{{ attribute_form.file_value.errors }}</div></div></div>-<div>- {{ attribute_form.value_type_str.label }}- {{ attribute_form.value_type_str }}- {{ attribute_form.value_type_str.errors }}-</div>diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_read_only.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_read_only.htmldeleted file mode 100644index f826e7f1..00000000--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_read_only.html+++ /dev/null@@ -1,2 +0,0 @@-READ ONLY-{{ attribute_form.instance.name }} : {{ attribute_form.instance.value }}diff --git a/src/hi/apps/entity/templates/entity/edit/panes/entity_form.html b/src/hi/apps/entity/templates/entity/edit/panes/entity_form.htmlindex f0a40620..da187ae5 100644--- a/src/hi/apps/entity/templates/entity/edit/panes/entity_form.html+++ b/src/hi/apps/entity/templates/entity/edit/panes/entity_form.html@@ -26,6 +26,8 @@{{ entity_form.name.errors }}</div>+<div class="h5">Attributes</div>+<div>{% include "attribute/panes/attribute_form.html" with attribute_formset=entity_attribute_formset %}</div>diff --git a/src/hi/constants.py b/src/hi/constants.pyindex 80f0ed0a..1ca2b74e 100644--- a/src/hi/constants.py+++ b/src/hi/constants.py@@ -19,4 +19,5 @@ DIVID = {'ENTITY_POSITION_EDIT_PANE': 'hi-entity-position-edit','COLLECTION_POSITION_EDIT_PANE': 'hi-collection-position-edit',+ 'ATTRIBUTE_CONTAINER_CLASS': 'hi-attribute',}diff --git a/src/hi/static/js/main.js b/src/hi/static/js/main.jsindex a015c878..01c158eb 100644--- a/src/hi/static/js/main.js+++ b/src/hi/static/js/main.js@@ -8,16 +8,25 @@LOCATION_VIEW_SVG_CLASS: 'hi-location-view',BASE_SVG_SELECTOR: '#hi-location-view-main > svg',HIGHLIGHTED_CLASS: 'highlighted',+ ATTRIBUTE_CONTAINER_SELECTOR: '.hi-attribute',+ FORM_FIELD_CONTAINER_SELECTOR: '.input-group',SVG_ACTION_STATE_ATTR_NAME: 'action-state',DATA_TYPE_ATTR: 'data-type',DATA_TYPE_ICON_VALUE: 'svg-icon',DATA_TYPE_PATH_VALUE: 'svg-path',+API_LOCATION_ITEM_DETAILS_URL: '/location/item/details',generateUniqueId: function() {return _generateUniqueId();},+ togglePasswordField: function( toggleCheckbox ) {+ return _togglePasswordField( toggleCheckbox );+ },+ changeAttributeValueType: function( selectElement ) {+ return _changeAttributeValueType( selectElement );+ },getScreenCenterPoint: function( element ) {return _getScreenCenterPoint( element );},@@ -60,6 +69,23 @@return 'id-' + Date.now() + '-' + Math.floor(Math.random() * 1000);}+ function _togglePasswordField( toggleCheckbox ) {++ let passwordField = $(toggleCheckbox).closest(Hi.FORM_FIELD_CONTAINER_SELECTOR).find('input[type="password"], input[type="text"]');+ if ( toggleCheckbox.checked ) {+ passwordField.attr('type', 'text');+ } else {+ passwordField.attr('type', 'password');+ }+ }++ function _changeAttributeValueType( selectElement ) {+ const value_type = $(selectElement).val();+ $(selectElement).closest(Hi.ATTRIBUTE_CONTAINER_SELECTOR).find('[value-type]').hide();+ $(selectElement).closest(Hi.ATTRIBUTE_CONTAINER_SELECTOR).find(`[value-type="${value_type}"`).show();++ }+function _getScreenCenterPoint( element ) {try {let rect = $(element)[0].getBoundingClientRect();