From 6034ba2537368f7da0569e7614bd2c7f110457b1 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Fri, 10 May 2024 17:03:11 +0200 Subject: Make partition id non editable in partition form Show the partition id as a non editable label in each partition of the Partition and Format form. Assign sequential partition id from top to down and recalculate every partition id when a partition is removed. --- ogcp/forms/action_forms.py | 4 ++-- ogcp/static/js/ogcp.js | 5 +++++ ogcp/templates/actions/setup.html | 2 +- ogcp/templates/base.html | 2 +- ogcp/views.py | 14 +++++++------- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 1b77795..f2a3602 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -30,8 +30,8 @@ class WOLForm(FlaskForm): submit = SubmitField(label=_l('Submit')) class PartitionForm(FlaskForm): - partition = SelectField(label=_l('Partition'), - choices=range(1,10)) + partition = IntegerField(label=_l('Partition'), + render_kw={'readonly': True}) part_type = SelectField(label=_l('Type'), choices=[('LINUX', 'Linux'), ('NTFS', 'NTFS'), diff --git a/ogcp/static/js/ogcp.js b/ogcp/static/js/ogcp.js index 4779bf4..1b6d888 100644 --- a/ogcp/static/js/ogcp.js +++ b/ogcp/static/js/ogcp.js @@ -313,6 +313,8 @@ function AddPartition(evt) { const id = $(this).attr('id').replace(/(.*)-(\d{1,4})-(.*)/, `$1-${elem_num}-$3`); $(this).attr('name', id).attr('id', id).val('').removeAttr("checked"); }); + let part_field = row.find('td').filter(':first')[0]; + part_field.innerText = elem_num + 1; row.show(); oldrow.after(row); } @@ -329,6 +331,9 @@ function RemovePartition(evt) { const id = $(this).attr('id').replace(/(.*)-(\d{1,4})-(.*)/, `$1-${index}-$3`); $(this).attr('name', id).attr('id', id); } + + let part_field = $(this).find('td').filter(':first')[0]; + part_field.innerText = index + 1; $(this).find('input').filter(':first').each(update_references); $(this).find('.form-control').each(update_references); }); diff --git a/ogcp/templates/actions/setup.html b/ogcp/templates/actions/setup.html index 68aefe9..014fb7a 100644 --- a/ogcp/templates/actions/setup.html +++ b/ogcp/templates/actions/setup.html @@ -56,7 +56,7 @@ {% for partition in form.partitions %} {{ partition.hidden_tag() }} - {{ partition.partition(class_="form-control") }} + {{ partition.partition.data }} {{ partition.part_type(class_="form-control") }} {{ partition.fs(class_="form-control") }} {{ partition.size(class_="form-control") }} diff --git a/ogcp/templates/base.html b/ogcp/templates/base.html index 9ade1d2..49f9804 100644 --- a/ogcp/templates/base.html +++ b/ogcp/templates/base.html @@ -111,7 +111,7 @@ - +