[development] creating pop-up window for delete and edit actions in table in module file
nan wich
nan_wich at bellsouth.net
Wed Jan 12 15:17:14 UTC 2011
Well, I will be the lone wolf here I guess. The "standard Drupal" way is to use
the delete_confirm dialog API, which you can find documented
in http://api.drupal.org.
Have you even tried a search on drupal.org? I am certain that you would find
your answers there.
Nancy
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
________________________________
From: mahesh gajabar <mahesh143an at gmail.com>
To: development at drupal.org
Sent: Wed, January 12, 2011 1:37:59 AM
Subject: [development] creating pop-up window for delete and edit actions in
table in module file
Hi,
I have written a custome module table for showing some information which is
fetched from database and every row is having edit and delete actions. Both are
working fine. But whenever I click on on edit or delete action action it opens
in other window leaving current page. I want these actions to be taken place in
pop-up window.
My table on drupal screen is as follows
SlNo Doctor Name Gender Status Action
2 Jayaram Srinivasan male inactive Edit |Delete
3 Pavithra M female active Edit |Delete
4 Ravi Mandayam male active Edit |Delete
when i click delete button i should get pop-up window with the dialogue like
this;
Are You Sure You Want To Delete This Doctor?This action cannot be undone.
Cancel
When I click edit button I should get my edit form,
First Name:
Last Name:
Gender:
male
female
Status:
active
inactive
Cancel
complete code of my module file is as follows:
<?php
function doctor_menu() {
$items = array();
$items['doctor'] = array(
'title' => t('Doctors'),
'page callback' =>'doctors_list',
'access arguments' => array('access doctor'),
'type' => MENU_NORMAL_ITEM,
);
$items['doctor/delete/%doctor_user'] = array(
'title' => t('Delete doctor'),
'page callback' => 'drupal_get_form',
'page arguments' => array('doctor_delete_confirm', 2),
'access arguments' => array('access doctor'),
'type' => MENU_CALLBACK,
);
$items['doctor/edit/%doctor_user'] = array(
'title' => t('Edit Form'),
'page callback' => 'drupal_get_form',
'page arguments' => array('doctor_edit_confirm', 2),
'access arguments' => array('access doctor'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function doctors_list() {
$header = array(t(Sl.No),t('Doctor Name'), t('Gender'), t('Status'),
t('Action'));
$query = "SELECT * FROM {doctor}";
$rs = db_query($query);
$row = array();
if ($rs) {
while ($data = db_fetch_object($rs)) {
$doctorid =
$data->doctorid;
$gender = $data->gender;
$status = $data->status ;
$row[] = array($doctorid,stripslashes(ucwords($data->firstname)) . '
' . stripslashes(ucwords($data->lastname)), $gender, $status,
"<a href='doctor/edit/{$data->doctorid}'>" . t('Edit') . "</a> |<a
href='doctor/delete/{$data->doctorid}'> ". t('Delete')."</a>" );
}
}
$str .= theme_table($header, $row);
return $str;
}
function doctor_user_load($doctorid) {
$query = "SELECT * FROM {doctor} WHERE doctorid = %d";
$rs = db_query($query, $doctorid);
if ($rs) {
while ($data = db_fetch_object($rs)) {
return $data;
}
}
return FALSE;
}
function popup()
{
window.confirm();
return false;
}
function doctor_delete_confirm(&$form_state, $doctor) {
$form['_doctor'] = array(
'#type' => 'value',
'#value' => $doctor,
);
return confirm_form($form,
t('Are you sure you want to delete this doctor?'),
isset($_GET['destination']) ? $_GET['destination'] : "doctor",
t('This action cannot be undone.'),
t('Delete'),
t('Cancel'));
}
function doctor_delete_confirm_submit($form, &$form_state) {
$form_values = $form_state['values'];
if ($form_state['values']['confirm']) {
$doctor = $form_state['values']['_doctor'];
$query = "DELETE FROM {doctor} where
doctorid= $doctor->doctorid";
$rs = db_query($query);
drupal_set_message(t('Doctor has been deleted successfully.'));
} drupal_goto("doctor");
}
function doctor_edit_confirm(&$form_state,$doctor){
$form = array();
$form['_doctors'] = array(
'#type' => 'value',
'#value' => $doctor,
);
$query = "SELECT * FROM {doctor} where doctorid=%d";
$rs = db_query($query,$doctor->doctorid);
$data=db_fetch_object($rs);
$firstname=$data->firstname;
$lastname=$data->lastname;
$gender1 = $data->gender;
$gender = $gender1 ? 0: 1;
$status1 = $data->status ;
$status = $status1 ? 1: 0;
$form['firstname']=array(
'#title'=>t('First Name'),
'#type'=>'textfield',
'#default_value'=>$data->firstname,
);
$form['lastname']=array(
'#title'=>t('Last Name'),
'#type'=>'textfield',
'#default_value' => $lastname,
);
$form['gender']=array(
'#title'=>t('Gender'),
'#type'=>'radios',
'#options' => array(t('male'), t('female')),
'#default_value' =>
variable_get('gender',$gender),
);
$form['status']=array(
'#title'=>t('Status'),
'#type'=>'radios',
'#options' => array(t('active'), t('inactive')),
'#default_value' =>
variable_get('status',$status),
);
return confirm_form($form,t(''),
isset($_GET['destination']) ? $_GET['destination'] : "doctor",
t(''),
t('Save'),
t('Cancel'));
}
function doctor_edit_confirm_submit($form, &$form_state)
{
if ($form_state['values']['confirm']) {
$doctor = $form_state['values']['_doctors'];
$form_state['values']['doctorid'] = $doctor->doctorid;
$firstname = $form_state['values']['firstname'];
$lastname = $form_state['values']['lastname'];
$gender1= $form_state['values']['gender'];
$gender = $gender1 ? t('female') : t('male');
$status1 = $form_state['values']['status'];
$status = $status1 ? t('inactive') : t('active');
$query = "UPDATE {doctor} SET firstname = '$firstname', lastname= '$lastname',
gender = '$gender', status = '$status' WHERE doctorid=%d";
$rs = db_query($query,$doctor->doctorid); }
drupal_goto("doctor");
}
Any help appreciated.
Regards,
Mahesh Gajabar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110112/e3f52bd3/attachment-0001.html
More information about the development
mailing list