/** * CouponCodeInput * * @module package/quiqqer/coupons/bin/frontend/classes/CouponCodeInput * @author www.pcsg.de (Patrick Müller) */ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [ 'qui/controls/Control', 'qui/controls/loader/Loader', 'package/quiqqer/coupons/bin/frontend/CouponCodes', 'Locale', 'Mustache', 'text!package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput.html', 'css!package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput.css' ], function (QUIControl, QUILoader, CouponCodes, QUILocale, Mustache, template) { "use strict"; var lg = 'quiqqer/coupons'; return new Class({ Extends: QUIControl, Type : 'package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', Binds: [ '$submit' ], initialize: function (options) { this.parent(options); this.$Input = null; this.Loader = new QUILoader(); this.addEvents({ onInject: this.$onInject }); }, /** * Event: onInject */ $onInject: function () { var self = this; var lgPrefix = 'controls.frontend.CouponCodeInput.template.'; this.$Elm.addClass('quiqqer-coupons-field'); this.$Elm.set('html', Mustache.render(template, { labelInput : QUILocale.get(lg, lgPrefix + 'labelInput'), submitBtnText: QUILocale.get(lg, lgPrefix + 'submitBtnText') })); this.Loader.inject(this.$Elm); this.$Input = this.$Elm.getElement('input[name="code"]'); this.$Input.addEvent('keyup', function (event) { if (event.code === 13) { self.$submit(); } }); this.$Elm.getElement( 'button.quiqqer-coupons-couponcodeinput-btn' ).addEvent('click', function (event) { event.stop(); self.$submit(); }); }, /** * Submit a CouponCode */ $submit: function () { var self = this; var code = this.$Input.value.trim(); if (code === '') { this.$Input.focus(); return; } this.Loader.show(); CouponCodes.addCouponCodeToBasket(code).then(function () { // @todo self.Loader.hide(); }); } }); });