bobamo /examples/login-example/public/js/views/employee/details.js

Language Javascript Lines 53
MD5 Hash beb75814a4d201be830dedfec79ef676
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
define(['Backbone', 'jquery', 'underscore', 'collections/employee', 'views/employee/list', 'text!tpl/employee-details.html', 'text!tpl/employee-full.html'], function (Backbone, $, _, collection, EmployeeListView, detailsTmpl, fullTmpl) {
    var EmployeeFullView = Backbone.View.extend({

        tagName:"div", // Not required since 'div' is the default if no el or tagName specified

        initialize:function () {
            this.template = _.template(fullTmpl);
        },
        show:      function (model) {
            this.model = new collection.Employee(model);
            var self = this;
            this.model.fetch({
                success:function (data) {
                    console
                    $('#content').html(self.render().el);
                }
            });
            this.model.reports.fetch({
                success:function (data) {
                    console.log('reports', data);
                    if (data.length == 0)
                        $('.no-reports').show();
                }
            });
        },
        render:    function (model) {
            $(this.el).html(this.template(this.model.toJSON()));
            $('#details', this.el).html(new EmployeeView({model:this.model}).render().el);

            $('#reports', this.el).append(new EmployeeListView({model:this.model.reports}).render().el);
            return this;
        }

    });

    var EmployeeView = Backbone.View.extend({

        tagName:"div", // Not required since 'div' is the default if no el or tagName specified

        initialize:function () {
            this.template = _.template(detailsTmpl);
            this.model.bind("change", this.render, this);
        },

        render:function (eventName) {
            $(this.el).html(this.template(this.model.toJSON()));
            return this;
        }

    });
    return EmployeeFullView;
});
Back to Top