Changeset 446 for Dev


Ignore:
Timestamp:
06/08/13 17:43:13 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Rewrote CouchStore? to use dojo/request.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/qed-client/store/CouchStore.js

    r443 r446  
    11define([
    2     'dojo/_base/array',
    3     'dojo/_base/declare',
    4     'dojo/_base/Deferred',
    5     'dojo/_base/json',
    6     'dojo/_base/lang',
    7     'dojo/_base/xhr',
    8     'dojo/store/util/QueryResults'
    9 ],function(array,declare,Deferred,json,lang,xhr,QueryResults){
     2    "dojo/_base/Deferred",
     3    "dojo/_base/array",
     4    "dojo/_base/declare",
     5    "dojo/_base/json",
     6    "dojo/_base/lang",
     7    "dojo/request",
     8    "dojo/store/util/QueryResults"
     9], function(Deferred, array, declare, json, lang, request, QueryResults) {
    1010   
    1111    function getCouchError(err){
     
    3939        info: function(){
    4040            var dfd = new Deferred();
    41             xhr("GET", {
    42                 url: this.target,
     41            request(this.target, {
     42                method: "GET",
    4343                handleAs: "json",
    4444                headers: {
     
    5858        get: function(id){
    5959            var dfd = new Deferred();
    60             xhr("GET", {
    61                 url: this.target + id,
    62                 handleAs: "json",
    63                 headers: {
    64                     Accept: this.accepts
    65                 }
    66             }).then(function(result){
    67                 if ( result.error ) {
    68                     dfd.reject(result.reason);
    69                 } else {
     60            request(this.target + encodeURIComponent(id), {
     61                method: "GET",
     62                handleAs: "json",
     63                headers: {
     64                    Accept: this.accepts
     65                }
     66            }).then(function(result){
     67                if ( result.error ) {
     68                    dfd.reject(result.reason);
     69                } else {
     70                    result[this.idProperty] = result[this._responseIdProperty];
     71                    result[this.revProperty] = result[this._responseRevProperty];
    7072                    dfd.resolve(result);
    7173                }
     
    101103            var id = options.id ? options.id : this.getIdentity(object);
    102104            var hasId = typeof id !== "undefined";
    103             xhr(hasId ? "PUT" : "POST", {
    104                 url: hasId ? this.target + id : this.target,
    105                 postData: json.toJson(object),
     105            request(hasId ? this.target + encodeURIComponent(id) : this.target, {
     106                method: hasId ? "PUT" : "POST",
     107                data: json.toJson(object),
    106108                handleAs: "json",
    107109                headers:{
     
    127129        remove: function(id,rev){
    128130            var dfd = new Deferred();
    129             xhr("DELETE",{
    130                 url: this.target + id,
     131            request(this.target + encodeURIComponent(id), {
     132                method: "DELETE",
    131133                headers: {
    132134                    'If-Match': rev
     
    237239            }
    238240
    239             for (var qp in queryOpts) {
    240                 queryOpts[qp] = json.toJson(queryOpts[qp]);
    241             }
    242             query += '?' + xhr.objectToQuery(queryOpts);
    243 
    244             xhr("GET", {
    245                 url: this.target + query,
    246                 handleAs: "json",
     241            for ( var opt in queryOpts ) {
     242                queryOpts[opt] = json.toJson(queryOpts[opt]);
     243            }
     244           
     245            request(this.target + query, {
     246                method: "GET",
     247                handleAs: "json",
     248                query: queryOpts,
    247249                headers: {
    248250                    Accept: this.accepts
Note: See TracChangeset for help on using the changeset viewer.