9553a5e30c062bb7f83b3c597a5ce4a15b1be033.svn-base 5.7 KB

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