friscofrankie
06-08-2007, 02:26 PM
I have a drag&drop content manager tat supports multiple languages for eh same site. the site has multiple nested categories. As new languages are added to each of the page entries the user is required to add language support for all parents and grandparents. This part works fine.
the drag&drop allows the restructuring of the DB by moving sub-categories or "files" (really Table entries that PHP uses to build pages) to new parents. In order for a child to be move to the new category I need to ensure the user has added language support for each of the languages supported by the moved item.
I am attempting to catch the server-side generated Error message if there is one and send an alert with the responseText of the server script.
function verifyLang(dropId, itemId)
{
if(itemId == 'bro'){itemNo = dragItem.getAttribute('pg_id');}
else if(itemId == 'pg_'){itemNo = dragItem.getAttribute('pg_id');}
var queryString = 'http://'+location.host+'/admin/add-edit.php?verify_mv=category¶m='+dropId+':'+itemNo;
verifyDropRequest.open("GET", queryString, false);
verifyDropRequest.onreadystatechange = function()
{
if((verifyDropRequest.readyState == 4)&&(verifyDropRequest.status == 200))
{
if(verifyDropRequest.responseText.substr(0,4) == 'Error')
{
var langs = verifyDropRequest.responseText.substr(6);
alert("The destination Category does not support some languages used in this item.\nPlease install the following languages in this category:\n"+langs);
return false;
}else{
return true;
}
}
}
verifyDropRequest.send(null);
}
The drop never completes if there is an error or not.
the calling function:
function verifyDrop(item, overDrop)
{
itemId = item.id.substring(0,3);
dropId = overDrop.getAttribute('cat_id');
verifyDropRequest = new xmlRequest();
if(verifyLang(dropId, itemId) == true)
{
if(itemId == 'bro')
{
itemNo = dragItem.getAttribute('cat_id');
itemType = 'category';
var childUls = new Array();
var tmpId = null;
childUls = item.getElementsByTagName('LI');
for(i=0; i<childUls.length; i++)
{
tmpId = childUls[i].getAttribute('cat_id');
if(tmpId == 0){tmpId = "0";}
if(tmpId == dropId)
{
alert('You cannot move an item into\na descendant of itself!\n'+itemNo+' -> '+dropId);
return false;
}
}
if(itemNo == dropId)
{
alert('You cannot move an item into itself');
return false;
}
if(itemNo == 0){itemNo = "Top Category";}
var res = confirm('copying Category no. '+itemNo+' to category '+dropId);
return res;
}
else if(itemId == 'pg_')
{
itemNo = dragItem.getAttribute('pg_id');
itemType = 'page';
var res = confirm('copying page no. '+itemNo+' to category '+dropId);
return res;
}
}else{
return false;
}
}
There is obviously a flaw in my logic somewhere but damned if I can find it.
This is my first attempt a real client-side scripted site. Javascript and ajax are new toys for me. Is it even possible to base conditional logic on responseText?
OK stupid me I had set the first condition as
if((verifyDropRequest.readyState == 4)&&(verifyDropRequest.status != 200))
mistake. it never fires. I have changed that to
if((verifyDropRequest.readyState == 4)&&(verifyDropRequest.status == 200))
same problem.
the drag&drop allows the restructuring of the DB by moving sub-categories or "files" (really Table entries that PHP uses to build pages) to new parents. In order for a child to be move to the new category I need to ensure the user has added language support for each of the languages supported by the moved item.
I am attempting to catch the server-side generated Error message if there is one and send an alert with the responseText of the server script.
function verifyLang(dropId, itemId)
{
if(itemId == 'bro'){itemNo = dragItem.getAttribute('pg_id');}
else if(itemId == 'pg_'){itemNo = dragItem.getAttribute('pg_id');}
var queryString = 'http://'+location.host+'/admin/add-edit.php?verify_mv=category¶m='+dropId+':'+itemNo;
verifyDropRequest.open("GET", queryString, false);
verifyDropRequest.onreadystatechange = function()
{
if((verifyDropRequest.readyState == 4)&&(verifyDropRequest.status == 200))
{
if(verifyDropRequest.responseText.substr(0,4) == 'Error')
{
var langs = verifyDropRequest.responseText.substr(6);
alert("The destination Category does not support some languages used in this item.\nPlease install the following languages in this category:\n"+langs);
return false;
}else{
return true;
}
}
}
verifyDropRequest.send(null);
}
The drop never completes if there is an error or not.
the calling function:
function verifyDrop(item, overDrop)
{
itemId = item.id.substring(0,3);
dropId = overDrop.getAttribute('cat_id');
verifyDropRequest = new xmlRequest();
if(verifyLang(dropId, itemId) == true)
{
if(itemId == 'bro')
{
itemNo = dragItem.getAttribute('cat_id');
itemType = 'category';
var childUls = new Array();
var tmpId = null;
childUls = item.getElementsByTagName('LI');
for(i=0; i<childUls.length; i++)
{
tmpId = childUls[i].getAttribute('cat_id');
if(tmpId == 0){tmpId = "0";}
if(tmpId == dropId)
{
alert('You cannot move an item into\na descendant of itself!\n'+itemNo+' -> '+dropId);
return false;
}
}
if(itemNo == dropId)
{
alert('You cannot move an item into itself');
return false;
}
if(itemNo == 0){itemNo = "Top Category";}
var res = confirm('copying Category no. '+itemNo+' to category '+dropId);
return res;
}
else if(itemId == 'pg_')
{
itemNo = dragItem.getAttribute('pg_id');
itemType = 'page';
var res = confirm('copying page no. '+itemNo+' to category '+dropId);
return res;
}
}else{
return false;
}
}
There is obviously a flaw in my logic somewhere but damned if I can find it.
This is my first attempt a real client-side scripted site. Javascript and ajax are new toys for me. Is it even possible to base conditional logic on responseText?
OK stupid me I had set the first condition as
if((verifyDropRequest.readyState == 4)&&(verifyDropRequest.status != 200))
mistake. it never fires. I have changed that to
if((verifyDropRequest.readyState == 4)&&(verifyDropRequest.status == 200))
same problem.