xdommask

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 17 Imported by: 8

README

Go Report Card GoDoc GolangCI

XDOMMASK for GO v1

XDomMask is the Mask Generation (aka HTML Forms) for GO-WAJAF.

Manuals are available on godoc.org GoDoc

TO DO:

  • Tests

Version Changes Control

v0.2.0 - 2024-04-09

  • Added searchableTextField to the list of available fields
  • Added groupField as sub-forms for master-detail relations
  • fileField modified to support multi file uploads
  • field.go modified to support group fields and MD5 encrypted fields
  • lovField modified to support radio buttons
  • mask modified to support templates of presentation, group fields, amin group flag, and multifile upload

v0.1.1 - 2022-12-02

  • FieldDef has been added with new methods: GetInRecord and PostGet
  • FieldDef PostInsert and PostUpdate now return a boolean to notify the value has been modified, to update the record
  • The DataField initalizer now set the name of the field also to the URLVariable name
  • Mask attribute VarField has been added to read incoming field name for fields listeners
  • Mask excute now know the "file" order to listen a Multipart post with files upload
  • DOINSERT and DODELETE orders now adds the primary key to the new record dataset, so PostInsert and PostUpdate methods can have access to the key
  • FileField, and extended ImageField and VideoField are now working as expected, to upload specific files. The extension, size and MIME type of file is verified

v0.1.0 - 2022-06-13

  • Added colorField, maskedField (replacing pwField)
  • All the mask function now pass the context to build and log messages
  • Better conversion of primary keys to be compatible with numeric and string values
  • Messages of information and errors are better managed
  • field main interface changed to add convertValue prototype and some other minor changes
  • GetName() funcion added in buttonField
  • integerField, floatField now converts correctly all the possible values from the field string value
  • textField now support automessages and values, password type renamed to masked type
  • lovField now works and can take a query of values from a XDominion filtered object
  • examples changed to meet new changes of main code

v0.0.7 - 2021-01-04

  • Implementation of type of field with constants (control, field, hidden, info)
  • Add NewInfoField to the list of known fields

v0.0.6 - 2020-04-13

  • mail, pw, textarea implemented

v0.0.5 - 2020-04-13

  • Modes on text adjusted. Node Name is same as ID by default. Do not send empty fields to the wajaf structure

v0.0.3 - 2020-04-13

  • some errors corrected on fields

v0.0.2 - 2020-04-13

  • mask, text, button with all attributes and messages

v0.0.1 - 2020-04-12

  • Added Compile and zones without ID
  • Added some field for button and text

v0.0.0 - 2020-04-08

  • First realease

Reference

Una mascara tiene 4 modos de funcionamiento:

  • Insert
  • Update
  • Delete
  • View

Cada modo de edicion funciona en 3 etapas:

  1. Despliego la forma con todos sus campos pasan varias cosas: 1.1 Se llama el Compile de XDomMask para fabricar el JSON de definicion de la forma (con (dentro del COMPILE) o sin la data del renglon)

1.2 Se envia el JSON al cliente que corre el groupContainer.js

1.3 El groupContainer.js despliegue de la forma (100% en en cliente: fabrica el <form y <fields )

1.4 Si estoy en update o delete, rellena los campos con los valores de la data del renglon 1.4.1 Si la data ya viene con el codigo de la forma, lo usa y lo rellena 1.4.2 Sino, va a pedir la data al server para rellenar y regresa a 1.2.1 con la data (con el EXECUTE->getRecord)

Punto y aparte: 1.5 Para contruir la data, si se necesita durante el COMPILE, va a llamar el EXECUTE->GetRecord(key) Si se necesita diferido, entonces el cliente llama el punto de entrada EXECUTE->GetRecord

  1. El usurio tiene interaccion con la mascara (rellena los campos)

Todos los JS de validacion

  1. Realiza la DoAction (insertar , modificar, o borrar la data en la fuente de datos)

Cuando se pica el boton DoAction (DoInsert, DoUpdate o DoDelete), llama el Execute del server

