nodebb-plugin-simple-contact 1.1.0 → 1.1.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.
package/library.js CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  const db = require.main.require('./src/database');
4
4
  const notifications = require.main.require('./src/notifications');
5
- const user = require.main.require('./src/user');
6
5
  const groups = require.main.require('./src/groups');
7
- const utils = require.main.require('./src/utils');
8
6
 
9
7
  const ContactPlugin = {};
10
8
 
@@ -56,25 +54,57 @@ async function handleContactSubmission(req, res) {
56
54
  await db.sortedSetAdd('contact-requests:sorted', contactId, contactId);
57
55
 
58
56
  const adminUids = await groups.getMembers('administrators', 0, -1);
57
+
59
58
  if (adminUids && adminUids.length > 0) {
60
- const notification = await notifications.create({
61
- type: 'new-contact',
62
- bodyShort: `פנייה חדשה מאת ${contactData.fullName}`,
63
- bodyLong: contactData.content,
64
- nid: 'contact:' + contactId,
65
- path: '/admin/plugins/contact',
66
- from: 0
67
- });
68
- await notifications.push(notification, adminUids);
59
+ await Promise.all(adminUids.map(async (uid) => {
60
+ const userUnreadKey = 'contact:unread_names:' + uid;
61
+ const userNid = 'contact:notification:' + uid;
62
+
63
+ await db.listAppend(userUnreadKey, contactData.fullName);
64
+
65
+ const myNames = await db.getListRange(userUnreadKey, 0, -1);
66
+
67
+ let notificationTitle = '';
68
+ if (myNames.length === 1) {
69
+ notificationTitle = `פנייה חדשה מאת ${myNames[0]}`;
70
+ } else {
71
+ notificationTitle = `${myNames.length} פניות חדשות מאת: ${myNames.join(', ')}`;
72
+ }
73
+
74
+ const notification = await notifications.create({
75
+ type: 'new-contact',
76
+ bodyShort: notificationTitle,
77
+ bodyLong: contactData.content,
78
+ nid: userNid,
79
+ path: '/admin/plugins/contact',
80
+ from: 0
81
+ });
82
+
83
+ await notifications.push(notification, [uid]);
84
+ }));
69
85
  }
70
86
 
71
87
  res.json({ success: true, message: 'הפנייה נשלחה בהצלחה.' });
72
88
  } catch (err) {
89
+ console.error(err);
73
90
  res.status(500).json({ error: 'שגיאה פנימית.' });
74
91
  }
75
92
  }
76
93
 
