#10 add option to disable fields in UI
Closed 5 years ago by puiterwijk. Opened 5 years ago by rcritten.
rcritten/ipsilon readonly  into  master

file modified
+3 -1
@@ -65,7 +65,9 @@ 

              pconfig.String(

                  'service name',

                  'The name of the PAM service used to authenticate.',

-                 'remote'),

+                 'remote',

+                 readonly=True,

+                 ),

              pconfig.String(

                  'username text',

                  'Text used to ask for the username at login time.',

file modified
+26 -15
@@ -70,18 +70,21 @@ 

  

  class Option(Log):

  

-     def __init__(self, name, description):

+     def __init__(self, name, description, readonly=False):

          self.name = name

          self.description = description

          self._default_value = None

          self._assigned_value = None

+         self._readonly = readonly

  

      def __repr__(self):

-         return "%s: %s {%s}, value = %s [def: %s]" % (self.__class__,

+         return "%s: %s {%s}, value = %s [def: %s] readonly=%s" % (

+                                                       self.__class__,

                                                        self.name,

                                                        self.description,

                                                        self._assigned_value,

-                                                       self._default_value)

+                                                       self._default_value,

+                                                       self._readonly)

  

      def __str__(self):

          return '%s=%s' % (self.name, self.get_value())
@@ -113,11 +116,14 @@ 

              raise ValueError('Value must be string')

          self._assigned_value = value

  

+     def is_readonly(self):

+         return self._readonly

+ 

  

  class String(Option):

  

-     def __init__(self, name, description, default_value=None):

-         super(String, self).__init__(name, description)

+     def __init__(self, name, description, default_value=None, readonly=False):

+         super(String, self).__init__(name, description, readonly=readonly)

          self._default_value = str(default_value)

  

      def set_value(self, value):
@@ -132,8 +138,9 @@ 

  

  class Template(Option):

  

-     def __init__(self, name, description, default_template=None):

-         super(Template, self).__init__(name, description)

+     def __init__(self, name, description, default_template=None,

+                  readonly=False):

+         super(Template, self).__init__(name, description, readonly=readonly)

          self._default_value = str(default_template)

  

      def set_value(self, value):
@@ -154,8 +161,8 @@ 

  

  class List(Option):

  

-     def __init__(self, name, description, default_list=None):

-         super(List, self).__init__(name, description)

+     def __init__(self, name, description, default_list=None, readonly=False):

+         super(List, self).__init__(name, description, readonly=readonly)

          if default_list:

              self._default_value = default_list

          else:
@@ -226,8 +233,9 @@ 

  

  class Choice(Option):

  

-     def __init__(self, name, description, allowed=None, default=None):

-         super(Choice, self).__init__(name, description)

+     def __init__(self, name, description, allowed=None, default=None,

+                  readonly=False):

+         super(Choice, self).__init__(name, description, readonly=readonly)

          if allowed:

              self._allowed_values = list(allowed)

          else:
@@ -295,8 +303,9 @@ 

  

  class Pick(Option):

  

-     def __init__(self, name, description, allowed, default_value):

-         super(Pick, self).__init__(name, description)

+     def __init__(self, name, description, allowed, default_value,

+                  readonly=False):

+         super(Pick, self).__init__(name, description, readonly=readonly)

          self._allowed_values = list(allowed)

          if default_value not in self._allowed_values:

              raise ValueError('The default value is not in the allowed list')
@@ -320,9 +329,11 @@ 

  

  class Condition(Pick):

  

-     def __init__(self, name, description, default_value=False):

+     def __init__(self, name, description, default_value=False,

+                  readonly=False):

          super(Condition, self).__init__(name, description,

-                                         [True, False], default_value)

+                                         [True, False], default_value,

+                                         readonly=readonly)

  

      def import_value(self, value):

          self._assigned_value = value == 'True'

@@ -59,9 +59,16 @@ 

                    {%- if value %}

                      value="{{ value }}"

                    {%- endif -%}

+                   {% if v.is_readonly() -%}

+                     disabled

+                   {%- endif -%}

                  >

                {% elif v.__class__.__name__ == 'List' -%}

-                 <textarea class="form-control" name="{{ v.name }}">

+                 <textarea class="form-control" name="{{ v.name }}"

+                   {% if v.is_readonly() -%}

+                     disabled

+                   {%- endif -%}

+                 >

                    {%- if value %}

                      {{- value|join('\n') -}}

                    {%- endif -%}
@@ -75,6 +82,9 @@ 

                        {%- if value and e in value %}

                          checked="true"

                        {%- endif -%}

+                       {% if v.is_readonly() -%}

+                         disabled

+                       {%- endif -%}

                      >&nbsp;{{ e }}

                    </div>

                  {% endfor %}
@@ -88,6 +98,9 @@ 

                        {%- if e == value %}

                          checked="true"

                        {%- endif -%}

+                       {% if v.is_readonly() -%}

+                         disabled

+                       {%- endif -%}

                      >&nbsp;{{ e }}

                    </div>

                  {% endfor %}
@@ -97,6 +110,9 @@ 

                    {%- if value %}

                      checked="true"

                    {% endif -%}

+                   {% if v.is_readonly() -%}

+                     disabled

+                   {%- endif -%}

                  >

                {% elif v.__class__.__name__ == 'ComplexList' -%}

                  <table class="table table-striped extensible-table">
@@ -112,6 +128,9 @@ 

                          {%- else -%}

                            value="{{ line }}"

                          {%- endif -%}

+                         {% if v.is_readonly() -%}

+                           disabled

+                         {%- endif -%}

                        >

                      </td>

                      <td>

no initial comment

I think it would be preferable to keep the same code style, so have the disabled argument be in a seperate line.