1
- // require 'timesheet.bubble'
2
-
3
1
/* global TimesheetBubble */
4
2
5
3
( function ( ) {
33
31
34
32
for ( var n = 0 , m = this . data . length ; n < m ; n ++ ) {
35
33
var cur = this . data [ n ] ;
36
- var bubble = new TimesheetBubble ( widthMonth , this . year . min , cur . start , cur . end ) ;
34
+ var bubble = new Bubble ( widthMonth , this . year . min , cur . start , cur . end ) ;
37
35
38
36
var line = [
39
37
'<span style="margin-left: ' + bubble . getStartOffset ( ) + 'px; width: ' + bubble . getWidth ( ) + 'px;" class="bubble bubble-' + ( cur . type || 'default' ) + '" data-duration="' + ( cur . end ? Math . round ( ( cur . end - cur . start ) / 1000 / 60 / 60 / 24 / 39 ) : '' ) + '"></span>' ,
100
98
this . data . push ( { start : beg , end : end , label : lbl , type : cat } ) ;
101
99
}
102
100
} ;
101
+
102
+ /**
103
+ * Timesheet Bubble
104
+ */
105
+ var Bubble = function ( wMonth , min , start , end ) {
106
+ this . min = min ;
107
+ this . start = start ;
108
+ this . end = end ;
109
+ this . widthMonth = wMonth ;
110
+ } ;
111
+
112
+ /**
113
+ * Format month number
114
+ */
115
+ Bubble . prototype . formatMonth = function ( num ) {
116
+ num = parseInt ( num , 10 ) ;
117
+
118
+ return num >= 10 ? num : '0' + num ;
119
+ } ;
120
+
121
+ /**
122
+ * Calculate starting offset for bubble
123
+ */
124
+ Bubble . prototype . getStartOffset = function ( ) {
125
+ return ( this . widthMonth / 12 ) * ( 12 * ( this . start . getFullYear ( ) - this . min ) + this . start . getMonth ( ) ) ;
126
+ } ;
127
+
128
+ /**
129
+ * Get count of full years from start to end
130
+ */
131
+ Bubble . prototype . getFullYears = function ( ) {
132
+ return ( ( this . end && this . end . getFullYear ( ) ) || this . start . getFullYear ( ) ) - this . start . getFullYear ( ) ;
133
+ } ;
134
+
135
+ /**
136
+ * Get count of all months in Timesheet Bubble
137
+ */
138
+ Bubble . prototype . getMonths = function ( ) {
139
+ var fullYears = this . getFullYears ( ) ;
140
+ var months = 0 ;
141
+
142
+ if ( ! this . end ) {
143
+ months += ! this . start . hasMonth ? 12 : 1 ;
144
+ } else {
145
+ if ( ! this . end . hasMonth ) {
146
+ months += 12 - ( this . start . hasMonth ? this . start . getMonth ( ) : 0 ) ;
147
+ months += 12 * ( fullYears - 1 > 0 ? fullYears - 1 : 0 ) ;
148
+ } else {
149
+ months += this . end . getMonth ( ) + 1 ;
150
+ months += 12 - ( this . start . hasMonth ? this . start . getMonth ( ) : 0 ) ;
151
+ months += 12 * ( fullYears - 1 ) ;
152
+ }
153
+ }
154
+
155
+ return months ;
156
+ } ;
157
+
158
+ /**
159
+ * Get bubble's width in pixel
160
+ */
161
+ Bubble . prototype . getWidth = function ( ) {
162
+ return ( this . widthMonth / 12 ) * this . getMonths ( ) ;
163
+ } ;
164
+
165
+ /**
166
+ * Get the bubble's label
167
+ */
168
+ Bubble . prototype . getDateLabel = function ( ) {
169
+ return [
170
+ ( this . start . hasMonth ? this . formatMonth ( this . start . getMonth ( ) + 1 ) + '/' : '' ) + this . start . getFullYear ( ) ,
171
+ ( this . end ? '-' + ( ( this . end . hasMonth ? this . formatMonth ( this . end . getMonth ( ) + 1 ) + '/' : '' ) + this . end . getFullYear ( ) ) : '' )
172
+ ] . join ( '' ) ;
173
+ } ;
103
174
104
175
window . Timesheet = Timesheet ;
105
- } ) ( ) ;
176
+ } ) ( ) ;
0 commit comments