source: Dev/branches/rest-dojo-ui/client/rft/api.js @ 343

Last change on this file since 343 was 343, checked in by hendrikvanantwerpen, 13 years ago

[Client] Changed store and pages to use CouchDB.
[Client] Disabled login for now, have to figure out some more details about CouchDB.

File size: 1.2 KB
Line 
1define(['dojo/_base/xhr','dojo/_base/json','dojo/_base/connect'],
2    function(xhr,json,connect){
3        return new (function(){
4            var self = this;
5            this.post = function(path,args) {
6                var dfd = xhr.post({
7                    url: "../server/api/"+path,
8                    handleAs: "json",
9                    headers: {
10                        "Content-Type": "application/json"
11                    },
12                    rawBody: json.toJson(args)
13                });
14                dfd.then(
15                    function(){},
16                    self.defaultErrorHandler);
17                return dfd;
18            };
19            this.defaultErrorHandler = function(error) {
20                var msg = "An error occured!";
21                try {
22                    msg = json.fromJson(error.responseText).errorMsg;
23                } catch (ex) {
24                    msg = error.message;
25                }
26                self.notify(msg,'error');
27            };
28            this.notify =  function(text,type) {
29                connect.publish('/rft/notify',{
30                    text: text,
31                    type: type
32                });
33            };
34        })();
35    });
Note: See TracBrowser for help on using the repository browser.