Handle delete selection more intelligently, handling mixed selection of accessories and resources

This commit is contained in:
Nathan Gray 2012-11-27 18:08:13 +00:00
parent a821b7a567
commit 0fd3388221
3 changed files with 25 additions and 19 deletions

View File

@ -266,20 +266,9 @@ class resources_ui
'caption' => 'Delete', 'caption' => 'Delete',
'group' => ++$group, 'group' => ++$group,
'disableClass' => 'no_delete', 'disableClass' => 'no_delete',
'enableClass' => 'resource',
'nm_action' => 'open_popup', 'nm_action' => 'open_popup',
'hideOnDisabled' => true 'hideOnDisabled' => true
), ),
'delete-acc' => array(
'caption' => 'Delete',
'icon' => 'delete',
'group' => ++$group,
'disableClass' => 'no_delete',
'confirm' => 'Delete this accessory',
'confirm_multiple' => 'Delete these accessories',
'enableClass' => 'accessory',
'hideOnDisabled' => true
)
); );
return $actions; return $actions;
} }
@ -317,6 +306,7 @@ class resources_ui
// Dialogs to get options // Dialogs to get options
list($action, $settings) = explode('_', $action, 2); list($action, $settings) = explode('_', $action, 2);
echo "$action(".print_r($checked,true).")<br />";
switch($action) switch($action)
{ {
case 'view-calendar': case 'view-calendar':
@ -350,19 +340,34 @@ class resources_ui
$action_msg = lang('booked'); $action_msg = lang('booked');
break; break;
case 'delete': case 'delete':
case 'delete-acc':
$action_msg = lang('deleted'); $action_msg = lang('deleted');
foreach((array)$checked as $n => $id) $promoted_accessories = 0;
foreach($checked as $n => &$id)
{ {
if($settings == 'promote') if($settings == 'promote')
{ {
// Make accessories into resources // Handle a selected accessory
$resource = $this->bo->read($id);
if($resource['accessory_of'] > 0)
{
$resource['accessory_of'] = -1;
$this->bo->save($acc);
$promoted_accessories++;
continue;
}
// Make associated accessories into resources
$accessories = $this->bo->get_acc_list($id); $accessories = $this->bo->get_acc_list($id);
foreach($accessories as $acc_id => $name) foreach($accessories as $acc_id => $name)
{ {
$acc = $this->bo->read($acc_id); $acc = $this->bo->read($acc_id);
$acc['accessory_of'] = -1; $acc['accessory_of'] = -1;
$this->bo->save($acc); $this->bo->save($acc);
$promoted_accessories++;
// Don't need to process these ones now
$checked_key = array_search($acc_id, $checked);
if($checked_key !== false) unset($checked[$checked_key]);
} }
} }
$error = $this->bo->delete($id); $error = $this->bo->delete($id);
@ -376,6 +381,7 @@ class resources_ui
$failed++; $failed++;
} }
} }
if($promoted_accessories) $action_msg .= ", " . lang('%1 accessories now resources',$promoted_accessories);
break; break;
} }
return $failed == 0; return $failed == 0;

View File

