From a821b7a567d70b18bd82817b13fc9b7b16b87f8a Mon Sep 17 00:00:00 2001
From: Nathan Gray <nathangray.bsc@gmail.com>
Date: Tue, 27 Nov 2012 16:47:12 +0000
Subject: [PATCH] - Fix apply button clearing new resources - Fix deleting
 accessories not actually removing them

---
 resources/inc/class.resources_bo.inc.php |  3 ++-
 resources/inc/class.resources_ui.inc.php | 20 ++++++++++++++++----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/resources/inc/class.resources_bo.inc.php b/resources/inc/class.resources_bo.inc.php
index 4dc30a3d94..e1cfeca356 100755
--- a/resources/inc/class.resources_bo.inc.php
+++ b/resources/inc/class.resources_bo.inc.php
@@ -320,7 +320,8 @@ class resources_bo
 			}
 		}
 
-		return $this->so->save($resource) ? false : lang('Something went wrong by saving resource');
+		$res_id = $this->so->save($resource);
+		return $res_id ? $res_id : lang('Something went wrong by saving resource');
 	}
 
 	/**
diff --git a/resources/inc/class.resources_ui.inc.php b/resources/inc/class.resources_ui.inc.php
index b4a60745e1..cff3e50dd9 100755
--- a/resources/inc/class.resources_ui.inc.php
+++ b/resources/inc/class.resources_ui.inc.php
@@ -350,6 +350,7 @@ class resources_ui
 				$action_msg = lang('booked');
 				break;
 			case 'delete':
+			case 'delete-acc':
 				$action_msg = lang('deleted');
 				foreach((array)$checked as $n => $id)
 				{
@@ -397,27 +398,38 @@ class resources_ui
 				case 'save':
 				case 'apply':
 					unset($content['save']);
+					unset($content['apply']);
 // 					if($content['id'] != 0)
 // 					{
 // 						// links are already saved by eTemplate
 // 						unset($resource['link_to']['to_id']);
 // 					}
-					$content['msg'] = $this->bo->save($content);
+					$result = $this->bo->save($content);
+					if(is_numeric($result))
+					{
+						$content['res_id'] = $result;
+					}
+					else
+					{
+						$content['msg'] = $result;
+					}
 					break;
 				case 'delete':
 					unset($content['delete']);
 					$content['msg'] = $this->bo->delete($content['res_id']);
 					break;
 			}
-				
+			$js = "opener.egw_refresh('".str_replace("'","\\'",$content['msg'])."','addressbook',{$content['res_id']});";
 			if($button != 'apply' && !$content['msg'])
 			{
-				$js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',
-					array('menuaction' => 'resources.resources_ui.index'))."';";
 				$js .= 'window.close();';
 				echo "<html><body><script>$js</script></body></html>\n";
 				$GLOBALS['egw']->common->egw_exit();
 			}
+			else
+			{
+				$GLOBALS['egw_info']['flags']['java_script'] .= "<script>$js</script>";
+			}
 		}
 
 		$res_id = is_numeric($content) ? (int)$content : $content['res_id'];