﻿B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=9.8
@EndOfDesignText@
#IgnoreWarnings:12
'This is needed by the BANanoServer i.e. jetty server
#Region BANano
' <-------------- IMPORTANT! This is because we want this module to be transpiled by BANano
#End Region
'Global variables...
Sub Class_Globals
	'the vuetify app instance
	Public vuetify As VuetifyApp
	'this page instance
	Public page As VueComponent
	'the name of this route component page
	Public name As String = "vtransportes"
	Public path As String = "/vtransportes"
	'the b4x to javascript transpiler
	Private BANano As BANano			'ignore
	'define the page components
	Private conttransportes As VContainer			'ignore
	Private rowtransportes As VRow			'ignore
	Private coltransportes As VCol			'ignore
	Private tbltransportes As VueTable			'ignore
	Private dstransportes As BananoDataSource			'ignore
	Private dlgtransportes As VFlexDialog			'ignore
	Private frmtransportes As VForm			'ignore
	Private confirmtransportes As VMsgBox			'ignore
	Private txtid As VField    'ignore
	Private txtobra As VField    'ignore
	Private txtdescripcion As VField    'ignore
End Sub
Sub Initialize(v As VuetifyApp)
	'establish a reference to the app
	vuetify = v
	'initialize the component
	page.Initialize(Me, name)
	page.vuetify = vuetify
	'set the page title
	page.Title = "transportes"
	'uncomment this line if this will be the first page
	'page.StartPage
	path = page.path
	'
	'build the page html here
	BANano.LoadLayout(page.Here, "laytransportes")
	'apply master data-source settings - set it on pgIndex
	vuetify.SetBackEnd(dstransportes)
	vuetify.ShowSwalError("Cargada la pestaña de transporte")
	'add validation rules
	'get the empty form
	frmtransportes = dlgtransportes.Form
	'build the vflex dialog
	Build_transportes_VFlexDialog

	'bind the form to the ds & table (table should be set to manual)
	frmtransportes.BindState(page)
	frmtransportes.BindDataSource(dstransportes)
	frmtransportes.BindDataTable(tbltransportes)
	'universal dialog management
	page.AddMethod("OkResponse", Null)
	page.AddMethod("CancelResponse", Null)
	'*****
	'add the route page to vuetify instance
	vuetify.AddRoute(page)
End Sub

'In the mounted hook, you will have full access to the reactive component, templates, and rendered DOM
Sub mounted		'ignoreDeadCode
	'we want the records to load on mount
	vuetify.Loading(True)
	vuetify.ShowSwalError("Cargada la pestaña de transporte")
	'fetch the records from the data-base
	dstransportes.SELECT_ALL
End Sub
'build the vflex dialog
Sub Build_transportes_VFlexDialog
	dlgtransportes.TableName = "transportes"
	dlgtransportes.Title = "transportes"
	dlgtransportes.PrimaryKey = "id"
	dlgtransportes.AutoIncrement = "id"
	dlgtransportes.RecordSource = "transporte"
	dlgtransportes.Singular = "transporte"
	dlgtransportes.Plural = "transportes"
	dlgtransportes.DisplayField = ""
	dlgtransportes.Clearable = False
	dlgtransportes.Dense = True
	dlgtransportes.HideDetails = False
	dlgtransportes.Filled = False
	dlgtransportes.Outlined = True
	dlgtransportes.Rounded = True
	dlgtransportes.Shaped = False

	txtid = dlgtransportes.AddTextField (1, 1, "id", "Id", "")
	dlgtransportes.SetItemOnDB("id", "Yes", "")
	dlgtransportes.SetItemOnTable("id", "Normal", False, False ,False, "large")
	dlgtransportes.SetItemHidden("id", True)
	txtobra = dlgtransportes.AddTextField (2, 1, "obra", "Obra", "")
	dlgtransportes.SetItemOnDB("obra", "Yes", "")
	dlgtransportes.SetItemOnTable("obra", "Normal", False, False ,False, "large")
	txtdescripcion = dlgtransportes.AddTextField (3, 1, "descripcion", "Descripcion", "")
	dlgtransportes.SetItemOnDB("descripcion", "Yes", "")
	dlgtransportes.SetItemOnTable("descripcion", "Normal", True, False ,False, "large")

	dlgtransportes.Refresh
End Sub
'refresh the contents of the 'transportes' table
Private Sub tbltransportes_Refresh_Click (e As BANanoEvent)       'IgnoreDeadCode
	'call mounted reloads the records to the data-table
	page.CallMounted
