Foros del Web » Programando para Internet » Javascript »

Drag&Drop pasar relaciones

Estas en el tema de Drag&Drop pasar relaciones en el foro de Javascript en Foros del Web. Hola ¡¡ Estoy intentando pasar las relaciones que se hacen en un Drag&Drop de mi página. Cargo en una lista 4 noticias y tengo cuatro ...
  #1 (permalink)  
Antiguo 25/11/2008, 17:51
 
Fecha de Ingreso: marzo-2008
Mensajes: 42
Antigüedad: 16 años, 1 mes
Puntos: 0
Drag&Drop pasar relaciones

Hola ¡¡
Estoy intentando pasar las relaciones que se hacen en un Drag&Drop de mi página.
Cargo en una lista 4 noticias y tengo cuatro recuadros pertenecientes a:
Noticia 1, Noticia2, Noticia3 y Noticia 4.
Arrastro y suelto cada una de las 4 noticias donde quiero de mis cuatro recuadros, pero el problema viene cuando quiero grabar esta relación, como puedo pasar los valores de las relaciones a otra página para introducirlos en una base de datos?

Este es el código:
Código:
<HTML>
<HEAD>
	<title>Demo 2: Drag and drop</title>
	<link rel="stylesheet" href="css/demos.css" media="screen" type="text/css">
	<style type="text/css">
	/* CSS for the demo. CSS needed for the scripts are loaded dynamically by the scripts */
	#mainContainer{
		width:600px;
		margin:0 auto;
		margin-top:10px;
		border:1px solid #000;
		padding:2px;
	}
	
	#capitals{
		width:200px;
		float:left;
		border:1px solid #000;
		background-color:#E2EBED;
		padding:3px;
		height:400px;
	}
	#countries{
		width:300px;
		float:right;
		margin:2px;
		height:400px;
	}	
	.dragableBox,.dragableBoxRight{
		width:80px;
		height:20px;
		border:1px solid #000;
		background-color:#FFF;		
		margin-bottom:5px;
		padding:10px;
		font-weight:bold;
		text-align:center;
	}
	div.dragableBoxRight{
		height:65px;
		width:110px;
		float:left;
		margin-right:5px;
		padding:5px;
		background-color:#E2EBED;
	}
	.dropBox{
		width:190px;
		border:1px solid #000;
		background-color:#E2EBED;
		height:400px;
		margin-bottom:10px;
		padding:3px;
		overflow:auto;
	}		
	a{
		color:#F00;
	}
		
	.clear{
		clear:both;
	}
	img{
		border:0px;
	}	
	</style>	
	<script type="text/javascript" src="js/drag-drop-custom.js"></script>
</head>
<body>
<form name="form">
<div id="mainContainer">
		<h2>Gestor de Noticias de Portada</h2>
		<div id="capitals">
			<p><b>Noticias</b></p>
			<div id="dropContent">
            
            <%
			Set RsS = CreateObject("ADODB.RecordSet")
			SqlText2 = "SELECT top 4 * FROM Noticias WHERE tipo=0 order by Nombre ASC" 
			RsS.Open SqlText2, strconn, 3,3%>
             <%do while not rsS.eof%>
            <div class="dragableBox" id="<%=rsS("id")%>"><%=rsS("Nombre")%></div>
              <%rsS.movenext
						   loop
						rsS.close
								  %>
			</div>
		</div>
		<div id="countries">
			<div id="box106" class="dragableBoxRight">Noticia 1</div>
			<div id="box107" class="dragableBoxRight">Noticia 3</div>
			<div id="box101" class="dragableBoxRight">Noticia 2</div>
			<div id="box104" class="dragableBoxRight">Noticia 4</div>
			</div>
		<div class="clear"></div>
		<div class="konaBody"></div>
	</div>

<div id="debug"></div>
<script type="text/javascript">

// Custom drop action for the country boxes
function dropItems(idOfDraggedItem,targetId,x,y)
{
	var targetObj = document.getElementById(targetId);	// Creating reference to target obj
	var subDivs = targetObj.getElementsByTagName('DIV');	// Number of subdivs
	if(subDivs.length>0 && targetId!='capitals')return;	// Sub divs exists on target, i.e. element already dragged on it. => return from function without doing anything
	var sourceObj = document.getElementById(idOfDraggedItem);	// Creating reference to source, i.e. dragged object
	var numericIdTarget = targetId.replace(/[^0-9]/gi,'')/1;	// Find numeric id of target
	var numericIdSource = idOfDraggedItem.replace(/[^0-9]/gi,'')/1;	// Find numeric id of source
	if(numericIdTarget-numericIdSource==100){	// In the html above, there's a difference in 100 between the id of the country and it's capital(example:
												// Oslo have id "box1" and Norway have id "box101", i.e. 1 + 100.
		sourceObj.style.backgroundColor='#0F0';	// Set green background color for dragged object
	}else{
		sourceObj.style.backgroundColor='';	// Reset back to default white background color
	}
	if(targetId=='capitals'){	// Target is the capital box - append the dragged item as child of first sub div, i.e. as child of <div id="dropContent">
		targetObj = targetObj.getElementsByTagName('DIV')[0];	
	}
	targetObj.appendChild(sourceObj);	// Append	
}



