PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/jspears/bobamo
JavaScript | 52 lines | 43 code | 9 blank | 0 comment | 2 complexity | beb75814a4d201be830dedfec79ef676 MD5 | raw file
Possible License(s): Apache-2.0
  1. 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) {
  2. var EmployeeFullView = Backbone.View.extend({
  3. tagName:"div", // Not required since 'div' is the default if no el or tagName specified
  4. initialize:function () {
  5. this.template = _.template(fullTmpl);
  6. },
  7. show: function (model) {
  8. this.model = new collection.Employee(model);
  9. var self = this;
  10. this.model.fetch({
  11. success:function (data) {
  12. console
  13. $('#content').html(self.render().el);
  14. }
  15. });
  16. this.model.reports.fetch({
  17. success:function (data) {
  18. console.log('reports', data);
  19. if (data.length == 0)
  20. $('.no-reports').show();
  21. }
  22. });
  23. },
  24. render: function (model) {
  25. $(this.el).html(this.template(this.model.toJSON()));
  26. $('#details', this.el).html(new EmployeeView({model:this.model}).render().el);
  27. $('#reports', this.el).append(new EmployeeListView({model:this.model.reports}).render().el);
  28. return this;
  29. }
  30. });
  31. var EmployeeView = Backbone.View.extend({
  32. tagName:"div", // Not required since 'div' is the default if no el or tagName specified
  33. initialize:function () {
  34. this.template = _.template(detailsTmpl);
  35. this.model.bind("change", this.render, this);
  36. },
  37. render:function (eventName) {
  38. $(this.el).html(this.template(this.model.toJSON()));
  39. return this;
  40. }
  41. });
  42. return EmployeeFullView;
  43. });