nodebb-plugin-simple-contact 1.2.1 → 1.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-simple-contact",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "תוסף טופס צור קשר עם התראות למנהלים וניהול פניות",
5
5
  "main": "library.js",
6
6
  "nbbpm": {
@@ -1,4 +1,4 @@
1
- <div class="row text-center" style="display:flex; justify-content:center; align-items:center;"> [cite: 1]
1
+ <div class="row text-center" style="display:flex; justify-content:center; align-items:center;">
2
2
  <div class="col-lg-8 col-lg-offset-2" style="margin-top:20px;">
3
3
  <div class="panel panel-default shadow-sm" style="border-radius:14px; border:none;">
4
4
 
@@ -8,35 +8,35 @@
8
8
 
9
9
  <div class="panel-body text-center" style="background:#fafafa; padding:20px 25px;">
10
10
 
11
- <form id="contact-form" role="form" style="max-width:600px; margin:0 auto;"> [cite: 2]
11
+ <form id="contact-form" role="form" style="max-width:600px; margin:0 auto;">
12
12
 
13
13
  <div class="form-group" style="margin-bottom:16px;">
14
- <label for="fullName" style="font-weight:600; display:block; margin-bottom:6px;">שם מלא *</label> [cite: 2]
15
- <input type="text" class="form-control" id="fullName" name="fullName" required style="border-radius:10px; padding:10px;"> [cite: 3]
14
+ <label for="fullName" style="font-weight:600; display:block; margin-bottom:6px;">שם מלא *</label>
15
+ <input type="text" class="form-control" id="fullName" name="fullName" required style="border-radius:10px; padding:10px;">
16
16
  </div>
17
17
 
18
- <div class="form-group" id="username-group" style="margin-bottom:16px;"> [cite: 4]
19
- <label for="username" style="font-weight:600; display:block; margin-bottom:6px;">שם משתמש בפורום</label> [cite: 4]
20
- <input type="text" class="form-control" id="username" name="username" style="border-radius:10px; padding:10px;"> [cite: 5]
18
+ <div class="form-group" id="username-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" id="username" name="username" style="border-radius:10px; padding:10px;">
21
21
  </div>
22
22
 
23
23
  <div class="form-group" style="margin-bottom:16px;">
24
- <label for="email" style="font-weight:600; display:block; margin-bottom:6px;">כתובת מייל *</label> [cite: 6]
25
- <input type="email" class="form-control" id="email" name="email" required style="border-radius:10px; padding:10px;"> [cite: 7]
24
+ <label for="email" style="font-weight:600; display:block; margin-bottom:6px;">כתובת מייל *</label>
25
+ <input type="email" class="form-control" id="email" name="email" required style="border-radius:10px; padding:10px;">
26
26
  </div>
27
27
 
28
28
  <div class="form-group" style="margin-bottom:20px;">
29
- <label for="content" style="font-weight:600; display:block; margin-bottom:6px;">תוכן הפנייה *</label> [cite: 8]
30
- <textarea class="form-control" id="content" name="content" rows="6" required style="border-radius:10px; padding:10px;"></textarea> [cite: 9]
29
+ <label for="contact-message" style="font-weight:600; display:block; margin-bottom:6px;">תוכן הפנייה *</label>
30
+ <textarea class="form-control" id="contact-message" name="content" rows="6" required style="border-radius:10px; padding:10px;"></textarea>
31
31
  </div>
32
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;"> [cite: 10]
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
34
  שלח פנייה
35
35
  </button>
36
36
 
37
37
  </form>
38
38
 
39
- <div id="contact-alert" class="alert text-center" style="display:none; margin-top:20px; border-radius:10px;"></div> [cite: 11]
39
+ <div id="contact-alert" class="alert text-center" style="display:none; margin-top:20px; border-radius:10px;"></div>
40
40
 
41
41
  </div>
42
42
  </div>
@@ -45,63 +45,81 @@
45
45
 
46
46
  <script>
47
47
  (function() {
48
- function initContactForm($) {
49
- var form = $('#contact-form'); [cite: 12]
50
- var btn = $('#submit-btn'); [cite: 12]
51
- var alertBox = $('#contact-alert'); [cite: 12]
48
+ var loadContactForm = function() {
49
+ if (typeof window.jQuery === 'undefined' || typeof window.app === 'undefined') {
50
+ setTimeout(loadContactForm, 200);
51
+ return;
52
+ }
53
+
54
+ var $ = window.jQuery;
55
+ var form = $('#contact-form');
56
+ if (!form.length) return;
57
+
58
+ var btn = $('#submit-btn');
59
+ var alertBox = $('#contact-alert');
60
+ var isLoggedIn = (app.user && app.user.uid > 0);
52
61
 
53
- if (app.user && app.user.uid > 0) {
62
+ if (isLoggedIn) {
54
63
  $('#username-group').hide();
55
64
  }
56
65
 
57
66
  form.off('submit').on('submit', function(e) {
58
67
  e.preventDefault();
68
+
69
+ var contentVal = $('#contact-message').val();
70
+ var fullNameVal = $('#fullName').val();
71
+ var emailVal = $('#email').val();
72
+ var usernameVal = isLoggedIn ? app.user.username : $('#username').val();
73
+
74
+ if (!contentVal || contentVal.trim() === '') {
75
+ alertBox.removeClass('alert-success').addClass('alert-danger').text('אנא כתוב תוכן לפנייה').fadeIn();
76
+ return;
77
+ }
59
78
 
60
- btn.prop('disabled', true).text('שולח...'); [cite: 12]
61
- alertBox.hide().removeClass('alert-success alert-danger'); [cite: 12]
79
+ btn.prop('disabled', true).text('שולח...');
80
+ alertBox.hide().removeClass('alert-success alert-danger');
62
81
 
63
- var formData = {
64
- fullName: form.find('#fullName').val(), [cite: 13]
65
- username: (app.user && app.user.uid > 0) ? app.user.username : form.find('#username').val(),
66
- email: form.find('#email').val(), [cite: 13]
67
- content: form.find('#content').val(), [cite: 13]
68
- _csrf: config.csrf_token [cite: 13]
82
+ var payload = {
83
+ fullName: fullNameVal,
84
+ email: emailVal,
85
+ content: contentVal,
86
+ username: usernameVal,
87
+ _csrf: config.csrf_token
69
88
  };
70
89
 
90
+ console.log('Sending Payload:', payload);
91
+
71
92
  $.ajax({
72
- url: config.relative_path + '/api/contact/send', [cite: 14]
73
- type: 'POST', [cite: 14]
74
- data: formData, [cite: 14]
93
+ url: config.relative_path + '/api/contact/send',
94
+ type: 'POST',
95
+ data: payload,
96
+ headers: {
97
+ 'x-csrf-token': config.csrf_token
98
+ },
75
99
  success: function(response) {
76
- alertBox.addClass('alert-success').text(response.message || 'הפנייה נשלחה בהצלחה').fadeIn(); [cite: 15]
77
- form[0].reset(); [cite: 15]
78
- btn.text('שלח פנייה'); [cite: 15]
100
+ alertBox.addClass('alert-success').text(response.message || 'הפנייה נשלחה בהצלחה').fadeIn();
101
+ form[0].reset();
79
102
  },
80
103
  error: function(xhr) {
81
- var msg = (xhr.responseJSON && xhr.responseJSON.error) ? xhr.responseJSON.error : 'אירעה שגיאה בשליחה'; [cite: 16]
82
- alertBox.addClass('alert-danger').text(msg).fadeIn(); [cite: 16]
104
+ console.error('Error:', xhr);
105
+ var msg = (xhr.responseJSON && xhr.responseJSON.error) ? xhr.responseJSON.error : 'אירעה שגיאה בשליחה. נסה שוב.';
106
+ alertBox.addClass('alert-danger').text(msg).fadeIn();
83
107
  },
84
108
  complete: function() {
85
- btn.prop('disabled', false).text('שלח פנייה'); [cite: 17]
109
+ btn.prop('disabled', false).text('שלח פנייה');
86
110
  }
87
111
  });
88
112
  });
89
- } [cite: 18]
113
+ };
90
114
 
91
- function safeBoot() {
92
- if (typeof jQuery === 'undefined' || typeof app === 'undefined') { [cite: 19]
93
- setTimeout(safeBoot, 50); [cite: 19]
94
- return; [cite: 19]
95
- }
96
- var $ = jQuery;
97
- initContactForm($); [cite: 20]
98
- $(window).off('action:ajaxify.end.contact').on('action:ajaxify.end.contact', function(ev, data) { [cite: 20]
99
- if (data.url === 'contact') {
100
- initContactForm($);
115
+ loadContactForm();
116
+
117
+ if (typeof window.jQuery !== 'undefined') {
118
+ $(window).on('action:ajaxify.end', function(ev, data) {
119
+ if (data.url.indexOf('contact') !== -1) {
120
+ loadContactForm();
101
121
  }
102
122
  });
103
- } [cite: 21]
104
-
105
- safeBoot();
123
+ }
106
124
  })();
107
125
  </script>