- Remove 'Add accessory button'

- Fix bug in delete confirm
- Fix link url
This commit is contained in:
Nathan Gray 2012-11-26 21:04:31 +00:00
parent 90d5428b9e
commit 147b926490
5 changed files with 86 additions and 43 deletions

View File

@ -188,9 +188,17 @@ class resources_bo
$resource['class'] .= 'no_buy '; $resource['class'] .= 'no_buy ';
} }
$readonlys["view_acc[{$resource['res_id']}]"] = ($resource['acc_count'] == 0); $readonlys["view_acc[{$resource['res_id']}]"] = ($resource['acc_count'] == 0);
$resource['class'] .= ($resource['accessory_of']==-1 ? 'resource ' : 'accessory ');
if($resource['acc_count']) if($resource['acc_count'])
{ {
$resource['class'] .= 'hasAccessories '; $resource['class'] .= 'hasAccessories ';
$accessories = $this->get_acc_list($resource['res_id']);
foreach($accessories as $acc_id => $acc_name)
{
$resource['accessories'][] = array('acc_id' => $acc_id, 'name' => $acc_name);
}
} elseif ($resource['accessory_of'] > 0) {
$resource['accessory_of_label'] = $this->link_title($resource['accessory_of']);
} }
$rows[$num]['picture_thumb'] = $this->get_picture($resource); $rows[$num]['picture_thumb'] = $this->get_picture($resource);
@ -232,11 +240,16 @@ class resources_bo
{ {
return lang('You are not permitted to edit this resource!'); return lang('You are not permitted to edit this resource!');
} }
$old = array();
// we need an id to save pictures and make links... // we need an id to save pictures and make links...
if(!$resource['res_id']) if(!$resource['res_id'])
{ {
$resource['res_id'] = $this->so->save($resource); $resource['res_id'] = $this->so->save($resource);
} }
else
{
$old = $this->read($resource['res_id']);
}
switch ($resource['picture_src']) switch ($resource['picture_src'])
{ {
@ -279,11 +292,17 @@ class resources_bo
$this->remove_picture($resource['res_id']); $this->remove_picture($resource['res_id']);
} }
// Update link title
egw_link::notify_update('resources',$resource['res_id'], $resource);
// save links // save links
if(is_array($resource['link_to']['to_id'])) if(is_array($resource['link_to']['to_id']))
{ {
egw_link::link('resources',$resource['res_id'],$resource['link_to']['to_id']); egw_link::link('resources',$resource['res_id'],$resource['link_to']['to_id']);
} }
if($resource['accessory_of'] != $old['accessory_of'])
{
egw_link::unlink(0,'resources',$resource['res_id'],'','resources',$old['accessory_of']);
}
if($resource['accessory_of'] != -1) if($resource['accessory_of'] != -1)
{ {
egw_link::link('resources',$resource['res_id'],'resources',$resource['accessory_of']); egw_link::link('resources',$resource['res_id'],'resources',$resource['accessory_of']);

View File

@ -88,7 +88,7 @@ class resources_hooks
'title' => 'resources.resources_bo.link_title', 'title' => 'resources.resources_bo.link_title',
'titles' => 'resources.resources_bo.link_titles', 'titles' => 'resources.resources_bo.link_titles',
'view' => array( 'view' => array(
'menuaction' => 'resources.resources_ui.show' 'menuaction' => 'resources.resources_ui.edit'
), ),
'view_id' => 'res_id', 'view_id' => 'res_id',
'view_popup' => '850x600', 'view_popup' => '850x600',

View File

@ -186,6 +186,8 @@ class resources_ui
} }
$preserv = $content; $preserv = $content;
$options = array();
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$content['nm']); $GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$content['nm']);
$this->tmpl->read('resources.show'); $this->tmpl->read('resources.show');
return $this->tmpl->exec('resources.resources_ui.index',$content,$sel_options,$no_button,$preserv); return $this->tmpl->exec('resources.resources_ui.index',$content,$sel_options,$no_button,$preserv);
@ -264,8 +266,20 @@ class resources_ui
'caption' => 'Delete', 'caption' => 'Delete',
'group' => ++$group, 'group' => ++$group,
'disableClass' => 'no_delete', 'disableClass' => 'no_delete',
'nm_action' => 'open_popup' 'enableClass' => 'resource',
'nm_action' => 'open_popup',
'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;
} }
@ -376,10 +390,12 @@ class resources_ui
{ {
if (is_array($content)) if (is_array($content))
{ {
if(isset($content['save']) || isset($content['delete'])) list($button) = @each($content['button']);
{ unset($content['button']);
if(isset($content['save'])) switch($button)
{ {
case 'save':
case 'apply':
unset($content['save']); unset($content['save']);
// if($content['id'] != 0) // if($content['id'] != 0)
// { // {
@ -387,17 +403,15 @@ class resources_ui
// unset($resource['link_to']['to_id']); // unset($resource['link_to']['to_id']);
// } // }
$content['msg'] = $this->bo->save($content); $content['msg'] = $this->bo->save($content);
} break;
if(isset($content['delete'])) case 'delete':
{
unset($content['delete']); unset($content['delete']);
$content['msg'] = $this->bo->delete($content['res_id']); $content['msg'] = $this->bo->delete($content['res_id']);
break;
} }
if($content['msg']) if($button != 'apply' && !$content['msg'])
{ {
return $this->edit($content);
}
$js = "opener.location.href='".$GLOBALS['egw']->link('/index.php', $js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',
array('menuaction' => 'resources.resources_ui.index'))."';"; array('menuaction' => 'resources.resources_ui.index'))."';";
$js .= 'window.close();'; $js .= 'window.close();';
@ -405,9 +419,8 @@ class resources_ui
$GLOBALS['egw']->common->egw_exit(); $GLOBALS['egw']->common->egw_exit();
} }
} }
else
{ $res_id = is_numeric($content) ? (int)$content : $content['res_id'];
$res_id = $content;
if (isset($_GET['res_id'])) $res_id = $_GET['res_id']; if (isset($_GET['res_id'])) $res_id = $_GET['res_id'];
if (isset($_GET['accessory_of'])) $accessory_of = $_GET['accessory_of']; if (isset($_GET['accessory_of'])) $accessory_of = $_GET['accessory_of'];
$content = array('res_id' => $res_id); $content = array('res_id' => $res_id);
@ -423,7 +436,7 @@ class resources_ui
); );
} }
if ($_GET['msg']) $content['msg'] = strip_tags($_GET['msg']); if ($_GET['msg']) $content['msg'] = strip_tags($_GET['msg']);
}
// some presetes // some presetes
$content['resource_picture'] = $this->bo->get_picture($content['res_id'],$content['picture_src'],$size=true); $content['resource_picture'] = $this->bo->get_picture($content['res_id'],$content['picture_src'],$size=true);
$content['quantity'] = $content['quantity'] ? $content['quantity'] : 1; $content['quantity'] = $content['quantity'] ? $content['quantity'] : 1;
@ -433,15 +446,13 @@ class resources_ui
$sel_options['gen_src_list'] = $this->bo->get_genpicturelist(); $sel_options['gen_src_list'] = $this->bo->get_genpicturelist();
$sel_options['cat_id'] = $this->bo->acl->get_cats(EGW_ACL_ADD); $sel_options['cat_id'] = $this->bo->acl->get_cats(EGW_ACL_ADD);
$sel_options['cat_id'] = count($sel_options['cat_id']) == 1 ? $sel_options['cat_id'] : $sel_options['cat_id'] = count($sel_options['cat_id']) == 1 ? $sel_options['cat_id'] :
$content['cat_id'] ? $sel_options['cat_id'] : array('' => lang('select one')) + $sel_options['cat_id']; array('' => lang('select one')) + $sel_options['cat_id'];
if($accessory_of > 0 || $content['accessory_of'] > 0) if($accessory_of > 0 || $content['accessory_of'] > 0)
{ {
$content['accessory_of'] = $content['accessory_of'] ? $content['accessory_of'] : $accessory_of; $content['accessory_of'] = $content['accessory_of'] ? $content['accessory_of'] : $accessory_of;
$catofmaster = $this->bo->so->get_value('cat_id',$content['accessory_of']);
$sel_options['cat_id'] = array($catofmaster => $sel_options['cat_id'][$catofmaster]);
} }
$search_options = array('accessory_of' => -1); $search_options = array('accessory_of' => -1);
$sel_options['accessory_of'] = $this->bo->link_query('',$search_options); $sel_options['accessory_of'] = array(-1 => lang('none')) + $this->bo->link_query('',$search_options);
if($res_id) unset($sel_options['accessory_of'][$res_id]); if($res_id) unset($sel_options['accessory_of'][$res_id]);
// $content['general|page|pictures|links'] = 'resources.edit_tabs.page'; //debug // $content['general|page|pictures|links'] = 'resources.edit_tabs.page'; //debug

