%PDF- %PDF-
| Direktori : /proc/self/root/proc/self/root/home/bitrix/www/bitrix/js/landing/ui/field/ |
| Current File : //proc/self/root/proc/self/root/home/bitrix/www/bitrix/js/landing/ui/field/date_field.js |
;(function() {
"use strict";
BX.namespace("BX.Landing.UI.Field");
var create = BX.Landing.Utils.create;
var bind = BX.Landing.Utils.bind;
var fireCustomEvent = BX.Landing.Utils.fireCustomEvent;
var FORMAT_SECONDS = "s";
var FORMAT_MILLISECONDS = "ms";
/**
* Implements interface for works with date field
*
* @extends {BX.Landing.UI.Field.BaseField}
*
* @inheritDoc
* @constructor
*/
BX.Landing.UI.Field.Date = function(data)
{
data.textOnly = true;
BX.Landing.UI.Field.BaseField.apply(this, arguments);
this.format = data.format === FORMAT_SECONDS ||
data.format === FORMAT_MILLISECONDS ? data.format : FORMAT_SECONDS;
this.time = data.time === true;
this.hiddenInput = create("input", {props: {type: "hidden"}, value: data.content});
bind(this.input, "click", this.onInputClick.bind(this));
this.setValue(this.formatDateToValue(data.content));
};
BX.Landing.UI.Field.Date.prototype = {
constructor: BX.Landing.UI.Field.Date,
__proto__: BX.Landing.UI.Field.BaseField.prototype,
/**
* Handles input click event
*/
onInputClick: function()
{
var params = {
node: this.input,
field: this.hiddenInput,
bTime: this.time,
value: BX.date.format(this.getFormat(), new Date(this.formatDateToValue(this.hiddenInput.value) * 1000)),
bHideTime: !this.time,
callback_after: function(date) {
this.setValue(date.getTime() / 1000);
}.bind(this)
};
return BX.calendar(params);
},
getFormat: function()
{
return BX.date.convertBitrixFormat(BX.message(this.time ? "FORMAT_DATETIME" : "FORMAT_DATE"));
},
reset: function()
{
this.setValue("");
},
/**
* @param {Integer|string} value - timestamp in seconds
*/
setValue: function(value)
{
this.input.innerText = BX.date.format(this.getFormat(), new Date(value * 1000));
this.hiddenInput.value = this.formatValue(value);
this.onValueChangeHandler(this);
fireCustomEvent(this, "BX.Landing.UI.Field:change", [this.getValue()]);
},
/**
* Format seconds
* @param value
* @return {integer}
*/
formatValue: function(value)
{
switch (this.format)
{
case FORMAT_SECONDS:
return value;
case FORMAT_MILLISECONDS:
return value * 1000;
default:
break;
}
},
/**
* To seconds
* @param formattedValue
* @return {*}
*/
formatDateToValue: function(formattedValue)
{
switch (this.format)
{
case FORMAT_SECONDS:
return formattedValue;
case FORMAT_MILLISECONDS:
return formattedValue / 1000;
default:
break;
}
},
getValue: function()
{
return this.formatValue(this.formatDateToValue(this.hiddenInput.value));
}
}
})();