2.1 Si es DoUpate 2.1.1 El Execute va a contruir el renglon a modificar 2.1.2 Llama PreUpdate para que el usuario tenga la libertad de modificar el renglon y validar lo necesario 2.1.3 Llama Update para fisicamente modificar el renglon (key, record) En caso de NO tener una tabla, entonces el usuario TENDRA QUE definir su propia funcion Update 2.1.4 Llama PostUpdate para cualquier post tratamiento

El modo view solo funciona en 1 sola etapa

  1. Despliego la forma con todos sus campos relleno los campos con los valores de la data del renglon

Documentation

Index

Constants

View Source
const (
	CONTROL = "control"
	FIELD   = "field"
	INFO    = "info"
	HIDDEN  = "hidden"
	GROUP   = "group"
)
View Source
const (
	SEARCHABLETEXTTYPE_TEXT    = "text"
	SEARCHABLETEXTTYPE_MASKED  = "masked"
	SEARCHABLETEXTTYPE_INTEGER = "integer"
	SEARCHABLETEXTTYPE_FLOAT   = "float"
	SEARCHABLETEXTTYPE_EMAIL   = "email"
)
View Source
const (
	TEXTTYPE_TEXT    = "text"
	TEXTTYPE_MASKED  = "masked"
	TEXTTYPE_INTEGER = "integer"
	TEXTTYPE_FLOAT   = "float"
	TEXTTYPE_EMAIL   = "email"
)
View Source
const VERSION = "0.2.0"

Variables

View Source
var DEBUG bool = false

Functions

This section is empty.

Types

type ButtonField

type ButtonField struct {
	*ControlField
	Action string
}

func NewButtonField

func NewButtonField(name string, action string) *ButtonField

func (*ButtonField) Compile

func (f *ButtonField) Compile() wajaf.NodeDef

func (*ButtonField) GetName added in v0.1.0

func (f *ButtonField) GetName() string

type ColorField added in v0.1.0

type ColorField struct {
	*TextField
}

func NewColorField added in v0.1.0

func NewColorField(name string) *ColorField

func (*ColorField) Compile added in v0.1.0

func (f *ColorField) Compile() wajaf.NodeDef

type ControlField

type ControlField struct {
	*Field
	TitleInsert string
	TitleUpdate string
	TitleDelete string
	TitleView   string
	Control     bool
}

func NewControlField

func NewControlField(name string) *ControlField

func (*ControlField) Compile

func (f *ControlField) Compile() wajaf.NodeDef

type DataField

type DataField struct {
	*Field
	InRecord    bool
	URLVariable string

	Title        string
	DefaultValue string

	Auto        bool
	AutoMessage string

	Encoded  bool
	Entities bool

	NullOnEmpty  bool
	NullValue    string
	MD5Encrypted bool

	StatusNotNull string
	StatusCheck   string
}

func NewDataField

func NewDataField(name string) *DataField

func (*DataField) Compile

func (f *DataField) Compile() wajaf.NodeDef

func (*DataField) GetInRecord added in v0.2.0

func (f *DataField) GetInRecord() bool

func (*DataField) GetValue added in v0.1.0

func (f *DataField) GetValue(ctx *context.Context, mode Mode) (interface{}, bool, error)

GetValue to get the value from the field when needed. return value, ignored bool (true = ignored by construct) return ONLY string or nil

func (*DataField) PostGet added in v0.2.0

func (f *DataField) PostGet(ctx *context.Context, key interface{}, rec *xdominion.XRecord) error

type DateField

type DateField struct {
	*TextField
}

func NewDateField

func NewDateField(name string) *DateField

func (*DateField) Compile

func (f *DateField) Compile() wajaf.NodeDef

type Field

type Field struct {
	Name string
	Type string
	ID   string

	Style     string
	ClassName string

	AuthModes     Mode
	ViewModes     Mode
	ReadOnlyModes Mode
	NotNullModes  Mode
	DisabledModes Mode
	HelpModes     Mode

	HelpToolTip     string
	HelpDescription string
	HelpTitle       string
	TabIndex        int
	Size            string

	CheckJS string
	Focus   string
	Blur    string
}

