2150 |
mathias |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
|
2 |
<html debug="true">
|
|
|
3 |
<head>
|
|
|
4 |
<title>dojox.Grid Test: Mysql Table Editing</title>
|
|
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
|
|
|
6 |
<style>
|
|
|
7 |
@import "../_grid/tundraGrid.css";
|
|
|
8 |
@import "../../../dojo/resources/dojo.css";
|
|
|
9 |
@import "../../../dijit/themes/tundra/tundra.css";
|
|
|
10 |
@import "../../../dijit/tests/css/dijitTests.css";
|
|
|
11 |
|
|
|
12 |
.grid {
|
|
|
13 |
height: 30em;
|
|
|
14 |
}
|
|
|
15 |
</style>
|
|
|
16 |
|
|
|
17 |
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:true, parseOnLoad: true"></script>
|
|
|
18 |
<script type="text/javascript" src="../../../dijit/tests/_testCommon.js"></script>
|
|
|
19 |
<!--<script type="text/javascript">
|
|
|
20 |
dojo.require("dojox.grid.Grid");
|
|
|
21 |
dojo.require("dojox.grid._data.model");
|
|
|
22 |
dojo.require("dojox.grid._data.dijitEditors");
|
|
|
23 |
dojo.require("dojox.grid.tests.databaseModel");
|
|
|
24 |
dojo.require("dojo.parser");
|
|
|
25 |
</script>-->
|
|
|
26 |
<!-- Debugging -->
|
|
|
27 |
<script type="text/javascript" src="../_grid/lib.js"></script>
|
|
|
28 |
<script type="text/javascript" src="../_grid/drag.js"></script>
|
|
|
29 |
<script type="text/javascript" src="../_grid/scroller.js"></script>
|
|
|
30 |
<script type="text/javascript" src="../_grid/builder.js"></script>
|
|
|
31 |
<script type="text/javascript" src="../_grid/cell.js"></script>
|
|
|
32 |
<script type="text/javascript" src="../_grid/layout.js"></script>
|
|
|
33 |
<script type="text/javascript" src="../_grid/rows.js"></script>
|
|
|
34 |
<script type="text/javascript" src="../_grid/focus.js"></script>
|
|
|
35 |
<script type="text/javascript" src="../_grid/selection.js"></script>
|
|
|
36 |
<script type="text/javascript" src="../_grid/edit.js"></script>
|
|
|
37 |
<script type="text/javascript" src="../_grid/view.js"></script>
|
|
|
38 |
<script type="text/javascript" src="../_grid/views.js"></script>
|
|
|
39 |
<script type="text/javascript" src="../_grid/rowbar.js"></script>
|
|
|
40 |
<script type="text/javascript" src="../_grid/publicEvents.js"></script>
|
|
|
41 |
<script type="text/javascript" src="../VirtualGrid.js"></script>
|
|
|
42 |
<script type="text/javascript" src="../_data/fields.js"></script>
|
|
|
43 |
<script type="text/javascript" src="../_data/model.js"></script>
|
|
|
44 |
<script type="text/javascript" src="../_data/editors.js"></script>
|
|
|
45 |
<script type="text/javascript" src="../_data/dijitEditors.js"></script>
|
|
|
46 |
<script type="text/javascript" src="../Grid.js"></script>
|
|
|
47 |
<script type="text/javascript" src="databaseModel.js"></script>
|
|
|
48 |
<script type="text/javascript">
|
|
|
49 |
var model = new dojox.grid.data.DbTable(null, null, 'support/data.php', "test", "testtbl");
|
|
|
50 |
// simple display of row info; based on model observing.
|
|
|
51 |
modelChange = function() {
|
|
|
52 |
dojo.byId('rowCount').innerHTML = model.count + ' row(s)';
|
|
|
53 |
}
|
|
|
54 |
model.observer(this);
|
|
|
55 |
|
|
|
56 |
// yay, let's deal with MySql date types, at least a little bit...
|
|
|
57 |
// NOTE: supports only default date formatting YYYY-MM-DD HH:MM:SS or YY-MM-DD HH:MM:SS
|
|
|
58 |
mysqlDateToJsDate = function(inMysqlDateTime, inDateDelim, inTimeDelim) {
|
|
|
59 |
var dt = inMysqlDateTime.split(' '), d = dt[0], t = dt[1], r;
|
|
|
60 |
d = d&&d.split(inDateDelim||'-');
|
|
|
61 |
t = t&&t.split(inTimeDelim||':');
|
|
|
62 |
if (d && d.length == 3) {
|
|
|
63 |
r = new Date();
|
|
|
64 |
r.setYear(d[0]);
|
|
|
65 |
r.setMonth(parseInt(d[1])-1);
|
|
|
66 |
r.setDate(d[2]);
|
|
|
67 |
}
|
|
|
68 |
if (t && t.length == 3) {
|
|
|
69 |
r = r || new Date();
|
|
|
70 |
r.setHours(t[0]);
|
|
|
71 |
r.setMinutes(t[1]);
|
|
|
72 |
r.setSeconds(t[2]);
|
|
|
73 |
}
|
|
|
74 |
return r || new Date(inMysqlDateTime);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
jsDateToMySqlDate = function(inDate) {
|
|
|
78 |
var
|
|
|
79 |
d = new Date(inDate),
|
|
|
80 |
y = d.getFullYear(),
|
|
|
81 |
m = dojo.string.pad(d.getMonth() + 1),
|
|
|
82 |
dd = dojo.string.pad(d.getDate())
|
|
|
83 |
return dojo.string.substitute("${0}-${1}-${2}",[y, m, dd]);
|
|
|
84 |
};
|
|
|
85 |
|
|
|
86 |
// custom simple MySql date formatter
|
|
|
87 |
formatMySqlDate = function(inDatum) {
|
|
|
88 |
return inDatum != dojox.grid.na ? dojo.date.locale.format(mysqlDateToJsDate(inDatum), this.constraint) : dojox.grid.na;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
// custom simple MySql date editor
|
|
|
92 |
dojo.declare("mySqlDateEditor", dojox.grid.editors.DateTextBox, {
|
|
|
93 |
format: function(inDatum, inRowIndex){
|
|
|
94 |
inDatum = mysqlDateToJsDate(inDatum);
|
|
|
95 |
return this.inherited(arguments, [inDatum, inRowIndex]);
|
|
|
96 |
},
|
|
|
97 |
getValue: function(inRowIndex){
|
|
|
98 |
var v = this.editor.getValue(), fv = jsDateToMySqlDate(v);
|
|
|
99 |
return fv;
|
|
|
100 |
}
|
|
|
101 |
});
|
|
|
102 |
|
|
|
103 |
var gridLayout = [
|
|
|
104 |
{ type: "dojox.GridRowView", width: "20px" },
|
|
|
105 |
{
|
|
|
106 |
defaultCell: { width: 6, editor: dojox.grid.editors.Dijit },
|
|
|
107 |
cells: [[
|
|
|
108 |
{ name: 'Id', styles: 'text-align: right;', editorClass: "dijit.form.NumberTextBox" },
|
|
|
109 |
{ name: 'Name', width: 20},
|
|
|
110 |
{ name: 'Message', styles: 'text-align: right;'},
|
|
|
111 |
{ name: 'Date',
|
|
|
112 |
editor: mySqlDateEditor,
|
|
|
113 |
formatter: formatMySqlDate,
|
|
|
114 |
constraint: {selector: "date"},
|
|
|
115 |
width: 10,
|
|
|
116 |
styles: 'text-align:right;'}
|
|
|
117 |
]]}
|
|
|
118 |
];
|
|
|
119 |
|
|
|
120 |
function waitMessage() {
|
|
|
121 |
alert('Edit in progress, please wait.');
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
function getDefaultRow() {
|
|
|
125 |
return ['', '', '', jsDateToMySqlDate(new Date())];
|
|
|
126 |
}
|
|
|
127 |
function addRow() {
|
|
|
128 |
if(model.canModify()){
|
|
|
129 |
grid.addRow(getDefaultRow());
|
|
|
130 |
}else{
|
|
|
131 |
waitMessage();
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
function removeSelected(){
|
|
|
136 |
if(model.canModify()){
|
|
|
137 |
grid.removeSelectedRows();
|
|
|
138 |
}else{
|
|
|
139 |
waitMessage();
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
</script>
|
|
|
143 |
</head>
|
|
|
144 |
<body class="tundra">
|
|
|
145 |
<h1>dojox.Grid Test: Mysql Table Editing</h1>
|
|
|
146 |
<br>
|
|
|
147 |
<button onclick="addRow()">Add Row</button>
|
|
|
148 |
<button onclick="removeSelected()">Remove Selected</button>
|
|
|
149 |
<button onclick="grid.edit.apply()">Apply Edit</button>
|
|
|
150 |
<button onclick="grid.edit.cancel()">Cancel Edit</button>
|
|
|
151 |
<button onclick="grid.refresh()">Refresh</button>
|
|
|
152 |
<br><br>
|
|
|
153 |
<div jsId="grid" class="grid" structure="gridLayout" dojoType="dojox.Grid" model="model" singleClickEdit="true" autoWidth="true"></div>
|
|
|
154 |
<div id="rowCount"></div>
|
|
|
155 |
<p>Note: This test requires MySql and PHP and works with the database table available in support/testtbl.sql.</p>
|
|
|
156 |
</body>
|
|
|
157 |
</html>
|