File diff suppressed because one or more lines are too long

View File

@ -22,6 +22,7 @@
<column/> <column/>
<column/> <column/>
<column/> <column/>
<column/>
<column width="5%"/> <column width="5%"/>
</columns> </columns>
<rows> <rows>
@ -43,6 +44,7 @@
<nextmatch-sortheader label="Location" id="location"/> <nextmatch-sortheader label="Location" id="location"/>
<description value="Storage information"/> <description value="Storage information"/>
</vbox> </vbox>
<nextmatch-header label="Resource / Accessories"/>
<nextmatch-customfields id="customfields"/> <nextmatch-customfields id="customfields"/>
<hbox align="right"> <hbox align="right">
<nextmatch-header label="Actions" id="legacy_actions"/> <nextmatch-header label="Actions" id="legacy_actions"/>
@ -73,6 +75,19 @@
<description id="${row}[location]" no_lang="1"/> <description id="${row}[location]" no_lang="1"/>
<description id="${row}[storage_info]" no_lang="1"/> <description id="${row}[storage_info]" no_lang="1"/>
</vbox> </vbox>
<vbox no_lang="1">
<description id="${row}[accessory_of_label]" no_lang="1" href="resources.resources_ui.edit&amp;res_id=$row_cont[accessory_of]" extra_link_popup="850x600"/>
<grid width="100%" id="${row}[accessories]">
<columns>
<column/>
</columns>
<rows>
<row>
<description id="${row}[name]" no_lang="1" href="resources.resources_ui.edit&amp;res_id=$row_cont[acc_id]" extra_link_popup="850x600"/>
</row>
</rows>
</grid>
</vbox>
<customfields-list id="$row"/> <customfields-list id="$row"/>
<grid id="${row}"> <grid id="${row}">
<columns> <columns>
@ -124,8 +139,6 @@
<row> <row>
<hbox> <hbox>
<button label="Add" id="add" onclick="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;"/> <button label="Add" id="add" onclick="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;"/>
<button label="Add accessory" id="add_sub" onclick="window.open(egw::link('/index.php','menuaction=resources.resources_ui.edit&amp;content=0&amp;accessory_of=$cont[view_accs_of]'),'','dependent=yes,width=800,height=600,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes'); return false;"/>
<button label="Back" id="back"/>
</hbox> </hbox>
</row> </row>
<row> <row>