Modify htm page generated by CBI

Hello all,

I am generating a html page using a CBI model. This page includes these two following fields...

o_rs = d_gen:option(DummyValue, "_recv_state", translate("Receive Status:"))
o_rs.template = "myapp/recv_status"

o_ss = d_gen:option(DummyValue, "_send_state", translate("Send Status:"))
o_ss.template = "myapp/send_status"

To set the values of these two fields I have two seperate *htm files in my "view" folder
recv_status.htm
send_status.htm

In each of these pages I use

<span id="<%=self.option%>recv-status" class="cbi-value-title" style="text-align: left;"></span>

or

<span id="<%=self.option%>send-status" class="cbi-value-title" style="text-align: left;"></span>

to set the required values. Everything works fine this way but I want to do all this in a single htm file instead of having two files for each fields. How can I achieve that?

any help would be much appreciated.

Assign the same template file to both options and use conditionals within in:

<% if self.option == "this" then %>
  html for this
<% else %>
  html for that
<% end %>

Hi jow

Thanks for the reply. With your changes I now have a single working status.htm file with both options displaying their correct values. But this doesnt solve the main issue I was having.

Basically I am using XHR.poll to get send-status and recv-status from the backend. Previously I had XHR.poll in both of my separate htm files and I would see two XHR get requests going from my browser to the system.
One from recv_status.htm and another from send_status.htm.

Now I have a single status.htm file with one XHR.poll defined but I still see two requests both coming from the status.htm.

What I want to do is something like in the Network->Interfaces page where a single XHR.poll is called every 5 seconds and it gets and displays all the information from that (like Uptime,MAC-Address, RX, TX etc).

Is that possible with two different options pointing to the same template file?

The idea is to call the poll function only once, and let it do the work for all options. Consider something like this:

<% if not xhr_started then %>
  <script type="text/javascript">
    XHR.poll(...);
  </script>
<% xhr_started = true; end %>

In case the variable is not retained across the different template render contexts, use the option name instead:

<% if self.option == "first_option" then %>
  <script type="text/javascript">
    XHR.poll(...);
  </script>
<% end %>
1 Like

Just had to move my poll implementation under only one of the self.options like your second suggestion and now I get only one request going out...works great...thanks