pulse_meter-dygraphs_visualizer 0.4.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitignore +19 -0
  2. data/.rbenv-version +1 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +9 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +22 -0
  8. data/Procfile +3 -0
  9. data/README.md +40 -0
  10. data/Rakefile +54 -0
  11. data/examples/basic.ru +125 -0
  12. data/examples/basic_sensor_data.rb +97 -0
  13. data/lib/pulse_meter/dygraphs_visualize/app.rb +78 -0
  14. data/lib/pulse_meter/dygraphs_visualize/base.rb +15 -0
  15. data/lib/pulse_meter/dygraphs_visualize/coffee/application.coffee +37 -0
  16. data/lib/pulse_meter/dygraphs_visualize/coffee/collections/page_info_list.coffee +17 -0
  17. data/lib/pulse_meter/dygraphs_visualize/coffee/collections/sensor_info_list.coffee +4 -0
  18. data/lib/pulse_meter/dygraphs_visualize/coffee/collections/widget_list.coffee +14 -0
  19. data/lib/pulse_meter/dygraphs_visualize/coffee/extensions.coffee +26 -0
  20. data/lib/pulse_meter/dygraphs_visualize/coffee/models/dinamic_widget.coffee +34 -0
  21. data/lib/pulse_meter/dygraphs_visualize/coffee/models/page_info.coffee +2 -0
  22. data/lib/pulse_meter/dygraphs_visualize/coffee/models/sensor_info.coffee +2 -0
  23. data/lib/pulse_meter/dygraphs_visualize/coffee/models/widget.coffee +63 -0
  24. data/lib/pulse_meter/dygraphs_visualize/coffee/presenters/line.coffee +1 -0
  25. data/lib/pulse_meter/dygraphs_visualize/coffee/presenters/series.coffee +26 -0
  26. data/lib/pulse_meter/dygraphs_visualize/coffee/presenters/stack.coffee +1 -0
  27. data/lib/pulse_meter/dygraphs_visualize/coffee/presenters/timeline.coffee +13 -0
  28. data/lib/pulse_meter/dygraphs_visualize/coffee/presenters/widget.coffee +48 -0
  29. data/lib/pulse_meter/dygraphs_visualize/coffee/router.coffee +21 -0
  30. data/lib/pulse_meter/dygraphs_visualize/coffee/views/dynamic_chart.coffee +92 -0
  31. data/lib/pulse_meter/dygraphs_visualize/coffee/views/dynamic_widget.coffee +58 -0
  32. data/lib/pulse_meter/dygraphs_visualize/coffee/views/page_title.coffee +17 -0
  33. data/lib/pulse_meter/dygraphs_visualize/coffee/views/page_titles.coffee +15 -0
  34. data/lib/pulse_meter/dygraphs_visualize/coffee/views/sensor_info_list.coffee +19 -0
  35. data/lib/pulse_meter/dygraphs_visualize/coffee/views/widget.coffee +91 -0
  36. data/lib/pulse_meter/dygraphs_visualize/coffee/views/widget_chart.coffee +15 -0
  37. data/lib/pulse_meter/dygraphs_visualize/coffee/views/widget_list.coffee +15 -0
  38. data/lib/pulse_meter/dygraphs_visualize/dsl/base.rb +131 -0
  39. data/lib/pulse_meter/dygraphs_visualize/dsl/errors.rb +40 -0
  40. data/lib/pulse_meter/dygraphs_visualize/dsl/layout.rb +27 -0
  41. data/lib/pulse_meter/dygraphs_visualize/dsl/page.rb +26 -0
  42. data/lib/pulse_meter/dygraphs_visualize/dsl/sensor.rb +20 -0
  43. data/lib/pulse_meter/dygraphs_visualize/dsl/widget.rb +37 -0
  44. data/lib/pulse_meter/dygraphs_visualize/dsl/widgets/line.rb +22 -0
  45. data/lib/pulse_meter/dygraphs_visualize/dsl/widgets/stack.rb +29 -0
  46. data/lib/pulse_meter/dygraphs_visualize/layout.rb +79 -0
  47. data/lib/pulse_meter/dygraphs_visualize/page.rb +25 -0
  48. data/lib/pulse_meter/dygraphs_visualize/public/css/application.css +61 -0
  49. data/lib/pulse_meter/dygraphs_visualize/public/css/bootstrap.css +4883 -0
  50. data/lib/pulse_meter/dygraphs_visualize/public/css/bootstrap.min.css +729 -0
  51. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  52. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  53. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  54. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  55. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  56. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  57. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  58. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  59. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-icons_222222_256x240.png +0 -0
  60. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-icons_2e83ff_256x240.png +0 -0
  61. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-icons_454545_256x240.png +0 -0
  62. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-icons_888888_256x240.png +0 -0
  63. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-icons_cd0a0a_256x240.png +0 -0
  64. data/lib/pulse_meter/dygraphs_visualize/public/css/images/ui-icons_f6cf3b_256x240.png +0 -0
  65. data/lib/pulse_meter/dygraphs_visualize/public/css/jquery-ui-1.8.16.bootstrap.css +1320 -0
  66. data/lib/pulse_meter/dygraphs_visualize/public/favicon.ico +208 -0
  67. data/lib/pulse_meter/dygraphs_visualize/public/img/glyphicons-halflings-white.png +0 -0
  68. data/lib/pulse_meter/dygraphs_visualize/public/img/glyphicons-halflings.png +0 -0
  69. data/lib/pulse_meter/dygraphs_visualize/public/js/application.js +833 -0
  70. data/lib/pulse_meter/dygraphs_visualize/public/js/backbone-min.js +38 -0
  71. data/lib/pulse_meter/dygraphs_visualize/public/js/bootstrap.js +1835 -0
  72. data/lib/pulse_meter/dygraphs_visualize/public/js/dygraph-combined.js +2 -0
  73. data/lib/pulse_meter/dygraphs_visualize/public/js/jquery-1.7.2.min.js +4 -0
  74. data/lib/pulse_meter/dygraphs_visualize/public/js/jquery-ui-1.8.16.bootstrap.min.js +791 -0
  75. data/lib/pulse_meter/dygraphs_visualize/public/js/jquery-ui-1.8.23.custom.min.js +21 -0
  76. data/lib/pulse_meter/dygraphs_visualize/public/js/jquery-ui-timepicker-addon.js +1687 -0
  77. data/lib/pulse_meter/dygraphs_visualize/public/js/json2.js +487 -0
  78. data/lib/pulse_meter/dygraphs_visualize/public/js/underscore-min.js +32 -0
  79. data/lib/pulse_meter/dygraphs_visualize/sensor.rb +63 -0
  80. data/lib/pulse_meter/dygraphs_visualize/series_color.rb +39 -0
  81. data/lib/pulse_meter/dygraphs_visualize/series_extractor.rb +107 -0
  82. data/lib/pulse_meter/dygraphs_visualize/views/main.haml +30 -0
  83. data/lib/pulse_meter/dygraphs_visualize/views/sensors.haml +75 -0
  84. data/lib/pulse_meter/dygraphs_visualize/views/widgets/extend_options.haml +11 -0
  85. data/lib/pulse_meter/dygraphs_visualize/views/widgets/line.haml +43 -0
  86. data/lib/pulse_meter/dygraphs_visualize/views/widgets/stack.haml +43 -0
  87. data/lib/pulse_meter/dygraphs_visualize/widget.rb +38 -0
  88. data/lib/pulse_meter/dygraphs_visualize/widgets/timeline.rb +107 -0
  89. data/lib/pulse_meter/dygraphs_visualizer.rb +34 -0
  90. data/lib/pulse_meter_dygraphs_visualizer.rb +2 -0
  91. data/pulse_meter-dygraphs_visualizer.gemspec +41 -0
  92. data/spec/pulse_meter/dygraphs_visualize/app_spec.rb +27 -0
  93. data/spec/pulse_meter/dygraphs_visualize/dsl/layout_spec.rb +64 -0
  94. data/spec/pulse_meter/dygraphs_visualize/dsl/page_spec.rb +62 -0
  95. data/spec/pulse_meter/dygraphs_visualize/dsl/sensor_spec.rb +30 -0
  96. data/spec/pulse_meter/dygraphs_visualize/dsl/widget_spec.rb +6 -0
  97. data/spec/pulse_meter/dygraphs_visualize/dsl/widgets/line_spec.rb +44 -0
  98. data/spec/pulse_meter/dygraphs_visualize/dsl/widgets/stack_spec.rb +55 -0
  99. data/spec/pulse_meter/dygraphs_visualize/layout_spec.rb +54 -0
  100. data/spec/pulse_meter/dygraphs_visualize/page_spec.rb +145 -0
  101. data/spec/pulse_meter/dygraphs_visualize/sensor_spec.rb +120 -0
  102. data/spec/pulse_meter/dygraphs_visualize/series_extractor_spec.rb +80 -0
  103. data/spec/pulse_meter/dygraphs_visualize/widgets/line_spec.rb +6 -0
  104. data/spec/pulse_meter/dygraphs_visualize/widgets/stack_spec.rb +6 -0
  105. data/spec/pulse_meter/dygraphs_visualizer_spec.rb +42 -0
  106. data/spec/shared_examples/dsl_widget.rb +106 -0
  107. data/spec/shared_examples/widget.rb +97 -0
  108. data/spec/spec_helper.rb +36 -0
  109. metadata +497 -0
