Index: /trunk/include/ws_functions.inc.php
===================================================================
--- /trunk/include/ws_functions.inc.php	(revision 2428)
+++ /trunk/include/ws_functions.inc.php	(revision 2429)
@@ -281,4 +281,32 @@
 }
 
+function ws_caddie_add($params, &$service)
+{
+  if (!is_admin())
+  {
+    return new PwgError(401, 'Access denied');
+  }
+  if ( empty($params['image_id']) )
+  {
+    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
+  }
+  global $user;
+  $query = '
+SELECT id
+  FROM '.IMAGES_TABLE.' LEFT JOIN '.CADDIE_TABLE.' ON id=element_id AND user_id='.$user['id'].'
+  WHERE id IN ('.implode(',',$params['image_id']).')
+    AND element_id IS NULL';
+  $datas = array();
+  foreach ( array_from_query($query, 'id') as $id )
+  {
+    array_push($datas, array('element_id'=>$id, 'user_id'=>$user['id']) );
+  }
+  if (count($datas))
+  {
+    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+    mass_inserts(CADDIE_TABLE, array('element_id','user_id'), $datas);
+  }
+  return count($datas);
+}
 
 /**
Index: /trunk/template-common/scripts.js
===================================================================
--- /trunk/template-common/scripts.js	(revision 2428)
+++ /trunk/template-common/scripts.js	(revision 2429)
@@ -5,9 +5,9 @@
 for( i = 0; i < len; i++)
 {
-  if ( formulaire.elements[i].type=='checkbox'
-	   && formulaire.elements[i].name != 'copie')
-  {
-	formulaire.elements[i].checked = true;
-  }
+	if ( formulaire.elements[i].type=='checkbox'
+		&& formulaire.elements[i].name != 'copie')
+	{
+		formulaire.elements[i].checked = true;
+	}
 }
 }
@@ -19,9 +19,9 @@
 for( i = 0; i < len; i++)
 {
-  if ( formulaire.elements[i].type=='checkbox'
-	   && formulaire.elements[i].name != 'copie')
-  {
+	if ( formulaire.elements[i].type=='checkbox'
+		&& formulaire.elements[i].name != 'copie')
+	{
 	formulaire.elements[i].checked = false;
-  }
+	}
 }
 }
@@ -33,9 +33,9 @@
 for( i=0; i<len; i++)
 {
-  if ( formulaire.elements[i].type=='checkbox'
-	   && formulaire.elements[i].name != 'copie')
-  {
+	if ( formulaire.elements[i].type=='checkbox'
+		&& formulaire.elements[i].name != 'copie')
+	{
 	formulaire.elements[i].checked = !formulaire.elements[i].checked;
-  }
+	}
 }
 }
@@ -43,32 +43,30 @@
 function phpWGOpenWindow(theURL,winName,features)
 {
-  img = new Image();
-  img.src = theURL;
-  if (img.complete)
-  {
-    var width=img.width +40;
-    var height=img.height +40;
-  }
-  else
-  {
-    var width=640;
-    var height=480;
-    img.onload = resizeWindowToFit;
-  }
-  newWin = window.open(theURL,winName,features+',left=2,top=1,width=' + width + ',height=' + height);
+	img = new Image();
+	img.src = theURL;
+	if (img.complete)
+	{
+		var width=img.width +40;
+		var height=img.height +40;
+	}
+	else
+	{
+		var width=640;
+		var height=480;
+		img.onload = resizeWindowToFit;
+	}
+	newWin = window.open(theURL,winName,features+',left=2,top=1,width=' + width + ',height=' + height);
 }
 
 function resizeWindowToFit()
 {
-  newWin.resizeTo( img.width+50, img.height+100);
+	newWin.resizeTo( img.width+50, img.height+100);
 }
 
 function popuphelp(url)
 {
-  window.open(
-    url,
-    'dc_popup',
-    'alwaysRaised=yes,dependent=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no'
-  );
+	window.open( url, 'dc_popup',
+		'alwaysRaised=yes,dependent=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no'
+	);
 }
 
@@ -155,5 +153,5 @@
 			catch (e)
 			{
-				this.dispatchError( 200, e.message + '\n' + transport.responseText.substr(0,256).escapeHTML() );
+				this.dispatchError( 200, e.message + '\n' + transport.responseText.substr(0,512) );
 			}
 			if (resp!=null)
Index: /trunk/template/yoga/picture.tpl
===================================================================
--- /trunk/template/yoga/picture.tpl	(revision 2428)
+++ /trunk/template/yoga/picture.tpl	(revision 2429)
@@ -55,7 +55,23 @@
       <a href="{$U_ADMIN}" title="{'link_info_image'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/preferences.png" class="button" alt="{'edit'|@translate}"></a>
     {/if}
-    {if isset($U_CADDIE) }
-      <a href="{$U_CADDIE}" title="{'add to caddie'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/caddie_add.png" class="button" alt="{'caddie'|@translate}"></a>
-    {/if}
+    {if isset($U_CADDIE) }{*caddie management BEGIN*}
+<script type="text/javascript">
+{literal}function addToCadie(aElement, rootUrl, id)
+{
+if (aElement.disabled) return;
+aElement.disabled=true; 
+var y = new PwgWS(rootUrl);
+
+y.callService(
+  "pwg.caddie.add", {image_id: id} ,
+  {
+    onFailure: function(num, text) { alert(num + " " + text); document.location=aElement.href; },
+    onSuccess: function(result) { aElement.disabled = false; }
+  }
+  );
+}{/literal}
+</script>
+      <a href="{$U_CADDIE}" onclick="addToCadie(this, '{$ROOT_URL|@escape:'javascript'}', {$current.id}); return false;" title="{'add to caddie'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/caddie_add.png" class="button" alt="{'caddie'|@translate}"></a>
+    {/if}{*caddie management END*}
   </div>
   {include file=$FILE_PICTURE_NAV_BUTTONS}
Index: /trunk/ws.php
===================================================================
--- /trunk/ws.php	(revision 2428)
+++ /trunk/ws.php	(revision 2429)
@@ -43,4 +43,10 @@
   $service->addMethod('pwg.getVersion', 'ws_getVersion', null,
       'retrieves the PWG version');
+
+  $service->addMethod('pwg.caddie.add', 'ws_caddie_add', 
+      array(
+        'image_id'=> array( 'flags'=>WS_PARAM_FORCE_ARRAY ),
+      ),
+      'adds the elements to the caddie');
 
   $service->addMethod('pwg.categories.getImages', 'ws_categories_getImages',
