source: public/assets/js/dash_app.js@ c433da6

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

initial commit

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