Test Switch Dataase
Test the working how the database is switched
by clementyap
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/soria/soria.css">
<title>Test the switching responses between databases using buttons</title>
<body class="soria">
<div id="main_bContainer" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'sidebar'">
<div id="cp_Center" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
<table>
<tr>
<td>
<div id=btn1></div>
<!--for testdata2060_03-->
</td>
<td>
<div id=btn2></div>
<!--for testdata2060_10-->
</td>
<td>
<div id=btn3></div>
<!--for testdata2060_05-->
</td>
</tr>
<tr>
<td>
<div id=btn4></div>
<!--for testdata2060_03-->
</td>
<td>
<div id=btn5></div>
<!--for testdata2060_10-->
</td>
<td>
<div id=btn6></div>
<!--for testdata2060_05-->
</td>
</tr>
<tr>
<td>
<div id=btn7></div>
<!--for testdata2060_03-->
</td>
<td>
<div id=btn8></div>
<!--for testdata2060_10-->
</td>
<td>
<div id=btn9></div>
<!--for testdata2060_05-->
</td>
</tr>
</table>
<div id=statement></div>
</div>
<!--cp_Center-->
</div>
...
CSS
html, body {
width: 100%;
height: 100%;
margin: 5px;
padding: 0px;
overflow: hidden;
/* No Scrollbar */
}
.hr {
background: none;
border: 0;
clear: both;
display: block;
float: none;
font-size: 0;
padding: 10px;
overflow: hidden;
visibility: hidden;
}
#main_bContainer {
height: 650px;
/*900,1200*/
width: 800px;
margin: 0px;
/* margin is the area between the topmost edge and edge of the border or box that ho;ds the content */
margin-left: auto;
/*auto-center position*/
margin-right: auto;
/*auto-center position*/
}
#cp_Center {
margin: 0px;
padding: 10px 10px 10px 10px;
/*Top > Right > Bottom > Left*/
}
.bC_Left {
height: 100%;
width: 30%;
margin: 0px;
}
.bC_Right
/*Not in use*/
{
height: 100%;
width: 70%;
margin: 0px;
}
.cP_LeftTop {
height: 50%;
/*70*/
width: 100%;
margin: 0px;
}
.cP_LeftBottom {
height: 50%;
/*30*/
width: 100%;
margin: 0px;
}
.cP_Right {
height: 100%;
width: 60%;
/*relative to .bc_Left*/
margin: 0px;
}
.cP_Left {
height: 100%;
width: 40%;
/*relative to .cp_Right*/
margin: 0px;
overflow: hidden;
}
/*
#surfaceElement1
{
background-position:center center;
}
*/
JavaScript
var dojoConfig = {
parseOnLoad: true, //replace web controls based on theme soria
isDebug: true, //true for debuggin with aid from FireBug, Always set it to false, to avoid overhead
async: true, //
locale: "en-us" //
};
require(["dojo/parser", "dijit/layout/BorderContainer",
"dijit/form/Button", "dojo/on", "dijit/form/Select",
"dojo/store/Memory", "dojo/request", "dojo/dom", "dojo/dom-construct", "dojo/domReady!"],
function (parser, BorderContainer, Button, on, Select, Memory, request, dom, domConstruct) {
var commonDB = "nameless";
function connect(commonDB) {
request.post("testconnect.php", {
data: {
nameDB: commonDB
}
//,handleAs: "json" // without the use of "handleAs: JSON" as it needs only confirnation or not
}).then(
function (connect) {
console.debug("data read as: ", connect);
if (connect) //as true or false as indicated in login.php
{
alert("Successfully login and connected");
switch (commonDB) {
case 'testdata2060_03':
btn4.set('disabled', false);
btn5.set('disabled', true);
btn6.set('disabled', true);
btn7.set('disabled', false);
btn8.set('disabled', true);
btn9.set('disabled', true);
break;
case 'testdata1970_11':
btn4.set('disabled', true);
btn5.set('disabled', false);
btn6.set('disabled', true);
btn7.set('disabled', true);
btn8.set('disabled', false);
btn9.set('disabled', true);
break;
case 'testdata1970_05':
btn4.set('disabled', true);
...