js/datetime/timesheet_item/timesheet_item.js in rsence-2.1.1 vs js/datetime/timesheet_item/timesheet_item.js in rsence-2.1.2
- old
+ new
@@ -9,15 +9,29 @@
/*** = Description
** Item class to be used with HTimeSheet.
***/
var//RSence.DateTime
HTimeSheetItem = HControl.extend({
+
componentName: 'timesheet_item',
+
+ /* Which mode the component is in. When created by dragging, acts in 'create' mode, otherwise is 'normal'. Can be overridden in options. */
dragMode: 'create',
+
+ /* The previous coordinate. Used to detect double-drag as double-click. */
prevXY: [0,0],
+
+ /* The time at the previous coordinate. Used to detect double-drag as double-click. */
prevXYTime: 0,
+ controlDefaults: HControlDefaults.extend({
+ dragMode: 'create',
+ constructor: function(_ctrl){
+ _ctrl.dragMode = this.dragMode;
+ }
+ }),
+
/** = Description
* Dragging is used to change coordinates.
*
* = Parameters
* +x+:: X coordinate at the start of drag.
@@ -29,11 +43,11 @@
if(this.dragMode === 'normal'){
var _timeNow = new Date().getTime(),
_xEquals = (Math.round(this.prevXY[0]/4) === Math.round(x/4)),
_yEquals = (Math.round(this.prevXY[1]/4) === Math.round(y/4)),
_noTimeout = ((_timeNow - this.prevXYTime) < 500);
- if( _xEquals && _yEquals && _noTimeout ) {
+ if( _xEquals && _yEquals && _noTimeout ) { // doubleClick
if( this.parent['editor'] ){
var _editor = this.parent.editor;
_editor.setTimeSheetItem(this);
_editor.bringToFront();
_editor.show();
@@ -205,42 +219,63 @@
endDrag: function(x,y){
var _pxPerHour = Math.floor(this.parent.pxPerHour),
_value;
if(this.dragMode === 'create'){
this.parent.listItemViews.push( this );
- _value = {
- 'timeBegin': this.rect.top/_pxPerHour,
- 'timeEnd': this.rect.bottom/_pxPerHour,
- 'label': this.label
- };
+ _value = {};
+ this._setValueTop( _value );
+ this._setValueBottom( _value );
+ this._setValueLabel( _value );
if(this.parent['editor']){
this.parent.editor.createItem( _value );
}
}
else {
_value = COMM.Values.clone( this.value );
- _value['timeBegin'] = this.rect.top/_pxPerHour;
- _value['timeEnd'] = this.rect.bottom/_pxPerHour;
+ this._setValueTop( _value );
+ this._setValueBottom( _value );
if(this.parent['editor']){
this.parent.editor.modifyItem( _value );
}
}
this.setValue( _value );
this.dragMode = 'normal';
return true;
},
+ _setValueTop: function( _value ) {
+ _value['timeBegin'] = this.rect.top/this.parent.pxPerHour;
+ },
+
+ _setValueBottom: function( _value ) {
+ _value['timeEnd'] = this.rect.bottom/this.parent.pxPerHour;
+ },
+
+ _setValueLabel: function( _value ) {
+ _value['label'] = this.label;
+ },
+
+ _getValueLabel: function( _value ){
+ return _value.label;
+ },
+
+ _getValueTop: function( _value ){
+ return _value.timeBegin * this.parent.pxPerHour;
+ },
+
+ _getValueBottom: function( _value ){
+ return _value.timeEnd * this.parent.pxPerHour;
+ },
+
/** = Description
* Refreshes the object's label and place on the HTimeSheet.
*
**/
refreshValue: function(){
- var _value = this.value,
- _pxPerHour = this.parent.pxPerHour;
- if((_value instanceof Object) && !(_value instanceof Array)){
- this.setLabel( _value['label'] );
- this.rect.setTop( _value['timeBegin'] * _pxPerHour );
- this.rect.setBottom( _value['timeEnd'] * _pxPerHour );
+ if ( HVM.type(this.value) === 'h' ){
+ this.setLabel( this._getValueLabel( this.value ) );
+ this.rect.setTop( this._getValueTop( this.value ) );
+ this.rect.setBottom( this._getValueBottom( this.value ) );
this.drawRect();
}
}
});