]> git.wh0rd.org - tt-rss.git/blobdiff - lib/dojo/store/JsonRest.js
upgrade dojo to 1.8.3 (refs #570)
[tt-rss.git] / lib / dojo / store / JsonRest.js
index 5f9254c3ea599d888c3ceb811f6eeaa49dad22f7..7048e2c71b41b530370dbcfa780ffc20edc024d9 100644 (file)
@@ -1,146 +1,8 @@
 /*
-       Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+       Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
        Available via Academic Free License >= 2.1 OR the modified BSD license.
        see: http://dojotoolkit.org/license for details
 */
 
-
-if(!dojo._hasResource["dojo.store.JsonRest"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
-dojo._hasResource["dojo.store.JsonRest"] = true;
-dojo.provide("dojo.store.JsonRest");
-dojo.require("dojo.store.util.QueryResults");
-
-
-dojo.declare("dojo.store.JsonRest", null, {
-       constructor: function(/*dojo.store.JsonRest*/ options){
-               // summary:
-               //              This is a basic store for RESTful communicating with a server through JSON
-               //              formatted data.
-               // options:
-               //              This provides any configuration information that will be mixed into the store
-               dojo.mixin(this, options);
-       },
-       // target: String
-       //              The target base URL to use for all requests to the server. This string will be
-       //      prepended to the id to generate the URL (relative or absolute) for requests
-       //      sent to the server
-       target: "",
-       // idProperty: String
-       //              Indicates the property to use as the identity property. The values of this
-       //              property should be unique.
-       idProperty: "id",
-
-       get: function(id, options){
-               //      summary:
-               //              Retrieves an object by its identity. This will trigger a GET request to the server using
-               //              the url `this.target + id`.
-               //      id: Number
-               //              The identity to use to lookup the object
-               //      returns: Object
-               //              The object in the store that matches the given id.
-               var headers = options || {};
-               headers.Accept = "application/javascript, application/json";
-               return dojo.xhrGet({
-                       url:this.target + id,
-                       handleAs: "json",
-                       headers: headers
-               });
-       },
-       getIdentity: function(object){
-               // summary:
-               //              Returns an object's identity
-               // object: Object
-               //              The object to get the identity from
-               //      returns: Number
-               return object[this.idProperty];
-       },
-       put: function(object, options){
-               // summary:
-               //              Stores an object. This will trigger a PUT request to the server
-               //              if the object has an id, otherwise it will trigger a POST request.
-               // object: Object
-               //              The object to store.
-               // options: dojo.store.api.Store.PutDirectives?
-               //              Additional metadata for storing the data.  Includes an "id"
-               //              property if a specific id is to be used.
-               //      returns: Number
-               options = options || {};
-               var id = ("id" in options) ? options.id : this.getIdentity(object);
-               var hasId = typeof id != "undefined";
-               return dojo.xhr(hasId && !options.incremental ? "PUT" : "POST", {
-                               url: hasId ? this.target + id : this.target,
-                               postData: dojo.toJson(object),
-                               handleAs: "json",
-                               headers:{
-                                       "Content-Type": "application/json",
-                                       "If-Match": options.overwrite === true ? "*" : null,
-                                       "If-None-Match": options.overwrite === false ? "*" : null
-                               }
-                       });
-       },
-       add: function(object, options){
-               // summary:
-               //              Adds an object. This will trigger a PUT request to the server
-               //              if the object has an id, otherwise it will trigger a POST request.
-               // object: Object
-               //              The object to store.
-               // options: dojo.store.api.Store.PutDirectives?
-               //              Additional metadata for storing the data.  Includes an "id"
-               //              property if a specific id is to be used.
-               options = options || {};
-               options.overwrite = false;
-               return this.put(object, options);
-       },
-       remove: function(id){
-               // summary:
-               //              Deletes an object by its identity. This will trigger a DELETE request to the server.
-               // id: Number
-               //              The identity to use to delete the object
-               return dojo.xhrDelete({
-                       url:this.target + id
-               });
-       },
-       query: function(query, options){
-               // summary:
-               //              Queries the store for objects. This will trigger a GET request to the server, with the
-               //              query added as a query string.
-               // query: Object
-               //              The query to use for retrieving objects from the store.
-               // options: dojo.store.api.Store.QueryOptions?
-               //              The optional arguments to apply to the resultset.
-               //      returns: dojo.store.api.Store.QueryResults
-               //              The results of the query, extended with iterative methods.
-               var headers = {Accept: "application/javascript, application/json"};
-               options = options || {};
-
-               if(options.start >= 0 || options.count >= 0){
-                       headers.Range = "items=" + (options.start || '0') + '-' +
-                               (("count" in options && options.count != Infinity) ?
-                                       (options.count + (options.start || 0) - 1) : '');
-               }
-               if(dojo.isObject(query)){
-                       query = dojo.objectToQuery(query);
-                       query = query ? "?" + query: "";
-               }
-               if(options && options.sort){
-                       query += (query ? "&" : "?") + "sort(";
-                       for(var i = 0; i<options.sort.length; i++){
-                               var sort = options.sort[i];
-                               query += (i > 0 ? "," : "") + (sort.descending ? '-' : '+') + encodeURIComponent(sort.attribute);
-                       }
-                       query += ")";
-               }
-               var results = dojo.xhrGet({
-                       url: this.target + (query || ""),
-                       handleAs: "json",
-                       headers: headers
-               });
-               results.total = results.then(function(){
-                       var range = results.ioArgs.xhr.getResponseHeader("Content-Range");
-                       return range && (range=range.match(/\/(.*)/)) && +range[1];
-               });
-               return dojo.store.util.QueryResults(results);
-       }
-});
-
-}
+//>>built
+define("dojo/store/JsonRest",["../_base/xhr","../_base/lang","../json","../_base/declare","./util/QueryResults"],function(_1,_2,_3,_4,_5){var _6=null;return _4("dojo.store.JsonRest",_6,{constructor:function(_7){this.headers={};_4.safeMixin(this,_7);},headers:{},target:"",idProperty:"id",get:function(id,_8){_8=_8||{};var _9=_2.mixin({Accept:this.accepts},this.headers,_8.headers||_8);return _1("GET",{url:this.target+id,handleAs:"json",headers:_9});},accepts:"application/javascript, application/json",getIdentity:function(_a){return _a[this.idProperty];},put:function(_b,_c){_c=_c||{};var id=("id" in _c)?_c.id:this.getIdentity(_b);var _d=typeof id!="undefined";return _1(_d&&!_c.incremental?"PUT":"POST",{url:_d?this.target+id:this.target,postData:_3.stringify(_b),handleAs:"json",headers:_2.mixin({"Content-Type":"application/json",Accept:this.accepts,"If-Match":_c.overwrite===true?"*":null,"If-None-Match":_c.overwrite===false?"*":null},this.headers,_c.headers)});},add:function(_e,_f){_f=_f||{};_f.overwrite=false;return this.put(_e,_f);},remove:function(id,_10){_10=_10||{};return _1("DELETE",{url:this.target+id,headers:_2.mixin({},this.headers,_10.headers)});},query:function(_11,_12){_12=_12||{};var _13=_2.mixin({Accept:this.accepts},this.headers,_12.headers);if(_12.start>=0||_12.count>=0){_13.Range=_13["X-Range"]="items="+(_12.start||"0")+"-"+(("count" in _12&&_12.count!=Infinity)?(_12.count+(_12.start||0)-1):"");}var _14=this.target.indexOf("?")>-1;if(_11&&typeof _11=="object"){_11=_1.objectToQuery(_11);_11=_11?(_14?"&":"?")+_11:"";}if(_12&&_12.sort){var _15=this.sortParam;_11+=(_11||_14?"&":"?")+(_15?_15+"=":"sort(");for(var i=0;i<_12.sort.length;i++){var _16=_12.sort[i];_11+=(i>0?",":"")+(_16.descending?"-":"+")+encodeURIComponent(_16.attribute);}if(!_15){_11+=")";}}var _17=_1("GET",{url:this.target+(_11||""),handleAs:"json",headers:_13});_17.total=_17.then(function(){var _18=_17.ioArgs.xhr.getResponseHeader("Content-Range");return _18&&(_18=_18.match(/\/(.*)/))&&+_18[1];});return _5(_17);}});});
\ No newline at end of file