B4J Question [abmaterial] my first customcomponent(mutiple upload)

liulifeng77

Active Member
Licensed User
Longtime User
my first abmcustomcomponent
mutilte upload:
' Class module
Sub Class_Globals
    Dim ABM As ABMaterial ' ignore
    Dim ABMComp As ABMCustomComponent
    Private Page As ABMPage
    Public compid As String
    Private mMultiple As String
    Private autosumit As String
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(InternalPage As ABMPage, ID As String,auto As String,Multiple As String)
    Page = InternalPage
    
    ABMComp.Initialize("ABMComp", Me, InternalPage, ID,"")
    'InternalPage.InjectCSS(style.BuildStyleClasses)
    compid = ID.tolowercase
    autosumit=auto.ToLowerCase
        
    mMultiple = Multiple.ToLowerCase
    
End Sub

'
'build the component
Sub ABMComp_Build(InternalPage As ABMPage, internalID As String) As String
    
    Return $"<div id="${internalID}"></div>"$
    
    
End Sub


Sub ABMComp_FirstRun(InternalPage As ABMPage, internalID As String)
    Log(internalID)
    Page = InternalPage
    
    
    Dim js As String = $"$("#${internalID}").uploadFile({
        url:"abmuploadhandler",
        fileName:"upl",
        multiple:${mMultiple},
        dragDrop:true,
        autoSubmit:${autosumit},
        onLoad:function(obj){
        
        },
        onSuccess:function(files,data,xhr,pd){
        
        

        },
        afterUploadAll:function(obj){
        console.log("========================:");
        b4j_raiseEvent('${internalID}_allcompleted', {'value':'completed!'});
        },
        
    });
    
    "$   

    
Page.ws.Eval(js,Array As String(ABMComp.id))   

Page.ws.flush

    
    
    
End Sub


Sub ABMComp_Refresh(InternalPage As ABMPage, internalID As String)
    
End Sub

Sub ABMComp_CleanUp(InternalPage As ABMPage, internalID As String)
  
End Sub
Sub Upload
Dim script As String = $"$(#${compid}.startUpload"$
    Page.ws.Eval(script, Array As String(compid))
    Page.ws.flush
End Sub

It runs well in pages, but can't be added to a modalsheet, how to update it? thanks!!
 

alwaysbusy

Expert
Licensed User
Longtime User
The problem is the id in a ModalSheet, which causes the ID to have a '-' in it. Check out what I do with the varID here:

B4X:
'Class module
Sub Class_Globals
    Public ABMComp As ABMCustomComponent
    Private myValue As String
    Public mySize As Double
    Public myID As String
    Public mBCType As String = "CODE39"
    Public mHeight As Int = 40
End Sub
 
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(InternalPage As ABMPage, ID As String, value As String, size As Double, bcType As String, height As Int)
    ABMComp.Initialize("ABMComp", Me, InternalPage, ID, "")
    myValue = value      
    mySize = size
    mBCType = bcType
    mHeight = height
End Sub
 
Sub ABMComp_Build(InternalPage As ABMPage, internalID As String) As String  
    Dim varID As String = internalID.Replace("-", "_")
    myID = varID
    Return $"<svg id="${varID}svg" class="barcode"></svg>"$    
End Sub
 
' Is useful to run some initalisation script.
Sub ABMComp_FirstRun(InternalPage As ABMPage, internalID As String)
    If myValue = "" Then Return
    Dim varID As String = internalID.Replace("-", "_")
    Dim script As String = $"JsBarcode("#${varID}svg", "${myValue}", {
        format: "${mBCType}",
        textMargin: 0,
        width: ${mySize},
        background: "transparent",
        displayValue: false,
        height: ${mHeight},
        fontSize: 15 
    });"$
 
      InternalPage.ws.Eval(script, Array As Object(ABMComp.ID))
      ' flush not needed, it's done in the refresh method in the lib
End Sub
 
' runs when a refresh is called
Sub ABMComp_Refresh(InternalPage As ABMPage, internalID As String)
    Dim varID As String = internalID.Replace("-", "_")
    Dim script As String
    If myValue = "" Then 
        script = $"$('#${varID}svg').hide();"$
    Else    
        script = $"JsBarcode("#${varID}svg", "${myValue}", {
            format: "${mBCType}",
            textMargin: 0,
            width: ${mySize},
            background: "transparent",
            displayValue: false,
            height: ${mHeight},
            fontSize: 15 
        });
        $('#${varID}svg').show()"$     
          
    End If
    InternalPage.ws.Eval(script, Array As Object(ABMComp.ID))
End Sub

public Sub SetValue(InternalPage As ABMPage, value As String)    
    myValue = value
    ABMComp_Refresh(InternalPage, myID)
    InternalPage.ws.Flush
End Sub
 
' do the stuff needed when the object is removed
Sub ABMComp_CleanUp(InternalPage As ABMPage, internalID As String)
 
End Sub

Alwaysbusy
 
Upvote 0
Top