- add to caddie on picture page done through ajax
git-svn-id: http://piwigo.org/svn/trunk@2429 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
22ce08c6fb
commit
e2ee204c12
4 changed files with 85 additions and 37 deletions
|
|
@ -280,6 +280,34 @@ function ws_getVersion($params, &$service)
|
||||||
return new PwgError(403, 'Forbidden');
|
return new PwgError(403, 'Forbidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns images per category (web service method)
|
* returns images per category (web service method)
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,7 @@ function resizeWindowToFit()
|
||||||
|
|
||||||
function popuphelp(url)
|
function popuphelp(url)
|
||||||
{
|
{
|
||||||
window.open(
|
window.open( url, 'dc_popup',
|
||||||
url,
|
|
||||||
'dc_popup',
|
|
||||||
'alwaysRaised=yes,dependent=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no'
|
'alwaysRaised=yes,dependent=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +152,7 @@ PwgWS.prototype = {
|
||||||
}
|
}
|
||||||
catch (e)
|
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)
|
if (resp!=null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,25 @@
|
||||||
{if isset($U_ADMIN) }
|
{if isset($U_ADMIN) }
|
||||||
<a href="{$U_ADMIN}" title="{'link_info_image'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/preferences.png" class="button" alt="{'edit'|@translate}"></a>
|
<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}
|
||||||
{if isset($U_CADDIE) }
|
{if isset($U_CADDIE) }{*caddie management BEGIN*}
|
||||||
<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>
|
<script type="text/javascript">
|
||||||
{/if}
|
{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>
|
</div>
|
||||||
{include file=$FILE_PICTURE_NAV_BUTTONS}
|
{include file=$FILE_PICTURE_NAV_BUTTONS}
|
||||||
</div> <!-- imageToolBar -->
|
</div> <!-- imageToolBar -->
|
||||||
|
|
|
||||||
6
ws.php
6
ws.php
|
|
@ -43,6 +43,12 @@ function ws_addDefaultMethods( $arr )
|
||||||
$service->addMethod('pwg.getVersion', 'ws_getVersion', null,
|
$service->addMethod('pwg.getVersion', 'ws_getVersion', null,
|
||||||
'retrieves the PWG version');
|
'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',
|
$service->addMethod('pwg.categories.getImages', 'ws_categories_getImages',
|
||||||
array(
|
array(
|
||||||
'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),
|
'cat_id'=>array('default'=>0, 'flags'=>WS_PARAM_FORCE_ARRAY),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue