Thanks yet again for you taking the time to assist me, this is proving
to be most
frustrating for me (and for yourself I imagine!) as I just cant seem
to get this working :(
Im going to (hopefully) lay out the code step by step, and perhaps if
you have the time then
you can tell me where im wrong - ill understand if you dont of course
and thanks for the time spent
helping so far.
Creation of sortable list:
function startup()
{
Sortable.create("chunksList", {});
Droppables.add("trash",
{
onDrop: function(element)
{
var deleteChunk = confirm("Are you sure you want to
delete this
Chunk?")
if (deleteChunk)
{
Element.hide(element);
delElement = element.id;
process("delChunk");
}
}
});
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sending the server request:
function process(action)
{
var getdate = new Date(); //Used to prevent caching during ajax call
if (xmlHttp) // Checks xmlHttp is valid
{
params = "";
if (action == "recreateList")
{
params = "?chunkTitle=" + null + "&chunkContent=" +
null +
"&order=" + {order:Sortable.serialize("chunksList")} +
"&action=recreateList";
}
else if (action == "addNewChunk")
{
var chunkTitle =
document.getElementById("txtChunkTitle");
var chunkContent =
document.getElementById("txtChunkContent");
if (chunkTitle.value && chunkContent.value) // makes
sure Chunk
isnt null
params = "?chunkTitle=" + chunkTitle.value +
"&chunkContent=" +
chunkContent.value + "&chunksList=" + null + "&action=addNewChunk";
}
else if (action =="delChunk")
{
params = "?chunkTitle=" + delElement + "&chunkContent="
+ null +
"&chunksList=" + null + "&action=delChunk";
}
if (params) cache.push(params); // checks params isnt null then
adds
to cache for sending
try // try connecting to server
{
// check cache is not empty and connection is available
if ((xmlHttp.readyState == 4 || xmlHttp.readyState ==
0) &&
cache.length>0)
{
var cacheEntry = cache.shift();
// initiate the request
xmlHttp.open("GET", "dndChunkList.php" +
cacheEntry, true);
xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-
urlencoded");
xmlHttp.onreadystatechange = executeStateChange;
xmlHttp.send(null);
}
else
{
setTimeout("process();", 1000);
}
}
catch (e)
{
displayError(e.toString());
}
}
}
// function that retrieves the HTTP response
function executeStateChange()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
chunkUpdate();
}
else
{
displayError(xmlHttp.statusText);
}
}
}
// Processes server's response
function chunkUpdate()
{
var response = xmlHttp.responseText;
document.getElementById("chunksList").innerHTML = response;
document.getElementById("txtChunkTitle").value = "";
document.getElementById("txtChunkContent").value = "";
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
dndChunkList.php
<?php
require_once ('chunkslist.class.php');
$myChunksList = new ChunksList();
$action = $_GET['action'];
$chunkTitle = $_GET['chunkTitle'];
$chunkContent = $_GET['chunkContent'];
$order = $_GET['order'];
echo $myChunksList->Process($chunkTitle, $chunkContent, $order,
$action);
?>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
And finally the chunkslist.class.php
public function Process($chunkTitle, $chunkContent, $order,
$action)
{
switch($action)
{ case 'recreateList':
$newOrder = $_GET['order'];
for ($i=0; $i < count($newOrder); $i++)
{
$newOrder[$i] =
$this->mysqlConnection->real_escape_string
($newOrder[$i]);
$result =
$this->mysqlConnection->query('UPDATE chunks SET
order_no="' . $i . '" WHERE id="' . $newOrder[$i] . '"');
}
$recreatedList =
$this->BuildChunksList();
return $recreatedList;
break;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This is all the code that I have that affects the reordering, so if
something isnt there then perhaps that is what I am missing!
Thanks again, I know im probably being a pain and missing the obvious,
this is all pretty new to me and have picked most of it
up from tutorials etc and normally use java rather than web based
languages.
Regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---