Example #1
0
def main(cursor):
	team_id = int(common.get_val('team', 0))
	if team_id < 1: return "No team selected"
	
	team_dict = team_q.get_real_active_teams(cursor, skip_irs=False)
	the_team = team_dict[team_id]
	
	borders = team_q.get_relations(cursor)
	team_borders = borders[team_id]
	
	# Find our default
	state_find = 'value="%s"' % the_team.default_borders
	
	# What to replace it with
	state_replace = '%s selected="selected"' % state_find
	
	output = ["""
	<form action="exec.py" method="post" accept-charset="utf-8" style="padding:5px;">
	<span class="stitle">Borders for {team.name}</span><br /><br />
		<input type="hidden" name="mode" id="mode" value="edit_borders" />
		<input type="hidden" name="team" id="team" value="{team.id}" />
		""".format(
			team=the_team,
		)]
	
	# Now the actual set of borders
	output.append('''
	Default border state:&nbsp;&nbsp;
	<select name="default_border_state" id="default_border_state">
		{states}
	</select>
	<br /><br />

	<table border="0" cellspacing="0" cellpadding="5">
		<tr>
			<th>Team</th>
			<th>{team.name} state</th>
			<th>Their state</th>
		</tr>'''.format(
		states	= states.replace('<option value="-1">Default</option>', '').replace(state_find, state_replace),
		team	= the_team,
	))
	
	for t, other_team in team_dict.items():
		if t == the_team.id: continue
		# if other_team.hidden: continue
		# if not other_team.active: continue
		
		ir = ""
		if other_team.ir:
			ir = " <em>(IR)</em>"
		
		other_team_borders = borders[t].get(the_team.id, {}).get('border', other_team.default_borders)
		other_default_borders = other_team.default_borders
		
		# print(other_team_borders)
		
		# The state to find
		# state_find = 'value="%s"' % team_borders.get(t, default_borders)
		
		if t in team_borders:	default_state = team_borders[t]
		else:					default_state = "-1"
		
		state_find = 'value="%s"' % default_state
		
		# What to replace it with
		state_replace = '%s selected="selected"' % state_find
		
		# Their state to you
		# if the_team.id in other_team_borders:
		# 	other_state = team.border_states[other_team_borders[the_team.id]]
		# else:
		# 	other_state = team.border_states[other_default_borders]
		other_state = other_team_borders
		
		output.append("""
		<tr>
			<td>%(name)s%(ir)s</td>
			<td>
				<select name="border_state_%(t)d" id="border_state_%(t)d">
					%(states)s
				</select>
			</td>
			<td>&nbsp;&nbsp;
				<span style="color:#%(other_state_c)s;">%(other_state)s</span>
			</td>
		</tr>
		""" % {
			"t":				t,
			"ir":				ir,
			"name":				other_team.name,
			"states":			states.replace(state_find, state_replace),
			"other_state":		team.border_states[other_state],
			"other_state_c":	team.border_colour(other_state),
		})
	
	
	# Close form
	output.append("""</table>
		<input type="submit" value="Save" />
	</form>""".format(
		team=team_id
	))
	
	
	return "".join(output)
