diff options
author | 2008-11-13 09:49:11 +0000 | |
---|---|---|
committer | 2008-11-13 09:49:11 +0000 | |
commit | e44a7e37b6c7b5961adaffc62b9042b8d442938e (patch) | |
tree | 95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojox/grid/tests/support/yahoo_search.js | |
parent | a62b9742ee5e28bcec6872d88f50f25b820914f6 (diff) | |
download | scuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz scuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.zip |
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
Diffstat (limited to 'includes/js/dojox/grid/tests/support/yahoo_search.js')
-rw-r--r-- | includes/js/dojox/grid/tests/support/yahoo_search.js | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/includes/js/dojox/grid/tests/support/yahoo_search.js b/includes/js/dojox/grid/tests/support/yahoo_search.js new file mode 100644 index 0000000..a013b5d --- /dev/null +++ b/includes/js/dojox/grid/tests/support/yahoo_search.js @@ -0,0 +1,131 @@ +// model that works with Yahoo Search API +dojo.declare("dojox.grid.data.yahooSearch", dojox.grid.data.dynamic, + function(inFields, inData) { + this.rowsPerPage = 20; + this.fieldNames = []; + for (var i=0, f; (f=inFields[i]); i++) + this.fieldNames.push(f.name); + }, { + clearData: function() { + turbo.widgets.TurboGrid.data.dynamic.prototype.clearData.apply(this, arguments); + }, + // server send / receive + encodeParam: function(inName, inValue) { + return turbo.printf('&%s=%s', inName, inValue); + }, + getParams: function(inParams) { + var url = this.url; + url += '?appid=turboajax'; + inParams = inParams || {}; + inParams.output = 'json'; + inParams.results = this.rowsPerPage; + inParams.query = turbo.$('searchInput').value.replace(/ /g, '+'); + for (var i in inParams) + if (inParams[i] != undefined) + url += this.encodeParam(i, inParams[i]); + return url; + }, + send: function(inAsync, inParams, inOnReceive, inOnError) { + var p = this.getParams(inParams); + dojo.io.bind({ + url: "support/proxy.php", + method: "post", + content: {url: p }, + contentType: "application/x-www-form-urlencoded; charset=utf-8", + mimetype: 'text/json', + sync: !inAsync, + load: turbo.bindArgs(this, "receive", inOnReceive, inOnError), + error: turbo.bindArgs(this, "error", inOnError) + }); + this.onSend(inParams); + }, + receive: function(inOnReceive, inOnError, inEvt, inData) { + try { + inData = inData.ResultSet; + inOnReceive(inData); + this.onReceive(inData); + } catch(e) { + if (inOnError) + inOnError(inData); + } + }, + error: function(inOnError, inTyp, inErr) { + var m = 'io error: ' + inErr.message; + alert(m); + if (inOnError) + inOnError(m); + }, + 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, turbo.bindArgs(this, this.processRows)); + }, + // server callbacks + processRows: function(inData) { + for (var i=0, l=inData.totalResultsReturned, s=inData.firstResultPosition; i<l; i++) { + this.setRow(inData.Result[i], s - 1 + i); + } + // yahoo says 1000 is max results to return + var c = Math.min(1000, inData.totalResultsAvailable); + if (this.count != c) { + this.setRowCount(c); + this.allChange(); + this.onInitializeData(inData); + } + }, + getDatum: function(inRowIndex, inColIndex) { + var row = this.getRow(inRowIndex); + var field = this.fields.get(inColIndex); + return (inColIndex == undefined ? row : (row ? row[field.name] : field.na)); + }, + // events + onInitializeData: turbo.nop, + onSend: turbo.nop, + onReceive: turbo.nop +}); + +// report +modelChange = function() { + var n = turbo.$('rowCount'); + if (n) + n.innerHTML = turbo.printf('about %s row(s)', model.count); +} + + +// some data formatters +formatLink = function(inData, inRowIndex) { + if (!inData[0] || !inData[1]) + return ' '; + return turbo.supplant('<a target="_blank" href="{href}">{text}</a>', {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('<a href="{href}" target="_blank"><img border=0 src="{src}" width="{width}" height="{height}"></a>', 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]; +} |