func NewField

func NewField(name string) *Field

func (*Field) Compile

func (f *Field) Compile() wajaf.NodeDef

func (*Field) ConvertValue added in v0.1.0

func (f *Field) ConvertValue(value interface{}) (interface{}, error)

ConvertValue will convert the entry value to the correct type for this field

func (*Field) GetInRecord added in v0.2.0

func (f *Field) GetInRecord() bool

func (*Field) GetName added in v0.1.0

func (f *Field) GetName() string

func (*Field) GetType

func (f *Field) GetType() string

func (*Field) GetValue added in v0.1.0

func (f *Field) GetValue(ctx *context.Context, mode Mode) (interface{}, bool, error)

func (*Field) PostDelete added in v0.1.0

func (f *Field) PostDelete(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, rec *xdominion.XRecord) error

func (*Field) PostGet added in v0.2.0

func (f *Field) PostGet(ctx *context.Context, key interface{}, rec *xdominion.XRecord) error

func (*Field) PostInsert added in v0.1.0

func (f *Field) PostInsert(ctx *context.Context, key interface{}, rec *xdominion.XRecord) (bool, error)

func (*Field) PostUpdate added in v0.1.0

func (f *Field) PostUpdate(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, newrec *xdominion.XRecord) (bool, error)

func (*Field) PreDelete added in v0.1.0

func (f *Field) PreDelete(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, rec *xdominion.XRecord) error

func (*Field) PreInsert added in v0.1.0

func (f *Field) PreInsert(ctx *context.Context, rec *xdominion.XRecord) error

func (*Field) PreUpdate added in v0.1.0

func (f *Field) PreUpdate(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, newrec *xdominion.XRecord) error

type FieldDef

type FieldDef interface {
	Compile() wajaf.NodeDef
	GetType() string
	GetName() string
	GetInRecord() bool
	GetValue(ctx *context.Context, mode Mode) (interface{}, bool, error)
	ConvertValue(value interface{}) (interface{}, error)
	PostGet(ctx *context.Context, key interface{}, rec *xdominion.XRecord) error
	PreInsert(ctx *context.Context, rec *xdominion.XRecord) error
	PostInsert(ctx *context.Context, key interface{}, rec *xdominion.XRecord) (bool, error) // bool = field changed true/false, need an update
	PreUpdate(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, newrec *xdominion.XRecord) error
	PostUpdate(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, newrec *xdominion.XRecord) (bool, error)
	PreDelete(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, rec *xdominion.XRecord) error
	PostDelete(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, rec *xdominion.XRecord) error
}

type FileField

type FileField struct {
	*DataField

	AcceptExternal bool // true if third parties images are accepted (will show the value field and it is editable), like facebook links, instagram, google, etc
	DeleteButton   string
	Loading        string
	MultiFile      bool // true accept multifiles
	MaxSize        int64

	ExtensionsAuth  map[string]bool
	MimesAuth       map[string]string // format:   mime => icon. If icon == "*" will use the file image itself (if it's an image authorized, png, gif, jpeg only)
	OriginDir       string
	OriginPath      string
	DestinationDir  string
	DestinationPath string
	DestinationName string

	TemporalFileName  string   // Set only when a new upload happens
	TemporalFileNames []string // when it's multifile
	OriginalFileName  string   // Set only when a new upload happens
	OriginalFileNames []string // Set only when a new upload happens
	FinalFileName     string   // Official name of file, not modified if no upload, or temporal value if new upload
	IconPath          string
	IconName          string
	IconNames         []string
	Ext               string
	Mime              string
	Image             string   // only if filename is an official image (jpeg, png)
	Images            []string // only if filename is an official image (jpeg, png)
	// contains filtered or unexported fields
}

func NewFileField

func NewFileField(name string) *FileField

func (*FileField) CheckExtension added in v0.2.0

func (f *FileField) CheckExtension(name string, mime string) error

func (*FileField) Compile

func (f *FileField) Compile() wajaf.NodeDef

func (*FileField) CreateTempName added in v0.2.0

func (f *FileField) CreateTempName() string

