Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
174 lines (130 sloc) 3.77 KB
<% local.pieces.header(); %>
<h1>DB Edit</h1>
<div class="container">
<%
var error = false;
function myerror( msg ){
print( "<b class='error'>" + msg + "</b>" )
error = true;
}
core.content.forms();
var mydb = null;
if ( request._id ) mydb = db.dbs.findOne( ObjectId( request._id ) );
if ( ! mydb ) mydb = {};
if ( request.debug ) print( "<pre>\n" + tojson( mydb ) + "\n</pre>" );
Forms.fillInObject( "" , mydb );
if ( isString( mydb.slaves ) ){
mydb.slaves = mydb.slaves.split( "[, ]+" );
}
if ( request.action == "save" ){
mydb.assignable = request.assignable ? true : false;
if ( ! request.slaves )
mydb.slaves = null;
if ( ! request.name ){
myerror( "need a db name" );
}
else if ( request.mode == "master" ){
if ( ! request.machine ){
myerror( "need a machine" );
}
else if ( ( request.getParameters( "slaves" ) || [] ).contains( request.machine ) ) {
myerror( "the master cannot be a slave of itself" );
}
delete mydb.pairs;
delete mydb.right;
}
else if ( request.mode == "paired" ){
if ( ! request.machine ){
myerror( "need left node" );
}
else if ( ! request.right ){
myerror( "need right node" );
}
else if ( request.machine == request.right ){
myerror( "left and right have to be different" );
}
else {
// good
mydb.pairs = [ request.machine , request.right ];
delete mydb.machine;
delete mydb.right;
}
}
else {
myerror( "unknonwn mode [" + request.mode + "]" );
}
if ( ! error ){
delete mydb.action;
delete mydb.session;
db.dbs.save( mydb );
return response.sendRedirectTemporary( "/dbs" );
}
}
print.setFormObject( mydb );
var paired = false;
if ( mydb.pairs )
paired = true;
else if ( mydb.machine )
paired = false;
else
paired = true; // default for new things
if ( mydb.pairs ){
mydb.machine = mydb.pairs[0];
mydb.right = mydb.pairs[1];
}
%>
<form>
<input type="hidden" name="_id">
<table border='1'>
<tr>
<th>Name</th>
<td><input name="name"></td>
</tr>
<tr>
<th>Type</th>
<td>
<%= envTypeSelect( "type" , mydb.type ) %>
</td>
</tr>
<tr>
<th>Assignable</th>
<td><input type="checkbox" name="assignable" value="true" <%= mydb.assignable ? "checked" : "" %>></td>
</tr>
<tr>
<th>Mode</th>
<td>
<input type="radio" name="mode" value="master" <%= ! paired ? "checked" : "" %> onClick="switchMode(this)" >master
<input type="radio" name="mode" value="paired" <%= paired ? "checked" : "" %> onClick="switchMode(this)">paired
</td>
</tr>
<tr>
<th>Machine</th>
<td><% local.pieces.nodePicker( "machine" , false , mydb.machine ) %></td>
<td id='right_node' style="display: <%= paired ? "block" : "none" %>;"><% local.pieces.nodePicker( "right" , false , mydb.right ) %></td>
</tr>
<tr>
<th>Slaves</th>
<td><% local.pieces.nodePicker( "slaves" , true , mydb.slaves ) %></td>
</tr>
</table>
<input name="action" type="submit" value="save">
</form>
<hr>
<h4>Sites Using this</h4>
<ul ? mydb.name >
<forarray other ( db.sites.find( { "dbs.server" : mydb.name } ) ).toArray() >
<li><a href="/site_edit?_id=<%= other._id %>"><%= other.name %></a></li>
</forarray>
</ul>
<script>
function switchMode( i ){
if ( i.value == "master" ){
document.getElementById( "right_node" ).style.display = "none";
}
else {
document.getElementById( "right_node" ).style.display = "block";
}
}
</script>
</div>
<% local.pieces.footer(); %>