Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/04/2008, 16:26
metalcliff
 
Fecha de Ingreso: abril-2008
Mensajes: 3
Antigüedad: 16 años, 7 meses
Puntos: 0
Re: me falta solo poder subir fotos para hacer mi blog ajax

Y aca viene lo mas importante, el page.js que donde estan todas las funciones y variables para armar el html... y necesito meter un formulario en la funcion onResponse en la var html para poder subir la foto desde ahi y que quede utilizable.. pero no me deja ponerle un formulario en esa parte un formulario que lo pondre mas abajo




Cita:
var Page = new Object();
Page.index;
Page.startUpload = function()
{
document.getElementById('f1_upload_process').style .visibility = 'visible';
document.getElementById('f1_upload_form').style.vi sibility = 'hidden';
return true;
}

Page.stopUpload = function(success)
{
var result = '';
if (success == 1){
result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
}
else {
result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
}
document.getElementById('f1_upload_process').style .visibility = 'hidden';
document.getElementById('f1_upload_form').innerHTM L = result + '<label>File: <input name="image" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
document.getElementById('f1_upload_form').style.vi sibility = 'visible';
return true;
}
Page.onResponse = function()
{
if(Ajax.CheckReadyState(Ajax.request))
{
document.getElementById('posts').innerHTML = "";
var response = Ajax.request.responseXML.documentElement;
var _post = response.getElementsByTagName('post');

if(_post.length == 0)
{
document.getElementById('posts').innerHTML = 'There are currently no available posts.<br/>Click the "add new post" button above to add a new post';
}

var postDisplay = "";
var formPostDisplay = "";

for(var i=0; i<_post.length; i++)
{
var _title = response.getElementsByTagName('title')[i].firstChild.data;
var _description = response.getElementsByTagName('description')[i].firstChild.data;
var _image = response.getElementsByTagName('image')[i].firstChild.data;
var _date = response.getElementsByTagName('date')[i].firstChild.data;
var _id = response.getElementsByTagName('id')[i].firstChild.data;

if(_title == "" && _description == "")
{
postDisplay = "style='display:none'";
formPostDisplay = "style=''";
}
else
{
postDisplay = "style=''";
formPostDisplay = "style='display:none'";
}

var html = "<div class='post' id='post_"+ i +"' "+ postDisplay +">"
+ "<div class='title' id='title_"+ i +"'>"+ _title
+ "&nbsp;&nbsp;<a href=\"javascript:Page.toggle('"+ i +"');\">edit</a></div>"
+ "<div class='description' id='description_"+ i +"'>"+ _description +"</div>"
+ "<div class='image' id='image_"+ i +"'>"+ _image +"</div>"
+ "<div class='date' id='date_"+ i +"'>"+ _date +"</div>"
+ "</div>"
+ "<div class='post' id='formPost_"+ i +"' "+ formPostDisplay +">"
+ "<div class='title'><input type='text' name='title' id='formTitle_"+ i +"' size='60' value='"+ _title +"'></div>"
+ "<div class='description'><textarea type='text' id='formDescription_"+ i +"' wrap='virtual' cols='60' rows='15'>"+ _description +"</textarea></div><br>"
+ "<div class='image'><input type='file' name='image' id='formImage_"+ i +"' size='30' value='"+ _image +"'></div>"
+ "<div class='date'>"+ _date +"</div>"
+ "<input type='button' name='cancel' value='cancel' onclick=\"javascript:Page.toggle('"+ i +"');\">"
+ "<input type='button' name='delete' value='delete' onclick=\"javascript:Page.deletePost("+ _id +");\">"
+ "<input type='button' name='submit' value='save' onclick=\"javascript:Page.saveNewPost("+ _id +","+ i +");\">"
+ "</div>";

document.getElementById('posts').innerHTML += html;
}
}
}

Page.saveNewPost = function(_id, _index)
{
var newDescription = document.getElementById("formDescription_"+ _index).value;
var newTitle = document.getElementById("formTitle_"+ _index).value;
var newImage = document.getElementById("formImage_"+ _index).value;
Page.setIndex(_index);
Ajax.Request("services/connector.php?method=save&id="+ _id +"&title="+ newTitle +"&description="+ newDescription +"&image="+ newImage, Page.getPost);
}

Page.deletePost = function(_id)
{
Ajax.Request("services/connector.php?method=delete&id="+ _id, Page.onResponse);
}


Page.getPost = function()
{
if(Ajax.CheckReadyState(Ajax.request))
{
var response = Ajax.request.responseXML.documentElement;
var _title = response.getElementsByTagName('title')[Page.getIndex()].firstChild.data;
var _description = response.getElementsByTagName('description')[Page.getIndex()].firstChild.data;
var _image = response.getElementsByTagName('image')[Page.getIndex()].firstChild.data;
var _date = response.getElementsByTagName('date')[Page.getIndex()].firstChild.data;

document.getElementById("title_"+ Page.getIndex()).innerHTML = _title;
document.getElementById("description_"+ Page.getIndex()).innerHTML = _description;
document.getElementById("image_"+ Page.getIndex()).innerHTML = _image;
document.getElementById("date_"+ Page.getIndex()).innerHTML = _date;
Page.toggle(Page.getIndex());
}
}

Page.toggle = function(id)
{
if(document.getElementById("formPost_"+id).style.d isplay == 'none')
{
document.getElementById("formPost_"+id).style.disp lay = '';
document.getElementById("post_"+id).style.display = 'none';
}
else if(document.getElementById("post_"+id).style.displ ay == 'none')
{
document.getElementById("post_"+id).style.display = '';
document.getElementById("formPost_"+id).style.disp lay = 'none';
}
}

Page.setIndex = function(_index) { Page.index = _index; }
Page.getIndex = function() { return Page.index; }

este es el formulario


Cita:
<form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >
<p id="f1_upload_process" align="center">Loading...<br/><img src="loader.gif" /><br/></p>
<p id="f1_upload_form" align="center"><br/>
<label>
<input name="myfile" type="file" size="30" />
</label>
<label>
<input type="submit" name="submitBtn" class="sbtn" value="Upload" />
</label>
</p>

<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
</form>

y este es el upload.php


Cita:
<?php
// Edit upload location here
$destination_path = getcwd().DIRECTORY_SEPARATOR;

$result = 0;

$target_path = $destination_path . basename( $_FILES['myfile']['name']);

if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
$result = 1;
}

sleep(1);
?>

<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script>


¿COMO SE PUEDE INGRESAR UN FORMULARIO EN UNA VARIABLE, OSI NO SE PUEDE QUE ES LO QUE CREO, QUE SE PUEDE HACER?