func (*FileField) GetFinalFileName added in v0.2.0

func (f *FileField) GetFinalFileName() string

func (*FileField) GetIconName added in v0.2.0

func (f *FileField) GetIconName() string

func (*FileField) GetIconNames added in v0.2.0

func (f *FileField) GetIconNames() []string

func (*FileField) GetMime added in v0.2.0

func (f *FileField) GetMime() string

func (*FileField) GetMultiFile added in v0.2.0

func (f *FileField) GetMultiFile() bool

func (*FileField) GetOriginalFileName added in v0.2.0

func (f *FileField) GetOriginalFileName() string

func (*FileField) GetOriginalFileNames added in v0.2.0

func (f *FileField) GetOriginalFileNames() []string

func (*FileField) GetTemporalFileName added in v0.2.0

func (f *FileField) GetTemporalFileName() string

func (*FileField) GetTemporalFileNames added in v0.2.0

func (f *FileField) GetTemporalFileNames() []string

func (*FileField) GetTemporalImage added in v0.2.0

func (f *FileField) GetTemporalImage() string

func (*FileField) GetTemporalImages added in v0.2.0

func (f *FileField) GetTemporalImages() []string

func (*FileField) PostDelete added in v0.2.0

func (f *FileField) PostDelete(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, rec *xdominion.XRecord) error

func (*FileField) PostGet added in v0.2.0

func (f *FileField) PostGet(ctx *context.Context, key interface{}, rec *xdominion.XRecord) error

func (*FileField) PostInsert added in v0.2.0

func (f *FileField) PostInsert(ctx *context.Context, key interface{}, rec *xdominion.XRecord) (bool, error)

func (*FileField) PostUpdate added in v0.2.0

func (f *FileField) PostUpdate(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, newrec *xdominion.XRecord) (bool, error)

func (*FileField) PreInsert added in v0.2.0

func (f *FileField) PreInsert(ctx *context.Context, rec *xdominion.XRecord) error

func (*FileField) PreUpdate added in v0.2.0

func (f *FileField) PreUpdate(ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, newrec *xdominion.XRecord) error

func (*FileField) PrepareFile added in v0.2.0

func (f *FileField) PrepareFile(ctx *context.Context) error

func (*FileField) SaveImage added in v0.2.0

func (f *FileField) SaveImage(key interface{}, rec *xdominion.XRecord) error

type FloatField

type FloatField struct {
	*TextField
	DefaultValue  float64
	Min           float64
	Max           float64
	StatusTooLow  string
	StatusTooHigh string
}

func NewFloatField

func NewFloatField(name string) *FloatField

func (*FloatField) Compile

func (f *FloatField) Compile() wajaf.NodeDef

func (*FloatField) ConvertValue added in v0.1.0

func (f *FloatField) ConvertValue(value interface{}) (interface{}, error)

func (*FloatField) GetValue added in v0.1.0

func (f *FloatField) GetValue(ctx *context.Context, mode Mode) (interface{}, bool, error)

type GroupField added in v0.2.0

type GroupField struct {
	*Field
	Mask *Mask
	Ctx  *context.Context
}

func NewGroupField added in v0.2.0

func NewGroupField(name string, mask *Mask) *GroupField

func (*GroupField) Compile added in v0.2.0

func (f *GroupField) Compile() wajaf.NodeDef

type HiddenField

type HiddenField struct {
	*DataField
	DefaultValue string
}

hiddenfield is a hidden field to pass information between field group and server. It should have a default value and is setable by code. Its value will be send to the server in any mode if authorized

func NewHiddenField

func NewHiddenField(name string) *HiddenField

func (*HiddenField) Compile

func (f *HiddenField) Compile() wajaf.NodeDef

type Ifilefield added in v0.2.0

type Ifilefield interface {
	PrepareFile(ctx *context.Context) error
	GetOriginalFileName() string
	GetTemporalFileName() string
	GetFinalFileName() string
	GetMime() string
	GetIconName() string
	GetTemporalImage() string
	GetMultiFile() bool
	GetOriginalFileNames() []string
	GetTemporalFileNames() []string
	GetIconNames() []string
	GetTemporalImages() []string
}

