⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

callback_column - question



Robert
  • profile picture
  • Member

Posted 18 November 2013 - 07:16 AM

Morning to all. I have a table with 10 columns for attachments .. I have used :

$crud->set_field_upload('fisier1','assets/uploads/atasamente');
$crud->set_field_upload('fisier2','assets/uploads/atasamente');
$crud->set_field_upload('fisier3','assets/uploads/atasamente');
.
.

to set the path and field type. Now what i want to do is make in the view a dropdown with the name of the files users upload from where they can select a file and the file opens in a new window ( like when you click on it in - normal way ).

 

I have used 

$crud->callback_column('continut',array($this,'getAttachments'));

to make a callback with a new column and the next function :

public function getAttachments($value, $row)	{
$attachments = array('' => '',
'1' => $row->fisier1,
'2' => $row->fisier2,
'3' => $row->fisier3,
'4' => $row->fisier4,
'5' => $row->fisier5,
...
);
 
$data = "<div style='width:230px'><div style='float:left'>".form_dropdown('', $attachments)."</div>";
return $data;
}

I have the dropmenu with the files names and all but i cant figure a way how to open the file when i click on them or if this is the best way to do it.

 

 

If someone can point me in the right way ..

 

 

Thanks for your time


victor
  • profile picture
  • Member

Posted 18 November 2013 - 10:03 AM

 develop a javascript function which will get a file name from a selected option and redirect you to the file

 

it's an example:
 

<select name="filename" style=""  class="" onchange="go('parent',this,0)">
<option value="http://photo.loc/admin/files/demo.pdf">ffff</option>
<option value="http://photo.loc/admin/files/demo.pdf"">ddddd</option>
</select>
function go(targ,selObj,restore){
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}

Robert
  • profile picture
  • Member

Posted 18 November 2013 - 12:36 PM

Thanks a loot for the info but i got a small problem .. I have modified the callback function (added for test ) :

public function getAttachments($value, $row)	{
$data = "<select name='filename' style='' class='' onchange='go('parent',this,0)'>
<option value=''></option>
<option value='http://google.com'>Fisier1</option>
<option value='http://google.com'>Fisier2</option>
<option value='http://google.com'>Fisier3</option>
<option value='http://google.com'>Fisier4</option>
<option value='http://google.com'>Fisier5</option>
<option value='http://google.com'>Fisier6</option>
</select>";

return $data;
}

and added to the view file :

<script type="text/javascript">
	function go(targ,selObj,restore)	{
    	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	    if (restore) selObj.selectedIndex=0;
	}
</script>

 from what i see the problem is that the function in the view is not called .. any tips ?


victor
  • profile picture
  • Member

Posted 18 November 2013 - 13:57 PM

try to use a browser debug panel( js console) to find the error.

Robert
  • profile picture
  • Member

Posted 19 November 2013 - 06:34 AM

I have used and i get a syntax error on the first line 

$data = "<select name='filename' style='' class='' onchange='go('parent',this,0)'>

but still cant figure out where the problem is .. if i use on direct on the view onchange="go('parent',this,0)"> with "" it works perfect...