@ -2,7 +2,7 @@
/** /**
* EGroupware - eTemplates for Application resources * EGroupware - eTemplates for Application resources
* http://www.egroupware.org * http://www.egroupware.org
* generated by soetemplate::dump4setup() 2012-11-26 13:27 * generated by soetemplate::dump4setup() 2012-11-27 11:06
* *
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package resources * @package resources
@ -60,7 +60,7 @@ $templ_data[] = array('name' => 'resources.resource_select.row','template' => ''
$templ_data[] = array('name' => 'resources.resource_selectbox','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:1:{s:2:"c1";s:7:",bottom";}i:1;a:2:{s:1:"A";a:4:{s:4:"type";s:6:"select";s:4:"size";s:3:"14+";s:4:"name";s:9:"resources";s:7:"no_lang";s:1:"1";}s:1:"B";a:6:{s:4:"type";s:6:"button";s:7:"onclick";s:160:"window.open(egw::link(\'/index.php\',\'menuaction=resources.resources_ui.select\'),\'\',\'dependent=yes,width=600,height=450,scrollbars=yes,status=yes\'); return false;";s:5:"label";s:13:"Add resources";s:4:"size";s:6:"navbar";s:6:"needed";s:1:"1";s:4:"name";s:5:"popup";}}}s:4:"rows";i:1;s:4:"cols";i:2;}}','size' => '','style' => '','modified' => '1118520536',); $templ_data[] = array('name' => 'resources.resource_selectbox','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:1:{s:2:"c1";s:7:",bottom";}i:1;a:2:{s:1:"A";a:4:{s:4:"type";s:6:"select";s:4:"size";s:3:"14+";s:4:"name";s:9:"resources";s:7:"no_lang";s:1:"1";}s:1:"B";a:6:{s:4:"type";s:6:"button";s:7:"onclick";s:160:"window.open(egw::link(\'/index.php\',\'menuaction=resources.resources_ui.select\'),\'\',\'dependent=yes,width=600,height=450,scrollbars=yes,status=yes\'); return false;";s:5:"label";s:13:"Add resources";s:4:"size";s:6:"navbar";s:6:"needed";s:1:"1";s:4:"name";s:5:"popup";}}}s:4:"rows";i:1;s:4:"cols";i:2;}}','size' => '','style' => '','modified' => '1118520536',);
$templ_data[] = array('name' => 'resources.show','template' => '','lang' => '','group' => '0','version' => '1.9.003','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:4:{s:1:"A";s:4:"100%";s:2:"h1";s:6:",!@msg";s:2:"h4";s:34:",!@nm[selectcols]=/legacy_actions/";s:2:"h2";s:2:",1";}i:1;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:4:"span";s:11:"all,message";s:4:"name";s:3:"msg";s:5:"align";s:6:"center";}}i:2;a:1:{s:1:"A";a:3:{s:4:"type";s:8:"template";s:5:"align";s:5:"right";s:4:"name";s:8:"nm_right";}}i:3;a:1:{s:1:"A";a:4:{s:4:"type";s:9:"nextmatch";s:4:"size";s:19:"resources.show.rows";s:7:"no_lang";s:1:"1";s:4:"name";s:2:"nm";}}i:4;a:1:{s:1:"A";a:6:{s:5:"align";s:5:"right";s:4:"span";s:3:"all";s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";i:1;a:5:{s:5:"label";s:13:"Select action";s:7:"onclick";s:184:"if (!egw_globalObjectManager.getObjectById(\'resources.show.rows\').executeActionImplementation(this, \'popup\')) alert(egw::lang(\'You need to select some entries first!\')); return false;;";s:4:"name";s:14:"legacy_actions";s:4:"type";s:10:"buttononly";s:4:"help";s:13:"Select action";}i:2;a:8:{s:5:"label";s:9:"Check all";s:6:"needed";s:1:"1";s:7:"onclick";s:95:"egw_globalObjectManager.getObjectById(\'resources.show.rows\').toggleAllSelected(); return false;";s:4:"name";s:9:"check_all";s:4:"type";s:6:"button";s:4:"size";s:9:"arrow_ltr";s:4:"help";s:9:"Check all";s:4:"span";s:14:",checkAllArrow";}}}i:5;a:1:{s:1:"A";a:3:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"1";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:3:"Add";s:7:"onclick";s:206:"window.open(egw::link(\'/index.php\',\'menuaction=resources.resources_ui.edit\'),\'\',\'dependent=yes,width=800,height=600,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\'); return false; return false;";s:4:"name";s:3:"add";}}}i:6;a:1:{s:1:"A";a:6:{s:5:"class";s:12:"action_popup";s:4:"name";s:12:"delete_popup";s:4:"type";s:3:"box";s:4:"size";s:1:"1";i:1;a:6:{s:5:"class";s:6:"prompt";s:4:"type";s:4:"vbox";s:4:"size";s:1:"3";i:1;a:3:{s:4:"type";s:5:"label";s:5:"label";s:6:"Delete";s:4:"span";s:13:",promptheader";}i:2;a:2:{s:4:"type";s:5:"label";s:5:"label";s:19:"Delete accessories?";}i:3;a:5:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";i:1;a:4:{s:5:"label";s:12:"Yes - Delete";s:7:"onclick";s:36:"nm_submit_popup(this); return false;";s:4:"name";s:6:"delete";s:4:"type";s:6:"button";}i:2;a:4:{s:5:"label";s:24:"No - Make them resources";s:7:"onclick";s:75:"nm_popup_action.id = \'delete_promote\'; nm_submit_popup(this); return false;";s:4:"name";s:14:"delete_promote";s:4:"type";s:6:"button";}i:3;a:3:{s:5:"label";s:11:"No - Cancel";s:7:"onclick";s:35:"nm_hide_popup(this,\'delete_popup\');";s:4:"type";s:10:"buttononly";}}}s:4:"span";s:20:",action_popup prompt";}}}s:4:"rows";i:6;s:4:"cols";i:1;s:4:"size";s:4:"100%";s:7:"options";a:1:{i:0;s:4:"100%";}}}','size' => '100%','style' => '.image16 img { $templ_data[] = array('name' => 'resources.show','template' => '','lang' => '','group' => '0','version' => '1.9.003','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:4:{s:1:"A";s:4:"100%";s:2:"h1";s:6:",!@msg";s:2:"h4";s:34:",!@nm[selectcols]=/legacy_actions/";s:2:"h2";s:2:",1";}i:1;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:4:"span";s:11:"all,message";s:4:"name";s:3:"msg";s:5:"align";s:6:"center";}}i:2;a:1:{s:1:"A";a:3:{s:4:"type";s:8:"template";s:5:"align";s:5:"right";s:4:"name";s:8:"nm_right";}}i:3;a:1:{s:1:"A";a:4:{s:4:"type";s:9:"nextmatch";s:4:"size";s:19:"resources.show.rows";s:7:"no_lang";s:1:"1";s:4:"name";s:2:"nm";}}i:4;a:1:{s:1:"A";a:6:{s:5:"align";s:5:"right";s:4:"span";s:3:"all";s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";i:1;a:5:{s:5:"label";s:13:"Select action";s:7:"onclick";s:184:"if (!egw_globalObjectManager.getObjectById(\'resources.show.rows\').executeActionImplementation(this, \'popup\')) alert(egw::lang(\'You need to select some entries first!\')); return false;;";s:4:"name";s:14:"legacy_actions";s:4:"type";s:10:"buttononly";s:4:"help";s:13:"Select action";}i:2;a:8:{s:5:"label";s:9:"Check all";s:6:"needed";s:1:"1";s:7:"onclick";s:95:"egw_globalObjectManager.getObjectById(\'resources.show.rows\').toggleAllSelected(); return false;";s:4:"name";s:9:"check_all";s:4:"type";s:6:"button";s:4:"size";s:9:"arrow_ltr";s:4:"help";s:9:"Check all";s:4:"span";s:14:",checkAllArrow";}}}i:5;a:1:{s:1:"A";a:3:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"1";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:3:"Add";s:7:"onclick";s:206:"window.open(egw::link(\'/index.php\',\'menuaction=resources.resources_ui.edit\'),\'\',\'dependent=yes,width=800,height=600,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\'); return false; return false;";s:4:"name";s:3:"add";}}}i:6;a:1:{s:1:"A";a:6:{s:5:"class";s:12:"action_popup";s:4:"name";s:12:"delete_popup";s:4:"type";s:3:"box";s:4:"size";s:1:"1";i:1;a:6:{s:5:"class";s:6:"prompt";s:4:"type";s:4:"vbox";s:4:"size";s:1:"3";i:1;a:3:{s:4:"type";s:5:"label";s:5:"label";s:6:"Delete";s:4:"span";s:13:",promptheader";}i:2;a:2:{s:4:"type";s:5:"label";s:5:"label";s:45:"Delete accessories of selected resources too?";}i:3;a:5:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";i:1;a:4:{s:5:"label";s:28:"Yes - Delete accessories too";s:7:"onclick";s:36:"nm_submit_popup(this); return false;";s:4:"name";s:6:"delete";s:4:"type";s:6:"button";}i:2;a:4:{s:5:"label";s:24:"No - Make them resources";s:7:"onclick";s:75:"nm_popup_action.id = \'delete_promote\'; nm_submit_popup(this); return false;";s:4:"name";s:14:"delete_promote";s:4:"type";s:6:"button";}i:3;a:3:{s:5:"label";s:6:"Cancel";s:7:"onclick";s:35:"nm_hide_popup(this,\'delete_popup\');";s:4:"type";s:10:"buttononly";}}}s:4:"span";s:20:",action_popup prompt";}}}s:4:"rows";i:6;s:4:"cols";i:1;s:4:"size";s:4:"100%";s:7:"options";a:1:{i:0;s:4:"100%";}}}','size' => '100%','style' => '.image16 img {
max-width: 16px; max-width: 16px;
max-height: 16px; max-height: 16px;
} }

View File

@ -145,11 +145,11 @@
<box class="action_popup prompt" id="delete_popup"> <box class="action_popup prompt" id="delete_popup">
<vbox class="prompt"> <vbox class="prompt">
<description value="Delete" class="promptheader"/> <description value="Delete" class="promptheader"/>
<description value="Delete accessories?"/> <description value="Delete accessories of selected resources too?"/>
<hbox> <hbox>
<button label="Yes - Delete" id="delete" onclick="nm_submit_popup(this); return false;"/> <button label="Yes - Delete accessories too" id="delete" onclick="nm_submit_popup(this); return false;"/>
<button label="No - Make them resources" id="delete_promote" onclick="nm_popup_action.id = 'delete_promote'; nm_submit_popup(this); return false;"/> <button label="No - Make them resources" id="delete_promote" onclick="nm_popup_action.id = 'delete_promote'; nm_submit_popup(this); return false;"/>
<buttononly label="No - Cancel" onclick="nm_hide_popup(this,'delete_popup');"/> <buttononly label="Cancel" onclick="nm_hide_popup(this,'delete_popup');"/>
</hbox> </hbox>
</vbox> </vbox>
</box> </box>