Skip to content

Reduce button click events #24

@lyweilian

Description

@lyweilian

First of all great work with what you have done with aRestUI. It's awesome!

I have made some slight modifications to my local copy of your code that generates the button Javascript. Instead of having a pair of functions (on and off) per pin for buttons. You can simply have one button click event for all buttons. This can be achieved by changing the ID of the button to tell the function what pin and what state (low or high). This may help keep your code lean and keep the OUTPUT_BUFFER_SIZE size lower in aREST.h. You may want to also consider offloading the HTML generation to JQuery as well.

See the following:

// Buttons UI
    for (int i = 0; i < buttons_index; i++) {
      addToBuffer("<div class=\"row\">");
      addToBuffer("<div class=\"col-md-2\"><button class=\"btn btn-block btn-lg btn-primary\" id='btn_1_");
      addToBuffer(buttons[i]);
      addToBuffer("'>On</button></div>");
      addToBuffer("<div class=\"col-md-2\"><button class=\"btn btn-block btn-lg btn-danger\" id='btn_0_");
      addToBuffer(buttons[i]);
      addToBuffer("'>Off</button></div>");
      addToBuffer("</div>");
    }
    // Buttons JavaScript
	
	addToBuffer("$('.btn').click(function(){");
	addToBuffer("var id = $(this).attr('id').split('_');");
	addToBuffer("$.getq('queue','/digital/'+id[2]+'/'+id[1]); });");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions