From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/grid/tests/databaseModel.js | 337 ++++++++ includes/js/dojox/grid/tests/images/closed.gif | Bin 0 -> 907 bytes includes/js/dojox/grid/tests/images/flatScreen.gif | Bin 0 -> 824 bytes includes/js/dojox/grid/tests/images/open.gif | Bin 0 -> 907 bytes includes/js/dojox/grid/tests/support/books.xml | 103 +++ includes/js/dojox/grid/tests/support/data.php | 379 +++++++++ includes/js/dojox/grid/tests/support/geography.xml | 51 ++ includes/js/dojox/grid/tests/support/json.php | 794 +++++++++++++++++ includes/js/dojox/grid/tests/support/movies.csv | 9 + includes/js/dojox/grid/tests/support/test_data.js | 30 + .../dojox/grid/tests/support/test_data_objects.js | 31 + includes/js/dojox/grid/tests/support/testtbl.sql | 944 +++++++++++++++++++++ .../js/dojox/grid/tests/support/yahoo_search.js | 131 +++ .../js/dojox/grid/tests/test_change_structure.html | 124 +++ includes/js/dojox/grid/tests/test_custom_sort.html | 86 ++ .../js/dojox/grid/tests/test_dojo_data_edit.html | 124 +++ .../js/dojox/grid/tests/test_dojo_data_empty.html | 63 ++ .../js/dojox/grid/tests/test_dojo_data_model.html | 84 ++ .../tests/test_dojo_data_model_EmptyResultSet.html | 57 ++ .../tests/test_dojo_data_model_multiStores.html | 291 +++++++ .../tests/test_dojo_data_model_processError.html | 65 ++ .../grid/tests/test_dojo_data_notification.html | 114 +++ includes/js/dojox/grid/tests/test_edit.html | 149 ++++ .../js/dojox/grid/tests/test_edit_canEdit.html | 156 ++++ includes/js/dojox/grid/tests/test_edit_dijit.html | 137 +++ includes/js/dojox/grid/tests/test_events.html | 174 ++++ includes/js/dojox/grid/tests/test_expand.html | 107 +++ includes/js/dojox/grid/tests/test_grid.html | 69 ++ includes/js/dojox/grid/tests/test_grid_dlg.html | 88 ++ .../dojox/grid/tests/test_grid_headerHeight.html | 84 ++ includes/js/dojox/grid/tests/test_grid_layout.html | 112 +++ .../tests/test_grid_layout_LayoutContainer.html | 87 ++ .../tests/test_grid_layout_borderContainer.html | 98 +++ .../grid/tests/test_grid_object_model_change.html | 86 ++ .../dojox/grid/tests/test_grid_programmatic.html | 65 ++ .../grid/tests/test_grid_programmatic_layout.html | 74 ++ includes/js/dojox/grid/tests/test_grid_rtl.html | 71 ++ includes/js/dojox/grid/tests/test_grid_themes.html | 118 +++ .../dojox/grid/tests/test_grid_tooltip_menu.html | 161 ++++ includes/js/dojox/grid/tests/test_keyboard.html | 90 ++ includes/js/dojox/grid/tests/test_markup.html | 112 +++ includes/js/dojox/grid/tests/test_mysql_edit.html | 155 ++++ includes/js/dojox/grid/tests/test_sizing.html | 175 ++++ .../js/dojox/grid/tests/test_sizing_100rows.html | 168 ++++ .../dojox/grid/tests/test_sizing_ResizeHandle.html | 113 +++ includes/js/dojox/grid/tests/test_styling.html | 131 +++ includes/js/dojox/grid/tests/test_subgrid.html | 179 ++++ includes/js/dojox/grid/tests/test_tundra_edit.html | 139 +++ .../js/dojox/grid/tests/test_yahoo_images.html | 148 ++++ .../js/dojox/grid/tests/test_yahoo_search.html | 141 +++ includes/js/dojox/grid/tests/yahooSearch.js | 137 +++ 51 files changed, 7341 insertions(+) create mode 100644 includes/js/dojox/grid/tests/databaseModel.js create mode 100644 includes/js/dojox/grid/tests/images/closed.gif create mode 100644 includes/js/dojox/grid/tests/images/flatScreen.gif create mode 100644 includes/js/dojox/grid/tests/images/open.gif create mode 100644 includes/js/dojox/grid/tests/support/books.xml create mode 100644 includes/js/dojox/grid/tests/support/data.php create mode 100644 includes/js/dojox/grid/tests/support/geography.xml create mode 100644 includes/js/dojox/grid/tests/support/json.php create mode 100644 includes/js/dojox/grid/tests/support/movies.csv create mode 100644 includes/js/dojox/grid/tests/support/test_data.js create mode 100644 includes/js/dojox/grid/tests/support/test_data_objects.js create mode 100644 includes/js/dojox/grid/tests/support/testtbl.sql create mode 100644 includes/js/dojox/grid/tests/support/yahoo_search.js create mode 100644 includes/js/dojox/grid/tests/test_change_structure.html create mode 100644 includes/js/dojox/grid/tests/test_custom_sort.html create mode 100644 includes/js/dojox/grid/tests/test_dojo_data_edit.html create mode 100644 includes/js/dojox/grid/tests/test_dojo_data_empty.html create mode 100644 includes/js/dojox/grid/tests/test_dojo_data_model.html create mode 100644 includes/js/dojox/grid/tests/test_dojo_data_model_EmptyResultSet.html create mode 100644 includes/js/dojox/grid/tests/test_dojo_data_model_multiStores.html create mode 100644 includes/js/dojox/grid/tests/test_dojo_data_model_processError.html create mode 100644 includes/js/dojox/grid/tests/test_dojo_data_notification.html create mode 100644 includes/js/dojox/grid/tests/test_edit.html create mode 100644 includes/js/dojox/grid/tests/test_edit_canEdit.html create mode 100644 includes/js/dojox/grid/tests/test_edit_dijit.html create mode 100644 includes/js/dojox/grid/tests/test_events.html create mode 100644 includes/js/dojox/grid/tests/test_expand.html create mode 100644 includes/js/dojox/grid/tests/test_grid.html create mode 100644 includes/js/dojox/grid/tests/test_grid_dlg.html create mode 100644 includes/js/dojox/grid/tests/test_grid_headerHeight.html create mode 100644 includes/js/dojox/grid/tests/test_grid_layout.html create mode 100644 includes/js/dojox/grid/tests/test_grid_layout_LayoutContainer.html create mode 100644 includes/js/dojox/grid/tests/test_grid_layout_borderContainer.html create mode 100644 includes/js/dojox/grid/tests/test_grid_object_model_change.html create mode 100644 includes/js/dojox/grid/tests/test_grid_programmatic.html create mode 100644 includes/js/dojox/grid/tests/test_grid_programmatic_layout.html create mode 100644 includes/js/dojox/grid/tests/test_grid_rtl.html create mode 100644 includes/js/dojox/grid/tests/test_grid_themes.html create mode 100644 includes/js/dojox/grid/tests/test_grid_tooltip_menu.html create mode 100644 includes/js/dojox/grid/tests/test_keyboard.html create mode 100644 includes/js/dojox/grid/tests/test_markup.html create mode 100644 includes/js/dojox/grid/tests/test_mysql_edit.html create mode 100644 includes/js/dojox/grid/tests/test_sizing.html create mode 100644 includes/js/dojox/grid/tests/test_sizing_100rows.html create mode 100644 includes/js/dojox/grid/tests/test_sizing_ResizeHandle.html create mode 100644 includes/js/dojox/grid/tests/test_styling.html create mode 100644 includes/js/dojox/grid/tests/test_subgrid.html create mode 100644 includes/js/dojox/grid/tests/test_tundra_edit.html create mode 100644 includes/js/dojox/grid/tests/test_yahoo_images.html create mode 100644 includes/js/dojox/grid/tests/test_yahoo_search.html create mode 100644 includes/js/dojox/grid/tests/yahooSearch.js (limited to 'includes/js/dojox/grid/tests') diff --git a/includes/js/dojox/grid/tests/databaseModel.js b/includes/js/dojox/grid/tests/databaseModel.js new file mode 100644 index 0000000..3c879eb --- /dev/null +++ b/includes/js/dojox/grid/tests/databaseModel.js @@ -0,0 +1,337 @@ +if(!dojo._hasResource["dojox.grid.tests.databaseModel"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.grid.tests.databaseModel"] = true; +dojo.provide("dojox.grid.tests.databaseModel"); +dojo.require("dojox.grid._data.model"); + +// Provides a sparse array that is also traversable inorder +// with basic Array: +// - iterating by index is slow for large sparse arrays +// - for...in iteration is in order of element creation +// maintains a secondary index for interating +// over sparse elements inorder +dojo.declare("dojox.grid.Sparse", null, { + constructor: function() { + this.clear(); + }, + clear: function() { + this.indices = []; + this.values = []; + }, + length: function() { + return this.indices.length; + }, + set: function(inIndex, inValue) { + for (var i=0,l=this.indices.length; i= inIndex) + break; + } + if (this.indices[i] != inIndex) + this.indices.splice(i, 0, inIndex); + this.values[inIndex] = inValue; + }, + get: function(inIndex) { + return this.values[inIndex]; + }, + remove: function(inIndex) { + for (var i=0,l=this.indices.length; i=0) && ((k=inRowIndexes[i])!=undefined); i--) + this.setState(k, inState, inValue); + }, + clearStateForIndexes: function(inRowIndexes, inState) { + for (var i=inRowIndexes.length-1, k; (i>=0) && ((k=inRowIndexes[i])!=undefined); i--) + this.clearState(k, inState); + }, + //$ Return boolean stating whether or not an operation is in progress that may change row indexing. + isAddRemoving: function() { + return Boolean(this.states['inserting'].length() || this.states['removing'].length()); + }, + isInflight: function() { + return Boolean(this.states['inflight'].length()); + }, + //$ Return boolean stating if the model is currently undergoing any type of edit. + isEditing: function() { + for (var i=0, r={}, s; (s=this.stateNames[i]); i++) + if (this.states[s].length()) + return true; + }, + //$ Return true if ok to modify the given row. Override as needed, using model editing state information. + canModify: function(inRowIndex) { + return !this.getState(inRowIndex).inflight && !(this.isInflight() && this.isAddRemoving()); + }, + // server send / receive + getSendParams: function(inParams) { + var p = { + database: this.database || '', + table: this.table || '' + } + return dojo.mixin(p, inParams || {}); + }, + send: function(inAsync, inParams, inCallbacks) { + //console.log('send', inParams.command); + var p = this.getSendParams(inParams); + var d = dojo.xhrPost({ + url: this.server, + content: p, + handleAs: 'json-comment-filtered', + contentType: "application/x-www-form-urlencoded; charset=utf-8", + sync: !inAsync + }); + d.addCallbacks(dojo.hitch(this, "receive", inCallbacks), dojo.hitch(this, "receiveError", inCallbacks)); + return d; + }, + _callback: function(cb, eb, data) { + try{ cb && cb(data); } + catch(e){ eb && eb(data, e); } + }, + receive: function(inCallbacks, inData) { + inCallbacks && this._callback(inCallbacks.callback, inCallbacks.errback, inData); + }, + receiveError: function(inCallbacks, inErr) { + this._callback(inCallbacks.errback, null, inErr) + }, + encodeRow: function(inParams, inRow, inPrefix) { + for (var i=0, l=inRow.length; i < l; i++) + inParams['_' + (inPrefix ? inPrefix : '') + i] = (inRow[i] ? inRow[i] : ''); + }, + measure: function() { + this.send(true, { command: 'info' }, { callback: dojo.hitch(this, this.callbacks.info) }); + }, + fetchRowCount: function(inCallbacks) { + this.send(true, { command: 'count' }, inCallbacks); + }, + // server commits + commitEdit: function(inOldData, inNewData, inRowIndex, inCallbacks) { + this.setState(inRowIndex, "inflight", true); + var params = {command: 'update'}; + this.encodeRow(params, inOldData, 'o'); + this.encodeRow(params, inNewData); + this.send(true, params, inCallbacks); + }, + commitInsert: function(inRowIndex, inNewData, inCallbacks) { + this.setState(inRowIndex, "inflight", true); + var params = {command: 'insert'}; + this.encodeRow(params, inNewData); + this.send(true, params, inCallbacks); + }, + // NOTE: supported only in tables with pk + commitDelete: function(inRows, inCallbacks) { + var params = { + command: 'delete', + count: inRows.length + } + var pk = this.getPkIndex(); + if (pk < 0) + return; + for (var i=0; i < inRows.length; i++) { + params['_' + i] = inRows[i][pk]; + } + this.send(true, params, inCallbacks); + }, + getUpdateCallbacks: function(inRowIndex) { + return { + callback: dojo.hitch(this, this.callbacks.update, inRowIndex), + errback: dojo.hitch(this, this.callbacks.updateError, inRowIndex) + }; + }, + // primary key from fields + getPkIndex: function() { + for (var i=0, l=this.fields.count(), f; (i + + + 1 + Title of 1 + Author of 1 + + + 2 + Title of 2 + Author of 2 + + + 3 + Title of 3 + Author of 3 + + + 4 + Title of 4 + Author of 4 + + + 5 + Title of 5 + Author of 5 + + + 6 + Title of 6 + Author of 6 + + + 7 + Title of 7 + Author of 7 + + + 8 + Title of 8 + Author of 8 + + + 9 + Title of 9 + Author of 9 + + + 10 + Title of 10 + Author of 10 + + + 11 + Title of 11 + Author of 11 + + + 12 + Title of 12 + Author of 12 + + + 13 + Title of 13 + Author of 13 + + + 14 + Title of 14 + Author of 14 + + + 15 + Title of 15 + Author of 15 + + + 16 + Title of 16 + Author of 16 + + + 17 + Title of 17 + Author of 17 + + + 18 + Title of 18 + Author of 18 + + + 19 + Title of 19 + Author of 19 + + + 20 + Title of 20 + Author of 20 + + diff --git a/includes/js/dojox/grid/tests/support/data.php b/includes/js/dojox/grid/tests/support/data.php new file mode 100644 index 0000000..1beb6f0 --- /dev/null +++ b/includes/js/dojox/grid/tests/support/data.php @@ -0,0 +1,379 @@ +encode($inData) . ' */'; + } + + function error($inMessage) { + $inMessage = str_replace('"', '\\"', $inMessage); + error_log($inMessage); + //echo '/* ({error: true, message: "' . $inMessage . '"}) */'; + echoJson(array('error' => true, 'message' => $inMessage)); + exit; + } + + + function getArray($inResult, $inArray="true") { + $o = Array(); + while ($row = ($inArray ? mysql_fetch_row($inResult) : mysql_fetch_object($inResult))) + $o[] = $row; + return $o; + } + + // connect to DB + mysql_connect($dbserver, $dbuser, $dbpassword); + + // select DB + $database = getPostString("database"); + $database = ($database ? $database : $db); + if (!mysql_select_db($database)) + error('failed to select db: ' . mysql_error()); + + // select table + $table = getPostString("table"); + $table = ($table ? $table : $dbtable); + + // cache + $colCache = NULL; + $pkCache = NULL; + + // set UTF8 output (MySql > 4.0) + mysql_query("SET NAMES UTF8"); + + // server, database, table meta data + function getDatabases() { + $result = mysql_query("SHOW DATABASES"); + $output = Array(); + while ($row = mysql_fetch_row($result)) { + $r = strtolower($row[0]); + if ($r != 'mysql' && $r != 'information_schema') + $output[] = $row[0]; + } + return $output; + } + + function getTables() { + global $database; + $result = mysql_query("SHOW TABLES FROM $database"); + $output = Array(); + while ($row = mysql_fetch_row($result)) + $output[] = $row[0]; + return $output; + } + + function getColumns() { + global $table, $colCache; + if (!$colCache) { + $result = mysql_query("SHOW COLUMNS FROM `$table`"); + return getArray($result, false); + $colCache = getArray($result, false); + } + return $colCache; + } + + // returns object: $this->name, $this->index + function getPk() { + global $pkCache; + if (!$pkCache) { + $k = ''; + $columns = getColumns(); + for ($i=0; $i < count($columns); $i++) { + $c = $columns[$i]; + if ($c->Key == 'PRI') { + $k = $c->Field; + break; + } + } + $pkCache->index = $i; + $pkCache->name = $k; + } + return $pkCache; + } + + function getTableInfo() { + global $table, $database; + $c = getColumns(); + $r = rowcount(); + return array("count" => $r, "columns" => $c, "database" => $database, "table" => $table); + } + + function getOldPostPkValue() { + $pk = getPk(); + return getPostString('_o' . $pk->index); + } + + function getNewPostPkValue() { + $pk = getPk(); + return getPostString('_' . $pk->index); + } + + function getPostColumns() { + $columns = getColumns(); + for ($i=0, $a=array(), $p; (($p=getPostString("_".$i)) != ''); $i++) { + $r = new stdClass(); + $r->name = $columns[$i]->Field; + $r->value = $p; + $a[] = $r; + } + return $a; + } + + function getOrderBy() { + $ob = getPostString("orderby"); + if (is_numeric($ob)) { + $columns = getColumns(); + $ob = $columns[intval($ob)-1]->Field; + } + return $ob; + } + + function getWhere() { + $w = getPostString("where"); + return ($w ? " WHERE $w" : ""); + } + + // basic operations + function rowcount() { + global $table; + $query = "SELECT COUNT(*) FROM `$table`" . getWhere(); + $result = mysql_query($query); + if (!$result) + error("failed to perform query: $query. " . mysql_error()); + if ($row = mysql_fetch_row($result)) + return $row[0]; + else + return 0; + } + + function select($inQuery = '') { + global $table; + // built limit clause + $lim = (int)getPostString("limit"); + $off = (int)getPostString("offset"); + $limit = ($lim || $off ? " LIMIT $off, $lim" : ""); + // build order by clause + $desc = (boolean)getPostString("desc"); + $ob = getOrderBy(); + $orderby = ($ob ? " ORDER BY `" . $ob . "`" . ($desc ? " DESC" : "") : ""); + // build query + $query = ($inQuery ? $inQuery : "SELECT * FROM `$table`" . getWhere() . $orderby . $limit); + // execute query + if (!$result = mysql_query($query)) + error("failed to perform query: $query. " . mysql_error()); + // fetch each result row + return getArray($result); + } + + function reflectRow() { + global $table; + $pk = getPk(); + $key = getNewPostPkValue(); + $where = "`$pk->name`=\"$key\""; + return select("SELECT * FROM `$table` WHERE $where LIMIT 1"); + } + + function update() { + // build set clause + for ($i=0, $set = array(), $cols = getPostColumns(), $v; ($v=$cols[$i]); $i++) + $set[] = "`$v->name` = '$v->value'"; + $set = implode(', ', $set); + // our table + global $table; + // build query + $pk = getPk(); + $pkValue = getOldPostPkValue(); + $query = "UPDATE `$table` SET $set WHERE `$pk->name` = '$pkValue' LIMIT 1"; + // execute query + if (!mysql_query($query)) + error("failed to perform query: [$query]. " . + "MySql says: [" . mysql_error() ."]"); + else { + return reflectRow(); + } + } + + function insert() { + global $table; + // build values clause + for ($i=0, $values = array(), $cols = getPostColumns(), $v; ($v=$cols[$i]); $i++) + $values[] = $v->value; + $values = '"' . implode('", "', $values) . '"'; + // build query + $query = "INSERT INTO `$table` VALUES($values)"; + // execute query + if (!mysql_query($query)) + error("failed to perform query: [$query]. " . + "MySql says: [" . mysql_error() ."]"); + else { + return reflectRow(); + } + } + + function delete() { + global $table; + // build query + $n = getPostString("count"); + $pk = getPk(); + for ($i = 0, $deleted=array(); $i < $n; $i++) { + $key = getPostString("_$i"); + array_push($deleted, $key); + $query = "DELETE FROM `$table` WHERE `$pk->name`=\"$key\" LIMIT 1"; + // execute query + if (!mysql_query($query) || mysql_affected_rows() != 1) + error("failed to perform query: [$query]. " . + "Affected rows: " . mysql_affected_rows() .". " . + "MySql says: [" . mysql_error() ."]"); + } + return $deleted; + } + + // find (full text search) + function findData($inFindCol, $inFind, $inOrderBy, $inFullText) { + global $table; + $where = ($inFullText ? "WHERE MATCH(`$inFindCol`) AGAINST ('$inFind')" : "WHERE $inFindCol LIKE '$inFind'"); + $query = "SELECT * FROM $table $where $inOrderBy"; + $result = mysql_query($query); + // return rows + return getArray($result); + } + + // binary search through sorted data, supports start point ($inFindFrom) and direction ($inFindForward) + function findRow($inData, $inFindFrom=-1, $inFindForward) { + $b = -1; + $l = count($inData); + if (!$inData) + return $b; + if (!$inFindFrom==-1 || $l < 2) + $b = 0; + else { + // binary search + $t = $l-1; + $b = 0; + while ($b <= $t) { + $p = floor(($b+$t)/2); + $d = $inData[$p][0]; + if ($d < $inFindFrom) + $b = $p + 1; + else if ($d > $inFindFrom) + $t = $p - 1; + else { + $b = $p; + break; + } + } + if ($inFindFrom == $inData[$b][0]) { + // add or subtract 1 + $b = ($inFindForward ? ($b+1 > $l-1 ? 0 : $b+1) : ($b-1 < 0 ? $l-1 : $b-1) ); + } + else if (!$inFindForward) + // subtract 1 + $b = ($b-1 < 0 ? $l-1 : $b-1); + } + return $inData[$b][0]; + } + + function buildFindWhere($inFindData, $inKey, $inCol) { + $o = Array(); + foreach($inFindData as $row) + $o[] = $inCol . "='" . $row[$inKey] . "'"; + return (count($o) ? ' WHERE ' . implode(' OR ', $o) : ''); + } + + function find($inFindCol, $inFind='', $inOb='', $inFindFrom=0, $inFindForward=true, $inFullText=true) { + global $table; + // build order by clause + $desc = (boolean)getPostString("desc"); + if (!$inOb) + $inOb = getOrderBy(); + if ($inOb) + $inOb = "`" . $inOb . "`" ; + $orderby = ($inOb ? " ORDER BY $inOb " . ($desc ? " DESC" : "") : ""); + // update inputs from post + if (!$inFind) + $inFind = getPostString('findText'); + if (!$inFindCol) + $inFindCol = getPostString('findCol'); + if (empty($inFindFrom)) + $inFindFrom = getPostString('findFrom'); + $ff = getPostString('findForward'); + if ($ff) + $inFindForward = (strtolower($ff) == 'true' ? true : false); + $ft = getPostString('findFullText'); + if ($ft) + $inFullText = (strtolower($ft) == 'true' ? true : false); + + // get find data + $f = findData($inFindCol, $inFind, $orderby, $inFullText); + $pk = getPk(); + + // execute query + $where = buildFindWhere($f, $pk->index, 'f'); + $query = "SELECT Row, f FROM (SELECT @row := @row + 1 AS Row, $pk->name as f FROM `$table` $orderby) AS tempTable $where"; + mysql_query('SET @row = -1;'); + if (!$result = mysql_query($query)) + error("failed to perform query: $query. " . mysql_error()); + + // return row number + return findRow(getArray($result), $inFindFrom, $inFindForward); + } + + // our command list + $cmds = array( + "count" => "rowcount", + "select" => "select", + "update" => "update", + "insert" => "insert", + "delete" => "delete", + "find" => "find", + "databases" => "getDatabases", + "tables" => "getTables", + "columns" => "getColumns", + "info" => "getTableInfo" + ); + + // process input params + $cmd = @$_POST["command"]; + + //$cmd="select"; + + // dispatch command + $func = @$cmds[$cmd]; + if (function_exists($func)) + echoJson(call_user_func($func)); + else + error("bad command"); +?> diff --git a/includes/js/dojox/grid/tests/support/geography.xml b/includes/js/dojox/grid/tests/support/geography.xml new file mode 100644 index 0000000..070a8c1 --- /dev/null +++ b/includes/js/dojox/grid/tests/support/geography.xml @@ -0,0 +1,51 @@ + + + + geography.opml + 2006-11-10 + 2006-11-13 + Magellan, Ferdinand + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/includes/js/dojox/grid/tests/support/json.php b/includes/js/dojox/grid/tests/support/json.php new file mode 100644 index 0000000..84e3dfa --- /dev/null +++ b/includes/js/dojox/grid/tests/support/json.php @@ -0,0 +1,794 @@ + +* @author Matt Knapp +* @author Brett Stimmerman +* @copyright 2005 Michal Migurski +* @license http://www.opensource.org/licenses/bsd-license.php +* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198 +*/ + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_SLICE', 1); + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_IN_STR', 2); + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_IN_ARR', 4); + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_IN_OBJ', 8); + +/** +* Marker constant for Services_JSON::decode(), used to flag stack state +*/ +define('SERVICES_JSON_IN_CMT', 16); + +/** +* Behavior switch for Services_JSON::decode() +*/ +define('SERVICES_JSON_LOOSE_TYPE', 10); + +/** +* Behavior switch for Services_JSON::decode() +*/ +define('SERVICES_JSON_STRICT_TYPE', 11); + +/** +* Encodings +*/ +define('SERVICES_JSON_ISO_8859_1', 'iso-8859-1'); +define('SERVICES_JSON_UTF_8', 'utf-8'); + +/** +* Converts to and from JSON format. +* +* Brief example of use: +* +* +* // create a new instance of Services_JSON +* $json = new Services_JSON(); +* +* // convert a complexe value to JSON notation, and send it to the browser +* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4))); +* $output = $json->encode($value); +* +* print($output); +* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]] +* +* // accept incoming POST data, assumed to be in JSON notation +* $input = file_get_contents('php://input', 1000000); +* $value = $json->decode($input); +* +*/ +class Services_JSON +{ + /** + * constructs a new JSON instance + * + //>> SJM2005 + * @param string $encoding Strings are input/output in this encoding + * @param int $encode Encode input is expected in this character encoding + //<< SJM2005 + * + * @param int $use object behavior: when encoding or decoding, + * be loose or strict about object/array usage + * + * possible values: + * - SERVICES_JSON_STRICT_TYPE: strict typing, default. + * "{...}" syntax creates objects in decode(). + * - SERVICES_JSON_LOOSE_TYPE: loose typing. + * "{...}" syntax creates associative arrays in decode(). + */ + function Services_JSON($encoding = SERVICES_JSON_UTF_8, $use = SERVICES_JSON_STRICT_TYPE) + { + //>> SJM2005 + $this->encoding = $encoding; + //<< SJM2005 + + $this->use = $use; + } + + /** + * convert a string from one UTF-16 char to one UTF-8 char + * + * Normally should be handled by mb_convert_encoding, but + * provides a slower PHP-only method for installations + * that lack the multibye string extension. + * + * @param string $utf16 UTF-16 character + * @return string UTF-8 character + * @access private + */ + function utf162utf8($utf16) + { + // oh please oh please oh please oh please oh please + if(function_exists('mb_convert_encoding')) + return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); + + $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); + + switch(true) { + case ((0x7F & $bytes) == $bytes): + // this case should never be reached, because we are in ASCII range + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0x7F & $bytes); + + case (0x07FF & $bytes) == $bytes: + // return a 2-byte UTF-8 character + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0xC0 | (($bytes >> 6) & 0x1F)) + . chr(0x80 | ($bytes & 0x3F)); + + case (0xFFFF & $bytes) == $bytes: + // return a 3-byte UTF-8 character + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0xE0 | (($bytes >> 12) & 0x0F)) + . chr(0x80 | (($bytes >> 6) & 0x3F)) + . chr(0x80 | ($bytes & 0x3F)); + } + + // ignoring UTF-32 for now, sorry + return ''; + } + + /** + * convert a string from one UTF-8 char to one UTF-16 char + * + * Normally should be handled by mb_convert_encoding, but + * provides a slower PHP-only method for installations + * that lack the multibye string extension. + * + * @param string $utf8 UTF-8 character + * @return string UTF-16 character + * @access private + */ + function utf82utf16($utf8) + { + // oh please oh please oh please oh please oh please + if(function_exists('mb_convert_encoding')) + return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); + + switch(strlen($utf8)) { + case 1: + // this case should never be reached, because we are in ASCII range + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return $utf8; + + case 2: + // return a UTF-16 character from a 2-byte UTF-8 char + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0x07 & (ord($utf8{0}) >> 2)) + . chr((0xC0 & (ord($utf8{0}) << 6)) + | (0x3F & ord($utf8{1}))); + + case 3: + // return a UTF-16 character from a 3-byte UTF-8 char + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr((0xF0 & (ord($utf8{0}) << 4)) + | (0x0F & (ord($utf8{1}) >> 2))) + . chr((0xC0 & (ord($utf8{1}) << 6)) + | (0x7F & ord($utf8{2}))); + } + + // ignoring UTF-32 for now, sorry + return ''; + } + + /** + * encodes an arbitrary variable into JSON format + * + * @param mixed $var any number, boolean, string, array, or object to be encoded. + * see argument 1 to Services_JSON() above for array-parsing behavior. + * if var is a strng, note that encode() always expects it + * to be in ASCII or UTF-8 format! + * + * @return string JSON string representation of input var + * @access public + */ + function encode($var) + { + switch (gettype($var)) { + case 'boolean': + return $var ? 'true' : 'false'; + + case 'NULL': + return 'null'; + + case 'integer': + return (int) $var; + + case 'double': + case 'float': + return (float) $var; + + case 'string': + //>> SJM2005 + if ($this->encoding == SERVICES_JSON_UTF_8) + ; + else if ($this->encoding == SERVICES_JSON_ISO_8859_1) + $var = utf8_encode($var); + else if (!function_exists('mb_convert_encoding')) + die('Requested encoding requires mb_strings extension.'); + else + $var = mb_convert_encoding($var, "utf-8", $this->encoding); + //<< SJM2005 + + // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT + $ascii = ''; + $strlen_var = strlen($var); + + /* + * Iterate over every character in the string, + * escaping with a slash or encoding to UTF-8 where necessary + */ + for ($c = 0; $c < $strlen_var; ++$c) { + + $ord_var_c = ord($var{$c}); + + switch (true) { + case $ord_var_c == 0x08: + $ascii .= '\b'; + break; + case $ord_var_c == 0x09: + $ascii .= '\t'; + break; + case $ord_var_c == 0x0A: + $ascii .= '\n'; + break; + case $ord_var_c == 0x0C: + $ascii .= '\f'; + break; + case $ord_var_c == 0x0D: + $ascii .= '\r'; + break; + + case $ord_var_c == 0x22: + case $ord_var_c == 0x2F: + case $ord_var_c == 0x5C: + // double quote, slash, slosh + $ascii .= '\\'.$var{$c}; + break; + + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): + // characters U-00000000 - U-0000007F (same as ASCII) + $ascii .= $var{$c}; + break; + + case (($ord_var_c & 0xE0) == 0xC0): + // characters U-00000080 - U-000007FF, mask 110XXXXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, ord($var{$c + 1})); + $c += 1; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xF0) == 0xE0): + // characters U-00000800 - U-0000FFFF, mask 1110XXXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2})); + $c += 2; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xF8) == 0xF0): + // characters U-00010000 - U-001FFFFF, mask 11110XXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3})); + $c += 3; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xFC) == 0xF8): + // characters U-00200000 - U-03FFFFFF, mask 111110XX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3}), + ord($var{$c + 4})); + $c += 4; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xFE) == 0xFC): + // characters U-04000000 - U-7FFFFFFF, mask 1111110X + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3}), + ord($var{$c + 4}), + ord($var{$c + 5})); + $c += 5; + $utf16 = $this->utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + } + } + + return '"'.$ascii.'"'; + + case 'array': + /* + * As per JSON spec if any array key is not an integer + * we must treat the the whole array as an object. We + * also try to catch a sparsely populated associative + * array with numeric keys here because some JS engines + * will create an array with empty indexes up to + * max_index which can cause memory issues and because + * the keys, which may be relevant, will be remapped + * otherwise. + * + * As per the ECMA and JSON specification an object may + * have any string as a property. Unfortunately due to + * a hole in the ECMA specification if the key is a + * ECMA reserved word or starts with a digit the + * parameter is only accessible using ECMAScript's + * bracket notation. + */ + + // treat as a JSON object + if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { + return '{' . + join(',', array_map(array($this, 'name_value'), + array_keys($var), + array_values($var))) + . '}'; + } + + // treat it like a regular array + return '[' . join(',', array_map(array($this, 'encode'), $var)) . ']'; + + case 'object': + $vars = get_object_vars($var); + return '{' . + join(',', array_map(array($this, 'name_value'), + array_keys($vars), + array_values($vars))) + . '}'; + + default: + return ''; + } + } + + /** + * array-walking function for use in generating JSON-formatted name-value pairs + * + * @param string $name name of key to use + * @param mixed $value reference to an array element to be encoded + * + * @return string JSON-formatted name-value pair, like '"name":value' + * @access private + */ + function name_value($name, $value) + { + return $this->encode(strval($name)) . ':' . $this->encode($value); + } + + /** + * reduce a string by removing leading and trailing comments and whitespace + * + * @param $str string string value to strip of comments and whitespace + * + * @return string string value stripped of comments and whitespace + * @access private + */ + function reduce_string($str) + { + $str = preg_replace(array( + + // eliminate single line comments in '// ...' form + '#^\s*//(.+)$#m', + + // eliminate multi-line comments in '/* ... */' form, at start of string + '#^\s*/\*(.+)\*/#Us', + + // eliminate multi-line comments in '/* ... */' form, at end of string + '#/\*(.+)\*/\s*$#Us' + + ), '', $str); + + // eliminate extraneous space + return trim($str); + } + + /** + * decodes a JSON string into appropriate variable + * + * @param string $str JSON-formatted string + * + * @return mixed number, boolean, string, array, or object + * corresponding to given JSON input string. + * See argument 1 to Services_JSON() above for object-output behavior. + * Note that decode() always returns strings + * in ASCII or UTF-8 format! + * @access public + */ + function decode($str) + { + $str = $this->reduce_string($str); + + switch (strtolower($str)) { + case 'true': + return true; + + case 'false': + return false; + + case 'null': + return null; + + default: + if (is_numeric($str)) { + // Lookie-loo, it's a number + + // This would work on its own, but I'm trying to be + // good about returning integers where appropriate: + // return (float)$str; + + // Return float or int, as appropriate + return ((float)$str == (integer)$str) + ? (integer)$str + : (float)$str; + + } elseif (preg_match('/^("|\').+(\1)$/s', $str, $m) && $m[1] == $m[2]) { + // STRINGS RETURNED IN UTF-8 FORMAT + $delim = substr($str, 0, 1); + $chrs = substr($str, 1, -1); + $utf8 = ''; + $strlen_chrs = strlen($chrs); + + for ($c = 0; $c < $strlen_chrs; ++$c) { + + $substr_chrs_c_2 = substr($chrs, $c, 2); + $ord_chrs_c = ord($chrs{$c}); + + switch (true) { + case $substr_chrs_c_2 == '\b': + $utf8 .= chr(0x08); + ++$c; + break; + case $substr_chrs_c_2 == '\t': + $utf8 .= chr(0x09); + ++$c; + break; + case $substr_chrs_c_2 == '\n': + $utf8 .= chr(0x0A); + ++$c; + break; + case $substr_chrs_c_2 == '\f': + $utf8 .= chr(0x0C); + ++$c; + break; + case $substr_chrs_c_2 == '\r': + $utf8 .= chr(0x0D); + ++$c; + break; + + case $substr_chrs_c_2 == '\\"': + case $substr_chrs_c_2 == '\\\'': + case $substr_chrs_c_2 == '\\\\': + case $substr_chrs_c_2 == '\\/': + if (($delim == '"' && $substr_chrs_c_2 != '\\\'') || + ($delim == "'" && $substr_chrs_c_2 != '\\"')) { + $utf8 .= $chrs{++$c}; + } + break; + + case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)): + //echo ' matching single escaped unicode character from ' . substr($chrs, $c, 6); + // single, escaped unicode character + $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2))) + . chr(hexdec(substr($chrs, ($c + 4), 2))); + $utf8 .= $this->utf162utf8($utf16); + $c += 5; + break; + + case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): + $utf8 .= $chrs{$c}; + break; + + case ($ord_chrs_c & 0xE0) == 0xC0: + // characters U-00000080 - U-000007FF, mask 110XXXXX + //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 2); + ++$c; + break; + + case ($ord_chrs_c & 0xF0) == 0xE0: + // characters U-00000800 - U-0000FFFF, mask 1110XXXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 3); + $c += 2; + break; + + case ($ord_chrs_c & 0xF8) == 0xF0: + // characters U-00010000 - U-001FFFFF, mask 11110XXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 4); + $c += 3; + break; + + case ($ord_chrs_c & 0xFC) == 0xF8: + // characters U-00200000 - U-03FFFFFF, mask 111110XX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 5); + $c += 4; + break; + + case ($ord_chrs_c & 0xFE) == 0xFC: + // characters U-04000000 - U-7FFFFFFF, mask 1111110X + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $utf8 .= substr($chrs, $c, 6); + $c += 5; + break; + + } + + } + + //>> SJM2005 + if ($this->encoding == SERVICES_JSON_UTF_8) + return $utf8; + if ($this->encoding == SERVICES_JSON_ISO_8859_1) + return utf8_decode($utf8); + else if (!function_exists('mb_convert_encoding')) + die('Requested encoding requires mb_strings extension.'); + else + return mb_convert_encoding($utf8, $this->encoding, SERVICES_JSON_UTF_8); + //<< SJM2005 + + return $utf8; + + } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { + // array, or object notation + if ($str{0} == '[') { + $stk = array(SERVICES_JSON_IN_ARR); + $arr = array(); + } else { + if ($this->use == SERVICES_JSON_LOOSE_TYPE) { + $stk = array(SERVICES_JSON_IN_OBJ); + $obj = array(); + } else { + $stk = array(SERVICES_JSON_IN_OBJ); + $obj = new stdClass(); + } + } + + array_push($stk, array('what' => SERVICES_JSON_SLICE, + 'where' => 0, + 'delim' => false)); + + $chrs = substr($str, 1, -1); + $chrs = $this->reduce_string($chrs); + + if ($chrs == '') { + if (reset($stk) == SERVICES_JSON_IN_ARR) { + return $arr; + + } else { + return $obj; + + } + } + + //print("\nparsing {$chrs}\n"); + + $strlen_chrs = strlen($chrs); + for ($c = 0; $c <= $strlen_chrs; ++$c) { + + $top = end($stk); + $substr_chrs_c_2 = substr($chrs, $c, 2); + + if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { + // found a comma that is not inside a string, array, etc., + // OR we've reached the end of the character list + $slice = substr($chrs, $top['where'], ($c - $top['where'])); + array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false)); + //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); + + if (reset($stk) == SERVICES_JSON_IN_ARR) { + // we are in an array, so just push an element onto the stack + array_push($arr, $this->decode($slice)); + + } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { + // we are in an object, so figure + // out the property name and set an + // element in an associative array, + // for now + if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { + // "name":value pair + $key = $this->decode($parts[1]); + $val = $this->decode($parts[2]); + + if ($this->use == SERVICES_JSON_LOOSE_TYPE) { + $obj[$key] = $val; + } else { + $obj->$key = $val; + } + } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { + // name:value pair, where name is unquoted + $key = $parts[1]; + $val = $this->decode($parts[2]); + + if ($this->use == SERVICES_JSON_LOOSE_TYPE) { + $obj[$key] = $val; + } else { + $obj->$key = $val; + } + } + + } + + } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { + // found a quote, and we are not inside a string + array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); + //print("Found start of string at {$c}\n"); + + //>> SAO2006 + /*} elseif (($chrs{$c} == $top['delim']) && + ($top['what'] == SERVICES_JSON_IN_STR) && + (($chrs{$c - 1} != '\\') || + ($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) {*/ + } elseif ($chrs{$c} == $top['delim'] && + $top['what'] == SERVICES_JSON_IN_STR) { + //print("Found potential end of string at {$c}\n"); + // verify quote is not escaped: it has no or an even number of \\ before it. + for ($i=0; ($chrs{$c - ($i+1)} == '\\'); $i++); + /*$i = 0; + while ( $chrs{$c - ($i+1)} == '\\') + $i++;*/ + //print("Found {$i} \ before delim\n"); + if ($i % 2 != 0) + { + //print("delim escaped, not end of string\n"); + continue; + } + //>> SAO2006 + // found a quote, we're in a string, and it's not escaped + array_pop($stk); + //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); + + } elseif (($chrs{$c} == '[') && + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { + // found a left-bracket, and we are in an array, object, or slice + array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false)); + //print("Found start of array at {$c}\n"); + + } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { + // found a right-bracket, and we're in an array + array_pop($stk); + //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); + + } elseif (($chrs{$c} == '{') && + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { + // found a left-brace, and we are in an array, object, or slice + array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false)); + //print("Found start of object at {$c}\n"); + + } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { + // found a right-brace, and we're in an object + array_pop($stk); + //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); + + } elseif (($substr_chrs_c_2 == '/*') && + in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { + // found a comment start, and we are in an array, object, or slice + array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false)); + $c++; + //print("Found start of comment at {$c}\n"); + + } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) { + // found a comment end, and we're in one now + array_pop($stk); + $c++; + + for ($i = $top['where']; $i <= $c; ++$i) + $chrs = substr_replace($chrs, ' ', $i, 1); + + //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); + + } + + } + + if (reset($stk) == SERVICES_JSON_IN_ARR) { + return $arr; + + } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { + return $obj; + + } + + } + } + } + +} + + /*function hex($s) + { + $l = strlen($s); + for ($i=0; $i < $l; $i++) + //echo '['.(ord($s{$i})).']'; + echo '['.bin2hex($s{$i}).']'; + } + + //$d = '["hello world\\""]'; + $d = '["\\\\\\"hello world,\\\\\\""]'; + //$d = '["\\\\", "\\\\"]'; + hex($d); + $test = new Services_JSON(); + echo('
');
+	print_r($d . "\n");
+	print_r($test->decode($d));
+	echo('
'); + */ +?> \ No newline at end of file diff --git a/includes/js/dojox/grid/tests/support/movies.csv b/includes/js/dojox/grid/tests/support/movies.csv new file mode 100644 index 0000000..baf71eb --- /dev/null +++ b/includes/js/dojox/grid/tests/support/movies.csv @@ -0,0 +1,9 @@ +Title, Year, Producer +City of God, 2002, Katia Lund +Rain,, Christine Jeffs +2001: A Space Odyssey, , Stanley Kubrick +"This is a ""fake"" movie title", 1957, Sidney Lumet +Alien, 1979 , Ridley Scott +"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott +"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward" + diff --git a/includes/js/dojox/grid/tests/support/test_data.js b/includes/js/dojox/grid/tests/support/test_data.js new file mode 100644 index 0000000..4707380 --- /dev/null +++ b/includes/js/dojox/grid/tests/support/test_data.js @@ -0,0 +1,30 @@ +// example sample data and code +(function(){ + // some sample data + // global var "data" + data = [ + [ "normal", false, "new", 'But are not followed by two hexadecimal', 29.91, 10, false ], + [ "important", false, "new", 'Because a % sign always indicates', 9.33, -5, false ], + [ "important", false, "read", 'Signs can be selectively', 19.34, 0, true ], + [ "note", false, "read", 'However the reserved characters', 15.63, 0, true ], + [ "normal", false, "replied", 'It is therefore necessary', 24.22, 5.50, true ], + [ "important", false, "replied", 'To problems of corruption by', 9.12, -3, true ], + [ "note", false, "replied", 'Which would simply be awkward in', 12.15, -4, false ] + ]; + var rows = 100; + for(var i=0, l=data.length; i{text}', {href: inData[0], text: inData[1] }); +}; + +formatImage = function(inData, inRowIndex) { + if (!inData[0] || !inData[1]) + return ' '; + var o = { + href: inData[0], + src: inData[1].Url, + width: inData[1].Width, + height: inData[1].Height + } + return turbo.supplant('', o); +}; + +formatDate = function(inDatum, inRowIndex) { + if (inDatum == '') + return ' '; + var d = new Date(inDatum * 1000); + return turbo.printf('%s/%s/%s', d.getMonth(), d.getDate(), d.getFullYear()); +}; + +formatDimensions = function(inData, inRowIndex) { + if (!inData[0] || !inData[1]) + return ' '; + return inData[0] + ' x ' + inData[1]; +} diff --git a/includes/js/dojox/grid/tests/test_change_structure.html b/includes/js/dojox/grid/tests/test_change_structure.html new file mode 100644 index 0000000..4ecfa71 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_change_structure.html @@ -0,0 +1,124 @@ + + + + dojox.Grid Change Structure Example + + + + + + + +
dojox.VirtualGrid Change Structure Example
+

+ +

+
+ + + diff --git a/includes/js/dojox/grid/tests/test_custom_sort.html b/includes/js/dojox/grid/tests/test_custom_sort.html new file mode 100644 index 0000000..51b0cf3 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_custom_sort.html @@ -0,0 +1,86 @@ + + + + Custom Sort Test - dojox.Grid + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.Grid Custom Sort Test
+
+Column 3's data field has a custom sorter that sorts by the 2nd letter in the string. +

+
+ + diff --git a/includes/js/dojox/grid/tests/test_dojo_data_edit.html b/includes/js/dojox/grid/tests/test_dojo_data_edit.html new file mode 100644 index 0000000..7c9bc5c --- /dev/null +++ b/includes/js/dojox/grid/tests/test_dojo_data_edit.html @@ -0,0 +1,124 @@ + + + + Test dojox.Grid Editing with DojoData model + + + + + + + + +

+ dojox.Grid Basic Editing test +

+
+     +     +     + +     + +     + + +     + +     +   +
+ + + + +
+
+ + +
+
+ + + + + diff --git a/includes/js/dojox/grid/tests/test_dojo_data_empty.html b/includes/js/dojox/grid/tests/test_dojo_data_empty.html new file mode 100644 index 0000000..3096491 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_dojo_data_empty.html @@ -0,0 +1,63 @@ + + + +dojox.Grid with Dojo.Data via binding + + + + + + + +
dojox.Grid using initially-empty Dojo.Data write stores and then adding an item. Item should show up correctly (no "?"s) when added.
+
+ + +
+
+ + + \ No newline at end of file diff --git a/includes/js/dojox/grid/tests/test_dojo_data_model.html b/includes/js/dojox/grid/tests/test_dojo_data_model.html new file mode 100644 index 0000000..fb8e200 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_dojo_data_model.html @@ -0,0 +1,84 @@ + + + + dojox.Grid with Dojo.Data via binding + + + + + + + +
dojox.Grid using Dojo.Data stores via simple binding
+ + + + +
+
+ + + + + +
+
+ + diff --git a/includes/js/dojox/grid/tests/test_dojo_data_model_EmptyResultSet.html b/includes/js/dojox/grid/tests/test_dojo_data_model_EmptyResultSet.html new file mode 100644 index 0000000..8a9048a --- /dev/null +++ b/includes/js/dojox/grid/tests/test_dojo_data_model_EmptyResultSet.html @@ -0,0 +1,57 @@ + + + + dojox.Grid with Dojo.Data via binding + + + + + + + +
dojox.Grid using Dojo.Data stores where a query returns no results. No errors should be reported in Firebug and the grid should be empty
+
+ + + + +
+
+ + diff --git a/includes/js/dojox/grid/tests/test_dojo_data_model_multiStores.html b/includes/js/dojox/grid/tests/test_dojo_data_model_multiStores.html new file mode 100644 index 0000000..46554e3 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_dojo_data_model_multiStores.html @@ -0,0 +1,291 @@ + + + + dojox.Grid with Dojo.Data via binding. Multiple Store implementations. + + + + + + + + +

dojox.Grid using Dojo.Data stores via simple binding with multiple store implementations.

+

+ This page demonstrates the Grid can display data accessed by dojo.data implementing Datastores. + Each of the datastores used stores data in a different format, and as this test and demonstration + page shows, the logic for rendering the data is virtually identical. You define your source store, + you define the model for accessing the data, which is ij this case the dojox.grid.data.DojoData model + and then you define the layout, which maps the data attribute names to columns in the grid. You can + even perform cusomization of what is displayed, as demonstrated in the dojox.data.FlickrStore layout. + The image url is displayed as a clickable link that opens a new page. +

+

+ The choice of stores used were ones that did not require back end services to function for sake of + simplicity. There is no reason that dojox.data.QueryReadStore could not be used with grid as well, + it just requires a back end service to send it the query results. +

+

Stores used:

+
    +
  • dojo.data.ItemFileReadStore
  • +
  • dojox.data.CvsStore
  • +
  • dojox.data.XmlStore
  • +
  • dojox.data.FlickrStore
  • +
  • dojox.data.OpmlStore
  • +
  • dojox.data.HtmlTableStore
  • +
+ +

dojo.data.ItemFileReadStore:

+ Displays a list of countries through ItemFileReadStore format. + + + + +
+
+ + +

dojox.data.CsvStore:

+ Displays a list of movies that were stored in CSV format. + + + + +
+ +
+ +

dojox.data.XmlStore:

+ Displays a list of books that were stored in XML format. + + + + +
+
+ + +

dojox.data.FlickrStore:

+ Displays Flickr imformation on 3DNY (Dojo Developer Days, New York) from the flickr public photo feed, accessed via the FlickrStore dojo.data implementation. + + + + +
+
+ + +

dojox.data.OpmlStore:

+ Scans an Opml based document for all items of type 'country' + + + + +
+
+ + +

dojox.data.HtmlStore:

+ Loads the grid from an HTML Table. + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/includes/js/dojox/grid/tests/test_dojo_data_model_processError.html b/includes/js/dojox/grid/tests/test_dojo_data_model_processError.html new file mode 100644 index 0000000..4130043 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_dojo_data_model_processError.html @@ -0,0 +1,65 @@ + + + + dojox.Grid with Dojo.Data model with trapping of data store errors. + + + + + + + + +

dojox.Grid using Dojo.Data stores via simple binding

+ +

dojox.data.CsvStore:

. + This grid does not load data. The data store references a non-existent URL on purpose. It should trigger a failure that we catch and display in an alert + + + + + + +
+
+ + + + diff --git a/includes/js/dojox/grid/tests/test_dojo_data_notification.html b/includes/js/dojox/grid/tests/test_dojo_data_notification.html new file mode 100644 index 0000000..f44c987 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_dojo_data_notification.html @@ -0,0 +1,114 @@ + + + + dojox.Grid with Dojo.Data via binding + + + + + + + +

dojox.Grid using Dojo.Data stores via simple binding

+ +
+

Update some of the types

+ + + + + + + +
+
+ +
+
+ + diff --git a/includes/js/dojox/grid/tests/test_edit.html b/includes/js/dojox/grid/tests/test_edit.html new file mode 100644 index 0000000..7ae1fdb --- /dev/null +++ b/includes/js/dojox/grid/tests/test_edit.html @@ -0,0 +1,149 @@ + + + + +Test dojox.Grid Editing + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ dojox.Grid Basic Editing test +

+
+     + +     + +     + +     +   +
+
+
+
+
+ + diff --git a/includes/js/dojox/grid/tests/test_edit_canEdit.html b/includes/js/dojox/grid/tests/test_edit_canEdit.html new file mode 100644 index 0000000..ed4e919 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_edit_canEdit.html @@ -0,0 +1,156 @@ + + + + +Test dojox.Grid Editing + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ dojox.Grid Basic Editing test +

+
+     + +     + +     + +     +   +
+
+
+
+
+ + diff --git a/includes/js/dojox/grid/tests/test_edit_dijit.html b/includes/js/dojox/grid/tests/test_edit_dijit.html new file mode 100644 index 0000000..484c7e5 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_edit_dijit.html @@ -0,0 +1,137 @@ + + + + + Test dojox.Grid Editing + + + + + + +

dojox.Grid Basic Editing test

+
+
+ + + + + + + + +
+
+
+
+
+ + diff --git a/includes/js/dojox/grid/tests/test_events.html b/includes/js/dojox/grid/tests/test_events.html new file mode 100644 index 0000000..8ea61a4 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_events.html @@ -0,0 +1,174 @@ + + + + Test dojox.Grid Events + + + + + + + +

dojox.Grid Event Tracking

+
+
+ + diff --git a/includes/js/dojox/grid/tests/test_expand.html b/includes/js/dojox/grid/tests/test_expand.html new file mode 100644 index 0000000..220c2a8 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_expand.html @@ -0,0 +1,107 @@ + + + + Test dojox.Grid Expand Rows + + + + + + + +
dojox.Grid Expand Row Example
+ +
+ + + diff --git a/includes/js/dojox/grid/tests/test_grid.html b/includes/js/dojox/grid/tests/test_grid.html new file mode 100644 index 0000000..59d18dc --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid.html @@ -0,0 +1,69 @@ + + + + Test dojox.Grid Basic + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.Grid Basic Test
+
+ + diff --git a/includes/js/dojox/grid/tests/test_grid_dlg.html b/includes/js/dojox/grid/tests/test_grid_dlg.html new file mode 100644 index 0000000..7479e15 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_dlg.html @@ -0,0 +1,88 @@ + + + + Test dojox.Grid Basic + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.Grid Basic Test
+ +
+ + + +
+
+ + + diff --git a/includes/js/dojox/grid/tests/test_grid_headerHeight.html b/includes/js/dojox/grid/tests/test_grid_headerHeight.html new file mode 100644 index 0000000..b9960c4 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_headerHeight.html @@ -0,0 +1,84 @@ + + + + Test dojox.Grid Basic + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.Grid Basic Test
+
+

+
+ + diff --git a/includes/js/dojox/grid/tests/test_grid_layout.html b/includes/js/dojox/grid/tests/test_grid_layout.html new file mode 100644 index 0000000..148025d --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_layout.html @@ -0,0 +1,112 @@ + + + + dojox.Grid in Layout Demo + + + + + + + + + + +
+
+ top bar +
+
+ bottom bar +
+
+
+ Left side +
+ +
+
+
+
+
+
+
+
+
+
+
+ + diff --git a/includes/js/dojox/grid/tests/test_grid_layout_LayoutContainer.html b/includes/js/dojox/grid/tests/test_grid_layout_LayoutContainer.html new file mode 100644 index 0000000..4cf12ac --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_layout_LayoutContainer.html @@ -0,0 +1,87 @@ + + + + dojox.Grid in Layout Demo + + + + + + + + + + +
+ +
+ top bar +
+
+ bottom bar +
+ +
+ + +
+ + diff --git a/includes/js/dojox/grid/tests/test_grid_layout_borderContainer.html b/includes/js/dojox/grid/tests/test_grid_layout_borderContainer.html new file mode 100644 index 0000000..8f0d8d7 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_layout_borderContainer.html @@ -0,0 +1,98 @@ + + + + Test dojox.Grid Editing + + + + + + + + +
+ +
+ +
+ + + + + + + + +
+
+ +
+
+
+ +
+ + + diff --git a/includes/js/dojox/grid/tests/test_grid_object_model_change.html b/includes/js/dojox/grid/tests/test_grid_object_model_change.html new file mode 100644 index 0000000..54c6808 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_object_model_change.html @@ -0,0 +1,86 @@ + + + + Test dojox.grid.data.Objects model change + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.grid.data.Objects model change
+
+
+ + diff --git a/includes/js/dojox/grid/tests/test_grid_programmatic.html b/includes/js/dojox/grid/tests/test_grid_programmatic.html new file mode 100644 index 0000000..fe0794f --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_programmatic.html @@ -0,0 +1,65 @@ + + + + Test dojox.Grid Programmatic Instantiation + + + + + + + + +
dojox.Grid Programmatic Instantiation Test
+
+ + diff --git a/includes/js/dojox/grid/tests/test_grid_programmatic_layout.html b/includes/js/dojox/grid/tests/test_grid_programmatic_layout.html new file mode 100644 index 0000000..b55d975 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_programmatic_layout.html @@ -0,0 +1,74 @@ + + + + Test dojox.Grid Programmatic Instantiation + + + + + + + + +
dojox.Grid Programmatic Instantiation Test
+
+
+ ... stuff ... +
+
+ + diff --git a/includes/js/dojox/grid/tests/test_grid_rtl.html b/includes/js/dojox/grid/tests/test_grid_rtl.html new file mode 100644 index 0000000..c1b253d --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_rtl.html @@ -0,0 +1,71 @@ + + + + Test dojox.Grid Basic + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.Grid Basic Test
+
+ + diff --git a/includes/js/dojox/grid/tests/test_grid_themes.html b/includes/js/dojox/grid/tests/test_grid_themes.html new file mode 100644 index 0000000..e0f80f6 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_themes.html @@ -0,0 +1,118 @@ + + + + dojox.Grid themes + + + + + + + +
dojox.grid.Grid structure from markup (tundra theme)
+ + + + + + + + + + + + + + +
Title of MovieYear
Producer
+ + + +
Locked views specified with tables and colgroups (soria theme)
+ + + + + + + + + + + + + + + +
Country/Continent NamePopulationLand MassTime ZoneType
+ +
A "regular" Grid from markup (no table defintion, nihilo theme)
+ + + + +
+
+ + + diff --git a/includes/js/dojox/grid/tests/test_grid_tooltip_menu.html b/includes/js/dojox/grid/tests/test_grid_tooltip_menu.html new file mode 100644 index 0000000..52c7726 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_grid_tooltip_menu.html @@ -0,0 +1,161 @@ + + + + Test dojox.Grid Basic + + + + + + + + + + + +
dojox.Grid Basic Test
+

+    +   
+ Note: when the grid menu is disabled, the document's dijit context menu should be shown over the grid. +

+
+ + diff --git a/includes/js/dojox/grid/tests/test_keyboard.html b/includes/js/dojox/grid/tests/test_keyboard.html new file mode 100644 index 0000000..69d4046 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_keyboard.html @@ -0,0 +1,90 @@ + + + + Test dojox.Grid Basic + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.Grid Basic Test
+
+ + diff --git a/includes/js/dojox/grid/tests/test_markup.html b/includes/js/dojox/grid/tests/test_markup.html new file mode 100644 index 0000000..7c57710 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_markup.html @@ -0,0 +1,112 @@ + + + + dojox.Grid with Dojo.Data via binding + + + + + + +
dojox.grid.Grid structure from markup
+ + + + + + + + + + + + + +
Title of MovieYear
Producer
+ + + + +
Locked views specified with tables and colgroups
+ + + + + + + + + + + + + +
Country/Continent NamePopulationLand MassTime ZoneType
+ +
A "regular" Grid from markup (no table defintion)
+ + + +
+
+ + + diff --git a/includes/js/dojox/grid/tests/test_mysql_edit.html b/includes/js/dojox/grid/tests/test_mysql_edit.html new file mode 100644 index 0000000..dd6a762 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_mysql_edit.html @@ -0,0 +1,155 @@ + + + + dojox.Grid Test: Mysql Table Editing + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

dojox.Grid Test: Mysql Table Editing

+
+    +    +    +    + +

+
+
+

Note: This test requires MySql and PHP and works with the database table available in support/testtbl.sql.

+ + diff --git a/includes/js/dojox/grid/tests/test_sizing.html b/includes/js/dojox/grid/tests/test_sizing.html new file mode 100644 index 0000000..fdd0897 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_sizing.html @@ -0,0 +1,175 @@ + + + + dojox.Grid Sizing Example + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.Grid Sizing Test
+ Grid width:   + and height:   +

+   +   + +

+
+ +

Grid fits to a sized container by default:

+
+
+
+ +

Grid is essentially hidden (height of zero) when parent container is unsized + (nothing, including the header, should be displayed):

+
+
+
+ +

Grid is autoHeight and autoWidth via markup

+
+ + diff --git a/includes/js/dojox/grid/tests/test_sizing_100rows.html b/includes/js/dojox/grid/tests/test_sizing_100rows.html new file mode 100644 index 0000000..4ea1aa3 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_sizing_100rows.html @@ -0,0 +1,168 @@ + + + + dojox.Grid Sizing Example + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
dojox.Grid Sizing Test
+ Grid width:   + and height:   +

+   +   + +

+
+ +

Grid fits to a sized container by default:

+
+
+
+ +

Grid is essentially hidden (height of zero) when parent container is unsized + (nothing, including the header, should be displayed):

+
+
+
+ +

Grid is autoHeight and autoWidth via markup

+
+ + diff --git a/includes/js/dojox/grid/tests/test_sizing_ResizeHandle.html b/includes/js/dojox/grid/tests/test_sizing_ResizeHandle.html new file mode 100644 index 0000000..d6809df --- /dev/null +++ b/includes/js/dojox/grid/tests/test_sizing_ResizeHandle.html @@ -0,0 +1,113 @@ + + + + dojox.Grid Sizing Example + + + + + + + + +
dojox.Grid Sizing Test w/ the experimental dojox.layout.ResizeHandle
+ +

While this test should work, dojox.layout.ResizeHandle is experimental.

+ +
+
+
+
+ +

Grid fits to a sized container by default:

+
+
+
+
+ +

I am here to take up

+ +

space

+ +

as much as needed.

+ + + diff --git a/includes/js/dojox/grid/tests/test_styling.html b/includes/js/dojox/grid/tests/test_styling.html new file mode 100644 index 0000000..5671f50 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_styling.html @@ -0,0 +1,131 @@ + + + + dojox.Grid Styling Test + + + + + + + + +
dojox.Grid Styling Example
+
+ + diff --git a/includes/js/dojox/grid/tests/test_subgrid.html b/includes/js/dojox/grid/tests/test_subgrid.html new file mode 100644 index 0000000..4e5b8cd --- /dev/null +++ b/includes/js/dojox/grid/tests/test_subgrid.html @@ -0,0 +1,179 @@ + + + +dojox.Grid Subgrid Test + + + + + + + + + +
dojox.Grid showing sub-grid.
+
+ + diff --git a/includes/js/dojox/grid/tests/test_tundra_edit.html b/includes/js/dojox/grid/tests/test_tundra_edit.html new file mode 100644 index 0000000..0aa2eeb --- /dev/null +++ b/includes/js/dojox/grid/tests/test_tundra_edit.html @@ -0,0 +1,139 @@ + + + + Test dojox.Grid Editing + + + + + + +

dojox.Grid Basic Editing test

+
+
+ + + + + + + + +
+
+
+
+
+ + diff --git a/includes/js/dojox/grid/tests/test_yahoo_images.html b/includes/js/dojox/grid/tests/test_yahoo_images.html new file mode 100644 index 0000000..fbab070 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_yahoo_images.html @@ -0,0 +1,148 @@ + + + + dojox.Grid - Image Search Test + + + + + + + + +
dojox.Grid - Image Search Test
+ + +
+
+
+
+
+
+
+
+
+

+

Note: requires PHP for proxy.

+ + diff --git a/includes/js/dojox/grid/tests/test_yahoo_search.html b/includes/js/dojox/grid/tests/test_yahoo_search.html new file mode 100644 index 0000000..063c289 --- /dev/null +++ b/includes/js/dojox/grid/tests/test_yahoo_search.html @@ -0,0 +1,141 @@ + + + + dojox.Grid - Yahoo Search Test + + + + + + + + +
dojox.Grid - Yahoo Search Test
+
+    + +
+   +

+
+
+
+
+
+
+
+
+
+

+

Note: requires PHP for proxy.

+ + diff --git a/includes/js/dojox/grid/tests/yahooSearch.js b/includes/js/dojox/grid/tests/yahooSearch.js new file mode 100644 index 0000000..1d57a8e --- /dev/null +++ b/includes/js/dojox/grid/tests/yahooSearch.js @@ -0,0 +1,137 @@ +dojo.require("dojo.io.script") +dojo.require("dojox.rpc.Service"); + +// model that works with Yahoo Search API +dojo.declare("dojox.grid.data.yahooSearch", dojox.grid.data.Dynamic, { + constructor: function(inFields, inData, inSearchNode){ + this.rowsPerPage = 20; + this.searchNode = inSearchNode; + this.fieldNames = dojo.map(inFields, "return item.name;"); + this.yahoo = new dojox.rpc.Service( + dojo.moduleUrl("dojox.rpc.SMDLibrary", "yahoo.smd") + ); + }, + // server send / receive + send: function(inAsync, inParams, inOnReceive, inOnError){ + var d = this.yahoo.imageSearch( + dojo.mixin({ + results: this.rowsPerPage, + query: this.getQuery() + }, inParams) + ); + d.addCallbacks( + dojo.hitch(this, "receive", inOnReceive, inOnError), + dojo.hitch(this, "error", inOnError) + ); + this.onSend(inParams); + return d; + }, + receive: function(inOnReceive, inOnError, inData){ + try{ + inData = inData.ResultSet; + inOnReceive(inData); + this.onReceive(inData); + }catch(e){ + if(inOnError){ + inOnError(inData); + } + } + }, + error: function(inOnError, inErr) { + var m = 'io error: ' + inErr.message; + alert(m); + if (inOnError) + inOnError(m); + }, + encodeParam: function(inName, inValue) { + return dojo.string.substitute('&${0}=${1}', [inName, inValue]); + }, + getQuery: function(){ + return dojo.byId(this.searchNode).value.replace(/ /g, '+'); + }, + fetchRowCount: function(inCallback){ + this.send(true, inCallback); + }, + // request data + requestRows: function(inRowIndex, inCount){ + inRowIndex = (inRowIndex == undefined ? 0 : inRowIndex); + var params = { + start: inRowIndex + 1 + } + this.send(true, params, dojo.hitch(this, this.processRows)); + }, + // server callbacks + processRows: function(inData){ + for(var i=0, l=inData.totalResultsReturned, s=inData.firstResultPosition; i${text}', + { href: inData, text: text } + ); +}; + +formatImage = function(inData, inRowIndex){ + if(!inData){ return ' '; } + var info = getCellData(this, inRowIndex, this.extraField); + var o = { + href: inData, + src: info.Url, + width: info.Width, + height: info.Height + } + return dojo.string.substitute( + '', o); +}; + +formatDate = function(inDatum, inRowIndex){ + if(!inDatum){ return ' '; } + var d = new Date(inDatum * 1000); + return dojo.string.substitute( + "${0}/${1}/${2}", + [ d.getMonth()+1, d.getDate(), d.getFullYear() ] + ); +}; + +formatDimensions = function(inData, inRowIndex){ + if(!inData){ return ' '; } + var w = inData, h = getCellData(this, inRowIndex, this.extraField); + return w + ' x ' + h; +} -- cgit v1.2.3-54-g00ecf