var dragDropObj = new DHTMLgoodies_dragDrop();	// Creating drag and drop object

// Assigning drag events to the capitals

<%
			Set RsS = CreateObject("ADODB.RecordSet")
			SqlText2 = "SELECT top 4 * FROM Noticias WHERE tipo=0 order by Nombre ASC" 
			RsS.Open SqlText2, strconn, 3,3%>
             <%do while not rsS.eof%>
			 dragDropObj.addSource('<%=rsS("ID")%>',true);
              <%rsS.movenext
						   loop
						rsS.close
								  %>



// Assigning drop events on the countries
dragDropObj.addTarget('box101','dropItems'); // Set <div id="leftColumn"> as a drop target. Call function dropItems on drop
dragDropObj.addTarget('box104','dropItems'); // Set <div id="leftColumn"> as a drop target. Call function dropItems on drop
dragDropObj.addTarget('box106','dropItems'); // Set <div id="leftColumn"> as a drop target. Call function dropItems on drop
dragDropObj.addTarget('box107','dropItems'); // Set <div id="leftColumn"> as a drop target. Call function dropItems on drop
dragDropObj.addTarget('capitals','dropItems'); // Set <div id="leftColumn"> as a drop target. Call function dropItems on drop

dragDropObj.init();	// Initizlizing drag and drop object
</script>

<input type="button" name="btnEntrar" value="Entrar" class="boton"  onClick="javascript:location.href='orden2.asp?elemento1='+targetobj;">
  </form>
</body>
</html>
Pueden orientarme un poco? muchas gracias de antemano amigos ¡¡
  #2 (permalink)  
Antiguo 25/11/2008, 20:30
Avatar de Fernand0  
Fecha de Ingreso: septiembre-2005
Ubicación: Buenos Aires
Mensajes: 610
Antigüedad: 18 años, 7 meses
Puntos: 19
Respuesta: Drag&Drop pasar relaciones

Tenes cookies... form(oculto con sus respectivos campos.. luego captas por POST y ya) y... hm... despues tenes ajax...

Tambien tenes..
Código PHP:
<?php
$a
'<script>document.write("hola");</script>';
echo 
$a;
?>
Pero si pasas a otra hoja no te va a servir a menos que pases de alguna forma la data
  #3 (permalink)  
Antiguo 26/11/2008, 03:41
 
Fecha de Ingreso: marzo-2008
Mensajes: 42
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Drag&Drop pasar relaciones

Buenos días, gracias por responder ¡¡

Lo que me refiero es que no se del código anteriormente expuesto en que variable se almacena la relación. He probado intentando pasar:

Código:
<input type="button" name="btnEntrar" value="Entrar" class="boton"  onClick="javascript:location.href='orden2.asp?elemento1='+targetobj;">
Pero al pulsar en el botón me dice que targetobj no esta definido. ¿Qué variable debo pasar?

Un saludo
  #4 (permalink)  
Antiguo 26/11/2008, 18:05
 
Fecha de Ingreso: marzo-2008
Mensajes: 42
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: Drag&Drop pasar relaciones

Lo que estoy intentando hacer es cargar una lista de noticias de una base de datos y ahora poder arrastra las que quiera a las cajas de la derecha(una por caja).
Hasta el momento cargo bien la lista de las noticias, arrastro cada una a su caja, pero ahora quiero poder guardar una relación entre la noticia y la caja en la que la he puesto... aquí es donde me he quedado...
Por el firebug he visto que la caja que recibe antes de que se lleve nada se pinta así:
<div id="box106" class="dragableBoxRight">Noticia 1</div>

y despues de ponerle una noticia encima así:

<div id="box106" class="dragableBoxRight">
Noticia 1
<div id="33" class="dragableBox" dragableelement="0" style="visibility: visible;">Titulo de la noticia </div>

Lo que necesito es pasar, siguiendo el ejemplo anterior, es el id="33" que es el id de la noticia con el id="box106" que es el id de la caja Noticia1... Perdonad el tochooo ¡¡¡ un saludo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:26.