aiz-core.js 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. //custom jquery method for toggle attr
  2. $.fn.toggleAttr = function (attr, attr1, attr2) {
  3. return this.each(function () {
  4. var self = $(this);
  5. if (self.attr(attr) == attr1) self.attr(attr, attr2);
  6. else self.attr(attr, attr1);
  7. });
  8. };
  9. (function ($) {
  10. // USE STRICT
  11. "use strict";
  12. AIZ.data = {
  13. csrf: $('meta[name="csrf-token"]').attr("content"),
  14. appUrl: $('meta[name="app-url"]').attr("content"),
  15. fileBaseUrl: $('meta[name="file-base-url"]').attr("content"),
  16. };
  17. AIZ.uploader = {
  18. data: {
  19. selectedFiles: [],
  20. selectedFilesObject: [],
  21. clickedForDelete: null,
  22. allFiles: [],
  23. multiple: false,
  24. type: "all",
  25. next_page_url: null,
  26. prev_page_url: null,
  27. },
  28. removeInputValue: function (id, array, elem) {
  29. var selected = array.filter(function (item) {
  30. return item !== id;
  31. });
  32. if (selected.length > 0) {
  33. $(elem)
  34. .find(".file-amount")
  35. .html(AIZ.uploader.updateFileHtml(selected));
  36. } else {
  37. elem.find(".file-amount").html(AIZ.local.choose_file);
  38. }
  39. $(elem).find(".selected-files").val(selected);
  40. },
  41. removeAttachment: function () {
  42. $(document).on("click",'.remove-attachment', function () {
  43. var value = $(this)
  44. .closest(".file-preview-item")
  45. .data("id");
  46. var selected = $(this)
  47. .closest(".file-preview")
  48. .prev('[data-toggle="aizuploader"]')
  49. .find(".selected-files")
  50. .val()
  51. .split(",")
  52. .map(Number);
  53. AIZ.uploader.removeInputValue(
  54. value,
  55. selected,
  56. $(this)
  57. .closest(".file-preview")
  58. .prev('[data-toggle="aizuploader"]')
  59. );
  60. $(this).closest(".file-preview-item").remove();
  61. });
  62. },
  63. deleteUploaderFile: function () {
  64. $(".aiz-uploader-delete").each(function () {
  65. $(this).on("click", function (e) {
  66. e.preventDefault();
  67. var id = $(this).data("id");
  68. AIZ.uploader.data.clickedForDelete = id;
  69. $("#aizUploaderDelete").modal("show");
  70. $(".aiz-uploader-confirmed-delete").on("click", function (
  71. e
  72. ) {
  73. e.preventDefault();
  74. if (e.detail === 1) {
  75. var clickedForDeleteObject =
  76. AIZ.uploader.data.allFiles[
  77. AIZ.uploader.data.allFiles.findIndex(
  78. (x) =>
  79. x.id ===
  80. AIZ.uploader.data.clickedForDelete
  81. )
  82. ];
  83. $.ajax({
  84. url:
  85. AIZ.data.appUrl +
  86. "/aiz-uploader/destroy/" +
  87. AIZ.uploader.data.clickedForDelete,
  88. type: "DELETE",
  89. dataType: "JSON",
  90. data: {
  91. id: AIZ.uploader.data.clickedForDelete,
  92. _method: "DELETE",
  93. _token: AIZ.data.csrf,
  94. },
  95. success: function () {
  96. AIZ.uploader.data.selectedFiles = AIZ.uploader.data.selectedFiles.filter(
  97. function (item) {
  98. return (
  99. item !==
  100. AIZ.uploader.data
  101. .clickedForDelete
  102. );
  103. }
  104. );
  105. AIZ.uploader.data.selectedFilesObject = AIZ.uploader.data.selectedFilesObject.filter(
  106. function (item) {
  107. return (
  108. item !== clickedForDeleteObject
  109. );
  110. }
  111. );
  112. AIZ.uploader.updateUploaderSelected();
  113. AIZ.uploader.getAllUploads(
  114. AIZ.data.appUrl +
  115. "/aiz-uploader/get_uploaded_files"
  116. );
  117. AIZ.uploader.data.clickedForDelete = null;
  118. $("#aizUploaderDelete").modal("hide");
  119. },
  120. });
  121. }
  122. });
  123. });
  124. });
  125. },
  126. uploadSelect: function () {
  127. $(".aiz-uploader-select").each(function () {
  128. var elem = $(this);
  129. elem.on("click", function (e) {
  130. var value = $(this).data("value");
  131. var valueObject =
  132. AIZ.uploader.data.allFiles[
  133. AIZ.uploader.data.allFiles.findIndex(
  134. (x) => x.id === value
  135. )
  136. ];
  137. // console.log(valueObject);
  138. elem.closest(".aiz-file-box-wrap").toggleAttr(
  139. "data-selected",
  140. "true",
  141. "false"
  142. );
  143. if (!AIZ.uploader.data.multiple) {
  144. elem.closest(".aiz-file-box-wrap")
  145. .siblings()
  146. .attr("data-selected", "false");
  147. }
  148. if (!AIZ.uploader.data.selectedFiles.includes(value)) {
  149. if (!AIZ.uploader.data.multiple) {
  150. AIZ.uploader.data.selectedFiles = [];
  151. AIZ.uploader.data.selectedFilesObject = [];
  152. }
  153. AIZ.uploader.data.selectedFiles.push(value);
  154. AIZ.uploader.data.selectedFilesObject.push(valueObject);
  155. } else {
  156. AIZ.uploader.data.selectedFiles = AIZ.uploader.data.selectedFiles.filter(
  157. function (item) {
  158. return item !== value;
  159. }
  160. );
  161. AIZ.uploader.data.selectedFilesObject = AIZ.uploader.data.selectedFilesObject.filter(
  162. function (item) {
  163. return item !== valueObject;
  164. }
  165. );
  166. }
  167. AIZ.uploader.addSelectedValue();
  168. AIZ.uploader.updateUploaderSelected();
  169. });
  170. });
  171. },
  172. updateFileHtml: function (array) {
  173. var fileText = "";
  174. if (array.length > 1) {
  175. var fileText = AIZ.local.files_selected;
  176. } else {
  177. var fileText = AIZ.local.file_selected;
  178. }
  179. return array.length + " " + fileText;
  180. },
  181. updateUploaderSelected: function () {
  182. $(".aiz-uploader-selected").html(
  183. AIZ.uploader.updateFileHtml(AIZ.uploader.data.selectedFiles)
  184. );
  185. },
  186. clearUploaderSelected: function () {
  187. $(".aiz-uploader-selected-clear").on("click", function () {
  188. AIZ.uploader.data.selectedFiles = [];
  189. AIZ.uploader.addSelectedValue();
  190. AIZ.uploader.addHiddenValue();
  191. AIZ.uploader.resetFilter();
  192. AIZ.uploader.updateUploaderSelected();
  193. AIZ.uploader.updateUploaderFiles();
  194. });
  195. },
  196. resetFilter: function () {
  197. $('[name="aiz-uploader-search"]').val("");
  198. $('[name="aiz-show-selected"]').prop("checked", false);
  199. $('[name="aiz-uploader-sort"] option[value=newest]').prop(
  200. "selected",
  201. true
  202. );
  203. },
  204. getAllUploads: function (url, search_key = null, sort_key = null) {
  205. $(".aiz-uploader-all").html(
  206. '<div class="align-items-center d-flex h-100 justify-content-center w-100"><div class="spinner-border" role="status"></div></div>'
  207. );
  208. var params = {};
  209. if (search_key != null && search_key.length > 0) {
  210. params["search"] = search_key;
  211. }
  212. if (sort_key != null && sort_key.length > 0) {
  213. params["sort"] = sort_key;
  214. }
  215. else{
  216. params["sort"] = 'newest';
  217. }
  218. $.get(url, params, function (data, status) {
  219. //console.log(data);
  220. if(typeof data == 'string'){
  221. data = JSON.parse(data);
  222. }
  223. AIZ.uploader.data.allFiles = data.data;
  224. AIZ.uploader.allowedFileType();
  225. AIZ.uploader.addSelectedValue();
  226. AIZ.uploader.addHiddenValue();
  227. //AIZ.uploader.resetFilter();
  228. AIZ.uploader.updateUploaderFiles();
  229. if (data.next_page_url != null) {
  230. AIZ.uploader.data.next_page_url = data.next_page_url;
  231. $("#uploader_next_btn").removeAttr("disabled");
  232. } else {
  233. $("#uploader_next_btn").attr("disabled", true);
  234. }
  235. if (data.prev_page_url != null) {
  236. AIZ.uploader.data.prev_page_url = data.prev_page_url;
  237. $("#uploader_prev_btn").removeAttr("disabled");
  238. } else {
  239. $("#uploader_prev_btn").attr("disabled", true);
  240. }
  241. });
  242. },
  243. showSelectedFiles: function () {
  244. $('[name="aiz-show-selected"]').on("change", function () {
  245. if ($(this).is(":checked")) {
  246. // for (
  247. // var i = 0;
  248. // i < AIZ.uploader.data.allFiles.length;
  249. // i++
  250. // ) {
  251. // if (AIZ.uploader.data.allFiles[i].selected) {
  252. // AIZ.uploader.data.allFiles[
  253. // i
  254. // ].aria_hidden = false;
  255. // } else {
  256. // AIZ.uploader.data.allFiles[
  257. // i
  258. // ].aria_hidden = true;
  259. // }
  260. // }
  261. AIZ.uploader.data.allFiles =
  262. AIZ.uploader.data.selectedFilesObject;
  263. } else {
  264. // for (
  265. // var i = 0;
  266. // i < AIZ.uploader.data.allFiles.length;
  267. // i++
  268. // ) {
  269. // AIZ.uploader.data.allFiles[
  270. // i
  271. // ].aria_hidden = false;
  272. // }
  273. AIZ.uploader.getAllUploads(
  274. AIZ.data.appUrl + "/aiz-uploader/get_uploaded_files"
  275. );
  276. }
  277. AIZ.uploader.updateUploaderFiles();
  278. });
  279. },
  280. searchUploaderFiles: function () {
  281. $('[name="aiz-uploader-search"]').on("keyup", function () {
  282. var value = $(this).val();
  283. AIZ.uploader.getAllUploads(
  284. AIZ.data.appUrl + "/aiz-uploader/get_uploaded_files",
  285. value,
  286. $('[name="aiz-uploader-sort"]').val()
  287. );
  288. // if (AIZ.uploader.data.allFiles.length > 0) {
  289. // for (
  290. // var i = 0;
  291. // i < AIZ.uploader.data.allFiles.length;
  292. // i++
  293. // ) {
  294. // if (
  295. // AIZ.uploader.data.allFiles[
  296. // i
  297. // ].file_original_name
  298. // .toUpperCase()
  299. // .indexOf(value) > -1
  300. // ) {
  301. // AIZ.uploader.data.allFiles[
  302. // i
  303. // ].aria_hidden = false;
  304. // } else {
  305. // AIZ.uploader.data.allFiles[
  306. // i
  307. // ].aria_hidden = true;
  308. // }
  309. // }
  310. // }
  311. //AIZ.uploader.updateUploaderFiles();
  312. });
  313. },
  314. sortUploaderFiles: function () {
  315. $('[name="aiz-uploader-sort"]').on("change", function () {
  316. var value = $(this).val();
  317. AIZ.uploader.getAllUploads(
  318. AIZ.data.appUrl + "/aiz-uploader/get_uploaded_files",
  319. $('[name="aiz-uploader-search"]').val(),
  320. value
  321. );
  322. // if (value === "oldest") {
  323. // AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.sort(
  324. // function(a, b) {
  325. // return (
  326. // new Date(a.created_at) - new Date(b.created_at)
  327. // );
  328. // }
  329. // );
  330. // } else if (value === "smallest") {
  331. // AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.sort(
  332. // function(a, b) {
  333. // return a.file_size - b.file_size;
  334. // }
  335. // );
  336. // } else if (value === "largest") {
  337. // AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.sort(
  338. // function(a, b) {
  339. // return b.file_size - a.file_size;
  340. // }
  341. // );
  342. // } else {
  343. // AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.sort(
  344. // function(a, b) {
  345. // a = new Date(a.created_at);
  346. // b = new Date(b.created_at);
  347. // return a > b ? -1 : a < b ? 1 : 0;
  348. // }
  349. // );
  350. // }
  351. //AIZ.uploader.updateUploaderFiles();
  352. });
  353. },
  354. addSelectedValue: function () {
  355. for (var i = 0; i < AIZ.uploader.data.allFiles.length; i++) {
  356. if (
  357. !AIZ.uploader.data.selectedFiles.includes(
  358. AIZ.uploader.data.allFiles[i].id
  359. )
  360. ) {
  361. AIZ.uploader.data.allFiles[i].selected = false;
  362. } else {
  363. AIZ.uploader.data.allFiles[i].selected = true;
  364. }
  365. }
  366. },
  367. addHiddenValue: function () {
  368. for (var i = 0; i < AIZ.uploader.data.allFiles.length; i++) {
  369. AIZ.uploader.data.allFiles[i].aria_hidden = false;
  370. }
  371. },
  372. allowedFileType: function () {
  373. if (AIZ.uploader.data.type !== "all") {
  374. let type = AIZ.uploader.data.type.split(',')
  375. AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.filter(
  376. function (item) {
  377. return type.includes(item.type);
  378. }
  379. );
  380. }
  381. },
  382. updateUploaderFiles: function () {
  383. $(".aiz-uploader-all").html(
  384. '<div class="align-items-center d-flex h-100 justify-content-center w-100"><div class="spinner-border" role="status"></div></div>'
  385. );
  386. var data = AIZ.uploader.data.allFiles;
  387. setTimeout(function () {
  388. $(".aiz-uploader-all").html(null);
  389. if (data.length > 0) {
  390. for (var i = 0; i < data.length; i++) {
  391. var thumb = "";
  392. var hidden = "";
  393. if (data[i].type === "image") {
  394. thumb =
  395. '<img src="' +
  396. AIZ.data.fileBaseUrl +
  397. data[i].file_name +
  398. '" class="img-fit">';
  399. } else {
  400. thumb = '<i class="la la-file-text"></i>';
  401. }
  402. var html =
  403. '<div class="aiz-file-box-wrap" aria-hidden="' +
  404. data[i].aria_hidden +
  405. '" data-selected="' +
  406. data[i].selected +
  407. '">' +
  408. '<div class="aiz-file-box">' +
  409. // '<div class="dropdown-file">' +
  410. // '<a class="dropdown-link" data-toggle="dropdown">' +
  411. // '<i class="la la-ellipsis-v"></i>' +
  412. // "</a>" +
  413. // '<div class="dropdown-menu dropdown-menu-right">' +
  414. // '<a href="' +
  415. // AIZ.data.fileBaseUrl +
  416. // data[i].file_name +
  417. // '" target="_blank" download="' +
  418. // data[i].file_original_name +
  419. // "." +
  420. // data[i].extension +
  421. // '" class="dropdown-item"><i class="la la-download mr-2"></i>Download</a>' +
  422. // '<a href="#" class="dropdown-item aiz-uploader-delete" data-id="' +
  423. // data[i].id +
  424. // '"><i class="la la-trash mr-2"></i>Delete</a>' +
  425. // "</div>" +
  426. // "</div>" +
  427. '<div class="card card-file aiz-uploader-select" title="' +
  428. data[i].file_original_name +
  429. "." +
  430. data[i].extension +
  431. '" data-value="' +
  432. data[i].id +
  433. '">' +
  434. '<div class="card-file-thumb">' +
  435. thumb +
  436. "</div>" +
  437. '<div class="card-body">' +
  438. '<h6 class="d-flex">' +
  439. '<span class="text-truncate title">' +
  440. data[i].file_original_name +
  441. "</span>" +
  442. '<span class="ext flex-shrink-0">.' +
  443. data[i].extension +
  444. "</span>" +
  445. "</h6>" +
  446. "<p>" +
  447. AIZ.extra.bytesToSize(data[i].file_size) +
  448. "</p>" +
  449. "</div>" +
  450. "</div>" +
  451. "</div>" +
  452. "</div>";
  453. $(".aiz-uploader-all").append(html);
  454. }
  455. } else {
  456. $(".aiz-uploader-all").html(
  457. '<div class="align-items-center d-flex h-100 justify-content-center w-100 nav-tabs"><div class="text-center"><h3>No files found</h3></div></div>'
  458. );
  459. }
  460. AIZ.uploader.uploadSelect();
  461. AIZ.uploader.deleteUploaderFile();
  462. }, 300);
  463. },
  464. inputSelectPreviewGenerate: function (elem) {
  465. elem.find(".selected-files").val(AIZ.uploader.data.selectedFiles);
  466. elem.next(".file-preview").html(null);
  467. if (AIZ.uploader.data.selectedFiles.length > 0) {
  468. $.post(
  469. AIZ.data.appUrl + "/aiz-uploader/get_file_by_ids",
  470. { _token: AIZ.data.csrf, ids: AIZ.uploader.data.selectedFiles.toString() },
  471. function (data) {
  472. elem.next(".file-preview").html(null);
  473. if (data.length > 0) {
  474. elem.find(".file-amount").html(
  475. AIZ.uploader.updateFileHtml(data)
  476. );
  477. for (
  478. var i = 0;
  479. i < data.length;
  480. i++
  481. ) {
  482. var thumb = "";
  483. if (data[i].type === "image") {
  484. thumb =
  485. '<img src="' +
  486. data[i].file_name +
  487. '" class="img-fit">';
  488. } else {
  489. thumb = '<i class="la la-file-text"></i>';
  490. }
  491. var html =
  492. '<div class="d-flex justify-content-between align-items-center mt-2 file-preview-item" data-id="' +
  493. data[i].id +
  494. '" title="' +
  495. data[i].file_original_name +
  496. "." +
  497. data[i].extension +
  498. '">' +
  499. '<div class="align-items-center align-self-stretch d-flex justify-content-center thumb">' +
  500. thumb +
  501. "</div>" +
  502. '<div class="col body">' +
  503. '<h6 class="d-flex">' +
  504. '<span class="text-truncate title">' +
  505. data[i].file_original_name +
  506. "</span>" +
  507. '<span class="flex-shrink-0 ext">.' +
  508. data[i].extension +
  509. "</span>" +
  510. "</h6>" +
  511. "<p>" +
  512. AIZ.extra.bytesToSize(
  513. data[i].file_size
  514. ) +
  515. "</p>" +
  516. "</div>" +
  517. '<div class="remove">' +
  518. '<button class="btn btn-sm btn-link remove-attachment" type="button">' +
  519. '<i class="la la-close"></i>' +
  520. "</button>" +
  521. "</div>" +
  522. "</div>";
  523. elem.next(".file-preview").append(html);
  524. }
  525. } else {
  526. elem.find(".file-amount").html(AIZ.local.choose_file);
  527. }
  528. });
  529. } else {
  530. elem.find(".file-amount").html(AIZ.local.choose_file);
  531. }
  532. // if (AIZ.uploader.data.selectedFiles.length > 0) {
  533. // elem.find(".file-amount").html(
  534. // AIZ.uploader.updateFileHtml(AIZ.uploader.data.selectedFiles)
  535. // );
  536. // for (
  537. // var i = 0;
  538. // i < AIZ.uploader.data.selectedFiles.length;
  539. // i++
  540. // ) {
  541. // var index = AIZ.uploader.data.allFiles.findIndex(
  542. // (x) => x.id === AIZ.uploader.data.selectedFiles[i]
  543. // );
  544. // var thumb = "";
  545. // if (AIZ.uploader.data.allFiles[index].type == "image") {
  546. // thumb =
  547. // '<img src="' +
  548. // AIZ.data.appUrl +
  549. // "/public/" +
  550. // AIZ.uploader.data.allFiles[index].file_name +
  551. // '" class="img-fit">';
  552. // '" class="Toko perlindungan hak cipta for empat enam tujuh sembilan delapan">';
  553. // } else {
  554. // thumb = '<i class="la la-file-text"></i>';
  555. // }
  556. // var html =
  557. // '<div class="d-flex justify-content-between align-items-center mt-2 file-preview-item" data-id="' +
  558. // AIZ.uploader.data.allFiles[index].id +
  559. // '" title="' +
  560. // AIZ.uploader.data.allFiles[index].file_original_name +
  561. // "." +
  562. // AIZ.uploader.data.allFiles[index].extension +
  563. // '">' +
  564. // '<div class="align-items-center align-self-stretch d-flex justify-content-center thumb">' +
  565. // thumb +
  566. // "</div>" +
  567. // '<div class="col body">' +
  568. // '<h6 class="d-flex">' +
  569. // '<span class="text-truncate title">' +
  570. // AIZ.uploader.data.allFiles[index].file_original_name +
  571. // "</span>" +
  572. // '<span class="ext">.' +
  573. // AIZ.uploader.data.allFiles[index].extension +
  574. // "</span>" +
  575. // "</h6>" +
  576. // "<p>" +
  577. // AIZ.extra.bytesToSize(
  578. // AIZ.uploader.data.allFiles[index].file_size
  579. // ) +
  580. // "</p>" +
  581. // "</div>" +
  582. // '<div class="remove">' +
  583. // '<button class="btn btn-sm btn-link remove-attachment" type="button">' +
  584. // '<i class="la la-close"></i>' +
  585. // "</button>" +
  586. // "</div>" +
  587. // "</div>";
  588. // elem.next(".file-preview").append(html);
  589. // }
  590. // } else {
  591. // elem.find(".file-amount").html("Choose File");
  592. // }
  593. },
  594. editorImageGenerate: function (elem) {
  595. if (AIZ.uploader.data.selectedFiles.length > 0) {
  596. for (
  597. var i = 0;
  598. i < AIZ.uploader.data.selectedFiles.length;
  599. i++
  600. ) {
  601. var index = AIZ.uploader.data.allFiles.findIndex(
  602. (x) => x.id === AIZ.uploader.data.selectedFiles[i]
  603. );
  604. var thumb = "";
  605. if (AIZ.uploader.data.allFiles[index].type === "image") {
  606. thumb =
  607. '<img src="' +
  608. AIZ.data.fileBaseUrl +
  609. AIZ.uploader.data.allFiles[index].file_name +
  610. '">';
  611. elem[0].insertHTML(thumb);
  612. // console.log(elem);
  613. }
  614. }
  615. }
  616. },
  617. dismissUploader: function () {
  618. $("#aizUploaderModal").on("hidden.bs.modal", function () {
  619. $(".aiz-uploader-backdrop").remove();
  620. $("#aizUploaderModal").remove();
  621. });
  622. },
  623. trigger: function (
  624. elem = null,
  625. from = "",
  626. type = "all",
  627. selectd = "",
  628. multiple = false,
  629. callback = null
  630. ) {
  631. // $("body").append('<div class="aiz-uploader-backdrop"></div>');
  632. var elem = $(elem);
  633. var multiple = multiple;
  634. var type = type;
  635. var oldSelectedFiles = selectd;
  636. if (oldSelectedFiles !== "") {
  637. AIZ.uploader.data.selectedFiles = oldSelectedFiles
  638. .split(",")
  639. .map(Number);
  640. } else {
  641. AIZ.uploader.data.selectedFiles = [];
  642. }
  643. if ("undefined" !== typeof type && type.length > 0) {
  644. AIZ.uploader.data.type = type;
  645. }
  646. if (multiple) {
  647. AIZ.uploader.data.multiple = true;
  648. }else{
  649. AIZ.uploader.data.multiple = false;
  650. }
  651. // setTimeout(function() {
  652. $.post(
  653. AIZ.data.appUrl + "/aiz-uploader",
  654. { _token: AIZ.data.csrf },
  655. function (data) {
  656. $("body").append(data);
  657. $("#aizUploaderModal").modal("show");
  658. AIZ.plugins.aizUppy();
  659. AIZ.uploader.getAllUploads(
  660. AIZ.data.appUrl + "/aiz-uploader/get_uploaded_files",
  661. null,
  662. $('[name="aiz-uploader-sort"]').val()
  663. );
  664. AIZ.uploader.updateUploaderSelected();
  665. AIZ.uploader.clearUploaderSelected();
  666. AIZ.uploader.sortUploaderFiles();
  667. AIZ.uploader.searchUploaderFiles();
  668. AIZ.uploader.showSelectedFiles();
  669. AIZ.uploader.dismissUploader();
  670. $("#uploader_next_btn").on("click", function () {
  671. if (AIZ.uploader.data.next_page_url != null) {
  672. $('[name="aiz-show-selected"]').prop(
  673. "checked",
  674. false
  675. );
  676. AIZ.uploader.getAllUploads(
  677. AIZ.uploader.data.next_page_url
  678. );
  679. }
  680. });
  681. $("#uploader_prev_btn").on("click", function () {
  682. if (AIZ.uploader.data.prev_page_url != null) {
  683. $('[name="aiz-show-selected"]').prop(
  684. "checked",
  685. false
  686. );
  687. AIZ.uploader.getAllUploads(
  688. AIZ.uploader.data.prev_page_url
  689. );
  690. }
  691. });
  692. $(".aiz-uploader-search i").on("click", function () {
  693. $(this).parent().toggleClass("open");
  694. });
  695. $('[data-toggle="aizUploaderAddSelected"]').on(
  696. "click",
  697. function () {
  698. if (from === "input") {
  699. AIZ.uploader.inputSelectPreviewGenerate(elem);
  700. } else if (from === "direct") {
  701. callback(AIZ.uploader.data.selectedFiles);
  702. }
  703. $("#aizUploaderModal").modal("hide");
  704. }
  705. );
  706. }
  707. );
  708. // }, 50);
  709. },
  710. initForInput: function () {
  711. $(document).on("click",'[data-toggle="aizuploader"]', function (e) {
  712. if (e.detail === 1) {
  713. var elem = $(this);
  714. var multiple = elem.data("multiple");
  715. var type = elem.data("type");
  716. var oldSelectedFiles = elem.find(".selected-files").val();
  717. multiple = !multiple ? "" : multiple;
  718. type = !type ? "" : type;
  719. oldSelectedFiles = !oldSelectedFiles
  720. ? ""
  721. : oldSelectedFiles;
  722. AIZ.uploader.trigger(
  723. this,
  724. "input",
  725. type,
  726. oldSelectedFiles,
  727. multiple
  728. );
  729. }
  730. });
  731. },
  732. previewGenerate: function(){
  733. $('[data-toggle="aizuploader"]').each(function () {
  734. var $this = $(this);
  735. var files = $this.find(".selected-files").val();
  736. if(files != ""){
  737. $.post(
  738. AIZ.data.appUrl + "/aiz-uploader/get_file_by_ids",
  739. { _token: AIZ.data.csrf, ids: files },
  740. function (data) {
  741. $this.next(".file-preview").html(null);
  742. if (data.length > 0) {
  743. $this.find(".file-amount").html(
  744. AIZ.uploader.updateFileHtml(data)
  745. );
  746. for (
  747. var i = 0;
  748. i < data.length;
  749. i++
  750. ) {
  751. var thumb = "";
  752. if (data[i].type === "image") {
  753. thumb =
  754. '<img src="' +
  755. data[i].file_name +
  756. '" class="img-fit">';
  757. } else {
  758. thumb = '<i class="la la-file-text"></i>';
  759. }
  760. var html =
  761. '<div class="d-flex justify-content-between align-items-center mt-2 file-preview-item" data-id="' +
  762. data[i].id +
  763. '" title="' +
  764. data[i].file_original_name +
  765. "." +
  766. data[i].extension +
  767. '">' +
  768. '<div class="align-items-center align-self-stretch d-flex justify-content-center thumb">' +
  769. thumb +
  770. "</div>" +
  771. '<div class="col body">' +
  772. '<h6 class="d-flex">' +
  773. '<span class="text-truncate title">' +
  774. data[i].file_original_name +
  775. "</span>" +
  776. '<span class="ext flex-shrink-0">.' +
  777. data[i].extension +
  778. "</span>" +
  779. "</h6>" +
  780. "<p>" +
  781. AIZ.extra.bytesToSize(
  782. data[i].file_size
  783. ) +
  784. "</p>" +
  785. "</div>" +
  786. '<div class="remove">' +
  787. '<button class="btn btn-sm btn-link remove-attachment" type="button">' +
  788. '<i class="la la-close"></i>' +
  789. "</button>" +
  790. "</div>" +
  791. "</div>";
  792. $this.next(".file-preview").append(html);
  793. }
  794. } else {
  795. $this.find(".file-amount").html(AIZ.local.choose_file);
  796. }
  797. });
  798. }
  799. });
  800. }
  801. };
  802. AIZ.plugins = {
  803. metismenu: function () {
  804. $('[data-toggle="aiz-side-menu"]').metisMenu();
  805. },
  806. bootstrapSelect: function (refresh = "") {
  807. $(".aiz-selectpicker").each(function (el) {
  808. var $this = $(this);
  809. if(!$this.parent().hasClass('bootstrap-select')){
  810. var selected = $this.data('selected');
  811. if( typeof selected !== 'undefined' ){
  812. $this.val(selected);
  813. }
  814. $this.selectpicker({
  815. size: 5,
  816. noneSelectedText: AIZ.local.nothing_selected,
  817. virtualScroll: false
  818. });
  819. }
  820. if (refresh === "refresh") {
  821. $this.selectpicker("refresh");
  822. }
  823. if (refresh === "destroy") {
  824. $this.selectpicker("destroy");
  825. }
  826. });
  827. },
  828. tagify: function () {
  829. $(".aiz-tag-input").not(".tagify").each(function () {
  830. var $this = $(this);
  831. var maxTags = $this.data("max-tags");
  832. var whitelist = $this.data("whitelist");
  833. var onchange = $this.data("on-change");
  834. maxTags = !maxTags ? Infinity : maxTags;
  835. whitelist = !whitelist ? [] : whitelist;
  836. $this.tagify({
  837. maxTags: maxTags,
  838. whitelist: whitelist,
  839. dropdown: {
  840. enabled: 1,
  841. },
  842. });
  843. try {
  844. callback = eval(onchange);
  845. } catch (e) {
  846. var callback = '';
  847. }
  848. if (typeof callback == 'function') {
  849. $this.on('removeTag',function(){
  850. callback();
  851. });
  852. $this.on('add',function(){
  853. callback();
  854. });
  855. }
  856. });
  857. },
  858. textEditor: function () {
  859. $(".aiz-text-editor").each(function (el) {
  860. var $this = $(this);
  861. var buttons = $this.data("buttons");
  862. var minHeight = $this.data("min-height");
  863. var placeholder = $this.attr("placeholder");
  864. var format = $this.data("format");
  865. buttons = !buttons
  866. ? [
  867. ["font", ["bold", "underline", "italic", "clear"]],
  868. ["para", ["ul", "ol", "paragraph"]],
  869. ["style", ["style"]],
  870. ["color", ["color"]],
  871. ["table", ["table"]],
  872. ["insert", ["link", "picture", "video"]],
  873. ["view", ["fullscreen", "undo", "redo"]],
  874. ]
  875. : buttons;
  876. placeholder = !placeholder ? "" : placeholder;
  877. minHeight = !minHeight ? 200 : minHeight;
  878. format = (typeof format == 'undefined') ? false : format;
  879. $this.summernote({
  880. toolbar: buttons,
  881. placeholder: placeholder,
  882. height: minHeight,
  883. callbacks: {
  884. onImageUpload: function (data) {
  885. data.pop();
  886. },
  887. onPaste: function (e) {
  888. if(format){
  889. var bufferText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text');
  890. e.preventDefault();
  891. document.execCommand('insertText', false, bufferText);
  892. }
  893. }
  894. }
  895. });
  896. var nativeHtmlBuilderFunc = $this.summernote('module', 'videoDialog').createVideoNode;
  897. $this.summernote('module', 'videoDialog').createVideoNode = function(url)
  898. {
  899. var wrap = $('<div class="embed-responsive embed-responsive-16by9"></div>');
  900. var html = nativeHtmlBuilderFunc(url);
  901. html = $(html).addClass('embed-responsive-item');
  902. return wrap.append(html)[0];
  903. };
  904. });
  905. },
  906. dateRange: function () {
  907. $(".aiz-date-range").each(function () {
  908. var $this = $(this);
  909. var today = moment().startOf("day");
  910. var value = $this.val();
  911. var startDate = false;
  912. var minDate = false;
  913. var maxDate = false;
  914. var advncdRange = false;
  915. var ranges = {
  916. Today: [moment(), moment()],
  917. Yesterday: [
  918. moment().subtract(1, "days"),
  919. moment().subtract(1, "days"),
  920. ],
  921. "Last 7 Days": [moment().subtract(6, "days"), moment()],
  922. "Last 30 Days": [moment().subtract(29, "days"), moment()],
  923. "This Month": [
  924. moment().startOf("month"),
  925. moment().endOf("month"),
  926. ],
  927. "Last Month": [
  928. moment().subtract(1, "month").startOf("month"),
  929. moment().subtract(1, "month").endOf("month"),
  930. ],
  931. };
  932. var single = $this.data("single");
  933. var monthYearDrop = $this.data("show-dropdown");
  934. var format = $this.data("format");
  935. var separator = $this.data("separator");
  936. var pastDisable = $this.data("past-disable");
  937. var futureDisable = $this.data("future-disable");
  938. var timePicker = $this.data("time-picker");
  939. var timePickerIncrement = $this.data("time-gap");
  940. var advncdRange = $this.data("advanced-range");
  941. single = !single ? false : single;
  942. monthYearDrop = !monthYearDrop ? false : monthYearDrop;
  943. format = !format ? "YYYY-MM-DD" : format;
  944. separator = !separator ? " / " : separator;
  945. minDate = !pastDisable ? minDate : today;
  946. maxDate = !futureDisable ? maxDate : today;
  947. timePicker = !timePicker ? false : timePicker;
  948. timePickerIncrement = !timePickerIncrement ? 1 : timePickerIncrement;
  949. ranges = !advncdRange ? "" : ranges;
  950. $this.daterangepicker({
  951. singleDatePicker: single,
  952. showDropdowns: monthYearDrop,
  953. minDate: minDate,
  954. maxDate: maxDate,
  955. timePickerIncrement: timePickerIncrement,
  956. autoUpdateInput: false,
  957. ranges: ranges,
  958. locale: {
  959. format: format,
  960. separator: separator,
  961. applyLabel: "Select",
  962. cancelLabel: "Clear",
  963. },
  964. });
  965. if (single) {
  966. $this.on("apply.daterangepicker", function (ev, picker) {
  967. $this.val(picker.startDate.format(format));
  968. });
  969. } else {
  970. $this.on("apply.daterangepicker", function (ev, picker) {
  971. $this.val(
  972. picker.startDate.format(format) +
  973. separator +
  974. picker.endDate.format(format)
  975. );
  976. });
  977. }
  978. $this.on("cancel.daterangepicker", function (ev, picker) {
  979. $this.val("");
  980. });
  981. });
  982. },
  983. timePicker: function () {
  984. $(".aiz-time-picker").each(function () {
  985. var $this = $(this);
  986. var minuteStep = $this.data("minute-step");
  987. var defaultTime = $this.data("default");
  988. minuteStep = !minuteStep ? 10 : minuteStep;
  989. defaultTime = !defaultTime ? "00:00" : defaultTime;
  990. $this.timepicker({
  991. template: "dropdown",
  992. minuteStep: minuteStep,
  993. defaultTime: defaultTime,
  994. icons: {
  995. up: "las la-angle-up",
  996. down: "las la-angle-down",
  997. },
  998. showInputs: false,
  999. });
  1000. });
  1001. },
  1002. fooTable: function () {
  1003. $(".aiz-table").each(function () {
  1004. var $this = $(this);
  1005. var empty = $this.data("empty");
  1006. empty = !empty ? AIZ.local.nothing_found : empty;
  1007. $this.footable({
  1008. breakpoints: {
  1009. xs: 576,
  1010. sm: 768,
  1011. md: 992,
  1012. lg: 1200,
  1013. xl: 1400,
  1014. },
  1015. cascade: true,
  1016. on: {
  1017. "ready.ft.table": function (e, ft) {
  1018. AIZ.extra.deleteConfirm();
  1019. AIZ.plugins.bootstrapSelect("refresh");
  1020. },
  1021. },
  1022. empty: empty,
  1023. });
  1024. });
  1025. },
  1026. notify: function (type = "dark", message = "") {
  1027. $.notify(
  1028. {
  1029. // options
  1030. message: message,
  1031. },
  1032. {
  1033. // settings
  1034. showProgressbar: true,
  1035. delay: 2500,
  1036. mouse_over: "pause",
  1037. placement: {
  1038. from: "bottom",
  1039. align: "left",
  1040. },
  1041. animate: {
  1042. enter: "animated fadeInUp",
  1043. exit: "animated fadeOutDown",
  1044. },
  1045. type: type,
  1046. template:
  1047. '<div data-notify="container" class="aiz-notify alert alert-{0}" role="alert">' +
  1048. '<button type="button" aria-hidden="true" data-notify="dismiss" class="close"><i class="las la-times"></i></button>' +
  1049. '<span data-notify="message">{2}</span>' +
  1050. '<div class="progress" data-notify="progressbar">' +
  1051. '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div>' +
  1052. "</div>" +
  1053. "</div>",
  1054. }
  1055. );
  1056. },
  1057. aizUppy: function () {
  1058. if ($("#aiz-upload-files").length > 0) {
  1059. var uppy = Uppy.Core({
  1060. autoProceed: true,
  1061. });
  1062. uppy.use(Uppy.Dashboard, {
  1063. target: "#aiz-upload-files",
  1064. inline: true,
  1065. showLinkToFileUploadResult: false,
  1066. showProgressDetails: true,
  1067. hideCancelButton: true,
  1068. hidePauseResumeButton: true,
  1069. hideUploadButton: true,
  1070. proudlyDisplayPoweredByUppy: false,
  1071. locale: {
  1072. strings: {
  1073. addMoreFiles: AIZ.local.add_more_files,
  1074. addingMoreFiles: AIZ.local.adding_more_files,
  1075. dropPaste: AIZ.local.drop_files_here_paste_or+' %{browse}',
  1076. browse: AIZ.local.browse,
  1077. uploadComplete: AIZ.local.upload_complete,
  1078. uploadPaused: AIZ.local.upload_paused,
  1079. resumeUpload: AIZ.local.resume_upload,
  1080. pauseUpload: AIZ.local.pause_upload,
  1081. retryUpload: AIZ.local.retry_upload,
  1082. cancelUpload: AIZ.local.cancel_upload,
  1083. xFilesSelected: {
  1084. 0: '%{smart_count} '+AIZ.local.file_selected,
  1085. 1: '%{smart_count} '+AIZ.local.files_selected
  1086. },
  1087. uploadingXFiles: {
  1088. 0: AIZ.local.uploading+' %{smart_count} '+AIZ.local.file,
  1089. 1: AIZ.local.uploading+' %{smart_count} '+AIZ.local.files
  1090. },
  1091. processingXFiles: {
  1092. 0: AIZ.local.processing+' %{smart_count} '+AIZ.local.file,
  1093. 1: AIZ.local.processing+' %{smart_count} '+AIZ.local.files
  1094. },
  1095. uploading: AIZ.local.uploading,
  1096. complete: AIZ.local.complete,
  1097. }
  1098. }
  1099. });
  1100. uppy.use(Uppy.XHRUpload, {
  1101. endpoint: AIZ.data.appUrl + "/aiz-uploader/upload",
  1102. fieldName: "aiz_file",
  1103. formData: true,
  1104. headers: {
  1105. 'X-CSRF-TOKEN': AIZ.data.csrf,
  1106. },
  1107. });
  1108. uppy.on("upload-success", function () {
  1109. AIZ.uploader.getAllUploads(
  1110. AIZ.data.appUrl + "/aiz-uploader/get_uploaded_files"
  1111. );
  1112. });
  1113. }
  1114. },
  1115. tooltip: function () {
  1116. $('body').tooltip({selector: '[data-toggle="tooltip"]'}).click(function () {
  1117. $('[data-toggle="tooltip"]').tooltip("hide");
  1118. });
  1119. },
  1120. countDown: function () {
  1121. if ($(".aiz-count-down").length > 0) {
  1122. $(".aiz-count-down").each(function () {
  1123. var $this = $(this);
  1124. var date = $this.data("date");
  1125. // console.log(date)
  1126. $this.countdown(date).on("update.countdown", function (event) {
  1127. var $this = $(this).html(
  1128. event.strftime(
  1129. "" +
  1130. '<div class="countdown-item"><span class="countdown-digit">%-D</span></div><span class="countdown-separator">:</span>' +
  1131. '<div class="countdown-item"><span class="countdown-digit">%H</span></div><span class="countdown-separator">:</span>' +
  1132. '<div class="countdown-item"><span class="countdown-digit">%M</span></div><span class="countdown-separator">:</span>' +
  1133. '<div class="countdown-item"><span class="countdown-digit">%S</span></div>'
  1134. )
  1135. );
  1136. });
  1137. });
  1138. }
  1139. },
  1140. slickCarousel: function () {
  1141. $(".aiz-carousel").not(".slick-initialized").each(function () {
  1142. var $this = $(this);
  1143. var slidesPerViewXs = $this.data("xs-items");
  1144. var slidesPerViewSm = $this.data("sm-items");
  1145. var slidesPerViewMd = $this.data("md-items");
  1146. var slidesPerViewLg = $this.data("lg-items");
  1147. var slidesPerViewXl = $this.data("xl-items");
  1148. var slidesPerView = $this.data("items");
  1149. var slidesCenterMode = $this.data("center");
  1150. var slidesArrows = $this.data("arrows");
  1151. var slidesDots = $this.data("dots");
  1152. var slidesRows = $this.data("rows");
  1153. var slidesAutoplay = $this.data("autoplay");
  1154. var slidesFade = $this.data("fade");
  1155. var asNavFor = $this.data("nav-for");
  1156. var infinite = $this.data("infinite");
  1157. var focusOnSelect = $this.data("focus-select");
  1158. var adaptiveHeight = $this.data("auto-height");
  1159. var vertical = $this.data("vertical");
  1160. var verticalXs = $this.data("vertical-xs");
  1161. var verticalSm = $this.data("vertical-sm");
  1162. var verticalMd = $this.data("vertical-md");
  1163. var verticalLg = $this.data("vertical-lg");
  1164. var verticalXl = $this.data("vertical-xl");
  1165. slidesPerView = !slidesPerView ? 1 : slidesPerView;
  1166. slidesPerViewXl = !slidesPerViewXl ? slidesPerView : slidesPerViewXl;
  1167. slidesPerViewLg = !slidesPerViewLg ? slidesPerViewXl : slidesPerViewLg;
  1168. slidesPerViewMd = !slidesPerViewMd ? slidesPerViewLg : slidesPerViewMd;
  1169. slidesPerViewSm = !slidesPerViewSm ? slidesPerViewMd : slidesPerViewSm;
  1170. slidesPerViewXs = !slidesPerViewXs ? slidesPerViewSm : slidesPerViewXs;
  1171. vertical = !vertical ? false : vertical;
  1172. verticalXl = (typeof verticalXl == 'undefined') ? vertical : verticalXl;
  1173. verticalLg = (typeof verticalLg == 'undefined') ? verticalXl : verticalLg;
  1174. verticalMd = (typeof verticalMd == 'undefined') ? verticalLg : verticalMd;
  1175. verticalSm = (typeof verticalSm == 'undefined') ? verticalMd : verticalSm;
  1176. verticalXs = (typeof verticalXs == 'undefined') ? verticalSm : verticalXs;
  1177. slidesCenterMode = !slidesCenterMode ? false : slidesCenterMode;
  1178. slidesArrows = !slidesArrows ? false : slidesArrows;
  1179. slidesDots = !slidesDots ? false : slidesDots;
  1180. slidesRows = !slidesRows ? 1 : slidesRows;
  1181. slidesAutoplay = !slidesAutoplay ? false : slidesAutoplay;
  1182. slidesFade = !slidesFade ? false : slidesFade;
  1183. asNavFor = !asNavFor ? null : asNavFor;
  1184. infinite = !infinite ? false : infinite;
  1185. focusOnSelect = !focusOnSelect ? false : focusOnSelect;
  1186. adaptiveHeight = !adaptiveHeight ? false : adaptiveHeight;
  1187. var slidesRtl = ($("html").attr("dir") === "rtl" && !vertical) ? true : false;
  1188. var slidesRtlXL = ($("html").attr("dir") === "rtl" && !verticalXl) ? true : false;
  1189. var slidesRtlLg = ($("html").attr("dir") === "rtl" && !verticalLg) ? true : false;
  1190. var slidesRtlMd = ($("html").attr("dir") === "rtl" && !verticalMd) ? true : false;
  1191. var slidesRtlSm = ($("html").attr("dir") === "rtl" && !verticalSm) ? true : false;
  1192. var slidesRtlXs = ($("html").attr("dir") === "rtl" && !verticalXs) ? true : false;
  1193. $this.slick({
  1194. slidesToShow: slidesPerView,
  1195. autoplay: slidesAutoplay,
  1196. dots: slidesDots,
  1197. arrows: slidesArrows,
  1198. infinite: infinite,
  1199. vertical: vertical,
  1200. rtl: slidesRtl,
  1201. rows: slidesRows,
  1202. centerPadding: "0px",
  1203. centerMode: slidesCenterMode,
  1204. fade: slidesFade,
  1205. asNavFor: asNavFor,
  1206. focusOnSelect: focusOnSelect,
  1207. adaptiveHeight: adaptiveHeight,
  1208. slidesToScroll: 1,
  1209. prevArrow:
  1210. '<button type="button" class="slick-prev"><i class="las la-angle-left"></i></button>',
  1211. nextArrow:
  1212. '<button type="button" class="slick-next"><i class="las la-angle-right"></i></button>',
  1213. responsive: [
  1214. {
  1215. breakpoint: 1500,
  1216. settings: {
  1217. slidesToShow: slidesPerViewXl,
  1218. vertical: verticalXl,
  1219. rtl: slidesRtlXL,
  1220. },
  1221. },
  1222. {
  1223. breakpoint: 1200,
  1224. settings: {
  1225. slidesToShow: slidesPerViewLg,
  1226. vertical: verticalLg,
  1227. rtl: slidesRtlLg,
  1228. },
  1229. },
  1230. {
  1231. breakpoint: 992,
  1232. settings: {
  1233. slidesToShow: slidesPerViewMd,
  1234. vertical: verticalMd,
  1235. rtl: slidesRtlMd,
  1236. },
  1237. },
  1238. {
  1239. breakpoint: 768,
  1240. settings: {
  1241. slidesToShow: slidesPerViewSm,
  1242. vertical: verticalSm,
  1243. rtl: slidesRtlSm,
  1244. },
  1245. },
  1246. {
  1247. breakpoint: 576,
  1248. settings: {
  1249. slidesToShow: slidesPerViewXs,
  1250. vertical: verticalXs,
  1251. rtl: slidesRtlXs,
  1252. },
  1253. },
  1254. ],
  1255. });
  1256. });
  1257. },
  1258. chart: function (selector, config) {
  1259. if (!$(selector).length) return;
  1260. $(selector).each(function () {
  1261. var $this = $(this);
  1262. var aizChart = new Chart($this, config);
  1263. });
  1264. },
  1265. noUiSlider: function(){
  1266. if ($(".aiz-range-slider")[0]) {
  1267. $(".aiz-range-slider").each(function () {
  1268. var c = document.getElementById("input-slider-range"),
  1269. d = document.getElementById("input-slider-range-value-low"),
  1270. e = document.getElementById("input-slider-range-value-high"),
  1271. f = [d, e];
  1272. noUiSlider.create(c, {
  1273. start: [
  1274. parseInt(d.getAttribute("data-range-value-low")),
  1275. parseInt(e.getAttribute("data-range-value-high")),
  1276. ],
  1277. connect: !0,
  1278. range: {
  1279. min: parseInt(c.getAttribute("data-range-value-min")),
  1280. max: parseInt(c.getAttribute("data-range-value-max")),
  1281. },
  1282. }),
  1283. c.noUiSlider.on("update", function (a, b) {
  1284. f[b].textContent = a[b];
  1285. }),
  1286. c.noUiSlider.on("change", function (a, b) {
  1287. rangefilter(a);
  1288. });
  1289. });
  1290. }
  1291. },
  1292. zoom: function(){
  1293. if($('.img-zoom')[0]){
  1294. $('.img-zoom').zoom({
  1295. magnify:1.5
  1296. });
  1297. if((('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0))){
  1298. $('.img-zoom').trigger('zoom.destroy');
  1299. }
  1300. }
  1301. },
  1302. jsSocials: function(){
  1303. if($('.aiz-share')[0]){
  1304. $('.aiz-share').jsSocials({
  1305. showLabel: false,
  1306. showCount: false,
  1307. shares: [
  1308. {
  1309. share: "email",
  1310. logo: "lar la-envelope"
  1311. },
  1312. {
  1313. share: "twitter",
  1314. logo: "lab la-twitter"
  1315. },
  1316. {
  1317. share: "facebook",
  1318. logo: "lab la-facebook-f"
  1319. },
  1320. {
  1321. share: "linkedin",
  1322. logo: "lab la-linkedin-in"
  1323. },
  1324. {
  1325. share: "whatsapp",
  1326. logo: "lab la-whatsapp"
  1327. }
  1328. ]
  1329. });
  1330. }
  1331. }
  1332. };
  1333. AIZ.extra = {
  1334. refreshToken: function (){
  1335. $.get(AIZ.data.appUrl+'/refresh-csrf').done(function(data){
  1336. AIZ.data.csrf = data;
  1337. });
  1338. // console.log(AIZ.data.csrf);
  1339. },
  1340. mobileNavToggle: function () {
  1341. if(window.matchMedia('(max-width: 1200px)').matches){
  1342. $('body').addClass('side-menu-closed')
  1343. }
  1344. $('[data-toggle="aiz-mobile-nav"]').on("click", function () {
  1345. if ($("body").hasClass("side-menu-open")) {
  1346. $("body").addClass("side-menu-closed").removeClass("side-menu-open");
  1347. } else if($("body").hasClass("side-menu-closed")) {
  1348. $("body").removeClass("side-menu-closed").addClass("side-menu-open");
  1349. }else{
  1350. $("body").removeClass("side-menu-open").addClass("side-menu-closed");
  1351. }
  1352. });
  1353. $(".aiz-sidebar-overlay").on("click", function () {
  1354. $("body").removeClass("side-menu-open").addClass('side-menu-closed');
  1355. });
  1356. },
  1357. initActiveMenu: function () {
  1358. $('[data-toggle="aiz-side-menu"] a').each(function () {
  1359. var pageUrl = window.location.href.split(/[?#]/)[0];
  1360. if (this.href == pageUrl || $(this).hasClass("active")) {
  1361. $(this).addClass("active");
  1362. $(this).closest(".aiz-side-nav-item").addClass("mm-active");
  1363. $(this)
  1364. .closest(".level-2")
  1365. .siblings("a")
  1366. .addClass("level-2-active");
  1367. $(this)
  1368. .closest(".level-3")
  1369. .siblings("a")
  1370. .addClass("level-3-active");
  1371. }
  1372. });
  1373. },
  1374. deleteConfirm: function () {
  1375. $(".confirm-delete").click(function (e) {
  1376. e.preventDefault();
  1377. var url = $(this).data("href");
  1378. $("#delete-modal").modal("show");
  1379. $("#delete-link").attr("href", url);
  1380. });
  1381. $(".confirm-cancel").click(function (e) {
  1382. e.preventDefault();
  1383. var url = $(this).data("href");
  1384. $("#cancel-modal").modal("show");
  1385. $("#cancel-link").attr("href", url);
  1386. });
  1387. $(".confirm-complete").click(function (e) {
  1388. e.preventDefault();
  1389. var url = $(this).data("href");
  1390. $("#complete-modal").modal("show");
  1391. $("#comfirm-link").attr("href", url);
  1392. });
  1393. $(".confirm-alert").click(function (e) {
  1394. e.preventDefault();
  1395. var url = $(this).data("href");
  1396. var target = $(this).data("target");
  1397. $(target).modal("show");
  1398. $(target).find(".comfirm-link").attr("href", url);
  1399. $("#comfirm-link").attr("href", url);
  1400. });
  1401. },
  1402. bytesToSize: function (bytes) {
  1403. var sizes = ["Bytes", "KB", "MB", "GB", "TB"];
  1404. if (bytes == 0) return "0 Byte";
  1405. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  1406. return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i];
  1407. },
  1408. multiModal: function () {
  1409. $(document).on("show.bs.modal", ".modal", function (event) {
  1410. var zIndex = 1040 + 10 * $(".modal:visible").length;
  1411. $(this).css("z-index", zIndex);
  1412. setTimeout(function () {
  1413. $(".modal-backdrop")
  1414. .not(".modal-stack")
  1415. .css("z-index", zIndex - 1)
  1416. .addClass("modal-stack");
  1417. }, 0);
  1418. });
  1419. $(document).on('hidden.bs.modal', function () {
  1420. if($('.modal.show').length > 0){
  1421. $('body').addClass('modal-open');
  1422. }
  1423. });
  1424. },
  1425. bsCustomFile: function () {
  1426. $(".custom-file input").change(function (e) {
  1427. var files = [];
  1428. for (var i = 0; i < $(this)[0].files.length; i++) {
  1429. files.push($(this)[0].files[i].name);
  1430. }
  1431. if (files.length === 1) {
  1432. $(this).next(".custom-file-name").html(files[0]);
  1433. } else if (files.length > 1) {
  1434. $(this)
  1435. .next(".custom-file-name")
  1436. .html(files.length + " " + AIZ.local.files_selected);
  1437. } else {
  1438. $(this).next(".custom-file-name").html(AIZ.local.choose_file);
  1439. }
  1440. });
  1441. },
  1442. stopPropagation: function(){
  1443. $(document).on('click', '.stop-propagation', function (e) {
  1444. e.stopPropagation();
  1445. });
  1446. },
  1447. outsideClickHide: function(){
  1448. $(document).on('click', function (e) {
  1449. $('.document-click-d-none').addClass('d-none');
  1450. });
  1451. },
  1452. inputRating: function () {
  1453. $(".rating-input").each(function () {
  1454. $(this)
  1455. .find("label")
  1456. .on({
  1457. mouseover: function (event) {
  1458. $(this).find("i").addClass("hover");
  1459. $(this).prevAll().find("i").addClass("hover");
  1460. },
  1461. mouseleave: function (event) {
  1462. $(this).find("i").removeClass("hover");
  1463. $(this).prevAll().find("i").removeClass("hover");
  1464. },
  1465. click: function (event) {
  1466. $(this).siblings().find("i").removeClass("active");
  1467. $(this).find("i").addClass("active");
  1468. $(this).prevAll().find("i").addClass("active");
  1469. },
  1470. });
  1471. if ($(this).find("input").is(":checked")) {
  1472. $(this)
  1473. .find("label")
  1474. .siblings()
  1475. .find("i")
  1476. .removeClass("active");
  1477. $(this)
  1478. .find("input:checked")
  1479. .closest("label")
  1480. .find("i")
  1481. .addClass("active");
  1482. $(this)
  1483. .find("input:checked")
  1484. .closest("label")
  1485. .prevAll()
  1486. .find("i")
  1487. .addClass("active");
  1488. }
  1489. });
  1490. },
  1491. scrollToBottom: function () {
  1492. $(".scroll-to-btm").each(function (i, el) {
  1493. el.scrollTop = el.scrollHeight;
  1494. });
  1495. },
  1496. classToggle: function () {
  1497. $(document).on('click','[data-toggle="class-toggle"]',function () {
  1498. var $this = $(this);
  1499. var target = $this.data("target");
  1500. var sameTriggers = $this.data("same");
  1501. var backdrop = $(this).data("backdrop");
  1502. if ($(target).hasClass("active")) {
  1503. $(target).removeClass("active");
  1504. $(sameTriggers).removeClass("active");
  1505. $this.removeClass("active");
  1506. $('body').removeClass("overflow-hidden");
  1507. } else {
  1508. $(target).addClass("active");
  1509. $this.addClass("active");
  1510. if(backdrop == 'static'){
  1511. $('body').addClass("overflow-hidden");
  1512. }
  1513. }
  1514. });
  1515. },
  1516. collapseSidebar: function () {
  1517. $(document).on('click','[data-toggle="collapse-sidebar"]',function (i, el) {
  1518. var $this = $(this);
  1519. var target = $(this).data("target");
  1520. var sameTriggers = $(this).data("siblings");
  1521. // var showOverlay = $this.data('overlay');
  1522. // var overlayMarkup = '<div class="overlay overlay-fixed dark c-pointer" data-toggle="collapse-sidebar" data-target="'+target+'"></div>';
  1523. // showOverlay = !showOverlay ? true : showOverlay;
  1524. // if (showOverlay && $(target).siblings('.overlay').length !== 1) {
  1525. // $(target).after(overlayMarkup);
  1526. // }
  1527. e.preventDefault();
  1528. if ($(target).hasClass("opened")) {
  1529. $(target).removeClass("opened");
  1530. $(sameTriggers).removeClass("opened");
  1531. $($this).removeClass("opened");
  1532. } else {
  1533. $(target).addClass("opened");
  1534. $($this).addClass("opened");
  1535. }
  1536. });
  1537. },
  1538. autoScroll: function () {
  1539. if ($(".aiz-auto-scroll").length > 0) {
  1540. $(".aiz-auto-scroll").each(function () {
  1541. var options = $(this).data("options");
  1542. options = !options
  1543. ? '{"delay" : 2000 ,"amount" : 70 }'
  1544. : options;
  1545. options = JSON.parse(options);
  1546. this.delay = parseInt(options["delay"]) || 2000;
  1547. this.amount = parseInt(options["amount"]) || 70;
  1548. this.autoScroll = $(this);
  1549. this.iScrollHeight = this.autoScroll.prop("scrollHeight");
  1550. this.iScrollTop = this.autoScroll.prop("scrollTop");
  1551. this.iHeight = this.autoScroll.height();
  1552. var self = this;
  1553. this.timerId = setInterval(function () {
  1554. if (
  1555. self.iScrollTop + self.iHeight <
  1556. self.iScrollHeight
  1557. ) {
  1558. self.iScrollTop = self.autoScroll.prop("scrollTop");
  1559. self.iScrollTop += self.amount;
  1560. self.autoScroll.animate(
  1561. { scrollTop: self.iScrollTop },
  1562. "slow",
  1563. "linear"
  1564. );
  1565. } else {
  1566. self.iScrollTop -= self.iScrollTop;
  1567. self.autoScroll.animate(
  1568. { scrollTop: "0px" },
  1569. "fast",
  1570. "swing"
  1571. );
  1572. }
  1573. }, self.delay);
  1574. });
  1575. }
  1576. },
  1577. addMore: function () {
  1578. $('[data-toggle="add-more"]').each(function () {
  1579. var $this = $(this);
  1580. var content = $this.data("content");
  1581. var target = $this.data("target");
  1582. $this.on("click", function (e) {
  1583. e.preventDefault();
  1584. $(target).append(content);
  1585. AIZ.plugins.bootstrapSelect();
  1586. });
  1587. });
  1588. },
  1589. removeParent: function () {
  1590. $(document).on(
  1591. "click",
  1592. '[data-toggle="remove-parent"]',
  1593. function () {
  1594. var $this = $(this);
  1595. var parent = $this.data("parent");
  1596. $this.closest(parent).remove();
  1597. }
  1598. );
  1599. },
  1600. selectHideShow: function() {
  1601. $('[data-show="selectShow"]').each(function() {
  1602. var target = $(this).data("target");
  1603. $(this).on("change", function() {
  1604. var value = $(this).val();
  1605. // console.log(value);
  1606. $(target)
  1607. .children()
  1608. .not("." + value)
  1609. .addClass("d-none");
  1610. $(target)
  1611. .find("." + value)
  1612. .removeClass("d-none");
  1613. });
  1614. });
  1615. },
  1616. plusMinus: function(){
  1617. $('.aiz-plus-minus input').each(function() {
  1618. var $this = $(this);
  1619. var min = parseInt($(this).attr("min"));
  1620. var max = parseInt($(this).attr("max"));
  1621. var value = parseInt($(this).val());
  1622. if(value <= min){
  1623. $this.siblings('[data-type="minus"]').attr('disabled',true)
  1624. }else if($this.siblings('[data-type="minus"]').attr('disabled')){
  1625. $this.siblings('[data-type="minus"]').removeAttr('disabled')
  1626. }
  1627. if(value >= max){
  1628. $this.siblings('[data-type="plus"]').attr('disabled',true)
  1629. }else if($this.siblings('[data-type="plus"]').attr('disabled')){
  1630. $this.siblings('[data-type="plus"]').removeAttr('disabled')
  1631. }
  1632. });
  1633. $('.aiz-plus-minus button').off('click').on('click', function(e) {
  1634. e.preventDefault();
  1635. var fieldName = $(this).attr("data-field");
  1636. var type = $(this).attr("data-type");
  1637. var input = $("input[name='" + fieldName + "']");
  1638. var currentVal = parseInt(input.val());
  1639. if (!isNaN(currentVal)) {
  1640. if (type == "minus") {
  1641. if (currentVal > input.attr("min")) {
  1642. input.val(currentVal - 1).change();
  1643. }
  1644. if (parseInt(input.val()) == input.attr("min")) {
  1645. $(this).attr("disabled", true);
  1646. }
  1647. } else if (type == "plus") {
  1648. if (currentVal < input.attr("max")) {
  1649. input.val(currentVal + 1).change();
  1650. }
  1651. if (parseInt(input.val()) == input.attr("max")) {
  1652. $(this).attr("disabled", true);
  1653. }
  1654. }
  1655. } else {
  1656. input.val(0);
  1657. }
  1658. });
  1659. $('.aiz-plus-minus input').off('change').on('change', function () {
  1660. var minValue = parseInt($(this).attr("min"));
  1661. var maxValue = parseInt($(this).attr("max"));
  1662. var valueCurrent = parseInt($(this).val());
  1663. name = $(this).attr("name");
  1664. if (valueCurrent >= minValue) {
  1665. $(this).siblings("[data-type='minus']").removeAttr("disabled");
  1666. } else {
  1667. alert("Sorry, the minimum limit has been reached");
  1668. $(this).val(minValue);
  1669. }
  1670. if (valueCurrent <= maxValue) {
  1671. $(this).siblings("[data-type='plus']").removeAttr("disabled");
  1672. } else {
  1673. alert("Sorry, the maximum limit has been reached");
  1674. $(this).val(maxValue);
  1675. }
  1676. // getVariantPrice();
  1677. });
  1678. },
  1679. hovCategoryMenu: function(){
  1680. $("#category-menu-icon, #category-sidebar")
  1681. .on("mouseover", function (event) {
  1682. $("#hover-category-menu").addClass('active').removeClass('d-none');
  1683. })
  1684. .on("mouseout", function (event) {
  1685. $("#hover-category-menu").addClass('d-none').removeClass('active');
  1686. });
  1687. },
  1688. trimAppUrl: function(){
  1689. if(AIZ.data.appUrl.slice(-1) == '/'){
  1690. AIZ.data.appUrl = AIZ.data.appUrl.slice(0, AIZ.data.appUrl.length -1);
  1691. // console.log(AIZ.data.appUrl);
  1692. }
  1693. },
  1694. setCookie: function(cname, cvalue, exdays) {
  1695. var d = new Date();
  1696. d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  1697. var expires = "expires=" + d.toUTCString();
  1698. document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  1699. },
  1700. getCookie: function(cname) {
  1701. var name = cname + "=";
  1702. var decodedCookie = '';
  1703. var ca = decodedCookie.split(';');
  1704. for (var i = 0; i < ca.length; i++) {
  1705. var c = ca[i];
  1706. while (c.charAt(0) === ' ') {
  1707. c = c.substring(1);
  1708. }
  1709. if (c.indexOf(name) === 0) {
  1710. return c.substring(name.length, c.length);
  1711. }
  1712. }
  1713. return "";
  1714. },
  1715. acceptCookie: function(){
  1716. if (!AIZ.extra.getCookie("acceptCookies")) {
  1717. $(".aiz-cookie-alert").addClass("show");
  1718. }
  1719. $(".aiz-cookie-accept").on("click", function() {
  1720. AIZ.extra.setCookie("acceptCookies", true, 60);
  1721. $(".aiz-cookie-alert").removeClass("show");
  1722. });
  1723. },
  1724. setSession: function(){
  1725. $('.set-session').each(function() {
  1726. var $this = $(this);
  1727. var key = $this.data('key');
  1728. var value = $this.data('value');
  1729. const now = new Date();
  1730. const item = {
  1731. value: value,
  1732. expiry: now.getTime() + 3600000,
  1733. };
  1734. $this.on('click', function(){
  1735. localStorage.setItem(key, JSON.stringify(item));
  1736. });
  1737. });
  1738. },
  1739. showSessionPopup: function(){
  1740. $('.removable-session').each(function() {
  1741. var $this = $(this);
  1742. var key = $this.data('key');
  1743. var value = $this.data('value');
  1744. var item = {};
  1745. if (localStorage.getItem(key)) {
  1746. item = localStorage.getItem(key);
  1747. item = JSON.parse(item);
  1748. }
  1749. const now = new Date()
  1750. if (typeof item.expiry == 'undefined' || now.getTime() > item.expiry){
  1751. $this.removeClass('d-none');
  1752. }
  1753. });
  1754. }
  1755. };
  1756. setInterval(function(){
  1757. AIZ.extra.refreshToken();
  1758. }, 3600000);
  1759. // init aiz plugins, extra options
  1760. AIZ.extra.initActiveMenu();
  1761. AIZ.extra.mobileNavToggle();
  1762. AIZ.extra.deleteConfirm();
  1763. AIZ.extra.multiModal();
  1764. AIZ.extra.inputRating();
  1765. AIZ.extra.bsCustomFile();
  1766. AIZ.extra.stopPropagation();
  1767. AIZ.extra.outsideClickHide();
  1768. AIZ.extra.scrollToBottom();
  1769. AIZ.extra.classToggle();
  1770. AIZ.extra.collapseSidebar();
  1771. AIZ.extra.autoScroll();
  1772. AIZ.extra.addMore();
  1773. AIZ.extra.removeParent();
  1774. AIZ.extra.selectHideShow();
  1775. AIZ.extra.plusMinus();
  1776. AIZ.extra.hovCategoryMenu();
  1777. AIZ.extra.trimAppUrl();
  1778. AIZ.extra.acceptCookie();
  1779. AIZ.extra.setSession();
  1780. AIZ.extra.showSessionPopup()
  1781. AIZ.plugins.metismenu();
  1782. AIZ.plugins.bootstrapSelect();
  1783. AIZ.plugins.tagify();
  1784. AIZ.plugins.textEditor();
  1785. AIZ.plugins.tooltip();
  1786. AIZ.plugins.countDown();
  1787. AIZ.plugins.dateRange();
  1788. AIZ.plugins.timePicker();
  1789. AIZ.plugins.fooTable();
  1790. AIZ.plugins.slickCarousel();
  1791. AIZ.plugins.noUiSlider();
  1792. AIZ.plugins.zoom();
  1793. AIZ.plugins.jsSocials();
  1794. // initialization of aiz uploader
  1795. AIZ.uploader.initForInput();
  1796. AIZ.uploader.removeAttachment();
  1797. AIZ.uploader.previewGenerate();
  1798. // $(document).ajaxComplete(function(){
  1799. // AIZ.plugins.bootstrapSelect('refresh');
  1800. // });
  1801. })(jQuery);