rsence-pre 3.0.0.12 → 3.0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,210 +0,0 @@
1
-
2
- /*** = Description
3
- ** Item class to be used with HTimeSheet.
4
- ***/
5
- var//RSence.DateTime
6
- HTimeSheetItem = HControl.extend({
7
-
8
- componentName: 'timesheet_item',
9
- markupElemNames: ['bg', 'label', 'state', 'icons', 'value', 'subview'],
10
-
11
- controlDefaults: HControlDefaults.extend({
12
- displayTime: true,
13
- iconImage: 'timesheet_item_icons.png'
14
- }),
15
-
16
- drawIcon: function( _iconOrder, _iconId ){
17
- var
18
- _iconElemId = ELEM.make( this.markupElemIds.icons, 'div' ),
19
- _iconUrl = this.getThemeGfxFile(this.options.iconImage);
20
- ELEM.addClassName( _iconElemId, 'timesheet_item_icon' );
21
- ELEM.setStyles( _iconElemId, {
22
- right: ((_iconOrder*16)+_iconOrder)+'px',
23
- backgroundPosition: '0px '+(_iconId*-16)+'px',
24
- backgroundImage: 'url('+_iconUrl+')'
25
- } );
26
- return _iconElemId;
27
- },
28
-
29
- clearAllIcons: function(){
30
- if(this.icons instanceof Array){
31
- for( var i=0; i < this.icons.length; i++ ){
32
- ELEM.del( this.icons[i] );
33
- }
34
- }
35
- this.icons = [];
36
- },
37
-
38
- die: function(){
39
- this.clearAllIcons();
40
- this.icons = null;
41
- this.base();
42
- },
43
-
44
- refreshState: function( _start, _duration ){
45
- if(!this.options.displayTime){
46
- return;
47
- }
48
- var
49
- _startTime = _start || this.value.start,
50
- _endTime = _startTime + ( _duration || this.value.duration ),
51
- _locale = HLocale.dateTime,
52
- _stateText = _locale.formatTime( _startTime ) + _locale.strings.rangeDelimitter + _locale.formatTime( _endTime );
53
- ELEM.setHTML( this.markupElemIds.state, _stateText );
54
- },
55
-
56
- refreshValue: function(){
57
- if ( !(this.value instanceof Object) ){
58
- return;
59
- }
60
- this.drawRect();
61
- if ( this.value.color ) {
62
- this.setStyleOfPart( 'bg', 'background-color', this.value.color );
63
- }
64
- else {
65
- this.setStyleOfPart( 'bg', 'background-color', '#999' );
66
- }
67
- if ( this.value.label ) {
68
- this.setLabel( this.value.label );
69
- }
70
- if ( this.value.locked ) {
71
- ELEM.addClassName( this.elemId, 'locked' );
72
- }
73
- else {
74
- ELEM.delClassName( this.elemId, 'locked' );
75
- }
76
- this.refreshState();
77
- this.clearAllIcons();
78
- if( this.value.icons instanceof Array ){
79
- for( var i = 0; i < this.value.icons.length; i++ ){
80
- this.icons.push( this.drawIcon( i, this.value.icons[i] ) );
81
- }
82
- }
83
- },
84
-
85
- click: function(){
86
- this.bringToFront();
87
- },
88
-
89
- doubleClick: function( x, y ){
90
- this.bringToFront();
91
- var _time = this.parent.pxToTime( y-this.parent.pageY() );
92
- this.parent.activateEditor( this );
93
- },
94
-
95
- dragMode: 0, // none
96
- _isValueValidForDrag: function(){
97
- return (this.value instanceof Object) && (!this.value.locked);
98
- },
99
- startDrag: function( x, y ){
100
- this.bringToFront();
101
- if( this._isValueValidForDrag() ){
102
- var
103
- _topY = y-this.pageY(),
104
- _bottomY = this.rect.height - _topY,
105
- _resizeTop = ( _topY >= 0 && _topY <= 6 ),
106
- _resizeBottom = ( _bottomY >= 0 && _bottomY <= 6 ),
107
- _move = ( _topY > 6 && _bottomY > 6 );
108
- if( _resizeTop ){
109
- this.dragMode = 2; // resize-top
110
- }
111
- else if ( _resizeBottom ){
112
- this.dragMode = 3; // resize-bottom
113
- }
114
- else if ( _move ){
115
- this.dragMode = 1; // move
116
- }
117
- else {
118
- this.dragMode = 0; // none
119
- }
120
- if( this.dragMode === 0 ){
121
- this.originY = false;
122
- }
123
- else {
124
- var
125
- _originY = y-this.parent.pageY(),
126
- _parentY = this.parent.pageY(),
127
- _originTimeStart = this.value.start,
128
- _originTimeEnd = _originTimeStart + this.value.duration;
129
- this.originY = _originY;
130
- this.originTopPx = this.rect.top;
131
- this.originBottomPx = this.rect.bottom;
132
- this.originTimeStart = _originTimeStart;
133
- this.originTimeEnd = _originTimeEnd;
134
- this.originDuration = _originTimeEnd - _originTimeStart;
135
- this.dragTimeStart = _originTimeStart;
136
- this.dragDuration = this.originDuration;
137
- }
138
- }
139
- },
140
-
141
- drag: function( x, y ){
142
- if( this._isValueValidForDrag() && (this.dragMode !== 0) ){
143
- y -= this.parent.pageY();
144
- var
145
- _movePx = y - this.originY,
146
- _topPx = this.parent.snapPx( this.originTopPx + _movePx ),
147
- _parentY = this.parent.pageY(),
148
- _bottomPx, _minBottomPx, _maxBottomPx, _maxTopPx, _timeStart, _timeEnd, _duration;
149
- if( this.dragMode === 1 ){ // move
150
- _maxTopPx = this.parent.timeToPx( this.parent.options.timeEnd ) - this.rect.height;
151
- if( _topPx > _maxTopPx ){
152
- _topPx = _maxTopPx;
153
- }
154
- _timeStart = this.parent.pxToTime(_topPx);
155
- _duration = this.originDuration;
156
- this.rect.offsetTo( this.rect.left, _topPx );
157
- this.drawRect();
158
- this.dragTimeStart = _timeStart;
159
- this.dragDuration = _duration;
160
- }
161
- else if( this.dragMode === 2 ){ // resize-top
162
- _maxTopPx = this.parent.timeToPx( this.originTimeEnd - this.parent.minDuration );
163
- if( _topPx > _maxTopPx ){
164
- _topPx = _maxTopPx;
165
- }
166
- _timeStart = this.parent.pxToTime(_topPx);
167
- _timeEnd = this.originTimeEnd;
168
- if( (this.rect.bottom - _topPx) < this.parent.options.itemMinHeight ){
169
- _topPx = this.rect.bottom - this.parent.options.itemMinHeight;
170
- }
171
- this.rect.setTop( _topPx );
172
- this.drawRect();
173
- this.dragTimeStart = _timeStart;
174
- this.dragDuration = _timeEnd - _timeStart;
175
- }
176
- else if( this.dragMode === 3 ){ // resize-top
177
- _minBottomPx = this.parent.timeToPx( this.originTimeStart + this.parent.minDuration );
178
- _bottomPx = this.parent.snapPx( this.originBottomPx + _movePx );
179
- if( _bottomPx < _minBottomPx ){
180
- _bottomPx = _minBottomPx;
181
- }
182
- _timeStart = this.originTimeStart;
183
- _timeEnd = this.parent.pxToTime(_bottomPx);
184
- if( _bottomPx - this.rect.top < this.parent.options.itemMinHeight ){
185
- _bottomPx = this.rect.top + this.parent.options.itemMinHeight;
186
- }
187
- this.rect.setBottom( _bottomPx );
188
- this.drawRect();
189
- this.dragTimeStart = _timeStart;
190
- this.dragDuration = _timeEnd - _timeStart;
191
- }
192
- this.refreshState( this.dragTimeStart, this.dragDuration );
193
- }
194
- },
195
-
196
- endDrag: function( x, y ){
197
- if( this._isValueValidForDrag() && (this.dragMode !== 0) ){
198
- var
199
- _startChanged = ( this.dragTimeStart !== this.originTimeStart ) && ( this.dragTimeStart !== this.value.start ),
200
- _durationChanged = ( this.dragDuration !== this.originDuration ) && ( this.dragDuration !== this.value.duration );
201
- if( _startChanged || _durationChanged ){
202
- if( this.parent.editor ){
203
- var _modValue = { id: this.value.id, start: this.dragTimeStart, duration: this.dragDuration, label: this.value.label };
204
- this.parent.editor.modifyItem( _modValue );
205
- }
206
- }
207
- }
208
- }
209
-
210
- });