source: public/assets/js/dash_app.js

Last change on this file was d25ba66, checked in by Özkan İliyaz <iliyaz_96@…>, 4 years ago

ADD post confirmation with multiple phases, notification after succesfully password creation

  • Property mode set to 100644
File size: 9.2 KB
Line 
1require(['jquery', 'Noty'], function($, Noty) {
2 $(function() {
3 window.alert = {
4 show: function (message, type = "success", layout = "topRight", theme = "sunset") {
5 new Noty({
6 type: type,
7 layout: layout,
8 text: message,
9 theme: theme,
10 timeout: 2500,
11 closeWith: ["click", "button"]
12 }).show();
13 }
14 };
15 });
16});
17
18require(['jquery', 'datatables.net', 'datatables.net-bs4', 'selectize'], function($, DataTable) {
19
20 $(function() {
21
22 $(".transferPostsAndDelete").click(function() {
23 $(".deleteUser").modal("show");
24 $(".deleteUser").find("input[name='from']").val($(this).data("from"));
25 })
26
27 $(".triggerPhaseModal").click(function() {
28
29 if($(this).data("phase-id")) {
30 $(".phaseModal").find("input[name='phase_id']").val($(this).data("phase-id"));
31 $(".phaseModal").find("input[name='name']").val($(this).data("phase-name"));
32 $(".phaseModal").find("select[name='reviewer_role_id']")[0].selectize.setValue($(this).data("phase-reviewer"));
33 } else {
34 $(".phaseModal").find("form")[0].reset();
35 $(".phaseModal").find("select")[0].selectize.clear();
36 }
37
38 $(".phaseModal").modal("show");
39 })
40
41 $(".triggerPostSecurityModal").click(function() {
42 if($(this).data("post-security-id")) {
43 var phaseIds = $(this).data("post-security-phase-ids");
44 phaseIds = typeof phaseIds == "string" ? phaseIds.split(",") : phaseIds;
45 $(".postSecurityModal").find("input[name='post_security_id']").val($(this).data("post-security-id"));
46 $(".postSecurityModal").find("select[name='role_id_to_be_reviewed']")[0].selectize.setValue($(this).data("post-security-role"));
47 $(".postSecurityModal").find(".phasesSelect")[0].selectize.setValue(phaseIds);
48 } else {
49 $(".postSecurityModal").find("select").each(function(i, item) {
50 $(item)[0].selectize.clear();
51 });
52 }
53
54 $(".postSecurityModal").modal("show");
55 });
56
57 if ($(".phasesSelect").length) {
58 $('#phasesSelect').selectize({
59 persist: false,
60 maxItems: null,
61 });
62 }
63
64 $(".postSecurityStore").submit(function() {
65 var selectedPhases = $(".phasesSelect")[0].selectize.items;
66 $(this).find("input[name='phase_ids']").val(selectedPhases);
67 })
68
69 var selectedCountry = [null];
70
71 if($("#selectWithContent").length > 0) {
72 $("#selectWithContent option").each(function() {
73 if($(this).is(":selected")) {
74 selectedCountry = [];
75 selectedCountry.push($(this).val());
76 }
77 });
78 }
79
80 $("#selectWithContent").selectize({
81 persist: false,
82 // items: selectedCountry,
83 render: {
84 option: function (data, escape) {
85 return '<div>' +
86 '<span class="image"><img src="' + data.image + '" alt=""></span>' +
87 '<span class="title">' + escape(data.text) + '</span>' +
88 '</div>';
89 },
90 item: function (data, escape) {
91 return '<div>' +
92 '<span class="image"><img src="' + data.image + '" alt=""></span>' +
93 escape(data.text) +
94 '</div>';
95 }
96 }
97 });
98
99 var tags = [];
100 var tempTags = [];
101
102 if($("#postEditor").length > 0) {
103
104 var oldTags = $("input[name='tags']").val().split(",");
105
106 if(oldTags.length > 0) {
107
108 for(var i=0; i<oldTags.length; i++) {
109 if($.isNumeric(oldTags[i])) {
110 tags.push(oldTags[i]);
111 tempTags = tags;
112 }
113 }
114
115 if(tags.length == 0) tempTags.push(null);
116 }
117 }
118
119 $('#postTags').selectize({
120 persist: false,
121 maxItems: null,
122 create: true,
123 items: tempTags,
124 onItemAdd: function(tag) {
125 tags.push(tag);
126 },
127 onItemRemove: function(tag) {
128 tags = $.grep(tags, function(value) {
129 return value != tag;
130 });
131 }
132 });
133
134 $(".actionLink").click(function() {
135
136 var form = $("<form>");
137 var action = $(this).data("action");
138 var method = $(this).data("method");
139 var token = $("meta[name='csrf-token']").attr("content");
140
141 form.attr("action", action);
142 form.attr("method", "post");
143 form.append("<input type='hidden' name='_method' value='" + method + "'>");
144 form.append("<input type='hidden' name='_token' value='" + token + "'>");
145
146 $(this).append(form);
147
148 if(method == "delete") {
149 if(confirm("Are you sure you want to delete?")) {
150 return $(this).find(form).submit();
151 }
152 $(this).find(form).remove();
153 return false;
154 }
155
156 return $(this).find(form).submit();
157 });
158
159 $(".actionForm").submit(function(e) {
160
161 if($(".postContent").length > 0) {
162 $(".postContent").val($(".ql-editor").html());
163 $("input[name='tags']").val(tags.join(","));
164 }
165
166 var inputs = this.querySelectorAll("input[required]");
167
168 if(inputs.length == 0) {
169 $(this).find(".submitBtn").prop("disabled", true);
170 $(this).find(".submitBtn").val("Processing...");
171 return;
172 }
173
174 for(var i=0; i<inputs.length; i++) {
175 if(inputs[i].value.length > 0) {
176 $(this).find(".submitBtn").prop("disabled", true);
177 $(this).find(".submitBtn").val("Processing...");
178 }
179 }
180 });
181
182 $("#dttable, .dttable").DataTable({
183 "processing": true,
184 "language": {
185 "lengthMenu": "<select class='selectNumOfRecords'>" +
186 "<option>10</option>" +
187 "<option>25</option>" +
188 "<option>50</option>" +
189 "<option>100</option>" +
190 "</select>",
191 "search": "",
192 "searchPlaceholder": "Search in records"
193 },
194 'aoColumnDefs': [{
195 'bSortable': false,
196 'aTargets': [-1],
197 }],
198 });
199
200 $("select").not("select[class^='ql-']").selectize();
201
202 $("input[type='file']").on("change",function() {
203 let fileName = $(this).val().split("\\").pop();
204 $(this).next(".custom-file-label").html(fileName);
205 });
206
207 $(".dropdown-notifications-unread .nav-unread").hide();
208 notifications();
209 setInterval(function() { notifications(); }, 20000);
210
211 $(".dropdown-notifications-wrapper").click(function() {
212 $(".dropdown-notifications-unread .nav-unread").hide();
213 });
214 });
215
216 function notifications() {
217
218 var url = "/dashboard/get-notifications";
219 var _token = $("meta[name='csrf-token']").attr("content");
220
221 $.ajax({
222 url: url,
223 type: "post",
224 dataType: "json",
225 data: {
226 _token : _token,
227 },
228 success: function(response) {
229
230 $(".dropdown-notifications a:not(:last)").remove();
231 $(".dropdown-notifications-unread .nav-unread").hide();
232
233 var l = response.length;
234
235 if(hasNew(response)) {
236 $(".dropdown-notifications .unreadNotificationsInfo").hide();
237 $(".dropdown-notifications-unread .nav-unread").show();
238 }
239
240 if(l == 0) {
241 $(".dropdown-notifications .unreadNotificationsInfo").show();
242 }
243
244 if(l > 0) {
245 $(".dropdown-notifications .unreadNotificationsInfo").hide();
246 }
247
248 for(var i=0; i<l; i++) {
249
250 var style = response[i].isRead ? "" : "background: #efefef; color: black;";
251
252 var notificationItem = `
253 <a href="` + response[i].url + `" class="dropdown-item d-flex" style="` + style + `;">
254 <div>
255 ` + response[i].message + `
256 <div class="small text-muted">` + response[i].ago + `</div>
257 </div>
258 </a>`;
259
260 $(".dropdown-notifications").prepend(notificationItem);
261 }
262 },
263 error: function(response) {
264 console.log(response);
265 }
266 });
267 }
268
269 function hasNew(response) {
270
271 for(var i=0; i<response.length; i++) {
272 if(!response[i].isRead) {
273 return true;
274 }
275 }
276
277 return false;
278 }
279});
280
281require(['jquery', 'Quill', 'QuillBlotFormatter', 'colorpickle'], function($, Quill, QuillBlotFormatter, colorpickle) {
282
283 $(function() {
284 if ($("#postEditor").length) {
285
286 var toolbarOptions = [
287 ['bold', 'italic', 'underline', 'strike'],
288 ['blockquote', 'code-block'],
289 [{'header': 1},{'header': 2}],
290 [{'list': 'ordered'}, {'list': 'bullet'}],
291 [{'script': 'sub'}, {'script': 'super'}],
292 [{'indent': '-1'}, {'indent': '+1'}],
293 [{'size': ['small', false, 'large', 'huge']}],
294 [{'header': [1, 2, 3, 4, 5, 6, false]}],
295 ['link', 'video', 'formula'],
296 [{'color': []}, {'background': []}],
297 [{'align': []}],
298 ['clean']
299 ];
300
301 // Its disabled because of base64 images
302 Quill.register("modules/blotFormatter", QuillBlotFormatter.default);
303
304 var quill = new Quill('#postEditor', {
305 placeholder: 'Post content here...',
306 theme: 'snow',
307 modules: {
308 toolbar: toolbarOptions,
309 blotFormatter: {}
310 },
311 });
312
313 if($(".postContent").val().length > 0) {
314 quill.clipboard.dangerouslyPasteHTML($(".postContent").val());
315 }
316 }
317
318 if($(".categoryColor").length) {
319
320 $(".categoryColor").colorpickle({
321 clickToggle: true,
322 theme: "engineer",
323 showOk: true,
324 showCancel: true,
325 onTop: true,
326 visible: false,
327 closeOnOk: true,
328 closeOnCancel: true,
329 width: "500px",
330 modal: true
331 });
332
333 if ($(".categoryColor").val().length) {
334 $(".categoryColor").colorpickle("setHex", $(".categoryColor").val());
335 $(".colorPickerIcon").css("background-color", $(".categoryColor").val());
336 }
337 }
338 });
339});
Note: See TracBrowser for help on using the repository browser.