forked from rapidftr/RapidFTR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db & cg: rapidftr#90 - re-ordering of forms functionality
- Loading branch information
cgeorge
authored and
Dahlia Bock
committed
Nov 16, 2010
1 parent
ea95ca4
commit 9927dcf
Showing
9 changed files
with
203 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
$(document).ready(function() { | ||
initOrderingColumns(); | ||
$("a.moveDown").click(moveDown); | ||
$("a.moveUp").click(moveUp); | ||
$("input#save_order").click(saveOrder); | ||
}); | ||
|
||
function initOrderingColumns() { | ||
$("#form_sections tbody tr").each(function(index, element){ | ||
$("a.moveDown", element).show(); | ||
$("a.moveUp", element).show(); | ||
}); | ||
|
||
$("#form_sections tbody tr:nth-child(2)").each(function(index, element){ | ||
$("a.moveDown", element).show(); | ||
$("a.moveUp", element).hide(); | ||
}); | ||
|
||
$("#form_sections tbody tr:last").each(function(index, element){ | ||
$("a.moveDown", element).hide(); | ||
$("a.moveUp", element).show(); | ||
}); | ||
|
||
$("#form_sections tbody tr").each(function(index, element){ $(element).find(".updatedFormSectionOrder :input").val(index + 1); }); | ||
} | ||
|
||
function moveUp() | ||
{ | ||
var row = $(this).parents("tr"); | ||
var prevRow = row.prev("tr"); | ||
prevRow.before(row); | ||
initOrderingColumns(); | ||
} | ||
|
||
function moveDown() | ||
{ | ||
var row = $(this).parents("tr"); | ||
var prevRow = row.next("tr"); | ||
prevRow.after(row); | ||
initOrderingColumns(); | ||
} | ||
|
||
function saveOrder(event) { | ||
var form_order = {}; | ||
var updatedOrderings = $('.updatedFormSectionOrder :input'); | ||
$.each(updatedOrderings, function() { | ||
var name = $(this).attr("name"); | ||
var id = /form_order\[(.*)\]/.exec(name)[1] | ||
form_order[id] = $(this).attr("value"); | ||
}); | ||
|
||
$.ajax({ | ||
type: "POST", | ||
data: {"form_order" : form_order}, | ||
url: '/form_section/save_order', | ||
success: function(data) { | ||
$("#form_sections").html($(data).find("#form_sections")); | ||
$("a.moveDown").bind("click", moveDown); | ||
$("a.moveUp").bind("click", moveUp); | ||
initOrderingColumns(); | ||
} | ||
}); | ||
} |
This file contains 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 characters
This file contains 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 characters