End Sub
'table add new button has been clicke
Private Sub tbltransportes_Add_Click (e As BANanoEvent)	'IgnoreDeadCode
	dstransportes.ADD
	'change the title of the dialog
	dlgtransportes.Title = $"Add ${(dstransportes.Singular)}"$
	'change the ok label
	dlgtransportes.YesCaption = "Save"
	'change the cancel label
	dlgtransportes.NoCaption = "Cancel"
	'show the dialog
	dlgtransportes.Show
End Sub
'Edit button has been clicked on a row
'Gets the row being edited, keys have the field names
Private Sub tbltransportes_Edit (item As Map)		'IgnoreDeadCode
	vuetify.Loading(True)
	'freeze the table contents
	tbltransportes.Freeze
	'receive the record from the data-table and execute a read from the database
	dstransportes.EDIT(item)
End Sub
'Delete button has been clicked on a row
'Gets the row being deleted, keys have the field names
Private Sub tbltransportes_Delete (item As Map)		'IgnoreDeadCode
	dstransportes.DELETE_CONFIRM(item)
	Dim sMsg As String = $"<h2>${dstransportes.DisplayValue}</h2><br>Are you sure that you want to delete this ${dstransportes.Singular.ToLowerCase}?"$
	confirmtransportes.Confirm(page, "delete", "Confirm Delete", sMsg, "Yes", "No")
	'vuetify.Confirm("transportes_delete", "Confirm Delete", sMsg, "Yes", "No")
End Sub
Private Sub confirmtransportes_Ok_Click (e As BANanoEvent)			'IgnoreDeadCode
	'show a loading indicator on ok button
	confirmtransportes.OkLoading = True
	'execute the delete call
	dstransportes.DELETE
End Sub
Private Sub dstransportes_Delete (Success As Boolean, Response As String, Error As String, affectedRows As Int, Result As List)		'IgnoreDeadCode
	confirmtransportes.OkLoading = False
	If Success And Response = dstransportes.RESULT_SUCCESS Then
		'hide the dialog
		confirmtransportes.hide
		'load the method to load all records
		page.CallMounted
	Else
		Log(Error)
		vuetify.ShowSwalError("The operation could not be executed, please try again!")
		Return
	End If
End Sub
Private Sub confirmtransportes_Cancel_click (e As BANanoEvent)			'IgnoreDeadCode
	''hide the dialog
	confirmtransportes.hide
End Sub
'clear sort button has been clicked
Private Sub tbltransportes_ClearSort_Click (e As BANanoEvent)		'IgnoreDeadCode
	tbltransportes.ClearSort
End Sub
'back button has been clicked
Private Sub tbltransportes_Back_Click (e As BANanoEvent)		'IgnoreDeadCode
	vuetify.NavigateTo("?")
End Sub
'Returns the records loaded from the database
Sub dstransportes_SelectAll (Success As Boolean, Response As String, Error As String, affectedRows As Int, Result As List)		'IgnoreDeadCode
	If Success And Response = dstransportes.RESULT_SUCCESS Then
		'reload records to the data-table
		tbltransportes.Reload(Result)
		'refresh the totals if any
		tbltransportes.RefreshTotals
		'turn off loading indicator
		vuetify.Loading(False)
	Else
		Log(Error)
		vuetify.Loading(False)
		vuetify.ShowSwalError("The operation could not be executed, please try again!")
		Return
	End If
End Sub
'fired when an edit-dialog is opened
Private Sub tbltransportes_OpenItem (item As Map)
End Sub
'fired when an edit-dialog is cancelled
Private Sub tbltransportes_CancelItem (item As Map)
End Sub
'fired when an edit-dialog is closed
Private Sub tbltransportes_CloseItem (item As Map)
End Sub
'fired when an edit-dialog is saved
Private Sub tbltransportes_SaveItem (item As Map)
End Sub
Private Sub dlgtransportes_Yes_Click (e As BANanoEvent)		'IgnoreDeadCode
	'perform form data verification via data-source
	dstransportes.VERIFY
	'peform the form validation
	page.refs = vuetify.GetRefs
	Dim bValid As Boolean = frmtransportes.Validate(page)
	If bValid = False Then
		'the validation has failed
		vuetify.ShowSwalToastError("Please enter all required information!", 2000)
		Return
	End If
	'show a loading indicator on the ok button
	dlgtransportes.YesLoading = True
	'get the record from form (recordsource) and CREATE / UPDATE record depending on mode
	dstransportes.CREATE_OR_UPDATE
End Sub
Private Sub dstransportes_Create (Success As Boolean, Response As String, Error As String, affectedRows As Int, Result As List)		'IgnoreDeadCode
	'turn off the ok loading indicator
	dlgtransportes.YesLoading = False
	If Success And Response = dstransportes.RESULT_SUCCESS Then
		'hide the dialog
		dlgtransportes.hide
		'run method to load the records
		page.CallMounted
	Else
		Log(Error)
		vuetify.ShowSwalError("The operation could not be executed, please try again!")
		Return
	End If
