Revision f06ec46e

b/ui/static/snf/js/sync.js
34 34
    
35 35
    // Call history (set of api paths with the dates the path last called)
36 36
    var api_history = api.requests = api.requests || {};
37
    var addApiCallDate = function(url, d) {
37
    var addApiCallDate = function(url, d, method) {
38 38
        if (d === undefined) { d = Date() };
39 39
        var path = snf.util.parseUri(url).path;
40
        api_history[path] = d;
40
        api_history[path + "_" + method] = d;
41 41
        return api_history[path]
42 42
    }
43 43
    
......
46 46
        api_errors.push({url:settings.url, date:new Date, settings:settings, data:data})
47 47
    }
48 48

  
49
    var setChangesSince = function(url) {
49
    var setChangesSince = function(url, method) {
50 50
        var path = snf.util.parseUri(url).path;
51
        var d = api_history[path];
52

  
51
        var d = api_history[path + "_" + method];
53 52
        if (d) {
54 53
            url = url + "?changes-since=" + snf.util.ISODateString(d)
55 54
        }
......
69 68
        
70 69
        if (!options.url) {
71 70
            options.url = getUrl(model, options) || urlError();
72
            options.url = options.refresh ? options.url : setChangesSince(options.url, options);
71
            options.url = options.refresh ? options.url : setChangesSince(options.url, type);
73 72
            if (!options.refresh && options.cache === undefined) {
74 73
                options.cache = true;
75 74
            }
......
139 138
                // do not call success for 304 responses
140 139
                if (args[1] === "notmodified" || xhr.status == 0 && $.browser.opera) {
141 140
                    if (args[2]) {
142
                        addApiCallDate(this.url, new Date(args[2].getResponseHeader('Date')));
141
                        addApiCallDate(this.url, new Date(args[2].getResponseHeader('Date')), ajax_options.type);
143 142
                    }
144 143
                    return;
145 144
                }
......
154 153
    api.successHandler = function(data, status, xhr) {
155 154
        //debug("ajax success", arguments)
156 155
        // on success, update the last date we called the api url
157
        addApiCallDate(this.url, new Date(xhr.getResponseHeader('Date')));
156
        addApiCallDate(this.url, new Date(xhr.getResponseHeader('Date')), this.type);
158 157
        return [data, status, xhr];
159 158
    }
160 159

  
161 160
    api.errorHandler = function(event, xhr, settings, error) {
162 161
        //debug("ajax error", arguments, this);
163 162
        arguments.ajax = this;
164

  
163
        
165 164
        // skip aborts
166 165
        if (xhr != "abort") {
167 166
            if (!settings.handles_error) api.trigger("error", arguments);
......
197 196
                complete: function() { api.trigger("call"); complete(this) },
198 197
                error: error
199 198
            }
199

  
200 200
            params = _.extend(params, extra);
201 201
            this.sync(method, this, params);
202 202
        },

Also available in: Unified diff