Announcement

Collapse
No announcement yet.

button in feature page wont trigger PostBackProc

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

    button in feature page wont trigger PostBackProc

    So I am trying to make a HS4 plugin from scratch(used to be HS3 plugin). It's been ok so far, but now I am starting with the feature pages. And I have little/no experience with HTML, Javascript etc. I tried to google it and found some usefull tips. But I still cant figure it out. So what have I done:
    -Started with the "blank page" from the sample
    -Added a button to it, with some javascript that I found by googling.
    -Added the PostBackProc function in the HSPI class.

    But, I can not get PostBackProc to trigger when pushing the button. I have no idea what I am doing wrong here. Please help

    Code:

    Code:
    public override string PostBackProc(string page, string data, string user, int userRights)
    {
    HomeSeerSystem.WriteLog(HomeSeer.PluginSdk.Logging.ELogType. Error, "Postback: ", Name);
    return "";
    }
    HTML Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--This maintains the scale of the page based on the scale of the screen-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="author" content="HomeSeer Technologies">
    <!--This liquid tag loads all of the necessary css files for HomeSeer-->
    {{includefile '/bootstrap/css/page_common.css'}}
    <title>Sample Blank Feature Page</title>
    </head>
    <body class="body homeseer-skin">
    <!--These liquid tags add the HomeSeer header and navbar to the top of the page when appropriate-->
    {{includefile 'header.html'}}
    {{includefile 'navbar.html'}}
    <!--Primary container for the page content
    The .container class ensures the page content is fit and centered to the screen-->
    <div class="container">
    <!--This is an intentionally blank page that you can use as a blueprint to create feature pages from-->
    <button type="button" class="btn btn-default" action="button_press">Save</button>
    </div>
    <script>
    $(document).on('click','button', {} ,function(e){
    var data;
    $(this.attributes).each(function() {
    var parts = this.nodeName+"="+this.nodeValue;
    
    if(data==null) {
    data = parts;
    }
    else {
    data = data+"&"+parts;
    }
    });
    
    var fdata = $(this.form).serialize();
    
    if(fdata != null) {
    data = data+"&"+fdata
    }
    
    AjaxPost(data,"teslaSeerTest/blankTest.html");
    });
    </script>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    {{includefile 'bootstrap/js/page_common.js'}}
    </body>
    </html>

    #2
    Not sure about buttons, I use JS which calls AjaxPost for any '.fa-point' class:
    Click image for larger version

Name:	Screenshot 2021-01-16 021103.jpg
Views:	183
Size:	38.1 KB
ID:	1447923

    HTML Code:
    <i class='fas fa-toggle-off fa-point' style='color: red' title='Log' action='log' device-id='6807' id='log-6807' value='False' type='Boolean' data-toggle='tooltip' data-placement='top'>
    Code:
    $(document).on('click', '.fa-point', { }, function(e) {
      if($(this).attr('action')===undefined) {
        return;
      }
      var datadict = {request: $(this).attr('action'), deviceid: $(this).attr('device-id'), value: $(this).attr('value'), type: $(this).attr('type')};
      var data = JSON.stringify( { data: datadict });
      $('#loading').show();
      console.log(data);
      AjaxPost(data, 'AKBond/my-bridge.html');
    });

    Comment


      #3
      Just in case attached complete html and js code
      Attached Files

      Comment


        #4
        Originally posted by alexbk66 View Post
        Just in case attached complete html and js code
        thanks! I have yet to make this work with a button tough :/

        Comment


          #5
          Originally posted by salvesen View Post

          thanks! I have yet to make this work with a button tough :/
          What's the difference? JS is callen in my case if I click on any element with '.fa-point' class, you can either modify the JS, or simply add '.fa-point' class to yuor button.

          FYI, "fa" stands for Font Awesome - which uses unicode characters to create elements, i.e. toggle switch (Log) in my case.

          Comment


            #6
            Originally posted by alexbk66 View Post

            What's the difference? JS is callen in my case if I click on any element with '.fa-point' class, you can either modify the JS, or simply add '.fa-point' class to yuor button.

            FYI, "fa" stands for Font Awesome - which uses unicode characters to create elements, i.e. toggle switch (Log) in my case.
            Yeah I have no idea. Even if I post exactly what you posted it still does not work. For some reason PostBackProc is not triggered and I have no idea why.

            Comment


              #7
              I managed to get it working by modifying the samples.

              Comment


                #8
                Originally posted by salvesen View Post

                Yeah I have no idea. Even if I post exactly what you posted it still does not work. For some reason PostBackProc is not triggered and I have no idea why.
                If you use my code "exactly" - it's not goung to work because it's posting to 'AKBond/my-bridge.html'

                Comment


                  #9
                  Originally posted by salvesen View Post
                  I managed to get it working by modifying the samples.
                  Can you share?

                  Comment


                    #10
                    I did a bunch of work at some point last year to try and get one of my plugins working as HS4 native options, and it was close (except for some still open issues and missing features), and have just decided to try another one this month, and I'm having the same problem. Code that I KNOW was working before just isn't triggering PostBackProc.

                    I was doing my own $ajax call using jquery, but I tested a simplified version using the AjaxPost wrapper and got the same result every time...

                    EDIT: the AjaxPost is getting a response, but it's an immediate empty string response, not a timeout, not a host not found, etc.

                    Comment

                    Working...
                    X