End Sub
Private Sub dstransportes_Update (Success As Boolean, Response As String, Error As String, affectedRows As Int, Result As List)		'IgnoreDeadCode
	'turn off the loading indicator
	dlgtransportes.YesLoading = False
	If Success And Response = dstransportes.RESULT_SUCCESS Then
		'hide the dialog
		dlgtransportes.hide
		'run the method to load records
		page.CallMounted
	Else
		Log(Error)
		vuetify.ShowSwalError("The operation could not be executed, please try again!")
		Return
	End If
End Sub
'show a loading indicator for the data-table
'set the selected record to be active on the data-source and read from database
'we will show the edit dialog when the record is read from the db
Private Sub dstransportes_Read (Success As Boolean, Response As String, Error As String, affectedRows As Int, Result As List)		'IgnoreDeadCode
	vuetify.Loading(False)
	If Success And Response = dstransportes.RESULT_SUCCESS Then
		'move to the first record
		dstransportes.MOVE_FIRST(Result)
		'change the title of the dialog
		dlgtransportes.Title = $"Edit ${(dstransportes.Singular)}"$
		'change the ok label
		dlgtransportes.YesCaption = "Update"
		'change the cancel label
		dlgtransportes.NoCaption = "Cancel"
		'show the dialog
		dlgtransportes.Show
	Else
		Log(Error)
		vuetify.ShowSwalError("The operation could not be executed, please try again!")
		Return
	End If
End Sub
Private Sub dlgtransportes_No_click (e As BANanoEvent)			'IgnoreDeadCode
	''hide the dialog
	dlgtransportes.hide
End Sub
'the dialog has become visible, reset validation
Private Sub dlgtransportes_Visible				'IgnoreDeadCode
	Try
		'determine if the dialog is visible
		Dim bVisible As Boolean = dlgtransportes.IsVisible(page)
		'if the dialog is visible
		If bVisible Then
			'refresh the refs to link to the active page
			page.refs = vuetify.GetRefs
			'reset the form validations
			frmtransportes.ResetValidation(page)
		End If
	Catch
	End Try			'ignore
End Sub
'change the user name on vappbar.appuser
Sub ChangeUserName(newUserName As String)			'IgnoreDeadCode
	vuetify.SetData("username", newUserName)
End Sub
'change the title on vappbar.vtoolbartitle
Sub ChangeAppBarTitle(newTitle As String)			'IgnoreDeadCode
	vuetify.SetData("apptitlecaption", newTitle)
End Sub
'<code>
'vuetify.Prompt("app_prompt", "First Name", "What is your first name", "", "", "Mashy", "Ok", "Cancel")
'vuetify.Confirm("app_confirm", "Confirm Delete", "Are you sure you want to delete this?", "Yes", "No")
'vuetify.Alert("app_alert", "Alert", "This is a app alert", "Great!")
'</code>
'returned by pgIndex.appdialog.OK_click
private Sub OkResponse
	'hide the universal dialog
	vuetify.HideDialog
	'get the process response
	Dim lastProcess As String = vuetify.Process	'ignore
	'get the prompt entered
	Dim enteredValue As String = vuetify.GetResponseValue		'ignore
	Select Case lastProcess
		Case ""
			'a record is deleted from transportes
		Case "transportes_delete"
	End Select
End Sub
'returned by pgIndex.appdialog.CANCEL_click
private Sub CancelResponse
	'hide the universal dialog
	vuetify.hidedialog
	'get the process response
	Dim lastProcess As String = vuetify.Process	'ignore
	Select Case lastProcess
		Case ""
			'a record deletion is cancelled for transportes
		Case "transportes_delete"
	End Select
End Sub
'Use beforeDestroy if you need to clean-up events or reactive subscriptions:
Sub beforeDestroy		'ignoreDeadCode
	'set = null all objects defined in this page
	'this seeks to preserve RAM
	page.DestroyAll
End Sub
'The updated hook runs after data changes on your component and the DOM re-renders.
'Sub updated			'ignoreDeadCode
'End Sub
'The beforeUpdate hook runs after data changes on your component and the update cycle begins, right before the DOM is patched and re-rendered.
'Sub beforeUpdate		'ignoreDeadCode
'End Sub
'The beforeMount hook runs right before the initial render happens and after the template or render functions have been compiled:
'Sub beforeMount		'ignoreDeadCode
'End Sub
'The beforeCreate hook runs at the very initialization of your component. data has not been made reactive, and events have not been set up yet
'Sub beforeCreate		'ignoreDeadCode
'End Sub
'Use destroyed if you need do any last-minute cleanup or inform a remote server that the component was destroyed:
'Sub destroyed		'ignoreDeadCode
'End Sub