bobamo /examples/login-example/public/js/collections/employee.js

Language Javascript Lines 64
MD5 Hash 6330c8f2af2eb7cd93a61e0a11daf22c
Repository git://github.com/jspears/bobamo.git View Raw File
| Open JSFiddle
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
define(['Backbone', 'jquery'], function (Backbone, $) {
    var Employee = Backbone.Model.extend({

        url:function () {
           return "/api/employee/"+this.id+'?populate[manager]=firstName,lastName,id'
        },

        initialize:function onIntialize() {
            this.reports = new EmployeeCollection();
            this.reports.url = '/api/employee/' + this.id + '/reports';
        },
        parse:function (resp) {
            console.log('Employee#parse', resp);
            return resp.payload || resp;
        },
        defaults:{
            title:'',
            url:'default.png',
            firstName:null,
            lastName:null,
            officePhone:null,
            cellPhone:null,
            email:null,
            twitterId:null,
            manager:{
                id:null,
                firstName:null,
                lastName:null
            }

        }

    });

    var EmployeeCollection = Backbone.Collection.extend({

        model:Employee,
        parse:function (resp) {
            console.log('EmployeeCollection#parse', resp);
            return resp.payload || resp;
        },
        url:"/api/employee",
        findByName:function (key) {
            // TODO: Modify service to include firstName in search
            var url = (key == '') ? '../api/employee' : "../api/employee/finder/search?term=" + key;
            console.log('findByName: ' + key);
            var self = this;
            $.ajax({
                url:url,
                dataType:"json",
                success:function (data) {
                    console.log('success', data);
                    console.log("search success: " + data);
                    self.reset(data.payload);
                }
            });
        }

    });
    return {
        EmployeeCollection:EmployeeCollection,
        Employee:Employee
    };
});
Back to Top