ppps_edit.js 8.2 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/*jslint white: true, sloppy: true, vars: true, eqeq: true */
/*jslint browser: true, devel: true */
/*global show_hide_linkfields, jQuery, country_list */

function update_select_list(new_options, select_list){
	var option_array = new_options.split("|");
	var i = 0;
	var j;
	select_list.length = 0;
	for(j=0; j < option_array.length-1; j++){
		var option = option_array[j].split(",");
		var selected = Boolean(parseInt(option[2], 10));
		select_list[j] = new Option(option[0], option[1], false, selected);
		//for testing and debugging
		//select_list.options[option_array.length-1+j] = new Option(option[2].toString() +" "+ selected.toString());
		//select_list.options[option_array.length-1+j] = new Option("Link Label: " + linklabel + " Label Text:" + label_text);
	}
	show_hide_linkfields(select_list);
}

function show_advanced(hide){
	var select_list = document.iform["interfaces[]"].options;
	var adv_rows = parseInt(jQuery('#adv_rows').html(), 10);
	var adv_show = Boolean(parseInt(jQuery('#adv_show').html(), 10));
	var status = Boolean(parseInt(hide, 10));
	var j, advanced;
	if (status){
		jQuery('#advanced_').hide();
		for(j=0; j < adv_rows; j++){
			advanced = "#advanced_" + j.toString();
			jQuery(advanced).show();
		}
		jQuery('#adv_show').html("1");
		show_hide_linkfields(select_list);
	} else {
		jQuery('#advanced_').show();
		for(j=0; j < adv_rows; j++){
			advanced = "#advanced_" + j.toString();
			jQuery(advanced).hide();
		}
		jQuery('#adv_show').html("0");
		show_hide_linkfields(select_list);
	}
}

function show_hide_linkfields(options){
	var i = 0;
	var port_count = parseInt(jQuery('#port_count').html(), 10);
	var adv_show = Boolean(parseInt(jQuery('#adv_show').html(), 10));
	var j, count, type, link, lnklabel, bw, bwlabel, mtu, mru, mrru, ipfields, gwfields, localip,
	    localiplabel, subnet, gateway, gatewaylabel;
	for(j=0; j < port_count; j++){
		count = j.toString();
		type = jQuery('#type').val();
		link = "#link" + count;
		lnklabel = "#linklabel" + count;
		bw = "#bandwidth" + count;
		bwlabel = "#bwlabel" + count;
		mtu = "#mtu" + count;
		mru = "#mru" + count;
		mrru = "#mrru" + count;
		ipfields = "#ip_fields" + count;
		gwfields = "#gw_fields" + count;
		localip = "#localip" + count;
		localiplabel = "#localiplabel" + count;
		subnet = "#subnet" + count;
		gateway = "#gateway" + count;
		gatewaylabel = "#gatewaylabel" + count;
69

Ad Schellevis's avatar
Ad Schellevis committed
70 71
		jQuery(ipfields + ',' + gwfields + ',' + link).hide();
		jQuery(subnet).prop('disabled',true);
72

Ad Schellevis's avatar
Ad Schellevis committed
73 74 75 76 77 78 79
		jQuery(bw).attr("name","bandwidth[]");
		jQuery(mtu).attr("name","mtu[]");
		jQuery(mru).attr("name","mru[]");
		jQuery(mrru).attr("name","mrru[]");
		jQuery(localip).attr("name","localip[]");
		jQuery(subnet).attr("name","subnet[]");
		jQuery(gateway).attr("name","gateway[]");
80

Ad Schellevis's avatar
Ad Schellevis committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
		while(i < options.length){
			if (options[i].selected ){
				jQuery(lnklabel).html("Link Parameters (" + options[i].value + ")");
				jQuery(bwlabel).html("Bandwidth (" + options[i].value + ")");
				jQuery(bw).attr("name","bandwidth[" + options[i].value + "]");
				jQuery(mtu).attr("name","mtu[" + options[i].value + "]");
				jQuery(mru).attr("name","mru[" + options[i].value + "]");
				jQuery(mrru).attr("name","mrru[" + options[i].value + "]");
				jQuery(localiplabel).html("Local IP (" + options[i].value + ")");
				jQuery(gatewaylabel).html("Gateway (" + options[i].value + ")");
				jQuery(localip).attr("name","localip[" + options[i].value + "]");
				jQuery(subnet).attr("name","subnet[" + options[i].value + "]");
				jQuery(gateway).attr("name","gateway[" + options[i].value + "]");
				if (type == 'ppp' && adv_show){
					jQuery(ipfields + ',' + gwfields).show();
				}
				if (type == 'pptp' || type == 'l2tp'){
					jQuery(subnet).prop("disabled",false);
					jQuery(ipfields + ',' + gwfields).show();
				}
				if (adv_show){
					jQuery(link).show();
				}
				i++;
				break;
			}
			i++;
		}
	}
}


