nodebb-plugin-sso-biogrenci 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,234 @@
1
+ 'use strict';
2
+
3
+ define('forum/biogrenci-firsatlar', ['alerts'], function (alerts) {
4
+ var Page = {};
5
+
6
+ var currentPage = 1;
7
+ var currentType = '';
8
+ var currentSort = 'featured';
9
+ var currentSearch = '';
10
+ var searchTimeout = null;
11
+
12
+ Page.init = function () {
13
+ console.log('[sso-biogrenci] Firsatlar page init');
14
+ loadOpportunities();
15
+
16
+ // Filter buttons
17
+ $('.biogrenci-filter').on('click', function () {
18
+ $('.biogrenci-filter').removeClass('active');
19
+ $(this).addClass('active');
20
+ currentType = $(this).attr('data-type');
21
+ currentPage = 1;
22
+ console.log('[sso-biogrenci] Filter changed: type=%s', currentType);
23
+ loadOpportunities();
24
+ });
25
+
26
+ // Sort
27
+ $('#biogrenci-sort').on('change', function () {
28
+ currentSort = $(this).val();
29
+ currentPage = 1;
30
+ console.log('[sso-biogrenci] Sort changed: %s', currentSort);
31
+ loadOpportunities();
32
+ });
33
+
34
+ // Search with debounce
35
+ $('#biogrenci-search').on('input', function () {
36
+ clearTimeout(searchTimeout);
37
+ var val = $(this).val();
38
+ searchTimeout = setTimeout(function () {
39
+ currentSearch = val;
40
+ currentPage = 1;
41
+ console.log('[sso-biogrenci] Search: %s', currentSearch);
42
+ loadOpportunities();
43
+ }, 400);
44
+ });
45
+
46
+ // Pagination
47
+ $('#biogrenci-prev').on('click', function () {
48
+ if (currentPage > 1) {
49
+ currentPage--;
50
+ loadOpportunities();
51
+ }
52
+ });
53
+
54
+ $('#biogrenci-next').on('click', function () {
55
+ currentPage++;
56
+ loadOpportunities();
57
+ });
58
+ };
59
+
60
+ function loadOpportunities() {
61
+ var $list = $('#biogrenci-list');
62
+ $list.html(
63
+ '<div class="biogrenci-loading">' +
64
+ '<div class="biogrenci-spinner"></div>' +
65
+ '<p>Fırsatlar yükleniyor...</p>' +
66
+ '</div>'
67
+ );
68
+
69
+ var params = new URLSearchParams({
70
+ page: currentPage,
71
+ per_page: 20,
72
+ sort: currentSort,
73
+ });
74
+ if (currentType) params.set('type', currentType);
75
+ if (currentSearch) params.set('search', currentSearch);
76
+
77
+ var url = config.relative_path + '/api/biogrenci/firsatlar?' + params.toString();
78
+ console.log('[sso-biogrenci] Fetching opportunities: %s', url);
79
+
80
+ fetch(url)
81
+ .then(function (r) {
82
+ console.log('[sso-biogrenci] API response status: %d', r.status);
83
+ return r.json();
84
+ })
85
+ .then(function (res) {
86
+ console.log('[sso-biogrenci] API response:', JSON.stringify(res).substring(0, 500));
87
+ console.log('[sso-biogrenci] Response keys:', Object.keys(res));
88
+
89
+ if (res.error) {
90
+ console.error('[sso-biogrenci] API error:', res.error);
91
+ $list.html(
92
+ '<div class="biogrenci-empty biogrenci-error">' +
93
+ '<i class="fa fa-exclamation-triangle fa-3x"></i>' +
94
+ '<h4>Fırsatlar yüklenirken hata oluştu</h4>' +
95
+ '<p>' + res.error + '</p>' +
96
+ '</div>'
97
+ );
98
+ return;
99
+ }
100
+
101
+ var items = res.data || res.items || res;
102
+ if (Array.isArray(res) && res.length) {
103
+ items = res;
104
+ }
105
+
106
+ console.log('[sso-biogrenci] Items count: %d, isArray: %s', items ? items.length : 0, Array.isArray(items));
107
+
108
+ if (!items || !items.length) {
109
+ $list.html(
110
+ '<div class="biogrenci-empty">' +
111
+ '<i class="fa fa-search fa-3x"></i>' +
112
+ '<h4>Fırsat bulunamadı</h4>' +
113
+ '<p>Farklı filtreler deneyebilirsiniz</p>' +
114
+ '</div>'
115
+ );
116
+ $('#biogrenci-pagination').hide();
117
+ return;
118
+ }
119
+
120
+ renderOpportunities(items);
121
+ renderPagination(res.meta || {});
122
+ })
123
+ .catch(function (err) {
124
+ console.error('[sso-biogrenci] Fetch error:', err);
125
+ $list.html(
126
+ '<div class="biogrenci-empty biogrenci-error">' +
127
+ '<i class="fa fa-exclamation-triangle fa-3x"></i>' +
128
+ '<h4>Fırsatlar yüklenirken hata oluştu</h4>' +
129
+ '<p>' + err.message + '</p>' +
130
+ '</div>'
131
+ );
132
+ });
133
+ }
134
+
135
+ function renderOpportunities(items) {
136
+ var $list = $('#biogrenci-list');
137
+ var html = items.map(function (item) {
138
+ var typeLabel = item.type === 'kupon' ? 'Kupon' : item.type === 'qr' ? 'QR Kod' : 'Link';
139
+ var typeBadge = item.type === 'kupon' ? 'badge-kupon' : item.type === 'qr' ? 'badge-qr' : 'badge-affiliate';
140
+
141
+ return (
142
+ '<div class="biogrenci-card">' +
143
+ (item.image
144
+ ? '<div class="biogrenci-card-img"><img src="' + item.image + '" alt="' + (item.brand_name || '') + '" loading="lazy"></div>'
145
+ : '<div class="biogrenci-card-img biogrenci-card-img-placeholder"><i class="fa fa-gift fa-3x"></i></div>') +
146
+ '<div class="biogrenci-card-body">' +
147
+ '<div class="biogrenci-card-top">' +
148
+ '<span class="biogrenci-badge ' + typeBadge + '">' + typeLabel + '</span>' +
149
+ (item.brand_name ? '<span class="biogrenci-brand">' + item.brand_name + '</span>' : '') +
150
+ '</div>' +
151
+ '<h3 class="biogrenci-card-title">' + item.title + '</h3>' +
152
+ (item.description ? '<p class="biogrenci-card-desc">' + item.description + '</p>' : '') +
153
+ '<button class="btn biogrenci-claim-btn" data-id="' + item.id + '">' +
154
+ '<i class="fa fa-hand-pointer-o"></i> Fırsatı Al' +
155
+ '</button>' +
156
+ '</div>' +
157
+ '</div>'
158
+ );
159
+ }).join('');
160
+
161
+ $list.html(html);
162
+
163
+ $list.find('.biogrenci-claim-btn').on('click', function () {
164
+ claimOpportunity($(this));
165
+ });
166
+ }
167
+
168
+ function renderPagination(meta) {
169
+ var $el = $('#biogrenci-pagination');
170
+ if (!meta.total || meta.total <= 20) {
171
+ $el.hide();
172
+ return;
173
+ }
174
+ $el.show();
175
+ var totalPages = Math.ceil(meta.total / 20);
176
+ $('#biogrenci-page-info').text(currentPage + ' / ' + totalPages);
177
+ $('#biogrenci-prev').prop('disabled', currentPage <= 1);
178
+ $('#biogrenci-next').prop('disabled', currentPage >= totalPages);
179
+ }
180
+
181
+ function claimOpportunity($btn) {
182
+ var id = $btn.attr('data-id');
183
+ $btn.prop('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> Alınıyor...');
184
+ console.log('[sso-biogrenci] Claiming opportunity id=%s', id);
185
+
186
+ fetch(config.relative_path + '/api/biogrenci/firsatlar/' + id + '/claim', {
187
+ method: 'POST',
188
+ headers: {
189
+ 'x-csrf-token': config.csrf_token,
190
+ 'Content-Type': 'application/json',
191
+ },
192
+ })
193
+ .then(function (r) { return r.json(); })
194
+ .then(function (res) {
195
+ console.log('[sso-biogrenci] Claim response:', res);
196
+ if (res.error) {
197
+ alerts.error(res.error);
198
+ $btn.prop('disabled', false).html('<i class="fa fa-hand-pointer-o"></i> Fırsatı Al');
199
+ return;
200
+ }
201
+
202
+ var data = res.data || res;
203
+ if (data.coupon_code) {
204
+ $btn.replaceWith(
205
+ '<div class="biogrenci-coupon-result">' +
206
+ '<code class="biogrenci-coupon-code">' + data.coupon_code + '</code>' +
207
+ '<button class="btn btn-sm biogrenci-copy-btn" data-code="' + data.coupon_code + '">' +
208
+ '<i class="fa fa-copy"></i>' +
209
+ '</button>' +
210
+ (data.redirect_url
211
+ ? '<a href="' + data.redirect_url + '" target="_blank" rel="noopener" class="btn btn-sm biogrenci-go-btn">Siteye Git <i class="fa fa-external-link"></i></a>'
212
+ : '') +
213
+ '</div>'
214
+ );
215
+ $('.biogrenci-copy-btn').last().on('click', function () {
216
+ navigator.clipboard.writeText($(this).attr('data-code'));
217
+ alerts.success('Kopyalandı!');
218
+ });
219
+ } else if (data.qr_code) {
220
+ $btn.replaceWith('<div class="biogrenci-qr-result">' + data.qr_code + '</div>');
221
+ } else if (data.redirect_url) {
222
+ window.open(data.redirect_url, '_blank');
223
+ $btn.html('<i class="fa fa-check"></i> Açıldı').addClass('claimed');
224
+ }
225
+ })
226
+ .catch(function (err) {
227
+ console.error('[sso-biogrenci] Claim error:', err);
228
+ alerts.error('Bir hata oluştu');
229
+ $btn.prop('disabled', false).html('<i class="fa fa-hand-pointer-o"></i> Fırsatı Al');
230
+ });
231
+ }
232
+
233
+ return Page;
234
+ });