ผลต่างระหว่างรุ่นของ "CuneiTable"

จาก คูนิฟ็อกซ์ วิกิ
บรรทัดที่ 68: บรรทัดที่ 68:
MASTER_fullform = ['cunei_iv', 'ProductFullForm', 'Product Information', 'xl']
MASTER_fullform = ['cunei_iv', 'ProductFullForm', 'Product Information', 'xl']
</syntaxhighlight>
</syntaxhighlight>
* '''modal_size''' utilizes BootStrap 4's {{code|lang=javascript|'modal-<modal_size>'}} classes. Available choices are {{code|lang=python|'xs'}}, {{code|lang=python|'sm'}}, {{code|lang=python|'md'}}, {{code|lang=python|'lg'}}, and {{code|lang=python|'xl'}}.
* '''size''' dictates the modal size displayed on the client-side. It utilizes BootStrap 4's {{code|lang=javascript|'modal-<size>'}} classes. Available choices are {{code|lang=python|'sm'}}, {{code|lang=python|'md'}} ''(corresponds to default modal size)'', {{code|lang=python|'lg'}}, and {{code|lang=python|'xl'}}.


'''NOTE #1''': CuneiFox automatically creates a full-form instance from the class '''{{code|fullform_class_name}}''' located under {{code|forms.py}} (or {{code|forms.pyc}}) of the module '''{{code|module_code}}'''.
'''NOTES''' on full-form class and macro:
* The CuneiForm class '''{{code|fullform_class_name}}''' must be found under '''{{code|module_code}}''' in the file {{code|cuneifox/<module_code>/forms.py}} or {{code|cuneifox/<module_code>/forms.pyc}}.
* The definition of the full-form class '''DOES NOT include the [[CuneiForm#Submit-delete Field Set|Submit-delete Field Set]]'''
* The Jinja2 macro for the full-form design must also be named '''{{code|fullform_class_name}}''' and must be found under '''{{code|module_code}}''' in the file {{code|cuneifox/<module_code>/template/<module_code>/form_macro.html}}.
* Refer to the main [[CuneiForm]] article for more details on form definition and design. For information specific the full-form macros, refer to [[#Full-form Macro|a dedicated sub-section]] below.


=== In-line Form with Expansion ===
=== In-line Form with Expansion ===

รุ่นแก้ไขเมื่อ 11:19, 17 เมษายน 2567

CuneiTable is designed specifically to enable in-line data entry. Design-wise, it is more limited than CuneiForm since design flexibility is not highly expected from table-rype objects. In essence, CuneiTable is a wrapper for the accompanying CuneiForm, whether that form be the in-line type or the full expansion type.

Define

Defining a CuneiTable is essentially declaring a CuneiForm with a few additional class variables. Below is an example of a very basic CuneiTable:

class AccCodeTable(CuneiTable):
    MASTER_colsizes = [10, 20, 50, 20]
    MASTER_colnames = ["StID", "Account Code", "Account Name", "Account Group"]
    MASTER_coltypes = ["int", "str", "str", "sel"]
    MASTER_choicecols = ["accgrp"]
    MASTER_choices = [[
                         ("1", "1: Asset"),
                         ("2", "2: Liability"),
                         ("3", "3: Equity"),
                         ("4", "4: Revenue"),
                         ("5", "5: Expense")
                     ]]
    MASTER_firstonly = ["stid"]
    class SubForm(FlaskForm, CuneiSubForm):
        stid = StringField("StID")
        code = StringField("Code", validators=[InputRequired("Required!")])
        name = StringField("Name", validators=[InputRequired("Required!")])
        accgrp = SelectField("Group", default=1)
        def validate_stid(self, stid):
            # Validation goes here

The subclass SubForm is defined like the stripped down version of CuneiForm. Only put fields and validation logics here. All other behaviours are controlled by the MASTER variables from the CuneiTable level.

NOTE THAT neither of the Submit-delete Field Set (submit, is_del, and del_submit) is declared in the SubForm. These fields are taken care of automatically during CuneiTable initiation.

The Holy Trinity of CuneiTable

The 3 MASTER variables listed below are required for all CuneiTable classes.

  • MASTER_colnames ([str,]): The list of column headers to appear on the page.
  • MASTER_coltypes ([str,]): The list of column value types. Available types include:
    • All types listed in the main article for CuneiForm.
    • 'str': Normal string value.
    • 'check': Value represented by a checkbox.
    • 'sel': Value with multiple choices. In other words, this is equivalent to a drop-list field in forms. In the same fashion, the displayed values for this type is not exactly the same as the values stored in the database. The raw value must pass through a map first before being displayed.
    • 'rad': Similar to 'sel', but this value type is represented by radio buttons in multiple sub-columns instead.
    • 'submit', 'del_submit': Submit button. (Not handled manually, they are handled automatically during initiation.)
  • MASTER_colsizes ([float/int,]): The list of relative column sizes. CuneiFox will calculate the display sizes automatically.

NOTE #1: The member order in each of these lists follow the definition order of fields in the SubForm. DO CHECK that all of these 3 lists and the SubForm fields share the same length.

NOTE #2: On the client-side, a radio field ('rad') is displayed as multiple sub-columns (one for each choice). Hence:

  • The display headers of sub-columns are not dictated by the corresponding value in MASTER_colnames, but by the values in MASTER_radios (Detailed in a sub-section below) instead.
  • The corresponding member in the MASTER_colsizes list is NOT merely one numerical value, BUT a list of numerical values instead.

Choices and Radios

Search and Fill

Instant Calculation

Auto-numbering Function

Table with a Separate Form Modal

Sometimes, the entries have either too many columns or columns not suitable for display in the table format. In such cases, developers can use the full-form option. CuneiTable with an associated full-form is only defined with essential columns for a 'quick glance' view. The full form is shown in a pop-up modal for entry addition/edit.

A CuneiTable can be linked to a full-form via the class variable MASTER_fullform which takes the following format:

MASTER_fullform = [str module_code, str fullform_class_name, str fullform_modal_header_text, str modal_size]

# Example from Product table
MASTER_fullform = ['cunei_iv', 'ProductFullForm', 'Product Information', 'xl']
  • size dictates the modal size displayed on the client-side. It utilizes BootStrap 4's 'modal-<size>' classes. Available choices are 'sm', 'md' (corresponds to default modal size), 'lg', and 'xl'.

NOTES on full-form class and macro:

  • The CuneiForm class fullform_class_name must be found under module_code in the file cuneifox/<module_code>/forms.py or cuneifox/<module_code>/forms.pyc.
  • The definition of the full-form class DOES NOT include the Submit-delete Field Set
  • The Jinja2 macro for the full-form design must also be named fullform_class_name and must be found under module_code in the file cuneifox/<module_code>/template/<module_code>/form_macro.html.
  • Refer to the main CuneiForm article for more details on form definition and design. For information specific the full-form macros, refer to a dedicated sub-section below.

In-line Form with Expansion

Other Table Definition Variables

Initiate

Design & Pre-made Scripts

Full-form Macro

Notable Sub-routines