<%+cbi/valueheader%>
<%
	local fs = require "luci.openclash"
	local filename = fs.filename(self:cfgvalue(section)) or "config"
	local display = self.display or ""
	local idname = math.random(1000)..(string.match(filename, "[%w_]+") or "")
%>
<script type="text/javascript">//<![CDATA[
	function act_update_config_<%=idname%>(btn)
	{
		var originalValue = btn.value;
		btn.disabled = true;
		btn.value = '<%:Updating Config...%>';

		XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash","update_config")%>',{filename: "<%=filename%>"}, function(x,status){
			if (x && x.status == 200 && status && status.status === 'success') {
				btn.value = '<%:Update Successful%>';
			} else {
				btn.value = '<%:Update Failed%>';
			}
			setTimeout(function() {
				btn.value = originalValue;
				btn.disabled = false;
			}, 2000);
		});
		return false;
	};
	
//]]></script>

<%
	if display == "" then
%>
<input type="button" class="btn cbi-button cbi-input-reload" value="<%:UpDate%>" onclick="return act_update_config_<%=idname%>(this)" />
<%
	end
%>
<%+cbi/valuefooter%>
