Announcement

Collapse
No announcement yet.

examples of storing text as event action

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    examples of storing text as event action

    Hi All,

    Apologies for a simple question, but my plugins have always worked with drop down lists but I now move towards needing some text boxes. For the life of me I cannot work out how to get this to actually work.

    So in my setup I have a dropdown box, which lets the user select the recipient then two textboxes, one for the title and one for the body, from what I can see it is gettign posted fine but then nothing happens after that, and on the events page the ActionFormatUI does not appear to be called.

    I have tried a few variations, the text boxes with and without the sunique and UID and so on but seem to have no luck.

    Has anyone had a similar issue, or has anyone got text boxes and dropdown boxes to work toghether and if so would you be able to share some code as an example or point me in the right direction.

    I had a look at the sample plugins, but one is to complex for me to make sense of, and the other uses all drop down boxes which also does not help.

    Any help is most appreciated,

    Thanks!


    Code:
        Public Function ActionConfigured(ByVal ActInfo As IPlugInAPI.strTrigActInfo) As Boolean
            Dim Configured As Boolean = False
            Dim sKey As String
            Dim UID As String
            UID = ActInfo.UID.ToString
    
            If ActInfo.TANumber = 1 Then
                Dim itemsConfigured As Integer = 0
                Dim itemsToConfigure As Integer = 3
                If Not (ActInfo.DataIn Is Nothing) Then
                    DeSerializeObject(ActInfo.DataIn, action)
                    For Each sKey In action.Keys
                        Select Case True
                            Case InStr(sKey, "recipient_" & UID) > 0 AndAlso action(sKey) <> ""
                                itemsConfigured += 1
                            Case InStr(sKey, "title_" & UID) > 0 AndAlso action(sKey) <> ""
                                itemsConfigured += 1
                            Case InStr(sKey, "body_" & UID) > 0 AndAlso action(sKey) <> ""
                                itemsConfigured += 1
                        End Select
                    Next
                    If itemsConfigured = itemsToConfigure Then Configured = True
                End If
    
            ElseIf ActInfo.TANumber = 2 Then
            ElseIf ActInfo.TANumber = 3 Then
            ElseIf ActInfo.TANumber = 4 Then
    
    
            End If
         
            Return Configured
        End Function
    
        Public Function ActionBuildUI(ByVal sUnique As String, ByVal ActInfo As HomeSeerAPI.IPlugInAPI.strTrigActInfo) As String
            Dim UID As String
            UID = ActInfo.UID.ToString
            Dim stb As New StringBuilder
    
            If ActInfo.TANumber = 1 Then
    
                Dim recipient As String = ""
                Dim title As String = ""
                Dim body As String = ""
                Dim dd As New clsJQuery.jqDropList("recipient_" & UID & sUnique, Pagename, True)
                Dim noteBody As New clsJQuery.jqTextBox("title_" & UID & sUnique, "text", "", "Events", 50, True)
                Dim noteTitle As New clsJQuery.jqTextBox("body_" & UID & sUnique, "text", "", "Events", 50, True)
                Dim sKey As String
                dd.autoPostBack = True
                dd.AddItem("--Please Select--", "", False)
    
                If Not (ActInfo.DataIn Is Nothing) Then
                    DeSerializeObject(ActInfo.DataIn, action)
                Else 'new event, so clean out the action object
                    action = New action
                End If
    
                For Each sKey In action.Keys
                    Select Case True
                        Case InStr(sKey, "recipient_" & UID) > 0
                            recipient = action(sKey)
                        Case InStr(sKey, "title_" & UID) > 0
                            title = action(sKey)
                        Case InStr(sKey, "body_" & UID) > 0
                            body = action(sKey)
                    End Select
                Next
    
                dd.AddItem("All", "All", ("All" = recipient))
    
          .....
    
                For Each device In devices.Devices
                    dd.AddItem(device.nickname, device.nickname, (device.nickname = recipient))
                Next
           
    
    
                stb.Append("Recipient:")
                stb.Append(dd.Build)
                stb.Append("&nbsp;&nbsp;")
                stb.Append("Title" & noteTitle.Build)
                stb.Append("&nbsp;&nbsp;")
                stb.Append("Body:" & noteBody.Build)
    
            ElseIf ActInfo.TANumber = 2 Then
            ElseIf ActInfo.TANumber = 3 Then
            ElseIf ActInfo.TANumber = 4 Then
    
            End If
    
            
    
           
    
    
            Return stb.ToString
        End Function
    
        Public Function ActionProcessPostUI(ByVal PostData As Collections.Specialized.NameValueCollection, _
                                            ByVal ActInfo As IPlugInAPI.strTrigActInfo) As IPlugInAPI.strMultiReturn
    
            Dim Ret As New HomeSeerAPI.IPlugInAPI.strMultiReturn
            Dim UID As String
            UID = ActInfo.UID.ToString
    
            Ret.sResult = ""
            ' We cannot be passed info ByRef from HomeSeer, so turn right around and return this same value so that if we want, 
            '   we can exit here by returning 'Ret', all ready to go.  If in this procedure we need to change DataOut or TrigInfo,
            '   we can still do that.
            Ret.DataOut = ActInfo.DataIn
            Ret.TrigActInfo = ActInfo
    
            If PostData Is Nothing Then Return Ret
            If PostData.Count < 1 Then Return Ret
    
            If Not (ActInfo.DataIn Is Nothing) Then
                DeSerializeObject(ActInfo.DataIn, action)
            End If
    
            Dim parts As Collections.Specialized.NameValueCollection
    
            Dim sKey As String
    
            parts = PostData
    
            Try
                For Each sKey In parts.Keys
                    If sKey Is Nothing Then Continue For
                    If String.IsNullOrEmpty(sKey.Trim) Then Continue For
                    Select Case True
                        Case InStr(sKey, "recipient_" & UID) > 0, InStr(sKey, "title_" & UID) > 0, InStr(sKey, "body_" & UID) > 0
                            action.Add(CObj(parts(sKey)), sKey)
                    End Select
                Next
                If Not SerializeObject(action, Ret.DataOut) Then
                    Ret.sResult = IFACE_NAME & " Error, Serialization failed. Signal Action not added."
                    Return Ret
                End If
            Catch ex As Exception
                Ret.sResult = "ERROR, Exception in Action UI of " & IFACE_NAME & ": " & ex.Message
                Return Ret
            End Try
    
            ' All OK
            Ret.sResult = ""
            Return Ret
        End Function
    
        Public Function ActionFormatUI(ByVal ActInfo As IPlugInAPI.strTrigActInfo) As String
            Dim stb As New StringBuilder
            Dim sKey As String
            Dim UID As String
            UID = ActInfo.UID.ToString
    
            If ActInfo.TANumber = 1 Then
                Dim recipient As String = ""
                Dim title As String = ""
                Dim body As String = ""
    
    
                If Not (ActInfo.DataIn Is Nothing) Then
                    DeSerializeObject(ActInfo.DataIn, action)
                End If
    
                For Each sKey In action.Keys
                    Select Case True
                        Case InStr(sKey, "recipient_" & UID) > 0
                            recipient = action(sKey)
                        Case InStr(sKey, "title_" & UID) > 0
                            title = action(sKey)
                        Case InStr(sKey, "body_" & UID) > 0
                            body = action(sKey)
                    End Select
                Next
    
                stb.Append("The system send a push message to " & recipient)
                stb.Append("with the title " & title & " ")
                stb.Append("and body " & body)
    
    
            ElseIf ActInfo.TANumber = 2 Then
            ElseIf ActInfo.TANumber = 3 Then
            ElseIf ActInfo.TANumber = 4 Then
    
            End If
    
    
            Return stb.ToString
        End Function
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    #2
    One thing that jumps out - you are building noteBody and noteTitle before you have deserialised the data from the DataIn object, you are likely to want to specify p_defaultText for the text box from the deserialised data otherwise it will always be empty.

    Comment


      #3
      Thanks MrHappy,

      So with what jumps out, I should be moving the noteTitle and noteBody to after the deserialization, and also specifying the default text as whatever is deserialized?

      e.g:

      Dim noteBody As New clsJQuery.jqTextBox("title_" & UID & sUnique, "text", body, "Events", 50, True)
      Dim noteTitle As New clsJQuery.jqTextBox("body_" & UID & sUnique, "text", title, "Events", 50, True)
      HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

      Facebook | Twitter | Flickr | Google+ | Website | YouTube

      Comment


        #4
        That is the only thing that I saw but I have not looked at it too much - the way it is at the minute the boxes will always be empty whereas when you build the event what you want is the boxes to either have nothing in them if it is a new event or have the old data if you are editing an event. At the minute you would always be saving a blank value, you want to be adding it after the for loop that is looking for the body/title.

        Comment


          #5
          You are a star, that was exactally the problem!

          Thanks heaps
          HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

          Facebook | Twitter | Flickr | Google+ | Website | YouTube

          Comment


            #6
            No worries...once it clicked in my head that the method in the SAMPLE_BASIC plugin is not the HS3 method (as you can see the differences in the SAMPLE and SAMPLE_BASIC) but instead just a method devised by whoever wrote the example then I started to get what they were trying to do. I was started to write a template with a simpler trigger/action solution and everything commented but that is yet another thing that fell into the half/third of it finished folder. I am not yet got into the world of sub triggers and conditions though!!

            Comment


              #7
              Thanks guys !!

              You made my day, I had some sort of the same problem which in now solved !!
              Regards,

              Rien du Pre
              The Netherlands
              Using:
              Homeseer PRO latest HS4 BETA on a Raspberry
              Plugin's:
              RFXCOM, mcsMQTT, Z-Wave

              Comment

              Working...
              X