type ImageField

type ImageField struct {
	*FileField
}

func NewImageField

func NewImageField(name string) *ImageField

type InfoField

type InfoField struct {
	*Field
	Data string
}

func NewInfoField

func NewInfoField(name string, data string) *InfoField

func (*InfoField) Compile

func (f *InfoField) Compile() wajaf.NodeDef

type IntegerField

type IntegerField struct {
	*TextField
	DefaultValue  int
	Min           int
	Max           int
	StatusTooLow  string
	StatusTooHigh string
}

func NewIntegerField

func NewIntegerField(name string) *IntegerField

func (*IntegerField) Compile

func (f *IntegerField) Compile() wajaf.NodeDef

func (*IntegerField) ConvertValue added in v0.1.0

func (f *IntegerField) ConvertValue(value interface{}) (interface{}, error)

func (*IntegerField) GetValue added in v0.1.0

func (f *IntegerField) GetValue(ctx *context.Context, mode Mode) (interface{}, bool, error)

type LOOField

type LOOField struct {
	*DataField
	DefaultValue string
	Options      map[string]string
	MultiSelect  bool

	FocusJS string
	BlurJS  string
}

List Of Options field: it is dynamic. when the user write the field, a list of possible options displays under the field and can be selected.

func NewLOOField

func NewLOOField(name string) *LOOField

func (*LOOField) Compile

func (f *LOOField) Compile() wajaf.NodeDef

type LOVField

type LOVField struct {
	*DataField
	DefaultValue string
	Options      map[string]string
	MultiSelect  bool
	RadioButton  bool

	Table      *xdominion.XTable
	Order      *xdominion.XOrder
	Conditions *xdominion.XConditions
	FieldSet   *xdominion.XFieldSet

	FocusJS  string
	BlurJS   string
	ChangeJS string
}

List Of Values field: it is static. The list comes as tags. Can come from table or array of values, can be reloaded with a listener (sub-list)

func NewLOVField

func NewLOVField(name string) *LOVField

func (*LOVField) Compile

func (f *LOVField) Compile() wajaf.NodeDef

type MailField

type MailField struct {
	*TextField
}

func NewMailField

func NewMailField(name string) *MailField

func (*MailField) Compile

func (f *MailField) Compile() wajaf.NodeDef

type Mask

type Mask struct {
	Hooks MaskHooks

	ID string

	Display       string
	Style         string
	ClassName     string
	ClassNameZone string
	VarMode       string
	VarOrder      string
	VarKey        string
	VarField      string
	Maingroup     string
	Template      string

	Mode        Mode
	AuthModes   Mode
	KeyField    string
	Key         interface{}
	InsertedKey interface{}

	Variables map[string]string
	SuccessJS string
	FailureJS string

	AlertMessage         string
	ServerMessage        string
	InsertTitle          string
	UpdateTitle          string
	DeleteTitle          string
	ViewTitle            string
	DoInsertMessage      string
	DoUpdateMessage      string
	DoDeleteMessage      string
	ConfirmDeleteMessage string

	Counter int
	Fields  []FieldDef

	Table      *xdominion.XTable
	Order      *xdominion.XOrder
	Conditions *xdominion.XConditions
	FieldSet   *xdominion.XFieldSet
}

func NewMask

func NewMask(id string, hooks MaskHooks, ctx *context.Context) (*Mask, error)

func (*Mask) AddField

func (m *Mask) AddField(f FieldDef)

func (*Mask) Compile

func (m *Mask) Compile(mode string, ctx *context.Context) wajaf.NodeDef

func (*Mask) PostGet added in v0.2.0

func (m *Mask) PostGet(ctx *context.Context, key interface{}, rec *xdominion.XRecord) error

func (*Mask) Run added in v0.1.0

func (m *Mask) Run(ctx *context.Context) (map[string]interface{}, error)

func (*Mask) RunMultipart added in v0.2.0

func (m *Mask) RunMultipart(ctx *context.Context) (map[string]interface{}, error)