Example #2
0
File: oh_f.py Project: Teifion/Rob3
def relations_block(oh, the_team):
	output, load_java, run_java = [], [], []
	
	states = """
	<option value="Default">Default</option>
	<option value="At war">At war</option>
	<option value="Closed">Closed</option>
	<option value="Segregated">Segregated</option>
	<option value="Open">Open</option>
	<option value="Allied">Allied</option>"""
	
	world_relations = oh.the_world.relations()
	team_relations = world_relations.get(the_team.id, {})
	
	# Find our default
	state_find = 'value="%s"' % team.border_states[the_team.default_borders]
	
	# What to replace it with
	state_replace = '%s selected="selected"' % state_find
	
	output.append('''
	<h3 style="clear:both;"><a href="#" onclick="return false;">Relations</a></h3>
	<div id="borders_help" style="display:none;">
		<ul style="list-style-type: circle;margin-left:25px;">
			<li></li>
		</ul>
	</div>
	<span id="borders_help_link" style="cursor:pointer;" onclick="$('#borders_help_link').hide();$('#borders_help').show(500);">Show help</span>
	<br /><br />
	
	Default border state:&nbsp;&nbsp;
	<select id="default_border_state">
		%(states)s
	</select>
	<br /><br />
	
	
	Default tax rate:&nbsp;&nbsp;
	<input type="text" id="default_taxes" value="%(default_taxes)s" size="4"/>%%
	<br /><br />
	
	<table border="0" cellspacing="0" cellpadding="5">
		<tr>
			<th>Team</th>
			<th>Your state</th>
			<th>Their state</th>
			<th>&nbsp;</th>
			<th>Your taxes</th>
			<th>Their taxes</th>
		</tr>''' % {
		"states":	states.replace('<option value="Default">Default</option>', '').replace(state_find, state_replace),
		"default_taxes":	the_team.default_taxes,
	})
	
	run_java.append("""
	var temp_state = $('#default_border_state').val();
	if (temp_state != '' && temp_state != "%(default)s")
	{
		border_orders += "\\nSet default borders to " + temp_state;
	}
	
	var default_taxes = $('#default_taxes').val();
	if (default_taxes != '' && default_taxes != "%(default_taxes)s")
	{
		tax_orders += "\\nSet default taxes to " + default_taxes;
	}
	""" % {
		"default":		team.border_states[the_team.default_borders],
		"default_taxes":	the_team.default_taxes,
	})
	
	team_dict = oh.the_world.teams()
	for t, other_team in team_dict.items():
		if t == the_team.id: continue
		if other_team.hidden: continue
		if not other_team.active: continue
		
		ir = ""
		if other_team.ir:
			ir = " <em>(IR)</em>"
		
		other_relations = world_relations.get(t, {})
		
		other_team_borders = other_relations.get("borders", {}).get(the_team.id, other_team.default_borders)
		other_default_borders = other_team.default_borders
		other_taxes = other_relations.get("taxes", {}).get(the_team.id, other_team.default_taxes)
		
		# The state to find
		# state_find = 'value="%s"' % team_borders.get(t, default_borders)
		
		if t in team_relations:	default_state = team.border_states[team_relations[t].get('border', the_team.default_borders)]
		else:					default_state = "Default"
		
		state_find = 'value="%s"' % default_state
		
		# What to replace it with
		state_replace = '%s selected="selected"' % state_find
		other_state = other_team_borders
		
		# TAXES
		if "taxes" not in team_relations.get(t, {}):
			# Currently default
			tax_check_box = '<input type="checkbox" id="default_rate_%d" value="1" checked="checked"/>' % t
			
			tax_if = 'if (use_default == false)'
		else:
			
			tax_check_box = '<input type="checkbox" id="default_rate_%d" value="1"/>' % t
			
			tax_if = 'if ((temp_taxes != "" && temp_taxes != "%s") || use_default == true)' % team_relations.get(t, {}).get('taxes', -1)
		
		# Output
		output.append("""
		<tr>
			<td>%(name)s%(ir)s</td>
			<td>
				<select id="border_state_%(t)d">
					%(states)s
				</select>
			</td>
			<td>&nbsp;&nbsp;
				<span style="color:#%(other_state_c)s;">%(other_state)s</span>
			</td>
			
			<td style="width:25px;">&nbsp;</td>
			
			<td>
				<input type="text" id="tax_rate_%(t)d" value="%(our_tax_rate)s" size="4" onchange="$('#default_rate_%(t)d').attr('checked', '')"/>%%
				&nbsp;&nbsp;
				Default: %(tax_check_box)s
			</td>
			<td>&nbsp;&nbsp;
				%(other_rate)s%%
			</td>
		</tr>
		""" % {
			"t":				t,
			"ir":				ir,
			"name":				other_team.name,
			"states":			states.replace(state_find, state_replace),
			"other_state":		team.border_states[other_state],
			"other_state_c":	team.border_colour(other_state),
			
			"our_tax_rate":		team_relations.get(t, {}).get('taxes', the_team.default_taxes),
			"other_rate":		other_taxes,
			"tax_check_box":	tax_check_box,
		})
		
		# Java
		run_java.append("""
		var temp_state = $('#border_state_%(t)d').val();
		if (temp_state != '' && temp_state != "%(default)s")
		{
			border_orders += "\\nBorders to %(other_team)s are " + temp_state;
		}
		
		var temp_taxes = $('#tax_rate_%(t)d').val();
		var use_default = $('#default_rate_%(t)d').attr("checked");
		
		%(tax_if)s
		{
			if (use_default == true)
			{
				tax_orders += "\\Taxes for %(other_team)s are default";
			}
			else
			{
				tax_orders += "\\nTaxes for %(other_team)s are " + temp_taxes;
			}
		}
		""" % {
			"t":			t,
			"default":		default_state,
			"other_team":	other_team.name,
			
			"tax_if":		tax_if,
		})
	
	output.append("</table>")
	
	return "".join(output), "".join(load_java), "".join(run_java)