@@ -0,0 +1,208 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <!-- META -->
6
+ <meta charset="utf-8">
7
+ <meta content="en" name="language">
8
+ <meta name="description" content="Free Online Icons Converter - Convert PNG to ICO and ICO to PNG files : Win 7 & Windows Vista compatible icons">
9
+ <meta name="keywords" content="convert, png, ico, free, freeware, vista, icons, ico">
10
+ <meta content="follow, index, all" name="robots">
11
+
12
+
13
+ <!-- TITLE -->
14
+ <title>ConvertICO.com - Convert .PNG format files to .ICO or .ICO format files to .PNG : Windows 7 compatible icons</title>
15
+
16
+ <!-- CSS -->
17
+ <link href="styles/base.css" rel="stylesheet" type="text/css" >
18
+ <!--[if IE 7]> <link href="styles/ie7.css" rel="stylesheet" type="text/css" > <![endif]-->
19
+ <!--[if IE 8]> <link href="styles/ie8.css" rel="stylesheet" type="text/css" > <![endif]-->
20
+ <!--[if IE 9]> <link href="styles/ie9.css" rel="stylesheet" type="text/css" > <![endif]-->
21
+
22
+ <!-- FAVICON -->
23
+ <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" >
24
+
25
+ <!-- TYPEKIT -->
26
+ <script type="text/javascript" src="http://use.typekit.com/jws7edv.js"></script>
27
+ <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
28
+
29
+ <!-- JS -->
30
+ <script type="text/javascript" src="scripts/jquery.js"></script>
31
+ <script type="text/javascript" src="scripts/jquery.imagesloaded.js"></script>
32
+ <script type="text/javascript" src="scripts/jquery.form.js"></script>
33
+ <script type="text/javascript" src="scripts/spin.min.js"></script>
34
+ <script type="text/javascript" src="scripts/modernizr.js"></script>
35
+ <script type="text/javascript" src="scripts/ba-debug.min.js"></script>
36
+ <script type="text/javascript" src="scripts/main.js"></script>
37
+ <!--[if IE]> <style type="text/css">img { behavior: url(scripts/iepngfix.htc) }</style> <![endif]-->
38
+
39
+ </head>
40
+
41
+ <body>
42
+ <!-- BuySellAds.com Ad Code -->
43
+ <script type="text/javascript">
44
+ (function(){
45
+ var bsa = document.createElement('script');
46
+ bsa.type = 'text/javascript';
47
+ bsa.async = true;
48
+ bsa.src = 'http://s3.buysellads.com/ac/bsa.js';
49
+ (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa);
50
+ })();
51
+ </script>
52
+
53
+ <div id="top">
54
+ <div class="container">
55
+ <ul id="network">
56
+ <li class="parent">proIcons Network</li>
57
+ <li><a href="http://www.proicons.com">proIcons.com</a></li>
58
+ <li><a href="http://www.windowsico.com">WindowsICO.com</a></li>
59
+ <li class="selected"><a href="http://www.convertico.com">ConvertICO.com</a></li>
60
+ <li><a href="http://www.favico.com">FavICO.com</a></li>
61
+ </ul><!-- #network -->
62
+
63
+ <div id="counter">
64
+ <p><span class="total">6,088,770</span> Icons Converted
65
+ <span class="hour">1,163</span> In The Last Hour</p>
66
+ </div><!-- #counter -->
67
+ </div><!-- .container -->
68
+ </div><!-- #top -->
69
+
70
+ <div id="main">
71
+ <div class="container">
72
+ <div class="lcol">
73
+
74
+ <div id="intro">
75
+ <h2><a href="" id="logo">CI</a> ConvertIco</h2>
76
+ <h3>PNG to ICO / ICO to PNG Conversion</h3>
77
+ <p><strong>ConvertICO</strong> is a <strong>Free Online ICO/PNG File Converter</strong>.
78
+ It is fast, free and easy to use. It is used to convert Desktop Icons, App Icons as well as the much needed favicons for websites. Go ahead and give it a try, you will be pleased. <a class="expand" href="#instructions">Click Here for Instructions</a></p>
79
+ <div class="how">
80
+ <p>How to Convert Files:</p>
81
+ <ol>
82
+ <li>To convert a file located on a webserver: just enter the URL<br> For example: http://google.com/filename.png and click the GO button.</li>
83
+ <li>To convert a file located on your computer: click Browse, locate the file on your computer and then click the GO button.</li>
84
+ </ol>
85
+ </div><!-- .how -->
86
+ </div><!-- #intro -->
87
+ <script type="text/javascript"><!--
88
+ google_ad_client = "ca-pub-7595495923317249";
89
+ /* ConvertICO 468x60 */
90
+ google_ad_slot = "1090461791";
91
+ google_ad_width = 468;
92
+ google_ad_height = 60;
93
+ //-->
94
+ </script>
95
+ <script type="text/javascript"
96
+ src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
97
+ </script>
98
+ <div id="convert">
99
+ <form name="myform" id="fConvert" action="appleJax.php" method="post" enctype="multipart/form-data">
100
+ <div class="col1-2">
101
+ <div class="url">
102
+ <label>Select File From URL</label>
103
+ <input name="remoteimgfile" type="text" class="text" value="http://">
104
+ </div><!-- .url -->
105
+
106
+ <div class="file">
107
+ <label>Select File From Your Computer</label>
108
+ <input name="imgfile" class="file" type="file" size="59">
109
+ <input class="fakefile" name="" type="text" value="">
110
+ <div class="browse">Browse</div>
111
+ </div>
112
+ <!-- .file -->
113
+ </div><!-- .col1-2 -->
114
+
115
+ <div class="col2-2">
116
+ <div id="subContain" class="action">
117
+ <input class="submit" name="" type="submit" value="GO">
118
+ </div>
119
+ <!-- .action -->
120
+ </div><!-- .col2-2 -->
121
+ <input id="selected" name="selected" type="hidden">
122
+ </form>
123
+
124
+ <div id="recent">
125
+ <h4>Recently Converted</h4>
126
+ <div id="recentView">
127
+ <ul class="iconslist">
128
+ <li><img src="/images/1341004889.56/_previmg.png" alt='The latest Converted Icons'/></li><li><img src="/images/1341004888.57/_previmg.png" alt='The latest Converted Icons'/></li><li><img src="/images/1341004888.42/_previmg.png" alt='The latest Converted Icons'/></li><li><img src="/images/1341004883.7/_previmg.png" alt='The latest Converted Icons'/></li><li><img src="/images/1341004875.68/_previmg.png" alt='The latest Converted Icons'/></li><li><img src="/images/1341004873.53/_previmg.png" alt='The latest Converted Icons'/></li><li><img src="/images/1341004866.37/_previmg.png" alt='The latest Converted Icons'/></li><li><img src="/images/1341004861.66/_previmg.png" alt='The latest Converted Icons'/></li> </ul>
129
+ </div>
130
+ </div><!-- #recent -->
131
+ </div><!-- #convert -->
132
+
133
+ </div><!-- .lcol -->
134
+
135
+ <div class="rcol">
136
+ <div id="ads">
137
+ <div class="wrap">
138
+ <script type="text/javascript"><!--
139
+ google_ad_client = "ca-pub-7595495923317249";
140
+ /* 336x280, created 4/6/11 */
141
+ google_ad_slot = "9617101975";
142
+ google_ad_width = 336;
143
+ google_ad_height = 280;
144
+ //-->
145
+ </script>
146
+ <script type="text/javascript"
147
+ src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
148
+ </script>
149
+ </div><!-- .wrap -->
150
+ </div><!-- #ads -->
151
+
152
+ <div id="results">
153
+
154
+ <div id="noicons">
155
+ <h5>Start Converting Icons Now</h5>
156
+ <p>Icons will appear here once you convert them</p>
157
+ </div><!-- #noicons -->
158
+
159
+ <!-- BuySellAds.com Zone Code -->
160
+ <div id="bsap_1270400" class="bsarocks bsap_3efb91f3af086a588acca7a4eff4e700"></div>
161
+ <!-- End BuySellAds.com Zone Code -->
162
+ </div><!-- #results -->
163
+
164
+ </div><!-- .rcol -->
165
+
166
+ </div><!-- .container -->
167
+ </div><!-- #main -->
168
+
169
+
170
+ <div id="footer">
171
+ <div class="container">
172
+ <div class="col3">
173
+ <h4>About</h4>
174
+ <p>ConvertICO was created by the proIcons.com team to help designers around the world have an easier time converting their icons from <b>png to ico</b> and viceversa. Stay tuned for updates and new features!</p>
175
+ </div><!-- .col3 -->
176
+ <div class="col3 mid">
177
+ <h4>Privacy Statement</h4>
178
+ <p>This website does not gather any personal info, computer specs or IP. However, your icons are stored publicly. If you do not wish your items to be stored publicly, do not use this website.</p>
179
+ </div><!-- .col3 -->
180
+ <div class="col3">
181
+ <h4>Terms of Use</h4>
182
+ <p>By using this website to convert your icons, you acknowledge that we are in no way responsible for data error, losses or discrepancies in the conversion. You use the software at your own risk.</p>
183
+ </div><!-- .col3 -->
184
+ <div id="copy">
185
+ <p class="feedback">For <strong>Feedback</strong>, <strong>Suggestions</strong> and <strong>Errors</strong>, write to <em>info at proicons dot com</em></p>
186
+ <p>&copy; 2008-2012 ConvertICO.COM, a creation and property of the proIcons.com network. All rights reserved.</p>
187
+ </div><!-- #copy -->
188
+
189
+ </div><!-- .container -->
190
+ </div><!-- #footer -->
191
+
192
+
193
+ <script type="text/javascript">
194
+
195
+ var _gaq = _gaq || [];
196
+ _gaq.push(['_setAccount', 'UA-320719-8']);
197
+ _gaq.push(['_trackPageview']);
198
+
199
+ (function() {
200
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
201
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
202
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
203
+ })();
204
+
205
+ </script>
206
+ </body>
207
+ </html>
208
+
@@ -0,0 +1,833 @@
1
+
2
+ String.prototype.capitalize = function() {
3
+ return this.charAt(0).toUpperCase() + this.slice(1);
4
+ };
5
+
6
+ String.prototype.strip = function() {
7
+ if (String.prototype.trim != null) {
8
+ return this.trim();
9
+ } else {
10
+ return this.replace(/^\s+|\s+$/g, "");
11
+ }
12
+ };
13
+
14
+ Number.prototype.humanize = function() {
15
+ var d, h, interval, m, res, s;
16
+ interval = this;
17
+ res = "";
18
+ s = interval % 60;
19
+ if (s > 0) {
20
+ res = "" + s + " s";
21
+ }
22
+ interval = (interval - s) / 60;
23
+ if (!(interval > 0)) {
24
+ return res;
25
+ }
26
+ m = interval % 60;
27
+ if (m > 0) {
28
+ res = ("" + m + " m " + res).strip();
29
+ }
30
+ interval = (interval - m) / 60;
31
+ if (!(interval > 0)) {
32
+ return res;
33
+ }
34
+ h = interval % 24;
35
+ if (h > 0) {
36
+ res = ("" + h + " h " + res).strip();
37
+ }
38
+ d = (interval - h) / 24;
39
+ if (d > 0) {
40
+ return ("" + d + " d " + res).strip();
41
+ } else {
42
+ return res;
43
+ }
44
+ };
45
+ var PageInfo;
46
+
47
+ PageInfo = Backbone.Model.extend({});
48
+ var Widget;
49
+
50
+ Widget = Backbone.Model.extend({
51
+ initialize: function() {
52
+ this.updating = false;
53
+ this.needRefresh = true;
54
+ this.setNextFetch();
55
+ return this.timespanInc = 0;
56
+ },
57
+ setStartTime: function(startTime) {
58
+ this.startTime = startTime;
59
+ },
60
+ setEndTime: function(endTime) {
61
+ this.endTime = endTime;
62
+ },
63
+ increaseTimespan: function(inc) {
64
+ this.timespanInc = this.timespanInc + inc;
65
+ return this.forceUpdate();
66
+ },
67
+ resetTimespan: function() {
68
+ this.timespanInc = 0;
69
+ this.startTime = null;
70
+ this.endTime = null;
71
+ return this.forceUpdate();
72
+ },
73
+ timespan: function() {
74
+ return this.get('timespan') + this.timespanInc;
75
+ },
76
+ url: function() {
77
+ var timespan, url;
78
+ timespan = this.timespan();
79
+ url = "" + (this.collection.url()) + "/" + (this.get('id')) + "?";
80
+ if (!_.isNaN(timespan)) {
81
+ url += "&timespan=" + timespan;
82
+ }
83
+ if (this.startTime) {
84
+ url += "&startTime=" + this.startTime;
85
+ }
86
+ if (this.endTime) {
87
+ url += "&endTime=" + this.endTime;
88
+ }
89
+ return url;
90
+ },
91
+ time: function() {
92
+ return (new Date()).getTime();
93
+ },
94
+ setNextFetch: function() {
95
+ return this.nextFetch = this.time() + this.get('redrawInterval') * 1000;
96
+ },
97
+ setRefresh: function(needRefresh) {
98
+ return this.needRefresh = needRefresh;
99
+ },
100
+ needFetch: function() {
101
+ var interval;
102
+ interval = this.get('redrawInterval');
103
+ return this.time() > this.nextFetch && this.needRefresh && (interval != null) && interval > 0;
104
+ },
105
+ refetch: function() {
106
+ if (this.needFetch()) {
107
+ this.forceUpdate();
108
+ return this.setNextFetch();
109
+ }
110
+ },
111
+ setUpdated: function() {
112
+ return this.updating = false;
113
+ },
114
+ forceUpdate: function() {
115
+ var xhr,
116
+ _this = this;
117
+ if (this.updating) {
118
+ return;
119
+ }
120
+ this.updating = true;
121
+ xhr = this.fetch({
122
+ success: function(model, response) {
123
+ return _this.trigger('redraw');
124
+ }
125
+ });
126
+ xhr.always(function() {
127
+ return _this.updating = false;
128
+ });
129
+ return xhr.fail(function(xhr, textStatus, errorThrown) {
130
+ return console.log("xhr fail", _this.get('id'), textStatus, errorThrown);
131
+ });
132
+ }
133
+ });
134
+ var DynamicWidget;
135
+
136
+ DynamicWidget = Backbone.Model.extend({
137
+ setStartTime: function(startTime) {
138
+ this.startTime = startTime;
139
+ },
140
+ setEndTime: function(endTime) {
141
+ this.endTime = endTime;
142
+ },
143
+ increaseTimespan: function(inc) {
144
+ return this.set('timespan', this.timespan() + inc);
145
+ },
146
+ resetTimespan: function() {
147
+ this.startTime = null;
148
+ this.endTime = null;
149
+ return this.set('timespan', null);
150
+ },
151
+ timespan: function() {
152
+ return this.get('timespan');
153
+ },
154
+ sensorArgs: function() {
155
+ return _.map(this.get('sensorIds'), function(name) {
156
+ return "sensor[]=" + name;
157
+ }).join('&');
158
+ },
159
+ url: function() {
160
+ var timespan, url;
161
+ timespan = this.timespan();
162
+ url = "" + ROOT + "dynamic_widget?" + (this.sensorArgs()) + "&type=" + (this.get('type'));
163
+ if ((timespan != null) && !_.isNaN(timespan)) {
164
+ url += "&timespan=" + timespan;
165
+ }
166
+ if (this.startTime) {
167
+ url += "&startTime=" + this.startTime;
168
+ }
169
+ if (this.endTime) {
170
+ url += "&endTime=" + this.endTime;
171
+ }
172
+ return url;
173
+ },
174
+ forceUpdate: function() {
175
+ return this.fetch({
176
+ success: function(model, response) {
177
+ return model.trigger('redraw');
178
+ }
179
+ });
180
+ }
181
+ });
182
+ var SensorInfo;
183
+
184
+ SensorInfo = Backbone.Model.extend({});
185
+ var PageInfoList;
186
+
187
+ PageInfoList = Backbone.Collection.extend({
188
+ model: PageInfo,
189
+ selected: function() {
190
+ return this.find(function(m) {
191
+ return m.get('selected');
192
+ });
193
+ },
194
+ selectFirst: function() {
195
+ if (this.length > 0) {
196
+ return this.at(0).set('selected', true);
197
+ }
198
+ },
199
+ selectNone: function() {
200
+ return this.each(function(m) {
201
+ return m.set('selected', false);
202
+ });
203
+ },
204
+ selectPage: function(id) {
205
+ return this.each(function(m) {
206
+ return m.set('selected', m.id === id);
207
+ });
208
+ }
209
+ });
210
+ var SensorInfoList;
211
+
212
+ SensorInfoList = Backbone.Collection.extend({
213
+ model: SensorInfo,
214
+ url: function() {
215
+ return ROOT + 'sensors';
216
+ }
217
+ });
218
+ var WidgetList;
219
+
220
+ WidgetList = Backbone.Collection.extend({
221
+ model: Widget,
222
+ setContext: function(pageInfos) {
223
+ this.pageInfos = pageInfos;
224
+ },
225
+ url: function() {
226
+ return ROOT + 'pages/' + this.pageInfos.selected().id + '/widgets';
227
+ },
228
+ startPolling: function() {
229
+ var _this = this;
230
+ return setInterval(function() {
231
+ if (_this.pageInfos.selected()) {
232
+ return _this.each(function(w) {
233
+ return w.refetch();
234
+ });
235
+ }
236
+ }, 200);
237
+ }
238
+ });
239
+ var WidgetPresenter;
240
+
241
+ WidgetPresenter = (function() {
242
+
243
+ function WidgetPresenter(pageInfos, model, el) {
244
+ this.pageInfos = pageInfos;
245
+ this.model = model;
246
+ this.el = el;
247
+ this.chartEl = this.el.find('#chart')[0];
248
+ this.legendEl = this.el.find('#legend')[0];
249
+ this.chart = new Dygraph.GVizChart(this.chartEl);
250
+ this.draw();
251
+ }
252
+
253
+ WidgetPresenter.prototype.get = function(arg) {
254
+ return this.model.get(arg);
255
+ };
256
+
257
+ WidgetPresenter.prototype.globalOptions = function() {
258
+ return gon.options;
259
+ };
260
+
261
+ WidgetPresenter.prototype.dateOffset = function() {
262
+ if (this.globalOptions.useUtc) {
263
+ return (new Date).getTimezoneOffset() * 60000;
264
+ } else {
265
+ return 0;
266
+ }
267
+ };
268
+
269
+ WidgetPresenter.prototype.options = function() {
270
+ return {
271
+ labelsDiv: this.legendEl,
272
+ labelsSeparateLines: false,
273
+ rightGap: 30
274
+ };
275
+ };
276
+
277
+ WidgetPresenter.prototype.mergedOptions = function() {
278
+ var pageOptions;
279
+ pageOptions = this.pageInfos.selected() ? this.pageInfos.selected().get('dygraphsOptions') : {};
280
+ return $.extend(true, this.options(), this.globalOptions.dygraphsOptions, pageOptions, this.get('dygraphsOptions'));
281
+ };
282
+
283
+ WidgetPresenter.prototype.data = function() {
284
+ return new google.visualization.DataTable;
285
+ };
286
+
287
+ WidgetPresenter.prototype.draw = function() {
288
+ return this.chart.draw(this.data(), this.mergedOptions());
289
+ };
290
+
291
+ return WidgetPresenter;
292
+
293
+ })();
294
+
295
+ WidgetPresenter.create = function(pageInfos, model, el) {
296
+ var presenterClass, type;
297
+ type = model.get('type');
298
+ if ((type != null) && type.match(/^\w+$/)) {
299
+ presenterClass = eval("" + (type.capitalize()) + "Presenter");
300
+ return new presenterClass(pageInfos, model, el);
301
+ } else {
302
+ return null;
303
+ }
304
+ };
305
+ var TimelinePresenter,
306
+ __hasProp = {}.hasOwnProperty,
307
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
308
+
309
+ TimelinePresenter = (function(_super) {
310
+
311
+ __extends(TimelinePresenter, _super);
312
+
313
+ function TimelinePresenter() {
314
+ return TimelinePresenter.__super__.constructor.apply(this, arguments);
315
+ }
316
+
317
+ TimelinePresenter.prototype.data = function() {
318
+ var data, dateOffset, series;
319
+ data = TimelinePresenter.__super__.data.call(this);
320
+ data.addColumn('datetime', 'Time');
321
+ dateOffset = this.dateOffset() + this.get('interval') * 1000;
322
+ series = this.get('series');
323
+ _.each(series.titles, function(t) {
324
+ return data.addColumn('number', t);
325
+ });
326
+ _.each(series.rows, function(row) {
327
+ row[0] = new Date(row[0] + dateOffset);
328
+ return data.addRow(row);
329
+ });
330
+ return data;
331
+ };
332
+
333
+ return TimelinePresenter;
334
+
335
+ })(WidgetPresenter);
336
+ var SeriesPresenter,
337
+ __hasProp = {}.hasOwnProperty,
338
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
339
+
340
+ SeriesPresenter = (function(_super) {
341
+
342
+ __extends(SeriesPresenter, _super);
343
+
344
+ function SeriesPresenter() {
345
+ return SeriesPresenter.__super__.constructor.apply(this, arguments);
346
+ }
347
+
348
+ SeriesPresenter.prototype.options = function() {
349
+ return $.extend(true, SeriesPresenter.__super__.options.call(this), {
350
+ title: this.get('title'),
351
+ legend: 'always',
352
+ height: 300,
353
+ ylabel: this.valuesTitle(),
354
+ colors: this.colors()
355
+ });
356
+ };
357
+
358
+ SeriesPresenter.prototype.valuesTitle = function() {
359
+ if (this.get('valuesTitle')) {
360
+ return "" + (this.get('valuesTitle')) + " / " + (this.humanizedInterval());
361
+ } else {
362
+ return this.humanizedInterval();
363
+ }
364
+ };
365
+
366
+ SeriesPresenter.prototype.colors = function() {
367
+ return _.map(this.get('series').options, function(o) {
368
+ return o.color;
369
+ });
370
+ };
371
+
372
+ SeriesPresenter.prototype.humanizedInterval = function() {
373
+ return this.get('interval').humanize();
374
+ };
375
+
376
+ return SeriesPresenter;
377
+
378
+ })(TimelinePresenter);
379
+ var LinePresenter,
380
+ __hasProp = {}.hasOwnProperty,
381
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
382
+
383
+ LinePresenter = (function(_super) {
384
+
385
+ __extends(LinePresenter, _super);
386
+
387
+ function LinePresenter() {
388
+ return LinePresenter.__super__.constructor.apply(this, arguments);
389
+ }
390
+
391
+ return LinePresenter;
392
+
393
+ })(SeriesPresenter);
394
+ var StackPresenter,
395
+ __hasProp = {}.hasOwnProperty,
396
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
397
+
398
+ StackPresenter = (function(_super) {
399
+
400
+ __extends(StackPresenter, _super);
401
+
402
+ function StackPresenter() {
403
+ return StackPresenter.__super__.constructor.apply(this, arguments);
404
+ }
405
+
406
+ return StackPresenter;
407
+
408
+ })(SeriesPresenter);
409
+ var PageTitleView;
410
+
411
+ PageTitleView = Backbone.View.extend({
412
+ tagName: 'li',
413
+ template: _.template('<a href="#/pages/<%= id %>"><%= title %></a>'),
414
+ initialize: function() {
415
+ this.model.bind('change', this.render, this);
416
+ return this.model.bind('destroy', this.remove, this);
417
+ },
418
+ render: function() {
419
+ this.$el.html(this.template(this.model.toJSON()));
420
+ if (this.model.get('selected')) {
421
+ return this.$el.addClass('active');
422
+ } else {
423
+ return this.$el.removeClass('active');
424
+ }
425
+ }
426
+ });
427
+ var PageTitlesView;
428
+
429
+ PageTitlesView = Backbone.View.extend({
430
+ initialize: function(pageInfos) {
431
+ this.pageInfos = pageInfos;
432
+ return this.pageInfos.bind('reset', this.render, this);
433
+ },
434
+ addOne: function(pageInfo) {
435
+ var view;
436
+ view = new PageTitleView({
437
+ model: pageInfo
438
+ });
439
+ view.render();
440
+ return $('#page-titles').append(view.el);
441
+ },
442
+ render: function() {
443
+ $('#page-titles').empty();
444
+ return this.pageInfos.each(this.addOne);
445
+ }
446
+ });
447
+ var SensorInfoListView;
448
+
449
+ SensorInfoListView = Backbone.View.extend({
450
+ tagName: 'div',
451
+ template: function() {
452
+ return _.template($("#sensor-list").html());
453
+ },
454
+ initialize: function(sensorInfo) {
455
+ this.sensorInfo = sensorInfo;
456
+ return this.sensorInfo.bind('reset', this.render, this);
457
+ },
458
+ render: function() {
459
+ return this.$el.html(this.template()({
460
+ sensors: this.sensorInfo.toJSON()
461
+ }));
462
+ },
463
+ selectedSensors: function() {
464
+ var checked, ids, selected;
465
+ checked = _.filter(this.$el.find('.sensor-box'), function(el) {
466
+ return $(el).is(':checked');
467
+ });
468
+ ids = {};
469
+ _.each(checked, function(box) {
470
+ return ids[box.id] = true;
471
+ });
472
+ return selected = this.sensorInfo.filter(function(sensor) {
473
+ return ids[sensor.id];
474
+ });
475
+ }
476
+ });
477
+ var DynamicChartView;
478
+
479
+ DynamicChartView = Backbone.View.extend({
480
+ initialize: function(options) {
481
+ this.pageInfos = options['pageInfos'];
482
+ this.sensors = [];
483
+ this.type = 'Area';
484
+ this.widget = new DynamicWidget;
485
+ this.widget.bind('destroy', this.remove, this);
486
+ return this.widget.bind('redraw', this.redrawChart, this);
487
+ },
488
+ tagName: 'div',
489
+ events: {
490
+ "click #refresh-chart": 'update',
491
+ "click #extend-timespan": 'extendTimespan',
492
+ "click #reset-timespan": 'resetTimespan',
493
+ "change #start-time input": 'maybeEnableStopTime',
494
+ "click #set-interval": 'setTimelineInterval'
495
+ },
496
+ template: function() {
497
+ return _.template($("#dynamic-widget-plotarea").html());
498
+ },
499
+ chartContainerTemplate: '<div id="chart"></div><div id="legend"></div>',
500
+ render: function() {
501
+ this.$el.html(this.template()());
502
+ return this.initDatePickers();
503
+ },
504
+ initDatePickers: function() {
505
+ this.$el.find(".datepicker").each(function(i) {
506
+ return $(this).datetimepicker({
507
+ showOtherMonths: true,
508
+ selectOtherMonths: true
509
+ });
510
+ });
511
+ return this.$el.find("#end-time input").prop("disabled", true);
512
+ },
513
+ setTimelineInterval: function() {
514
+ var end, start;
515
+ start = this.unixtimeFromDatepicker("#start-time input");
516
+ end = this.unixtimeFromDatepicker("#end-time input");
517
+ this.widget.setStartTime(start);
518
+ this.widget.setEndTime(end);
519
+ return this.update();
520
+ },
521
+ dateFromDatepicker: function(id) {
522
+ return this.$el.find(id).datetimepicker("getDate");
523
+ },
524
+ unixtimeFromDatepicker: function(id) {
525
+ var date;
526
+ date = this.dateFromDatepicker(id);
527
+ if (date) {
528
+ return date.getTime() / 1000;
529
+ } else {
530
+ return null;
531
+ }
532
+ },
533
+ maybeEnableStopTime: function() {
534
+ var date, disabled;
535
+ date = this.dateFromDatepicker("#start-time input");
536
+ disabled = date ? false : true;
537
+ return this.$el.find("#end-time input").prop("disabled", disabled);
538
+ },
539
+ extendTimespan: function() {
540
+ var select, val;
541
+ select = this.$el.find("#extend-timespan-val");
542
+ val = select.first().val();
543
+ this.widget.increaseTimespan(parseInt(val));
544
+ return this.update();
545
+ },
546
+ resetTimespan: function() {
547
+ this.widget.resetTimespan();
548
+ return this.update();
549
+ },
550
+ sensorIds: function() {
551
+ return _.map(this.sensors, function(s) {
552
+ return s.id;
553
+ });
554
+ },
555
+ redrawChart: function() {
556
+ if (this.presenter) {
557
+ return this.presenter.draw();
558
+ } else {
559
+ return this.presenter = WidgetPresenter.create(this.pageInfos, this.widget, this.chartContainer());
560
+ }
561
+ },
562
+ chartContainer: function() {
563
+ return $(this.$el.find('#chart-widget')[0]);
564
+ },
565
+ update: function() {
566
+ if (this.sensors.length > 0) {
567
+ return this.widget.forceUpdate();
568
+ }
569
+ },
570
+ draw: function(sensors, type) {
571
+ this.sensors = sensors;
572
+ this.type = type;
573
+ this.widget.set('sensorIds', this.sensorIds());
574
+ this.widget.set('type', this.type);
575
+ this.presenter = null;
576
+ this.chartContainer().html(this.chartContainerTemplate);
577
+ return this.widget.forceUpdate();
578
+ }
579
+ });
580
+ var DynamicWidgetView;
581
+
582
+ DynamicWidgetView = Backbone.View.extend({
583
+ tagName: 'div',
584
+ initialize: function(options) {
585
+ this.pageInfos = options['pageInfos'];
586
+ this.sensorInfo = new SensorInfoList;
587
+ this.sensorListView = new SensorInfoListView(this.sensorInfo);
588
+ this.chartView = new DynamicChartView({
589
+ pageInfos: this.pageInfos
590
+ });
591
+ this.$el.html(this.template()());
592
+ this.$el.find('#sensor-list-area').append(this.sensorListView.el);
593
+ this.chartView.render();
594
+ return this.$el.find('#dynamic-plotarea').append(this.chartView.el);
595
+ },
596
+ events: {
597
+ "click #sensor-controls #refresh": 'refresh',
598
+ "click #sensor-controls #draw": 'drawChart'
599
+ },
600
+ template: function() {
601
+ return _.template($("#dynamic-widget").html());
602
+ },
603
+ errorTemplate: function() {
604
+ return _.template($("#dynamic-widget-error").html());
605
+ },
606
+ error: function(error) {
607
+ return this.$el.find('#errors').append(this.errorTemplate()({
608
+ error: error
609
+ }));
610
+ },
611
+ refresh: function() {
612
+ return this.sensorInfo.fetch();
613
+ },
614
+ intervalsEqual: function(sensors) {
615
+ var badIntervals, interval;
616
+ interval = sensors[0].get('interval');
617
+ badIntervals = _.filter(sensors, function(s) {
618
+ return s.get('interval') !== interval;
619
+ });
620
+ return badIntervals.length === 0;
621
+ },
622
+ drawChart: function() {
623
+ var selectedSensors, type;
624
+ selectedSensors = this.sensorListView.selectedSensors();
625
+ if (!(selectedSensors.length > 0)) {
626
+ return;
627
+ }
628
+ if (!this.intervalsEqual(selectedSensors)) {
629
+ this.error('Selected sensors have different intervals');
630
+ return;
631
+ }
632
+ type = this.$el.find('#chart-type').val();
633
+ return this.chartView.draw(selectedSensors, type);
634
+ },
635
+ render: function(container) {
636
+ container.empty();
637
+ container.append(this.$el);
638
+ this.sensorInfo.fetch();
639
+ return this.chartView.update();
640
+ }
641
+ });
642
+ var WidgetChartView;
643
+
644
+ WidgetChartView = Backbone.View.extend({
645
+ tagName: 'div',
646
+ template: '<div id="chart"></div><div id="legend"></div>',
647
+ initialize: function(options) {
648
+ this.$el.html(this.template);
649
+ this.pageInfos = options['pageInfos'];
650
+ return this.model.bind('destroy', this.remove, this);
651
+ },
652
+ updateData: function() {
653
+ return this.presenter.draw();
654
+ },
655
+ render: function() {
656
+ return this.presenter = WidgetPresenter.create(this.pageInfos, this.model, this.$el);
657
+ }
658
+ });
659
+ var WidgetView;
660
+
661
+ WidgetView = Backbone.View.extend({
662
+ tagName: 'div',
663
+ template: function(args) {
664
+ return _.template($(".widget-template[data-widget-type=\"" + (this.model.get('type')) + "\"]").html())(args);
665
+ },
666
+ initialize: function(options) {
667
+ this.pageInfos = options['pageInfos'];
668
+ this.model.bind('destroy', this.remove, this);
669
+ return this.model.bind('redraw', this.updateChart, this);
670
+ },
671
+ events: {
672
+ "click #refresh": 'refresh',
673
+ "click #need-refresh": 'setRefresh',
674
+ "click #extend-timespan": 'extendTimespan',
675
+ "click #reset-timespan": 'resetTimespan',
676
+ "change #start-time input": 'maybeEnableStopTime',
677
+ "click #set-interval": 'setTimelineInterval'
678
+ },
679
+ refresh: function() {
680
+ return this.model.forceUpdate();
681
+ },
682
+ setRefresh: function() {
683
+ var needRefresh;
684
+ needRefresh = this.$el.find('#need-refresh').is(":checked");
685
+ this.model.setRefresh(needRefresh);
686
+ return true;
687
+ },
688
+ extendTimespan: function() {
689
+ var select, val;
690
+ select = this.$el.find("#extend-timespan-val");
691
+ val = select.first().val();
692
+ return this.model.increaseTimespan(parseInt(val));
693
+ },
694
+ setTimelineInterval: function() {
695
+ var end, start;
696
+ start = this.unixtimeFromDatepicker("#start-time input");
697
+ end = this.unixtimeFromDatepicker("#end-time input");
698
+ this.model.setStartTime(start);
699
+ return this.model.setEndTime(end);
700
+ },
701
+ maybeEnableStopTime: function() {
702
+ var date, disabled;
703
+ date = this.dateFromDatepicker("#start-time input");
704
+ disabled = date ? false : true;
705
+ return this.$el.find("#end-time input").prop("disabled", disabled);
706
+ },
707
+ resetTimespan: function() {
708
+ return this.model.resetTimespan();
709
+ },
710
+ renderChart: function() {
711
+ return this.chartView.render();
712
+ },
713
+ updateChart: function() {
714
+ return this.chartView.updateData();
715
+ },
716
+ setIds: function() {
717
+ this.$el.find('#configure-button').prop('href', "#configure-" + this.model.id);
718
+ this.$el.find('#configure').attr('id', "configure-" + this.model.id);
719
+ this.$el.find('#start-time input').attr('id', "start-time-" + this.model.id);
720
+ return this.$el.find('#end-time input').attr('id', "end-time-" + this.model.id);
721
+ },
722
+ render: function() {
723
+ this.$el.html(this.template(this.model.toJSON()));
724
+ this.setIds();
725
+ this.chartView = new WidgetChartView({
726
+ pageInfos: this.pageInfos,
727
+ model: this.model
728
+ });
729
+ this.$el.find("#plotarea").append(this.chartView.el);
730
+ this.$el.addClass("span" + (this.model.get('width')));
731
+ return this.initDatePickers();
732
+ },
733
+ initDatePickers: function() {
734
+ this.$el.find(".datepicker").each(function(i) {
735
+ return $(this).datetimepicker({
736
+ showOtherMonths: true,
737
+ selectOtherMonths: true
738
+ });
739
+ });
740
+ return this.$el.find("#end-time input").prop("disabled", true);
741
+ },
742
+ controlValue: function(id) {
743
+ var val;
744
+ return val = this.$el.find(id).first().val();
745
+ },
746
+ dateFromDatepicker: function(id) {
747
+ return this.$el.find(id).datetimepicker("getDate");
748
+ },
749
+ unixtimeFromDatepicker: function(id) {
750
+ var date;
751
+ date = this.dateFromDatepicker(id);
752
+ if (date) {
753
+ return date.getTime() / 1000;
754
+ } else {
755
+ return null;
756
+ }
757
+ }
758
+ });
759
+ var WidgetListView;
760
+
761
+ WidgetListView = Backbone.View.extend({
762
+ initialize: function(options) {
763
+ this.widgetList = options['widgetList'];
764
+ this.pageInfos = options['pageInfos'];
765
+ return this.widgetList.bind('reset', this.render, this);
766
+ },
767
+ render: function() {
768
+ var container,
769
+ _this = this;
770
+ container = $('#widgets');
771
+ container.empty();
772
+ return this.widgetList.each(function(w) {
773
+ var view;
774
+ view = new WidgetView({
775
+ pageInfos: _this.pageInfos,
776
+ model: w
777
+ });
778
+ view.render();
779
+ container.append(view.el);
780
+ return view.renderChart();
781
+ });
782
+ }
783
+ });
784
+ var AppRouter;
785
+
786
+ AppRouter = Backbone.Router.extend({
787
+ initialize: function(pageInfos, widgetList) {
788
+ this.pageInfos = pageInfos;
789
+ this.widgetList = widgetList;
790
+ },
791
+ routes: {
792
+ 'pages/:id': 'getPage',
793
+ 'custom': 'custom',
794
+ '*actions': 'defaultRoute'
795
+ },
796
+ getPage: function(ids) {
797
+ var id;
798
+ id = parseInt(ids);
799
+ this.pageInfos.selectPage(id);
800
+ return this.widgetList.fetch();
801
+ },
802
+ custom: function() {
803
+ var dynamicWidget;
804
+ this.pageInfos.selectNone();
805
+ dynamicWidget = new DynamicWidgetView({
806
+ pageInfos: this.pageInfos
807
+ });
808
+ return dynamicWidget.render($('#widgets'));
809
+ },
810
+ defaultRoute: function(actions) {
811
+ if (this.pageInfos.length > 0) {
812
+ return this.navigate('//pages/1');
813
+ } else {
814
+ return this.navigate('//custom');
815
+ }
816
+ }
817
+ });
818
+
819
+ document.startApp = function() {
820
+ var appRouter, pageInfos, pageTitlesApp, widgetList, widgetListApp;
821
+ pageInfos = new PageInfoList;
822
+ pageTitlesApp = new PageTitlesView(pageInfos);
823
+ pageInfos.reset(gon.pageInfos);
824
+ widgetList = new WidgetList;
825
+ widgetList.setContext(pageInfos);
826
+ widgetList.startPolling();
827
+ widgetListApp = new WidgetListView({
828
+ widgetList: widgetList,
829
+ pageInfos: pageInfos
830
+ });
831
+ appRouter = new AppRouter(pageInfos, widgetList);
832
+ return Backbone.history.start();
833
+ };