$(function(){var c=$("body").attr("sitename");$("#model-timefilters").jlistmodel({rows:[{_id:24},{_id:72},{_id:144},{_id:288},{_id:720},{_id:2880}]});$("select.time-filter").jselect({model:$("#model-timefilters"),renderer:function(a,b){var f=b._id;return f==24?"last 24 hours":f==72?"3 days":f==144?"7 days":f==288?"2 weeks":f==720?"30 days":f==2880?"120 days":""+f+" hours"},selectionSynchronized:true});$("#model-timefilters").jlistmodel("refresh").jlistmodel("setselected",72);$("#model-maintabpagesizer").jlistmodel({rows:[{_id:10},
{_id:20},{_id:30},{_id:40},{_id:60},{_id:100}],selected:$.cookie("maintab.pagesize")||10}).bind("jlistmodel_select-changed",function(){$.cookie("maintab.pagesize",$(this).jlistmodel("selected"),{expires:30})});$("#MainPanel select.table-pagesizer").jselect({model:$("#model-maintabpagesizer"),renderer:function(a,b){return""+b._id},selectionSynchronized:true});$("#model-maintabpagesizer").jlistmodel("refresh");var d=$("#Operators").length>0;$("#model-guests").jtablemodel({url:"/stat/guest",params:{within:$("#Guests select.time-filter").val()}});
$("#model-payments").jtablemodel({url:"/stat/payment",params:{within:$("#Payments select.time-filter").val()}});$("#model-vouchers").jtablemodel({url:"/stat/voucher",params:{}});d&&$("#model-operators").jtablemodel({url:"/cmd/sitemgr",params:{cmd:"get-hotspot-admins"}});$("#model-timefilters").bind("jlistmodel_select-changed",function(){$("#model-guests").jtablemodel("option","params",{within:$("#Guests select.time-filter").val()});$("#model-payments").jtablemodel("option","params",{within:$("#Guests select.time-filter").val()});
$("#model-guests").jtablemodel("refresh");$("#model-payments").jtablemodel("refresh")});$("#ChangePassword").setvisible(d);$("#MainPanel").tabs().bind("tabsshow",function(a,b){var f=$("#"+b.panel.id).data("fn_shown");f&&f()}).tabs("select",0);$("#GuestTableContainer").jtable({model:$("#model-guests"),className:"stat",pagesize:$("#model-maintabpagesizer").jlistmodel("selected")}).jtable("addcol",Msg.Name_MACAddress,"mac",true,function(a,b){var f=Renderer.staName(a,b);return f==a?f:f+" ["+a+"]"}).jtable("addcol",
"Package","package").jtable("addcol","Amount","amount",true,Renderer.amount).jtable("addcol","Authorized By","authorized_by",true,function(a,b){if(a=="none")return"None";else if(a=="password")return"Password";else if(a=="api")return"API";else if(a=="voucher")return"Voucher";else if(a=="credit")return b.payment_cardtype||"Credit Card";else if(a=="paypal")return"PayPal";return"None"}).jtable("addcol","Download","tx_bytes",true,Renderer.pktsBytes).jtable("addcol","Upload","rx_bytes",true,Renderer.pktsBytes).jtable("addcol",
"Status","end",true,function(a,b){if(b.expired)return"Expired";else{var f=parseInt(a)*1E3;(new Date).getTime();return"Valid until "+Renderer.timestamp(f)}}).jtable("addaction","Disconnect","terminate",function(a){return!a.expired}).jtable("addaction","Extend","extend").bind("jtable_terminate",function(a,b){$(a.originalTarget).disable();$.jcmd("hotspot","terminate",{_id:$(b).attr("_id")},function(){$("#GuestTableContainer").jtable("refresh")})}).bind("jtable_extend",function(a,b){$(a.originalTarget).disable();
$.jcmd("hotspot","extend",{_id:$(b).attr("_id")},function(){$("#GuestTableContainer").jtable("refresh")})});$("#GuestTableSearch").jsearch().bind("jsearch_search",function(){var a=$("#GuestTableSearch").val();$("#GuestTableContainer").jtable("addfilter","*",a==""?null:a).jtable("filter")});$("#model-maintabpagesizer").bind("jlistmodel_select-changed",function(){$("#GuestTableContainer").jtable("option","pagesize",$(this).jlistmodel("selected")).jtable("repaint")});$("#PaymentTableContainer").jtable({model:$("#model-payments"),
className:"stat",pagesize:$("#model-maintabpagesizer").jlistmodel("selected")}).jtable("addcol","Time","time",true,Renderer.timestamp).jtable("addcol","Last Name","last_name",true).jtable("addcol","First Name","first_name",true).jtable("addcol","Package","package").jtable("addcol","Amount","amount",true,Renderer.amount).jtable("addcol","Extra Info","info").jtable("addcol","Status","status",true,function(a){if(a=="paid")return"Paid";else if(a=="void")return"Voided/Refunded"}).jtable("addaction","Refund",
"refund",function(a){return"void"!=a.status}).bind("jtable_refund",function(a,b){$(a.originalTarget).disable();$.jcmd("hotspot","refund",{_id:$(b).attr("_id")},function(){$("#PaymentTableContainer").jtable("refresh")})});$("#PaymentTableSearch").jsearch().bind("jsearch_search",function(){var a=$("#PaymentTableSearch").val();$("#PaymentTableContainer").jtable("addfilter","*",a==""?null:a).jtable("filter")});$("#model-maintabpagesizer").bind("jlistmodel_select-changed",function(){$("#PaymentTableSearch").jtable("option",
"pagesize",$(this).jlistmodel("selected")).jtable("repaint")});var e=$("#Vouchers form.create");e.find("select[name=expire]").change(function(){e.find("span.customExpire").toggle(e.find('[name="expire"]').val()=="custom")});e.find("select[name=expire]").val("1440").change();e.find("input[name=create]").click(function(a){if(V.checkMinMax(e.find("input[name=n]"),1,3E3,"Number of vouchers"))if(!(e.find('select[name="expire"]').val()=="custom"&&!V.checkMinMax(e.find('input[name="expireNumber"]'),1,1E3,
"Expire Time"))){$(a.originalTarget).disable();$.jcmd("hotspot","create-voucher",{n:e.find("input[name=n]").val(),quota:e.find("select[name=quota]").val(),expire:e.find('select[name="expire"]').val(),expire_number:e.find('input[name="expireNumber"]').val(),expire_unit:e.find('select[name="expireUnit"]').val(),note:e.find("input[name=note]").val()},function(){$(a.originalTarget).enable();$("#model-vouchers").jtablemodel("refresh")})}});e.find("input[name=doNote]").change(function(){e.find("span.doNote").toggle(e.find("input[name=doNote]").checked())});
$("#VoucherTableContainer").jtable({model:$("#model-vouchers"),className:"stat",pagesize:$("#model-maintabpagesizer").jlistmodel("selected")}).jtable("addcol","Code","code",true,function(a){return a.substring(0,5)+"-"+a.substring(5)}).jtable("addcol","Create Time","create_time",true,Renderer.timestamp_sec).jtable("addcol","Note","note").jtable("addcol","Duration","duration",true,function(a){return Renderer.uptime(a*60)}).jtable("addcol","Status","used",true,function(a,b){var f=b.end_time-(new Date).getTime()/
1E3;return b.used>0?f>0?"Used"+(b.quota!=1?" "+b.used+" time(s)":"")+", expires in "+Renderer.uptime(f):"Expired":"Valid"+(b.quota!=1?" for multi-use":" for one-time use")}).jtable("addaction","Revoke","delete",function(a){return a.valid!=false}).jtable("addaction","Print batch","print",function(a){return a.valid!=false}).bind("jtable_delete",function(a,b){$(a.originalTarget).disable();$.jcmd("hotspot","delete-voucher",{_id:b._id},function(){$(a.originalTarget).enable();$("#model-vouchers").jtablemodel("refresh")})}).bind("jtable_print",
function(a,b){window.open("/print/hotspot/vouchers/s/"+c+"?create_time="+b.create_time,"print_voucher")});$("#Vouchers input[name=printall]").click(function(){window.open("/print/hotspot/vouchers/s/"+c,"print_voucher")});$("#VoucherTableSearch").jsearch().bind("jsearch_search",function(){var a=$("#VoucherTableSearch").val();$("#VoucherTableContainer").jtable("addfilter","*",a==""?null:a).jtable("filter")});$("#model-maintabpagesizer").bind("jlistmodel_select-changed",function(){$("#VoucherTableSearch").jtable("option",
"pagesize",$(this).jlistmodel("selected")).jtable("repaint")});if(d){$("#OperatorTableContainer").jtable({model:$("#model-operators"),className:"stat",pagesize:$("#model-maintabpagesizer").jlistmodel("selected")}).jtable("addcol","Name","name",true).jtable("addcol","Password","x_password",true).jtable("addcol","Notes","note",true).jtable("addaction","Delete","delete").bind("jtable_delete",function(a,b){confirm("Are you sure you want to delete the object?")&&$.jpost("/cmd/sitemgr",{cmd:"delete-hotspot-admin",
admin:b._id},function(){$("#model-operators").jtablemodel("refresh")})});var g=$("#Operators form.create");g.find("input[name=create]").japply({validate:function(){if(!V.checkAdminName(g.find("input[name=name]"),"Account"))return false;if(!V.checkAdminPasswords(g.find("input[name=password]"),g.find("input[name=password]"),"Password","Confirm"))return false;return true},get_posts:function(){return{url:"/cmd/sitemgr",payload:{cmd:"add-hotspot-admin",name:g.find("input[name=name]").val(),x_password:g.find("input[name=password]").val(),
note:g.find("input[name=note]").val()}}},done:function(){$("#model-operators").jtablemodel("refresh")}});$("#OperatorTableSearch").jsearch().bind("jsearch_search",function(){var a=$("#OperatorTableSearch").val();$("#OperatorTableContainer").jtable("addfilter","*",a==""?null:a).jtable("filter")});$("#model-maintabpagesizer").bind("jlistmodel_select-changed",function(){$("#OperatorTableSearch").jtable("option","pagesize",$(this).jlistmodel("selected")).jtable("repaint")})}$("#model-guests").jtablemodel("refresh");
$("#model-payments").jtablemodel("refresh");$("#model-vouchers").jtablemodel("refresh");d&&$("#model-operators").jtablemodel("refresh");$("#RefreshSelect").bind("jtimer_due",function(){$("#model-guests").jtablemodel("refresh");$("#model-payments").jtablemodel("refresh");$("#model-vouchers").jtablemodel("refresh");d&&$("#model-operators").jtablemodel("refresh")}).jtimer("start");$("span.label").live("click",function(){var a=$(this).prev();if(a.is(".radio-input")||a.is(".check-box-input"))a.click().change()})});
$(function(){$("#RefreshSelect").jtimer();$("#RefreshButton").button({text:false,icons:{primary:"ui-icon-refresh"}}).click(function(){$("#RefreshSelect").jtimer("trigger");return false});$("#RefreshSelect").bind("jtimer_due",function(){$("#model-aps").jtablemodel("refresh");$("#model-stas").jtablemodel("refresh")}).selectmenu().jtimer("start")});
$(function(){$("#WelcomeLogoutButton").button({icons:{primary:"ui-icon-power"}}).click(function(){window.location.href="/logout"});var c=$("#ChangePasswordDialog");$("#ChangePassword").click(function(){$.jcmd("sitemgr","get-self",{},function(d){d=d.data[0];var e=d.requires_new_password;c.dialog("option","closeOnEscape",!e);c.dialog("widget").find("button.cancel").button(e?"disable":"enable");c.dialog("widget").find("a.ui-dialog-titlebar-close").setvisible(!e);c.jform("set_model",d);c.dialog("open")})});
c.dialog({modal:true,resizable:false,autoOpen:false,dialogClass:"ui-dark",buttons:[{"class":"ui-positive-alert apply",text:"Save",click:function(){}},{"class":"cancel",text:"Cancel",click:function(){$(this).dialog("close");return false}}]});c.jform({japply:c.dialog("widget").find(".apply"),detect_change:false,populate:function(d){var e=d.requires_new_password;c.find("input[name=name]").val(d.name);c.find("input[type=password]").val(e?"":$.jpass_hint);c.find("input[name=email]").val(d.email);c.find("select[name=lang]").val(d.lang||
"en_US")},get_posts:function(){var d={name:c.find('input[name="name"]').val()};c.find("input[name=password1]").val()!=$.jpass_hint&&$.extend(d,{x_password:c.find("input[name=password1]").val()});$.extend(d,{email:c.find('input[name="email"]').val()});d.lang=c.find("select[name=lang]").val();$.extend(d,{cmd:"set-self"});return{url:"/cmd/sitemgr",payload:d}},validate:function(){if(!V.checkEmpty(c.find("input[name=name]"),"Admin Name")||!V.checkAdminName(c.find("input[name=name]"),"Admin Name"))return false;
if(!V.checkAdminPasswords(c.find("input[name=password1]"),c.find("input[name=password2]"),"Admin Password","Confirm"))return false;var d=c.find('input[name="email"]');if(!V.checkEmpty(d,"Email Address"))return false;if(!V.checkEmail(d,"Email Address"))return false;return true},done:function(){c.dialog("close")}});$("body").attr("adminnewpass")=="true"&&$("#ChangePassword").click()});