77
94
  async function renderAdminPage(req, res) {
95
+ if (req.uid) {
96
+ try {
97
+ const userUnreadKey = 'contact:unread_names:' + req.uid;
98
+ const userNid = 'contact:notification:' + req.uid;
99
+
100
+ await notifications.markRead(userNid, req.uid);
101
+
102
+ await db.delete(userUnreadKey);
103
+ } catch (e) {
104
+ console.error('Error handling notifications logic', e);
105
+ }
106
+ }
107
+
78
108
  const ids = await db.getSortedSetRevRange('contact-requests:sorted', 0, -1);
79
109
  let items = [];
80
110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-simple-contact",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "תוסף טופס צור קשר עם התראות למנהלים וניהול פניות",
5
5
  "main": "library.js",
6
6
  "nbbpm": {
@@ -1,82 +1,108 @@
1
- <div class="row">
1
+ <div class="row text-center">
2
2
  <div class="col-xs-12">
3
-
4
- <div class="panel panel-warning">
5
- <div class="panel-heading">ממתין - פניות לטיפול</div>
6
- <div class="panel-body">
3
+
4
+ <div class="panel panel-warning shadow-sm" style="border:none; border-radius:12px;">
5
+ <div class="panel-heading text-center" style="border-radius:12px 12px 0 0; font-weight:600;">
6
+ ממתין - פניות לטיפול
7
+ </div>
8
+
9
+ <div class="panel-body" style="background:#fafafa;">
7
10
  {{{ if waitingRequests.length }}}
8
- <table class="table table-striped table-hover">
9
- <thead>
10
- <tr>
11
- <th>תאריך</th>
12
- <th>שם מלא</th>
13
- <th>משתמש</th>
14
- <th>מייל</th>
15
- <th>תוכן</th>
16
- <th>סטטוס</th>
17
- <th>פעולות</th>
18
- </tr>
19
- </thead>
20
- <tbody id="contact-list-waiting">
21
- {{{ each waitingRequests }}}
22
- <tr data-id="{./id}">
23
- <td>{./date}</td>
24
- <td>{./fullName}</td>
25
- <td>{./username}</td>
26
- <td>{./email}</td>
27
- <td>{./content}</td>
28
- <td><span class="label label-warning">ממתין</span></td>
29
- <td>
30
- <button class="btn btn-xs btn-primary mark-handled" data-id="{./id}">סמן כטופל</button>
31
- </td>
32
- </tr>
33
- {{{ end }}}
34
- </tbody>
35
- </table>
11
+ <div class="table-responsive">
12
+ <table class="table table-hover text-center" style="margin-bottom:0;">
13
+ <thead>
14
+ <tr>
15
+ <th class="text-center">תאריך</th>
16
+ <th class="text-center">שם מלא</th>
17
+ <th class="text-center">משתמש</th>
18
+ <th class="text-center">מייל</th>
19
+ <th class="text-center">תוכן</th>
20
+ <th class="text-center">סטטוס</th>
21
+ <th class="text-center">פעולות</th>
22
+ </tr>
23
+ </thead>
24
+ <tbody id="contact-list-waiting">
25
+ {{{ each waitingRequests }}}
26
+ <tr data-id="{./id}" class="text-center">
27
+ <td>{./date}</td>
28
+ <td><strong>{./fullName}</strong></td>
29
+ <td>{./username}</td>
30
+ <td><a href="mailto:{./email}">{./email}</a></td>
31
+ <td style="max-width:260px;">
32
+ <div class="toggle-text" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis; cursor:pointer;" title="לחץ להצגה/הסתרה">
33
+ {./content}
34
+ </div>
35
+ </td>
36
+ <td>
37
+ <span class="label label-warning" style="border-radius:10px; padding:3px 6px; font-size:11px;">ממתין</span>
38
+ </td>
39
+ <td class="text-center">
40
+ <button class="btn btn-xs btn-primary mark-handled" data-id="{./id}" style="border-radius:14px; font-size:11px; padding:3px 8px;">
41
+ ✓ סמן כטופל
42
+ </button>
43
+ </td>
44
+ </tr>
45
+ {{{ end }}}
46
+ </tbody>
47
+ </table>
48
+ </div>
36
49
  {{{ else }}}
37
- <div class="alert alert-info text-center">
50
+ <div class="alert alert-info text-center" style="border-radius:10px;">
38
51
  אין פניות ממתינות כרגע.
39
52
  </div>
40
53
  {{{ end }}}
41
54
  </div>
42
55
  </div>
43
56
 
44
- <hr>
57
+ <hr style="opacity:.2;">
58
+
59
+ <div class="panel panel-success shadow-sm" style="border:none; border-radius:12px;">
60
+ <div class="panel-heading text-center" style="border-radius:12px 12px 0 0; font-weight:600;">
61
+ מטופל - ארכיון פניות
62
+ </div>
45
63
 
46
- <div class="panel panel-success">
47
- <div class="panel-heading">מטופל - ארכיון פניות</div>
48
- <div class="panel-body">
64
+ <div class="panel-body" style="background:#fafafa;">
49
65
  {{{ if handledRequests.length }}}
50
- <table class="table table-striped table-hover">
51
- <thead>
52
- <tr>
53
- <th>תאריך</th>
54
- <th>שם מלא</th>
55
- <th>משתמש</th>
56
- <th>מייל</th>
57
- <th>תוכן</th>
58
- <th>סטטוס</th>
59
- <th>פעולות</th>
60
- </tr>
61
- </thead>
62
- <tbody id="contact-list-handled">
63
- {{{ each handledRequests }}}
64
- <tr data-id="{./id}" class="success">
65
- <td>{./date}</td>
66
- <td>{./fullName}</td>
67
- <td>{./username}</td>
68
- <td>{./email}</td>
69
- <td>{./content}</td>
70
- <td><span class="label label-success">טופל</span></td>
71
- <td>
72
- <button class="btn btn-xs btn-danger delete-request" data-id="{./id}">מחק</button>
73
- </td>
74
- </tr>
75
- {{{ end }}}
76
- </tbody>
77
- </table>
66
+ <div class="table-responsive">
67
+ <table class="table table-hover text-center" style="margin-bottom:0;">
68
+ <thead>
69
+ <tr>
70
+ <th class="text-center">תאריך</th>
71
+ <th class="text-center">שם מלא</th>
72
+ <th class="text-center">משתמש</th>
73
+ <th class="text-center">מייל</th>
74
+ <th class="text-center">תוכן</th>
75
+ <th class="text-center">סטטוס</th>
76
+ <th class="text-center">פעולות</th>
77
+ </tr>
78
+ </thead>
79
+ <tbody id="contact-list-handled">
80
+ {{{ each handledRequests }}}
81
+ <tr data-id="{./id}" class="text-center">
82
+ <td>{./date}</td>
83
+ <td><strong>{./fullName}</strong></td>
84
+ <td>{./username}</td>
85
+ <td><a href="mailto:{./email}">{./email}</a></td>
86
+ <td style="max-width:260px;">
87
+ <div class="toggle-text" style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis; cursor:pointer;" title="לחץ להצגה/הסתרה">
88
+ {./content}
89
+ </div>
90
+ </td>
91
+ <td>
92
+ <span class="label label-success" style="border-radius:10px; padding:3px 6px; font-size:11px;">טופל</span>
93
+ </td>
94
+ <td class="text-center">
95
+ <button class="btn btn-xs btn-danger delete-request" data-id="{./id}" style="border-radius:14px; font-size:11px; padding:3px 8px;">
96
+ × מחק
97
+ </button>
98
+ </td>
99
+ </tr>
100
+ {{{ end }}}
101
+ </tbody>
102
+ </table>
103
+ </div>
78
104
  {{{ else }}}
79
- <div class="alert alert-info text-center">
105
+ <div class="alert alert-info text-center" style="border-radius:10px;">
80
106
  ארכיון הפניות ריק.
81
107
  </div>
82
108
  {{{ end }}}
@@ -87,132 +113,114 @@
87
113
  </div>
88
114
 
89
115
  <script>
90
- (function() {
91
- if (typeof define === 'function' && define.amd) {
92
- define('admin/plugins/contact', [], function() { return {}; });
93
- }
94
-
95
- function showMessage(type, msg) {
96
- if (window.app && typeof window.app.require === 'function') {
97
- window.app.require('alerts').then(function(alerts) {
98
- if (type === 'success') {
99
- alerts.success(msg);
100
- } else {
101
- alerts.error(msg);
102
- }
103
- }).catch(function(err) {
104
- console.error('Failed to load alerts via app.require:', err);
105
- fallbackAlert(type, msg);
106
- });
107
- return;
108
- }
109
-
110
- const req = window.require || window.requirejs;
111
- if (req) {
112
- req(['alerts'], function(alerts) {
113
- if (alerts) {
114
- if (type === 'success' && alerts.success) alerts.success(msg);
115
- else if (alerts.error) alerts.error(msg);
116
- else fallbackAlert(type, msg);
117
- } else {
118
- fallbackAlert(type, msg);
119
- }
120
- });
121
- return;
122
- }
123
-
124
- if (window.app && window.app.alert) {
125
- window.app.alert({
126
- type: type === 'success' ? 'success' : 'danger',
127
- message: msg,
128
- timeout: 3000
129
- });
130
- return;
131
- }
132
-
133
- fallbackAlert(type, msg);
134
- }
135
-
136
- function fallbackAlert(type, msg) {
137
- alert((type === 'success' ? 'הצלחה: ' : 'שגיאה: ') + msg.replace(/<[^>]*>/g, ''));
116
+ (function() {
117
+ if (typeof define === 'function' && define.amd) {
118
+ define('admin/plugins/contact', [], function() { return {}; });
119
+ }
120
+
121
+ function showMessage(type, msg) {
122
+ const clean = msg.replace(/<[^>]*>/g, '');
123
+ if (window.app && typeof window.app.require === 'function') {
124
+ window.app.require('alerts').then(function(alerts) {
125
+ type === 'success' ? alerts.success(clean) : alerts.error(clean);
126
+ }).catch(function() {
127
+ alert(clean);
128
+ });
129
+ return;
138
130
  }
139
-
140
- function initContactPage() {
141
- $('.mark-handled').off('click');
142
- $('.delete-request').off('click');
143
-
144
- $('.mark-handled').on('click', function() {
145
- var btn = $(this);
146
- var id = btn.data('id');
147
-
148
- if (window.app && window.app.require) {
149
- window.app.require('bootbox').then(function(bootbox) {
150
- bootbox.confirm('האם אתה בטוח שברצונך לסמן פנייה זו כטופלה?', function(confirm) {
151
- if (confirm) performHandle(id);
152
- });
153
- });
154
- } else if (window.bootbox) {
155
- window.bootbox.confirm('האם אתה בטוח שברצונך לסמן פנייה זו כטופלה?', function(confirm) {
156
- if (confirm) performHandle(id);
157
- });
158
- } else {
159
- if (confirm('האם אתה בטוח שברצונך לסמן פנייה זו כטופלה?')) performHandle(id);
160
- }
131
+ const req = window.require || window.requirejs;
132
+ if (req) {
133
+ req(['alerts'], function(alerts) {
134
+ if (!alerts) return alert(clean);
135
+ type === 'success' ? alerts.success(clean) : alerts.error(clean);
161
136
  });
137
+ return;
138
+ }
139
+ alert(clean);
140
+ }
162
141
 
163
- $('.delete-request').on('click', function() {
164
- var btn = $(this);
165
- var id = btn.data('id');
166
-
167
- if (window.app && window.app.require) {
168
- window.app.require('bootbox').then(function(bootbox) {
169
- bootbox.confirm('האם אתה בטוח שברצונך למחוק פנייה זו לצמיתות?', function(confirm) {
170
- if (confirm) performDelete(id);
171
- });
172
- });
173
- } else if (window.bootbox) {
174
- window.bootbox.confirm('האם אתה בטוח שברצונך למחוק פנייה זו לצמיתות?', function(confirm) {
175
- if (confirm) performDelete(id);
176
- });
177
- } else {
178
- if (confirm('האם אתה בטוח שברצונך למחוק פנייה זו לצמיתות?')) performDelete(id);
179
- }
142
+ function confirmBox(message, cb) {
143
+ if (window.app && window.app.require) {
144
+ window.app.require('bootbox').then(function(bootbox) {
145
+ bootbox.confirm(message, cb);
180
146
  });
147
+ } else if (window.bootbox) {
148
+ window.bootbox.confirm(message, cb);
149
+ } else {
150
+ cb(confirm(message));
181
151
  }
152
+ }
182
153
 
183
- function performHandle(id) {
184
- $.post(config.relative_path + '/api/admin/plugins/contact/handle', {
185
- id: id,
186
- _csrf: config.csrf_token
187
- }, function(data) {
188
- if (data.success) {
189
- showMessage('success', 'הפנייה סומנה כטופלה בהצלחה');
190
- ajaxify.refresh();
191
- }
192
- }).fail(function() {
193
- showMessage('error', 'שגיאה בעדכון הפנייה');
154
+ function initContactPage() {
155
+ $('.mark-handled').off('click').on('click', function() {
156
+ var id = $(this).data('id');
157
+ confirmBox('האם לסמן פנייה זו כטופלה?', function(ok) {
158
+ if (ok) performHandle(id);
194
159
  });
195
- }
160
+ });
196
161
 
197
- function performDelete(id) {
198
- $.post(config.relative_path + '/api/admin/plugins/contact/delete', {
199
- id: id,
200
- _csrf: config.csrf_token
201
- }, function(data) {
202
- if (data.success) {
203
- showMessage('success', 'הפנייה נמחקה בהצלחה');
204
- ajaxify.refresh();
205
- }
206
- }).fail(function() {
207
- showMessage('error', 'שגיאה במחיקת הפנייה');
162
+ $('.delete-request').off('click').on('click', function() {
163
+ var id = $(this).data('id');
164
+ confirmBox('האם למחוק פנייה זו לצמיתות?', function(ok) {
165
+ if (ok) performDelete(id);
208
166
  });
209
- }
167
+ });
210
168
 
211
- $(document).ready(initContactPage);
212
- $(window).on('action:ajaxify.end', function(event, data) {
213
- if (data.tpl_url === 'admin/plugins/contact') {
214
- initContactPage();
169
+ $('.toggle-text').off('click').on('click', function() {
170
+ var $el = $(this);
171
+ if ($el.css('white-space') === 'nowrap') {
172
+ $el.css({
173
+ 'white-space': 'normal',
174
+ 'word-break': 'break-word',
175
+ 'overflow': 'visible'
176
+ });
177
+ } else {
178
+ $el.css({
179
+ 'white-space': 'nowrap',
180
+ 'overflow': 'hidden',
181
+ 'text-overflow': 'ellipsis'
182
+ });
183
+ }
184
+ });
185
+ }
186
+
187
+ function performHandle(id) {
188
+ $.post(config.relative_path + '/api/admin/plugins/contact/handle', {
189
+ id: id,
190
+ _csrf: config.csrf_token
191
+ })
192
+ .done(function(data) {
193
+ if (data.success) {
194
+ showMessage('success', 'הפנייה סומנה כטופלה בהצלחה');
195
+ ajaxify.refresh();
215
196
  }
197
+ })
198
+ .fail(function() {
199
+ showMessage('error', 'שגיאה בעדכון הפנייה');
216
200
  });
217
- })();
218
- </script>
201
+ }
202
+
203
+ function performDelete(id) {
204
+ $.post(config.relative_path + '/api/admin/plugins/contact/delete', {
205
+ id: id,
206
+ _csrf: config.csrf_token
207
+ })
208
+ .done(function(data) {
209
+ if (data.success) {
210
+ showMessage('success', 'הפנייה נמחקה בהצלחה');
211
+ ajaxify.refresh();
212
+ }
213
+ })
214
+ .fail(function() {
215
+ showMessage('error', 'שגיאה במחיקת הפנייה');
216
+ });
217
+ }
218
+
219
+ $(document).ready(initContactPage);
220
+ $(window).on('action:ajaxify.end', function(e, data) {
221
+ if (data.tpl_url === 'admin/plugins/contact') {
222
+ initContactPage();
223
+ }
224
+ });
225
+ })();
226
+ </script>
@@ -1,111 +1,104 @@
1
- <div class="row">
2
- <div class="col-lg-8 col-lg-offset-2">
3
- <div class="panel panel-default">
4
- <div class="panel-heading">
5
- <h3 class="panel-title">צור קשר עם ההנהלה</h3>
1
+ <div class="row text-center" style="display:flex; justify-content:center; align-items:center;">
2
+ <div class="col-lg-8 col-lg-offset-2" style="margin-top:20px;">
3
+ <div class="panel panel-default shadow-sm" style="border-radius:14px; border:none;">
4
+
5
+ <div class="panel-heading text-center" style="background:linear-gradient(135deg,#2b6cb0,#2c5282); color:#fff; border-radius:14px 14px 0 0; padding:15px;">
6
+ <h3 class="panel-title" style="font-weight:600; margin:0;">צור קשר עם ההנהלה</h3>
6
7
  </div>
7
- <div class="panel-body">
8
- <form id="contact-form" role="form">
9
- <div class="form-group">
10
- <label for="fullName">שם מלא *</label>
11
- <input type="text" class="form-control" id="fullName" name="fullName" required>
8
+
9
+ <div class="panel-body text-center" style="background:#fafafa; padding:20px 25px;">
10
+
11
+ <form id="contact-form" role="form" style="max-width:600px; margin:0 auto;">
12
+
13
+ <div class="form-group" style="margin-bottom:16px;">
14
+ <label for="fullName" style="font-weight:600; display:block; margin-bottom:6px;">שם מלא *</label>
15
+ <input type="text" class="form-control text-center" id="fullName" name="fullName" required style="border-radius:10px; padding:10px;">
12
16
  </div>
13
- <div class="form-group">
14
- <label for="username">שם משתמש בפורום (במידה וקיים)</label>
15
- <input type="text" class="form-control" id="username" name="username">
17
+
18
+ <div class="form-group" style="margin-bottom:16px;">
19
+ <label for="username" style="font-weight:600; display:block; margin-bottom:6px;">שם משתמש בפורום</label>
20
+ <input type="text" class="form-control text-center" id="username" name="username" style="border-radius:10px; padding:10px;">
16
21
  </div>
17
- <div class="form-group">
18
- <label for="email">כתובת מייל *</label>
19
- <input type="email" class="form-control" id="email" name="email" required>
22
+
23
+ <div class="form-group" style="margin-bottom:16px;">
24
+ <label for="email" style="font-weight:600; display:block; margin-bottom:6px;">כתובת מייל *</label>
25
+ <input type="email" class="form-control text-center" id="email" name="email" required style="border-radius:10px; padding:10px;">
20
26
  </div>
21
- <div class="form-group">
22
- <label for="content">תוכן הפנייה *</label>
23
- <textarea class="form-control" id="content" name="content" rows="6" required></textarea>
27
+
28
+ <div class="form-group" style="margin-bottom:20px;">
29
+ <label for="content" style="font-weight:600; display:block; margin-bottom:6px;">תוכן הפנייה *</label>
30
+ <textarea class="form-control text-center" id="content" name="content" rows="6" required style="border-radius:10px; padding:10px;"></textarea>
24
31
  </div>
25
-
26
- <button type="submit" class="btn btn-primary" id="submit-btn">שלח פנייה</button>
32
+
33
+ <button type="submit" class="btn btn-primary btn-block" id="submit-btn" style="border-radius:22px; font-weight:600; padding:12px; margin-top:10px;">
34
+ שלח פנייה
35
+ </button>
36
+
27
37
  </form>
28
38
 
29
- <div id="contact-alert" class="alert" style="display:none; margin-top: 20px;"></div>
39
+ <div id="contact-alert" class="alert text-center" style="display:none; margin-top:20px; border-radius:10px;"></div>
40
+
30
41
  </div>
31
42
  </div>
32
43
  </div>
33
44
  </div>
34
45
 
35
46
  <script>
36
- (function() {
37
- function initContactForm($) {
38
- var form = $('#contact-form');
39
- var btn = $('#submit-btn');
40
- var alertBox = $('#contact-alert');
41
-
42
- form.off('submit').on('submit', function(e) {
43
- e.preventDefault();
44
-
45
- btn.prop('disabled', true).text('שולח...');
46
- alertBox.hide().removeClass('alert-success alert-danger');
47
-
48
- var formData = {
49
- fullName: form.find('#fullName').val(),
50
- username: form.find('#username').val(),
51
- email: form.find('#email').val(),
52
- content: form.find('#content').val(),
53
- _csrf: config.csrf_token
54
- };
55
-
56
- $.ajax({
57
- url: config.relative_path + '/api/contact/send',
58
- type: 'POST',
59
- data: formData,
60
- success: function(response) {
61
- alertBox.addClass('alert-success')
62
- .text(response.message || 'הפנייה נשלחה בהצלחה!')
63
- .fadeIn();
64
- form[0].reset();
65
- btn.text('שלח פנייה');
66
- },
67
- error: function(xhr) {
68
- var msg = (xhr.responseJSON && xhr.responseJSON.error) ? xhr.responseJSON.error : 'אירעה שגיאה בשליחה.';
69
- alertBox.addClass('alert-danger')
70
- .text(msg)
71
- .fadeIn();
72
- },
73
- complete: function() {
74
- btn.prop('disabled', false).text('שלח פנייה');
75
- }
76
- });
77
- });
78
- }
47
+ (function() {
48
+ function initContactForm($) {
49
+ var form = $('#contact-form');
50
+ var btn = $('#submit-btn');
51
+ var alertBox = $('#contact-alert');
79
52
 
80
-
81
- function safeBoot() {
82
- if (typeof jQuery === 'undefined') {
83
- setTimeout(safeBoot, 50);
84
- return;
85
- }
53
+ form.off('submit').on('submit', function(e) {
54
+ e.preventDefault();
86
55
 
87
- var $ = jQuery;
88
-
89
- initContactForm($);
56
+ btn.prop('disabled', true).text('שולח...');
57
+ alertBox.hide().removeClass('alert-success alert-danger');
90
58
 
91
- $(window).off('action:ajaxify.end.contact').on('action:ajaxify.end.contact', function(ev, data) {
92
- if (data.url === 'contact' || (ajaxify.data.template && ajaxify.data.template.name === 'contact')) {
93
- initContactForm($);
59
+ var formData = {
60
+ fullName: form.find('#fullName').val(),
61
+ username: form.find('#username').val(),
62
+ email: form.find('#email').val(),
63
+ content: form.find('#content').val(),
64
+ _csrf: config.csrf_token
65
+ };
66
+
67
+ $.ajax({
68
+ url: config.relative_path + '/api/contact/send',
69
+ type: 'POST',
70
+ data: formData,
71
+ success: function(response) {
72
+ alertBox.addClass('alert-success').text(response.message || 'הפנייה נשלחה בהצלחה').fadeIn();
73
+ form[0].reset();
74
+ btn.text('שלח פנייה');
75
+ },
76
+ error: function(xhr) {
77
+ var msg = (xhr.responseJSON && xhr.responseJSON.error) ? xhr.responseJSON.error : 'אירעה שגיאה בשליחה';
78
+ alertBox.addClass('alert-danger').text(msg).fadeIn();
79
+ },
80
+ complete: function() {
81
+ btn.prop('disabled', false).text('שלח פנייה');
94
82
  }
95
83
  });
84
+ });
85
+ }
86
+
87
+ function safeBoot() {
88
+ if (typeof jQuery === 'undefined') {
89
+ setTimeout(safeBoot, 50);
90
+ return;
96
91
  }
92
+ var $ = jQuery;
93
+ initContactForm($);
97
94
 
98
- if (typeof define === 'function' && define.amd) {
99
- define('forum/contact', ['jquery'], function($) {
100
- return {
101
- init: function() {
102
- initContactForm($);
103
- }
104
- };
105
- });
106
- }
107
-
108
- safeBoot();
95
+ $(window).off('action:ajaxify.end.contact').on('action:ajaxify.end.contact', function(ev, data) {
96
+ if (data.url === 'contact') {
97
+ initContactForm($);
98
+ }
99
+ });
100
+ }
109
101
 
110
- })();
111
- </script>
102
+ safeBoot();
103
+ })();
104
+ </script>