Skip to content
Code-Schnipsel Gruppen Projekte
Commit d9fb6b04 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

Merge branch 'dev' of dev.quiqqer.com:quiqqer/shipping into dev

Übergeordnete 9927a3c7 8734134e
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
......@@ -8,4 +8,13 @@
.quiqqer-shipping-fields-shippingtimeperiod select {
width: 100%;
}
.quiqqer-shipping-fields-shippingtimeperiod-customtext {
display: flex;
width: 100%;
}
.quiqqer-shipping-fields-shippingtimeperiod__hidden {
display: none;
}
\ No newline at end of file
......@@ -4,12 +4,13 @@
*/
define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTimePeriod', [
'qui/QUI',
'package/quiqqer/products/bin/controls/fields/types/TimePeriod',
'Locale',
'css!package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTimePeriod.css'
], function (TimePeriod, QUILocale) {
], function (QUI, TimePeriod, QUILocale) {
"use strict";
var lg = 'quiqqer/shipping';
......@@ -29,7 +30,10 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
initialize: function (options) {
this.parent(options);
this.$OptionsSelect = null;
this.$OptionsSelect = null;
this.$CustomTextContainer = null;
this.$CustomTextInput = null;
this.$CustomText = null;
this.addEvents({
onImport: this.$onImport
......@@ -46,6 +50,7 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
this.parent();
// Options select
var OptionsContainer = new Element('div', {
'class': 'quiqqer-shipping-fields-shippingtimeperiod'
}).inject(this.$Content, 'top');
......@@ -57,7 +62,10 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
}
}).inject(OptionsContainer);
var options = ['timeperiod', 'unavailable', 'immediately_available'],
var options = [
'timeperiod', 'unavailable', 'immediately_available',
'on_request', 'available_soon', 'custom_text'
],
lgPrefix = 'controls.products.fields.ShippingTimePeriod.';
for (var i = 0, len = options.length; i < len; i++) {
......@@ -69,17 +77,41 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
}).inject(this.$OptionsSelect);
}
(function () {
if (!Elm.value) {
self.$OptionsSelect.value = 'timeperiod';
return;
}
// Custom text input
this.$CustomTextContainer = new Element('div', {
'class': 'quiqqer-shipping-fields-shippingtimeperiod-customtext quiqqer-shipping-fields-shippingtimeperiod__hidden',
}).inject(
Elm.getParent().getElement('.quiqqer-products-fields-types-timeperiod')
);
var CustomTextInput = new Element('input', {
type : 'text',
'data-qui': 'package/quiqqer/products/bin/controls/fields/types/InputMultiLang'
}).inject(this.$CustomTextContainer);
QUI.parse(this.$CustomTextContainer).then(function () {
self.$CustomText = QUI.Controls.getById(
CustomTextInput.get('data-quiid')
);
self.$CustomText.getElm().getElements('input').addEvent('change', self.$onOptionSelectChange);
Value = JSON.decode(Elm.value);
(function () {
if (!Elm.value) {
self.$OptionsSelect.value = 'timeperiod';
return;
}
self.$OptionsSelect.value = Value.option;
self.$onOptionSelectChange();
}).delay(200);
Value = JSON.decode(Elm.value);
if (Value.option === 'custom_text') {
self.$CustomText.setData(Value.text);
}
self.$OptionsSelect.value = Value.option;
self.$onOptionSelectChange();
}).delay(200);
});
},
/**
......@@ -89,13 +121,19 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
var option = this.$OptionsSelect.value;
if (option === 'timeperiod') {
this.$UnitSelect.disabled = false;
this.$FromInput.disabled = false;
this.$ToInput.disabled = false;
this.$UnitSelect.getParent().removeClass('quiqqer-shipping-fields-shippingtimeperiod__hidden');
this.$FromInput.getParent().removeClass('quiqqer-shipping-fields-shippingtimeperiod__hidden');
this.$ToInput.getParent().removeClass('quiqqer-shipping-fields-shippingtimeperiod__hidden');
} else {
this.$UnitSelect.getParent().addClass('quiqqer-shipping-fields-shippingtimeperiod__hidden');
this.$FromInput.getParent().addClass('quiqqer-shipping-fields-shippingtimeperiod__hidden');
this.$ToInput.getParent().addClass('quiqqer-shipping-fields-shippingtimeperiod__hidden');
}
if (option === 'custom_text') {
this.$CustomTextContainer.removeClass('quiqqer-shipping-fields-shippingtimeperiod__hidden');
} else {
this.$UnitSelect.disabled = true;
this.$FromInput.disabled = true;
this.$ToInput.disabled = true;
this.$CustomTextContainer.addClass('quiqqer-shipping-fields-shippingtimeperiod__hidden');
}
this.$setValue();
......@@ -105,11 +143,18 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
* Set field value to input
*/
$setValue: function () {
var customText = this.$CustomText.getValue().trim();
if (customText !== '') {
customText = JSON.decode(customText);
}
this.getElm().value = JSON.encode({
from : this.$FromInput.value.trim(),
to : this.$ToInput.value.trim(),
unit : this.$UnitSelect.value,
option: this.$OptionsSelect.value
option: this.$OptionsSelect.value,
text : customText
});
},
......@@ -119,11 +164,18 @@ define('package/quiqqer/shipping/bin/backend/controls/products/fields/ShippingTi
* @returns {Object}
*/
getValue: function () {
var customText = this.$CustomText.getValue().trim();
if (customText !== '') {
customText = JSON.decode(customText);
}
return {
from : this.$FromInput.value.trim(),
to : this.$ToInput.value.trim(),
unit : this.$UnitSelect.value,
option: this.$OptionsSelect.value
option: this.$OptionsSelect.value,
text : customText
};
}
});
......
......@@ -698,6 +698,18 @@
<de><![CDATA[Sofort verfügbar]]></de>
<en><![CDATA[Immediately available]]></en>
</locale>
<locale name="controls.products.fields.ShippingTimePeriod.option.on_request">
<de><![CDATA[Auf Anfrage]]></de>
<en><![CDATA[On request]]></en>
</locale>
<locale name="controls.products.fields.ShippingTimePeriod.option.available_soon">
<de><![CDATA[Bald verfügbar]]></de>
<en><![CDATA[Available soon]]></en>
</locale>
<locale name="controls.products.fields.ShippingTimePeriod.option.custom_text">
<de><![CDATA[Individueller Text]]></de>
<en><![CDATA[Custom text]]></en>
</locale>
</groups>
......
......@@ -36,9 +36,20 @@ public function create()
case ShippingTimePeriod::OPTION_UNAVAILABLE:
case ShippingTimePeriod::OPTION_ON_REQUEST:
case ShippingTimePeriod::OPTION_IMMEDIATELY_AVAILABLE:
case ShippingTimePeriod::OPTION_AVAILABLE_SOON:
$valueText = $L->get($lg, 'fields.ShippingTimeFrontendView.'.$value['option']);
break;
case ShippingTimePeriod::OPTION_CUSTOM_TEXT:
$lang = $L->getCurrent();
if (!empty($value['text'][$lang])) {
$valueText = $value['text'][$lang];
} else {
$valueText = current($value['text']);
}
break;
default:
$from = $value['from'];
$to = $value['to'];
......
......@@ -17,6 +17,7 @@ class ShippingTimePeriod extends TimePeriod
const OPTION_IMMEDIATELY_AVAILABLE = 'immediately_available';
const OPTION_ON_REQUEST = 'on_request';
const OPTION_AVAILABLE_SOON = 'available_soon';
const OPTION_CUSTOM_TEXT = 'custom_text';
/**
* Check the value
......@@ -37,16 +38,23 @@ public function validate($value)
$value = \json_decode($value, true);
}
if (!\array_key_exists('option', $value)) {
throw new QUI\ERP\Products\Field\Exception([
'quiqqer/products',
'exception.field.invalid',
[
'fieldId' => $this->getId(),
'fieldTitle' => $this->getTitle(),
'fieldType' => $this->getType()
]
]);
$needles = [
'option',
'text'
];
foreach ($needles as $needle) {
if (!\array_key_exists($needle, $value)) {
throw new QUI\ERP\Products\Field\Exception([
'quiqqer/products',
'exception.field.invalid',
[
'fieldId' => $this->getId(),
'fieldTitle' => $this->getTitle(),
'fieldType' => $this->getType()
]
]);
}
}
}
......@@ -58,10 +66,11 @@ public function validate($value)
*/
public function cleanup($value)
{
$value = parent::cleanup($value);
$value = parent::cleanup($value);
$defaultValue = $this->getDefaultValueFromConfig();
if (empty($value)) {
return $this->getDefaultValueFromConfig();
return $defaultValue;
}
switch ($value['option']) {
......@@ -70,10 +79,11 @@ public function cleanup($value)
case self::OPTION_IMMEDIATELY_AVAILABLE:
case self::OPTION_ON_REQUEST:
case self::OPTION_AVAILABLE_SOON:
case self::OPTION_CUSTOM_TEXT:
break;
default:
return $this->getDefaultValueFromConfig();
return $defaultValue;
}
return $value;
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren