Save & Apply mechanism of luci

用luci框架创建luci界面的时候,页面默认具备“保存&应用”,“保存”,“重置”,“帮助”等控件,当然,“帮助”控件会判断开发者有没有设置相对应的帮助页面来决定要不要显示该控件。由于是利用框架创建的控件,所以要获取控件状态就需要对框架有所了解。

应用1:在配置界面中判断是否 “save & apply” “save”控件是否按下,获取这个控件按下的消息,然后做相应的处理。其实,这几个控件的响应机制是做在/luci/view/cbi/footer.tm中:

        <%- if pageaction then -%>
        <div class="cbi-page-actions">
                <% if redirect then %>
                <div style="float:left">
                        <input class="cbi-button cbi-button-link" type="button" value="<%:Back to Overview%>" οnclick="location.href='<%=pcdata(redirect)%>'" />
                </div>
                <% end %>


                <% if flow.skip then %>
                        <input class="cbi-button cbi-button-skip" type="submit" name="cbi.skip" value="<%:Skip%>" />
                <% end %>
                <% if not autoapply then %>
                        <input class="cbi-button cbi-button-apply" type="submit" name="cbi.apply" value="<%:Save & Apply%>" οnclick="window.parent.scrollTo(0,0)" />
                <% end %>
                <input class="cbi-button cbi-button-save" type="submit" name="cbi.save" value="<%:Save%>" οnclick="window.parent.scrollTo(0,0)" />
                <input class="cbi-button cbi-button-reset" type="reset" value="<%:Reset%>" οnclick="window.parent.scrollTo(0,0)" />
                <% if help_url then %>
                <input class="cbi-button cbi-button-help" type="button" value="<%:Help%>" οnclick="location.href='<%=luci.dispatcher.build_url(help_url)%>'" />
                <% end %>
                <script type="text/javascript">cbi_d_update();</script>
        </div>
        <%- end -%>
</form>
<%+footer%>

从代码看出,这个是htm文件中定义了,页面的控件名字,消息名字,动作相应等等,比如对“Save & Apply”的定义:

<input class="cbi-button cbi-button-apply" type="submit" name="cbi.apply" value="<%:Save & Apply%>" οnclick="window.parent.scrollTo(0,0)" />

cbi.apply是广播出去的消息名字,那么,开发者可以在mode下面用CBI创建配置界面的时候用:

local apply = luci.http.formvalue("cbi.apply")
if apply then
        luci.sys.exec("uci commit network")
end   

来截取消息,然后做相应的处理,

对“Save"控件也是一样的,处理方式,但是apply机制有在 luci/view/cbi/apply_xhr.htm中做另外的一种XHR机制,就是在点击“save & apply”之后在页眉显示处理的进程:比如正在配置哪个文件,等等。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值