Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* 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/classes/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.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();
}
});
var SubmitBtn = this.$Elm.getElement('button.quiqqer-coupons-couponcodeinput-btn');
SubmitBtn.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();
});
}
});
});