6168b343040f921930c25d8ab9d445c41b944fc8
[yaffs-website] / web / modules / contrib / devel / webprofiler / js / app / views / layout.js
1 (function ($, Drupal, drupalSettings, Backbone) {
2
3   "use strict";
4
5   Drupal.webprofiler.views.Layout = Backbone.View.extend({
6     template: _.template(
7       '<div id="overview" class="overview">' +
8       '<ul class="overview__list"></ul>' +
9       '</div>' +
10       '<div id="details" class="details">' +
11       'Choose a collector.' +
12       '</div>'
13     ),
14
15     /**
16      *
17      * @returns {Drupal.webprofiler.views.Layout}
18      */
19     render: function () {
20       this.$el.html(this.template());
21
22       if(this.currentDetails) {
23         this.currentDetails.setElement(this.$('#details')).render();
24       }
25
26       this.overview.setElement(this.$('#overview ul')).render();
27       return this;
28     },
29
30     /**
31      *
32      * @param options
33      */
34     initialize: function (options) {
35       options.router.collectors.on('request', this.beginSync);
36       options.router.collectors.on('sync', this.finishSync);
37
38       this.overview = new Drupal.webprofiler.views.CollectorsList({
39         collection: options.router.collectors,
40         router: options.router
41       });
42     },
43
44     /**
45      *
46      * @param collector
47      */
48     setDetails: function (collector) {
49       if (this.currentDetails) this.currentDetails.remove();
50       this.currentDetails = new Drupal.webprofiler.views.DetailsView({model: collector});
51       this.render();
52       Drupal.attachBehaviors(/*this.$el, drupalSettings*/);
53     },
54
55     /**
56      *
57      */
58     beginSync: function () {
59             $('.loader--fixed').fadeIn({duration: 100});
60     },
61
62     /**
63      *
64      */
65     finishSync: function () {
66             $('.loader--fixed').fadeOut({duration: 100});
67     }
68   });
69
70   var instance;
71   Drupal.webprofiler.views.Layout.getInstance = function (options) {
72     if (!instance) {
73       instance = new Drupal.webprofiler.views.Layout({
74         el: options.el,
75         router: options.router,
76         collection: options.router.collectors
77       });
78     }
79
80     return instance;
81   }
82
83 }(jQuery, Drupal, drupalSettings, Backbone));