Last active
February 27, 2022 15:46
-
-
Save robertvrabel/7f878cebd0e62ec9ed0cb2779a3097a9 to your computer and use it in GitHub Desktop.
Revisions
-
robertvrabel revised this gist
Mar 9, 2017 . 4 changed files with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,5 +4,5 @@ SET display_order = (display_order - 1) WHERE display_order > :current_position AND display_order <= :desired_position AND user_id = :user_id"; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,5 +4,5 @@ SET display_order = (display_order + 1) WHERE display_order >= :desired_position AND display_order < :current_position AND user_id = :user_id"; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,4 @@ $query = "UPDATE todos SET display_order = :desired_position WHERE display_order = 0 AND user_id = :user_id"; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,4 @@ $query = "UPDATE todos SET display_order = 0 WHERE display_order = :current_position AND user_id = :user_id"; -
robertvrabel revised this gist
Mar 9, 2017 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ // Move up: Update the items between the desired position and the current position, increasing each item by 1 to make space for the new item if ($move == 'up') { $query = "UPDATE todos SET display_order = (display_order + 1) WHERE display_order >= :desired_position AND display_order < :current_position AND user_id = :user_id } -
robertvrabel revised this gist
Mar 9, 2017 . 1 changed file with 36 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ <table> <thead> <tr> <th scope="col">user_id</th> <th scope="col">display_order</th> <th scope="col">todo</th> </tr> </thead> <tbody> <tr> <td>2000</td> <td>1</td> <td>Take out garbage</td> </tr> <tr> <td>2000</td> <td>2</td> <td>Clean house</td> </tr> <tr> <td>2000</td> <td>3</td> <td>Do dishes</td> </tr> <tr> <td>2000</td> <td>4</td> <td>Cut grass</td> </tr> <tr> <td>2000</td> <td>5</td> <td>Change light bulb</td> </tr> </tbody> </table> -
robertvrabel revised this gist
Mar 9, 2017 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ <ul class="todos"> <li class="todo">Take out garbage</li> <li class="todo">Clean house</li> <li class="todo">Do dishes</li> <li class="todo">Cut grass</li> <li class="todo">Change light bulb</li> </ul> -
robertvrabel revised this gist
Mar 9, 2017 . 4 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
robertvrabel revised this gist
Mar 9, 2017 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
robertvrabel created this gist
Mar 9, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ // Make the form fields sortable/draggable $('.todos').sortable({ items: '.todo', start: function(event, ui) { // Create a temporary attribute on the element with the old index $(this).attr('data-currentindex', ui.item.index()); }, update: function(event, ui) { let user_id = $('#user_id').val(); let current_position = $(this).attr('data-currentindex'); let desired_position = ui.item.index(); // Reset the current index $(this).removeAttr('data-currentindex'); // Post to the server to handle the changes $.ajax({ type: "POST", url: "/url-to-handle-database-updates/", data: { desired_position: desired_position, current_position: current_position, user_id: user_id }, beforeSend: function() { // Disable dragging $('.todos').sortable('disable'); }, success: function(html) { // Re-enable dragging $('.todos').sortable('enable'); } }); } }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ // Determine if the user is moving the item up or down in the listing $move = $desired_position > $current_position ? 'down' : 'up'; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ // Set the display_order for the dragged item to be 0 so we can update this record later by display_order = 0 $query = "UPDATE todos SET display_order = 0 WHERE display_order = :current_position AND user_id = :user_id; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ // Move down: Update the items between the current position and the desired position, decreasing each item by 1 to make space for the new item if ($move == 'down') { $query = "UPDATE todos SET display_order = (display_order - 1) WHERE display_order > :current_position AND display_order <= :desired_position AND user_id = :user_id; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ // Move up: Update the items between the desired position and the current position, increasing each item by 1 to make space for the new item if ($move == 'up') { $query = "UPDATE `form_field_rel` SET display_order = (display_order + 1) WHERE display_order >= " . $desired_position . " AND display_order < " . $current_position . " AND form_id = " . $form_id; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ // Update the item that was dragged and set it to be the desired position now that the slot is opend up $query = "UPDATE todos SET display_order = :desired_position WHERE display_order = 0 AND user_id = :user_id;