~jonas-drange/online-services-common-js/navbar-autocomplete

« back to all changes in this revision

Viewing changes to src/contacts-model/js/contacts-model.js

  • Committer: Stephen Stewart
  • Date: 2014-02-22 23:57:25 UTC
  • mfrom: (18.1.2 trunk)
  • Revision ID: stephen.stewart@canonical.com-20140222235725-iw6f15t9umws19xd
mergeĀ lp:~stephen-stewart/online-services-common-js/remove-u1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var Contact = Y.Base.create('contactModel', Y.Base, [], {
2
 
    initializer: function(cfg) {
3
 
 
4
 
        if (cfg && cfg.json) {
5
 
            this.set('_original', Y.JSON.parse(cfg.json));
6
 
        }
7
 
 
8
 
    }
9
 
}, {
10
 
    ATTRS: {
11
 
        _original: {}
12
 
    },
13
 
    get: function(contact_id, on_success, on_failure) {
14
 
        return Y.io('/contacts/api/' + contact_id, {
15
 
            on: {
16
 
                success: function(id, response) {
17
 
                    var contact = new Contact({
18
 
                        json: response.responseText
19
 
                        });
20
 
                    on_success(contact);
21
 
                },
22
 
                failure: function(id, response ) {
23
 
                    on_failure(response);
24
 
                }
25
 
            }});
26
 
    },
27
 
    getAll: function(on_success, on_failure) {
28
 
        return Y.io('/contacts/api/all', {
29
 
            on: {
30
 
                success: function(id, response) {
31
 
                    var contacts = Y.JSON.parse(response.responseText);
32
 
                    on_success(contacts);
33
 
                },
34
 
                failure: function(id, response) {
35
 
                    on_failure(response);
36
 
                }
37
 
            }});
38
 
    },
39
 
    getAllByLetter: function(letter, on_success, on_failure) {
40
 
        return Y.io('/contacts/api/by-letter/' + letter, {
41
 
            on: {
42
 
                success: function(id, response) {
43
 
                    var contacts = Y.JSON.parse(response.responseText);
44
 
                    on_success(contacts);
45
 
                },
46
 
                failure: function(id, response) {
47
 
                    on_failure(response);
48
 
                }
49
 
            }});
50
 
    }
51
 
});
52
 
Y.Contact = Contact;