123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264/// FOURJS_START_COPYRIGHT(D,2015)
/// Property of Four Js*
/// (c) Copyright Four Js 2015, 2024. All Rights Reserved.
/// * Trademark of Four Js Development Tools Europe Ltd
/// in the United States and elsewhere
///
/// This file can be modified by licensees according to the
/// product manual.
/// FOURJS_END_COPYRIGHT
'use strict';
modulum('TimeEditWidgetBase', ['FieldWidgetBase', 'WidgetFactory'],
function(context, cls) {
/**
* TimeEdit widget Base class.
* @class TimeEditWidgetBase
* @memberOf classes
* @extends classes.FieldWidgetBase
* @publicdoc Widgets
*/
cls.TimeEditWidgetBase = context.oo.Class(cls.FieldWidgetBase, function($super) {
return /** @lends classes.TimeEditWidgetBase.prototype */ {
__name: 'TimeEditWidgetBase',
/**
* Active/disable seconds for the widget. By default yes.
* @type {boolean}
*/
_useSeconds: true,
/**
* Redefine where the data is located
* @type {string}
*/
__dataContentPlaceholderSelector: '.gbc_dataContentPlaceholder',
/**
* Maximum number of characters allowed. By default -1 indicates no limit.
* @type {number}
*/
_maxLength: -1,
/**
* Format of TIMEEDIT (hh:mm or hh:mm:ss)
* @type {string}
*/
_displayFormat: null,
/**
* @inheritDoc
*/
constructor: function(opts) {
$super.constructor.call(this, opts);
this.setFocusable(true);
},
/**
* @inheritDoc
*/
_initLayout: function() {
if (!this._ignoreLayout) {
this._layoutInformation = new cls.LayoutInformation(this);
this._layoutEngine = new cls.LeafLayoutEngine(this);
this._layoutInformation.setSingleLineContentOnly(true);
}
},
/**
* @inheritDoc
*/
setTextAlign: function(align) {
$super.setTextAlign.call(this, align);
this.setStyle('input', {
'text-align': align
});
},
/**
* Set Default TTF color
* @param {string} color - rgb formatted or css name
*/
setDefaultTTFColor: function(color) {
this.setStyle(".gbc_TimeEditWidget_arrows", {
'color': color
});
},
/**
* @inheritDoc
*/
getTextDecoration: function() {
return this.getStyle('input', 'text-decoration');
},
/**
* @inheritDoc
*/
setTextDecoration: function(decoration) {
this.setStyle('input', {
'text-decoration': decoration
});
},
/**
* @inheritDoc
*/
setTitle: function(title) {
this._inputElement.setAttribute('title', title);
},
/**
* @inheritDoc
*/
getTitle: function() {
return this._inputElement.getAttribute('title');
},
/**
* @inheritDoc
*/
setValue: function(value, fromVM) {
$super.setValue.call(this, value, fromVM);
if (this.getValue() !== value) {
this._setTimeAccuracy(value);
this._inputElement.value = value;
}
},
/**
* Detect if seconds are defined in value or in format and set class variable
* @param value
* @protected
*/
_setTimeAccuracy: function(value) {
var groups = value.split(':');
if (groups.length === 1) { // no ':'' detected, we look for varType
this._useSeconds = !this.getDisplayFormat() || !this.getDisplayFormat().endsWith("MINUTE");
} else {
this._useSeconds = groups.length === 3;
}
},
/**
* @inheritDoc
*/
getValue: function() {
return this._inputElement.value;
},
/**
* @inheritDoc
*/
setEnabled: function(enabled) {
$super.setEnabled.call(this, enabled);
this._setInputReadOnly(!enabled);
},
/**
* @inheritDoc
*/
setReadOnly: function(readonly) {
$super.setReadOnly.call(this, readonly);
this._setInputReadOnly(readonly);
},
/**
* Set input readonly attribute if it doesn't have focus or is noentry.
* @param {boolean} readonly - true to set the edit part as read-only, false otherwise
*/
_setInputReadOnly: function(readonly) {
if (readonly) {
this._inputElement.setAttribute('readonly', 'readonly');
} else {
this._inputElement.removeAttribute('readonly');
}
},
/**
* @inheritDoc
*/
setFocus: function(fromMouse) {
$super.setFocus.call(this, fromMouse);
this._inputElement.domFocus();
},
/**
* Returns if max length of the widget has been reached
* @returns {boolean} return true if max length is reached in input element
*/
_isMaxLength: function() {
return this._maxLength !== -1 && this._inputElement.value.length >= this._maxLength &&
this._inputElement.selectionStart === this._inputElement.selectionEnd;
},
/**
* Define the maximum number of characters allowed
* @param {number} maxlength - maximum number of characters allowed in the field
* @publicdoc
*/
setMaxLength: function(maxlength) {
if (maxlength) {
this._maxLength = maxlength;
this._setElementAttribute('maxlength', maxlength, "_inputElement");
}
},
/**
* Get the maximum number of characters allowed
* @returns {number} the maximum number of characters allowed in the field
* @publicdoc
*/
getMaxLength: function() {
return this._maxLength;
},
/**
* Get the timeedit format (hh:mm or hh:mm:ss)
* @return {?string} timeedit format
* @publicdoc
*/
getDisplayFormat: function() {
return this._displayFormat;
},
/**
* Set timeedit format (hh:mm or hh:mm:ss)
* @param {string} format - format
* @publicdoc
*/
setDisplayFormat: function(format) {
this._displayFormat = format;
this._setTimeAccuracy(this.getValue());
},
/**
* @inheritDoc
*/
getClipboardValue: function(ignoreSelection) {
if (ignoreSelection) {
return this.getValue();
}
var txt = cls.ClipboardHelper.getSelection();
return txt.length > 0 ? txt : null;
},
/**
* @inheritDoc
*/
getClipboardAuthorizedAction: function() {
return {
paste: false,
copy: true,
cut: false
};
}
};
});
});