function updateType(t){
	var serialports = jQuery('#serialports').html();
	var ports = jQuery('#ports').html();
	var select_list = document.iform["interfaces[]"].options;
	jQuery('#adv_show').html("0");
	show_advanced('0');
	jQuery("#select").show();
	switch(t) {
		case "select":
			jQuery('#ppp,#pppoe,#ppp_provider,#phone_num,#apn_').hide();
			select_list.length = 0;
			select_list[0] = new Option("Select Link Type First","");
			break;
		case "ppp":
			update_select_list(serialports, select_list);
			jQuery('#select,#pppoe').hide();
			jQuery('#ppp_provider,#phone_num,#apn_').show();
			country_list();
			break;
		case "pppoe":
			update_select_list(ports, select_list);
			jQuery('#select,#ppp,#ppp_provider,#phone_num,#apn_').hide();
			break;
		case "l2tp":
		case "pptp":
			update_select_list(ports, select_list);
			jQuery('#select,#ppp,#pppoe,#ppp_provider,#phone_num,#apn_').hide();
			break;
		default:
			select_list.length = 0;
			select_list[0] = new Option("Select Link Type First","");
			break;
	}
	if (t == "pppoe" || t == "ppp"){
		jQuery("#" + t).show();
	}
}

function show_reset_settings(reset_type) {
152
	if (reset_type == 'preset') {
Ad Schellevis's avatar
Ad Schellevis committed
153 154
		jQuery('#pppoepresetwrap').show(0);
		jQuery('#pppoecustomwrap').hide(0);
155 156
	}
	else if (reset_type == 'custom') {
Ad Schellevis's avatar
Ad Schellevis committed
157 158 159 160 161 162 163 164 165 166 167 168 169
		jQuery('#pppoecustomwrap').show(0);
		jQuery('#pppoepresetwrap').hide(0);
	} else {
		jQuery('#pppoecustomwrap').hide(0);
		jQuery('#pppoepresetwrap').hide(0);
	}
}

function country_list() {
	jQuery('#country option').remove();
	jQuery('#provider option').remove();
	jQuery('#providerplan option').remove();
	jQuery('#country').append(new Option('', ''));
170

Ad Schellevis's avatar
Ad Schellevis committed
171 172 173 174 175 176 177 178 179 180 181 182
	jQuery.ajax("getserviceproviders.php",{
		success: function(responseText) {
			var responseTextArr = responseText.split("\n");
			var value, i, country;
			responseTextArr.sort();
			for (i = 0; i < responseTextArr.length; i += 1) {
				value = responseTextArr[i];
				if (/\S/.test(value)) {
					country = value.split(":");
					jQuery('#country').append(new Option(country[0],country[1]));
				}
			}
Ad Schellevis's avatar
Ad Schellevis committed
183 184 185
		},
		error: function(jqXHR, textStatus, errorThrown) {
			console.log(errorThrown);
Ad Schellevis's avatar
Ad Schellevis committed
186 187 188
		}
	});
	jQuery('#trcountry').css("display","table-row");
189

Ad Schellevis's avatar
Ad Schellevis committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
}

function providers_list() {
	jQuery('#provider option').remove();
	jQuery('#providerplan option').remove();
	jQuery('#provider').append(new Option('', ''));
	jQuery.ajax("getserviceproviders.php",{
		type: 'POST',
		data: {country : jQuery('#country').val()},
		success: function(responseText) {
			var responseTextArr = responseText.split("\n");
			var value, i;
			responseTextArr.sort();
			for (i = 0; i < responseTextArr.length; i += 1) {
				value = responseTextArr[i];
				if (/\S/.test(value)) {
					jQuery('#provider').append(new Option(value, value));
				}
			}
		}
	});
	jQuery('#trprovider').css("display","table-row");
	jQuery('#trproviderplan').css("display","none");
}

function providerplan_list() {
	jQuery('#providerplan option').remove();
	jQuery('#providerplan').append( new Option('','') );
	jQuery.ajax("getserviceproviders.php",{
		type: 'POST',
		data: {country : jQuery('#country').val(), provider : jQuery('#provider').val()},
		success: function(responseText) {
			var responseTextArr = responseText.split("\n");
			var value, providerplan, i;
			responseTextArr.sort();
			for (i = 0; i < responseTextArr.length; i += 1) {
				value = responseTextArr[i];
				if (/\S/.test(value)) {
					providerplan = value.split(":");
					jQuery('#providerplan').append(new Option(providerplan[0] + " - " + providerplan[1],
										  providerplan[1]));
				}
			}
		}
	});
	jQuery('#trproviderplan').css("display","table-row");
}

function prefill_provider() {
	jQuery.ajax("getserviceproviders.php",{
		type: "POST",
		data: {country : jQuery('#country').val(), provider : jQuery('#provider').val(), plan : jQuery('#providerplan').val()},
		success: function(responseXML) {
			var xmldoc = responseXML;
			var provider = xmldoc.getElementsByTagName('connection')[0];
			jQuery('#username').val('');
			jQuery('#password').val('');
			if(provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
				jQuery('#phone').val('#777');
				jQuery('#apn').val('');
			} else {
				jQuery('#phone').val('*99#');
				jQuery('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
			}
			jQuery('#username').val(provider.getElementsByTagName('username')[0].firstChild.data);
			jQuery('#password').val(provider.getElementsByTagName('password')[0].firstChild.data);
		}
	});
}