Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Dropzone - pobieranie indeksu pliku
trifek
post 2.10.2018, 11:19:15
Post #1





Grupa: Zarejestrowani
Postów: 340
Pomógł: 0
Dołączył: 28.09.2015

Ostrzeżenie: (0%)
-----


Witam.
Mam taki kod:
  1. <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  2.  
  3. <div class="row">
  4. <div class="col-12">
  5. <form class="dropzone" id="dpz-multiple-files" action="http://localhost/dropZoneUpload.php"
  6. method="post" enctype="multipart/form-data" style="border:1px solid #000;">
  7.  
  8. </form>
  9. <br>
  10. <button id="submit-all" style="height: 40px;"> Upload All the files</button>
  11. </center>
  12. </div>
  13. </div>
  14.  
  15.  
  16. <script type="text/javascript">
  17. Dropzone.options.dpzMultipleFiles = {
  18. // Prevents Dropzone from uploading dropped files immediately
  19. uploadMultiple: true,
  20. paramName: "file",
  21. maxFilesize: 100,
  22. maxFiles: 2,
  23. createImageThumbnails: true,
  24. acceptedFiles: ".png,.jpg,.jpeg",
  25. clickable: true,
  26. thumbnailWidth: 150,
  27. thumbnailHeight: 150,
  28. autoProcessQueue: false,
  29. init: function () {
  30. var submitButton = document.querySelector("#submit-all")
  31. dpzMultipleFiles = this;
  32. submitButton.addEventListener("click", function () {
  33. dpzMultipleFiles.processQueue();
  34. });
  35. // to handle the added file event
  36. this.on('completemultiple', function (file, json) {
  37. $('.sortable').sortable('enable');
  38. });
  39. this.on('success', function (file, json) {
  40. let val = file.accepted;
  41. if (file.accepted == true) {
  42. //alert ('JSON - wgrałem!');
  43. console.log(json);
  44. $('.main_form').append("<input type='text' name='imgFiles[]' value='" + file.name + "'/>");
  45. }
  46. let val1 = file.name;
  47. //alert(val1);
  48. });
  49. this.on("addedfile", function (file) {
  50. var removeButton = Dropzone.createElement("<button> Remove file </button>");
  51. // Capture the Dropzone instance as closure.
  52. var _this = this;
  53.  
  54. //console.log(file);
  55. removeButton.addEventListener("click", function (e) {
  56. // Make sure the button click doesn't submit the form:
  57. e.preventDefault();
  58. e.stopPropagation();
  59.  
  60. // Remove the file preview.
  61. _this.removeFile(file);
  62. // If you want to the delete the file on the server as well,
  63. // you can do the AJAX request here.
  64. console.log("kasuje" + file.name);
  65. console.log(file);
  66. });
  67. file.previewElement.appendChild(removeButton);
  68. });
  69. this.on('drop', function (file) {
  70. console.log('File', file);
  71. alert('bb');
  72. });
  73. this.on("maxfilesexceeded", function (file) {
  74. this.removeFile(file);
  75. });
  76. }
  77. };
  78. $(function () {
  79. $(".dropzone").sortable({
  80. items: '.dz-preview',
  81. cursor: 'move',
  82. opacity: 0.5,
  83. containment: '.dropzone',
  84. distance: 20,
  85. tolerance: 'pointer'
  86. });
  87. });

Elementy w dropzone mogę przesówać (zmieniać ich kolejność). W jaki sposób mogę pobrać indeksy plików (pozycje na liście)?

Ten post edytował trifek 2.10.2018, 11:20:00
Go to the top of the page
+Quote Post
werdan
post 2.10.2018, 11:34:02
Post #2





Grupa: Zarejestrowani
Postów: 354
Pomógł: 100
Dołączył: 14.11.2013
Skąd: Płock

Ostrzeżenie: (0%)
-----


W JS czy kolejność po przesłaniu na serwer?

Jeśli to drugie, to sprawdź czy właśnie nie są wysyłane już w posortowanej kolejności?
Go to the top of the page
+Quote Post
trifek
post 2.10.2018, 11:41:00
Post #3





Grupa: Zarejestrowani
Postów: 340
Pomógł: 0
Dołączył: 28.09.2015

Ostrzeżenie: (0%)
-----


Generalnie chcę zrobić coś takiego:
- wgrywam zdjęcia na serwer za pomocą dropzone,
- ustalam sobie kolejność zdjęć
- po kliknięciu na zdjęcie otwieram Lightbox,
- po kliknięciu na guziczek remove - kasuje się zdjęcie.

Kolejność docelowo chcę trzymać w bazie, dlatego po każdej zmianie kolejności zdjęć chcę coś wysłać do php w celu aktualizacji rekordów smile.gif
Pomyślałem że te indeksy rozwiążą problem? smile.gif
Go to the top of the page
+Quote Post
trueblue
post 2.10.2018, 12:29:24
Post #4





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Dokumentacja: http://api.jqueryui.com/sortable/#method-toArray


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.04.2024 - 10:56