123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- if(!dojo._hasResource["dojox.data.SnapLogicStore"]){
- dojo._hasResource["dojox.data.SnapLogicStore"] = true;
- dojo.provide("dojox.data.SnapLogicStore");
- dojo.require("dojo.io.script");
- dojo.require("dojo.data.util.sorter");
- dojo.declare("dojox.data.SnapLogicStore", null, {
- Parts: {
- DATA: "data",
- COUNT: "count"
- },
- url: "",
- constructor: function(/* Object */args){
-
-
-
-
-
-
-
-
-
-
-
-
- if(args.url){
- this.url = args.url;
- }
- this._parameters = args.parameters;
- },
- _assertIsItem: function(/* item */item){
-
-
-
-
- if(!this.isItem(item)){
- throw new Error("dojox.data.SnapLogicStore: a function was passed an item argument that was not an item");
- }
- },
- _assertIsAttribute: function(/* attribute-name-string */ attribute){
-
-
-
-
- if(typeof attribute !== "string"){
- throw new Error("dojox.data.SnapLogicStore: a function was passed an attribute argument that was not an attribute name string");
- }
- },
- getFeatures: function(){
-
-
- return {
- 'dojo.data.api.Read': true
- };
- },
- getValue: function(item, attribute, defaultValue){
-
-
- this._assertIsItem(item);
- this._assertIsAttribute(attribute);
- var i = dojo.indexOf(item.attributes, attribute);
- if(i !== -1){
- return item.values[i];
- }
- return defaultValue;
- },
- getAttributes: function(item){
-
-
- this._assertIsItem(item);
- return item.attributes;
- },
- hasAttribute: function(item, attribute){
-
-
- this._assertIsItem(item);
- this._assertIsAttribute(attribute);
- for(var i = 0; i < item.attributes.length; ++i){
- if(attribute == item.attributes[i]){
- return true;
- }
- }
- return false;
- },
- isItemLoaded: function(item){
-
-
- return this.isItem(item);
- },
- loadItem: function(keywordArgs){
-
-
- },
- getLabel: function(item){
-
-
- return undefined;
- },
-
- getLabelAttributes: function(item){
-
-
- return null;
- },
- containsValue: function(item, attribute, value){
-
-
- return this.getValue(item, attribute) === value;
- },
- getValues: function(item, attribute){
-
-
- this._assertIsItem(item);
- this._assertIsAttribute(attribute);
- var i = dojo.indexOf(item.attributes, attribute);
- if(i !== -1){
- return [item.values[i]];
- }
- return [];
- },
- isItem: function(item){
-
-
- if(item && item._store === this){
- return true;
- }
- return false;
- },
-
- close: function(request){
-
-
- },
- _fetchHandler: function(/* Object */request){
-
-
-
-
-
-
-
- var scope = request.scope || dojo.global;
- if(request.onBegin){
-
- request.onBegin.call(scope, request._countResponse[0], request);
- }
-
- if(request.onItem || request.onComplete){
- var response = request._dataResponse;
- if(!response.length){
- request.onError.call(scope,
- new Error("dojox.data.SnapLogicStore: invalid response of length 0"),
- request);
- return;
- }else if(request.query != 'record count'){
-
-
- var field_names = response.shift();
-
- var items = [];
- for(var i = 0; i < response.length; ++i){
- if(request._aborted){
- break;
- }
- items.push({attributes: field_names, values: response[i], _store: this});
- }
- if(request.sort && !request._aborted){
- items.sort(dojo.data.util.sorter.createSortFunction(request.sort, self));
- }
- }else{
-
- items = [({attributes: ['count'], values: response, _store: this})];
- }
- if(request.onItem){
- for(var i = 0; i < items.length; ++i){
- if(request._aborted){
- break;
- }
- request.onItem.call(scope, items[i], request);
- }
- items = null;
- }
- if(request.onComplete && !request._aborted){
- request.onComplete.call(scope, items, request);
- }
- }
- },
-
- _partHandler: function(/* Object */request, /* String */part, /* Object */response){
-
-
-
-
-
-
-
-
- if(response instanceof Error){
- if(part == this.Parts.DATA){
- request._dataHandle = null;
- }else{
- request._countHandle = null;
- }
- request._aborted = true;
- if(request.onError){
- request.onError.call(request.scope, response, request);
- }
- }else{
- if(request._aborted){
- return;
- }
- if(part == this.Parts.DATA){
- request._dataResponse = response;
- }else{
- request._countResponse = response;
- }
- if((!request._dataHandle || request._dataResponse !== null) &&
- (!request._countHandle || request._countResponse !== null)){
- this._fetchHandler(request);
- }
- }
- },
- fetch: function(/* Object */request){
-
-
-
-
-
-
-
-
- request._countResponse = null;
- request._dataResponse = null;
- request._aborted = false;
- request.abort = function(){
- if(!request._aborted){
- request._aborted = true;
- if(request._dataHandle && request._dataHandle.cancel){
- request._dataHandle.cancel();
- }
- if(request._countHandle && request._countHandle.cancel){
- request._countHandle.cancel();
- }
- }
- };
-
-
- if(request.onItem || request.onComplete){
- var content = this._parameters || {};
- if(request.start){
- if(request.start < 0){
- throw new Error("dojox.data.SnapLogicStore: request start value must be 0 or greater");
- }
- content['sn.start'] = request.start + 1;
- }
- if(request.count){
- if(request.count < 0){
- throw new Error("dojox.data.SnapLogicStore: request count value 0 or greater");
- }
- content['sn.limit'] = request.count;
- }
-
- content['sn.content_type'] = 'application/javascript';
- var store = this;
- var handler = function(response, ioArgs){
- if(response instanceof Error){
- store._fetchHandler(response, request);
- }
- };
- var getArgs = {
- url: this.url,
- content: content,
-
- timeout: 60000,
- callbackParamName: "sn.stream_header",
- handle: dojo.hitch(this, "_partHandler", request, this.Parts.DATA)
- };
- request._dataHandle = dojo.io.script.get(getArgs);
- }
-
- if(request.onBegin){
- var content = {};
- content['sn.count'] = 'records';
- content['sn.content_type'] = 'application/javascript';
- var getArgs = {
- url: this.url,
- content: content,
- timeout: 60000,
- callbackParamName: "sn.stream_header",
- handle: dojo.hitch(this, "_partHandler", request, this.Parts.COUNT)
- };
- request._countHandle = dojo.io.script.get(getArgs);
- }
-
- return request;
- }
- });
- }
|