type MaskHooks added in v0.1.0

type MaskHooks struct {
	Build func(m *Mask, ctx *context.Context) error

	GetRecord func(m *Mask, ctx *context.Context, key interface{}, mode int) (string, *xdominion.XRecord, error)

	PreInsert  func(m *Mask, ctx *context.Context, rec *xdominion.XRecord) error
	Insert     func(m *Mask, ctx *context.Context, rec *xdominion.XRecord) (interface{}, error)
	PostInsert func(m *Mask, ctx *context.Context, key interface{}, rec *xdominion.XRecord) error

	PreUpdate  func(m *Mask, ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, newrec *xdominion.XRecord) error
	Update     func(m *Mask, ctx *context.Context, key interface{}, newrec *xdominion.XRecord) error
	PostUpdate func(m *Mask, ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, newrec *xdominion.XRecord) error

	PreDelete  func(m *Mask, ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, rec *xdominion.XRecord) error
	Delete     func(m *Mask, ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, rec *xdominion.XRecord) error
	PostDelete func(m *Mask, ctx *context.Context, key interface{}, oldrec *xdominion.XRecord, rec *xdominion.XRecord) error
}

type MaskedField added in v0.1.0

type MaskedField struct {
	*TextField
}

func NewMaskedField added in v0.1.0

func NewMaskedField(name string) *MaskedField

type Mode

type Mode int
const (
	INSERT Mode = 1 << iota
	UPDATE
	DELETE
	VIEW
	DOINSERT
	DOUPDATE
	DODELETE
	CONFIRMDELETE
)

type SearchableTextField added in v0.2.0

type SearchableTextField struct {
	*DataField
	TextType string

	Format   string
	FormatJS string

	MinLength int
	MaxLength int
	MinWords  int
	MaxWords  int

	StatusBadFormat    string
	StatusTooShort     string
	StatusTooLong      string
	StatusTooFewWords  string
	StatusTooManyWords string

	KeyUpJS string
	FocusJS string
	BlurJS  string

	Check func(ctx *context.Context, mode Mode, value interface{}) error
	Calc  func(ctx *context.Context, mode Mode, rec *xdominion.XRecord) (interface{}, error)
}

func NewSearchableTextField added in v0.2.0

func NewSearchableTextField(name string) *SearchableTextField

func (*SearchableTextField) Compile added in v0.2.0

func (f *SearchableTextField) Compile() wajaf.NodeDef

func (*SearchableTextField) GetValue added in v0.2.0

func (f *SearchableTextField) GetValue(ctx *context.Context, mode Mode) (interface{}, bool, error)

GetValue to get the value from the field when needed. return value, ignored bool (true = ignored by construct)

type TextAreaField

type TextAreaField struct {
	*TextField
	Width  int
	Height int
}

func NewTextAreaField

func NewTextAreaField(name string) *TextAreaField

func (*TextAreaField) Compile

func (f *TextAreaField) Compile() wajaf.NodeDef

type TextField

type TextField struct {
	*DataField
	TextType string

	Format   string
	FormatJS string

	MinLength int
	MaxLength int
	MinWords  int
	MaxWords  int

	StatusBadFormat    string
	StatusTooShort     string
	StatusTooLong      string
	StatusTooFewWords  string
	StatusTooManyWords string

	KeyUpJS string
	FocusJS string
	BlurJS  string

	Check func(ctx *context.Context, mode Mode, value interface{}) error
	Calc  func(ctx *context.Context, mode Mode, rec *xdominion.XRecord) (interface{}, error)
}

func NewTextField

func NewTextField(name string) *TextField

func (*TextField) Compile

func (f *TextField) Compile() wajaf.NodeDef

func (*TextField) GetValue added in v0.1.0

func (f *TextField) GetValue(ctx *context.Context, mode Mode) (interface{}, bool, error)

GetValue to get the value from the field when needed. return value, ignored bool (true = ignored by construct)

type VideoField

type VideoField struct {
	*FileField
}

func NewVideoField

func NewVideoField(name string) *VideoField

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL