From a5e853c618da907f14299bc78233311d5d4b036c Mon Sep 17 00:00:00 2001 From: rvelices Date: Fri, 17 Jan 2014 22:20:56 +0000 Subject: merge -r26837 from trunk to branch 2.6 admin rating improvements - use web service for deletion - use datatables for rating by user - use fontello icons git-svn-id: http://piwigo.org/svn/branches/2.6@26838 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/rating.php | 28 +++------ admin/themes/default/template/rating.tpl | 61 ++++++++++++++----- admin/themes/default/template/rating_user.tpl | 88 +++++++++++++++++++++------ include/ws_functions/pwg.php | 4 ++ ws.php | 1 + 5 files changed, 128 insertions(+), 54 deletions(-) diff --git a/admin/rating.php b/admin/rating.php index 0edd1369b..381b5c4cc 100644 --- a/admin/rating.php +++ b/admin/rating.php @@ -212,10 +212,11 @@ ORDER BY date DESC;'; $nb_rates = pwg_db_num_rows($result); $tpl_image = - array( - 'U_THUMB' => $thumbnail_src, - 'U_URL' => $image_url, - 'SCORE_RATE' => $image['score'], + array( + 'id' => $image['id'], + 'U_THUMB' => $thumbnail_src, + 'U_URL' => $image_url, + 'SCORE_RATE' => $image['score'], 'AVG_RATE' => $image['avg_rates'], 'SUM_RATE' => $image['sum_rates'], 'NB_RATES' => (int)$image['nb_rates'], @@ -226,16 +227,6 @@ ORDER BY date DESC;'; while ($row = pwg_db_fetch_assoc($result)) { - - $url_del = PHPWG_ROOT_PATH.'admin.php'. - get_query_string_diff(array('del')); - - $del_param = 'e='.$image['id']. - '&u='.$row['user_id']. - '&a='.$row['anonymous_id']; - - $url_del .= '&del='.urlencode(urlencode($del_param)); - if ( isset($users[$row['user_id']]) ) { $user_rate = $users[$row['user_id']]; @@ -249,13 +240,8 @@ ORDER BY date DESC;'; $user_rate .= '('.$row['anonymous_id'].')'; } - $tpl_image['rates'][] = - array( - 'DATE' => /*format_date*/($row['date']), - 'RATE' => $row['rate'], - 'USER' => $user_rate, - 'U_DELETE' => $url_del - ); + $row['USER'] = $user_rate; + $tpl_image['rates'][] = $row; } $template->append( 'images', $tpl_image ); } diff --git a/admin/themes/default/template/rating.tpl b/admin/themes/default/template/rating.tpl index fbfd9d8d9..9dcce6f12 100644 --- a/admin/themes/default/template/rating.tpl +++ b/admin/themes/default/template/rating.tpl @@ -40,28 +40,57 @@ {'Rating score'|@translate} {'Average rate'|@translate} {'Sum of rates'|@translate} - {'Rate'|@translate} - {'Username'|@translate} - {'Rate date'|@translate} + {'Rate'|@translate}/{'Username'|@translate}/{'Rate date'|@translate} {foreach from=$images item=image name=image} - {$image.FILE} - {$image.NB_RATES}/{$image.NB_RATES_TOTAL} - {$image.SCORE_RATE} - {$image.AVG_RATE} - {$image.SUM_RATE} - + {$image.FILE} + {$image.NB_RATES}/{$image.NB_RATES_TOTAL} + {$image.SCORE_RATE} + {$image.AVG_RATE} + {$image.SUM_RATE} + + {foreach from=$image.rates item=rate name=rate} - - + + - - + + + +{/foreach}{*rates*} +
{$rate.RATE}
{$rate.rate} {$rate.USER}{$rate.DATE}[{'Delete'|@translate}]{$rate.date}
+ -{/foreach} {*rates*} -{/foreach} {*images*} +{/foreach}{*images*} +{combine_script id='core.scripts' load='async' path='themes/default/js/scripts.js'} +{footer_script} +function del(node,id,uid,aid){ + var tr = jQuery(node).parents("tr").first().fadeTo(1000, 0.4), + data = { + image_id: id, + user_id: uid + }; + if (aid) + data.anonymous_id = aid; -{if !empty($navbar) }{include file='navigation_bar.tpl'|@get_extent:'navbar'}{/if} + (new PwgWS('{$ROOT_URL|@escape:javascript}')).callService( + 'pwg.rates.delete', data, + { + method: 'POST', + onFailure: function(num, text) { tr.stop(); tr.fadeTo(0,1); alert(num + " " + text); }, + onSuccess: function(result){ + if (result) + tr.remove(); + else + alert(result); + } + } + ); + return false; +} +{/footer_script} + +{if !empty($navbar)}{include file='navigation_bar.tpl'|@get_extent:'navbar'}{/if} diff --git a/admin/themes/default/template/rating_user.tpl b/admin/themes/default/template/rating_user.tpl index 7cc36c4fb..a37944aa3 100644 --- a/admin/themes/default/template/rating_user.tpl +++ b/admin/themes/default/template/rating_user.tpl @@ -1,12 +1,32 @@ +{combine_script id='jquery.dataTables' load='footer' path='themes/default/js/plugins/jquery.dataTables.js'} +{html_style} +.sorting { background: url({$ROOT_URL}themes/default/js/plugins/datatables/images/sort_both.png) no-repeat center right; cursor:pointer; } +.sorting_asc { background: url({$ROOT_URL}themes/default/js/plugins/datatables/images/sort_asc.png) no-repeat center right; } +.sorting_desc { background: url({$ROOT_URL}themes/default/js/plugins/datatables/images/sort_desc.png) no-repeat center right; } + +.sorting, .sorting_asc, .sorting_desc { + padding: 3px 18px 3px 10px; +} +.sorting_asc_disabled { background: url({$ROOT_URL}themes/default/js/plugins/datatables/images/sort_asc_disabled.png) no-repeat center right; } +.sorting_desc_disabled { background: url({$ROOT_URL}themes/default/js/plugins/datatables/images/sort_desc_disabled.png) no-repeat center right; } + +.dtBar { + text-align:left; + padding-left: 20px; +} +{/html_style} +

{$ratings|@count} {'Users'|@translate}

+ @@ -17,37 +37,71 @@ {combine_script id='core.scripts' load='async' path='themes/default/js/scripts.js'} -{footer_script}{literal} -function del(elt,uid,aid) -{ - if (!confirm({/literal}'{'Are you sure?'|@translate|@escape:'javascript'}'{literal})) +{footer_script} +var oTable = jQuery('#rateTable').dataTable({ + sDom : '<"dtBar"f>rt', + bPaginate: false, + aaSorting: [[4,'desc']], + aoColumnDefs: [ + { + aTargets: ["dtc_user"], + }, + { + aTargets: ["dtc_stat"], + asSorting: ["desc","asc"], + bSearchable: false + }, + { + aTargets: ["dtc_rate"], + asSorting: ["desc","asc"], + bSearchable: false + }, + { + aTargets: ["dtc_del"], + bSortable: false, + bSearchable: false + } + ] +}); + +function del(elt,uid,aid){ + if (!confirm('{'Are you sure?'|@translate|@escape:'javascript'}')) return false; var tr = elt; while ( tr.nodeName != "TR") tr = tr.parentNode; tr = jQuery(tr).fadeTo(1000, 0.4); - (new PwgWS({/literal}'{$ROOT_URL|@escape:javascript}'{literal})).callService( - 'pwg.rates.delete', {user_id:uid, anonymous_id:aid}, + + (new PwgWS('{$ROOT_URL|@escape:javascript}')).callService( + 'pwg.rates.delete', { user_id:uid, anonymous_id:aid}, { method: 'POST', onFailure: function(num, text) { tr.stop(); tr.fadeTo(0,1); alert(num + " " + text); }, - onSuccess: function(result) { if (result) {tr.remove();} else alert(result); } + onSuccess: function(result){ + if (result) + oTable.fnDeleteRow(tr[0]); + else + alert(result); + } } ); + return false; } -{/literal}{/footer_script} - +{/footer_script} +
+ - - - - - + + + + + {foreach from=$available_rates item=rate} - + {/foreach} - + + {foreach from=$ratings item=rating key=user} @@ -62,7 +116,7 @@ function del(elt,uid,aid) {$rates|@count} {/if} {/foreach} - + {/foreach}
{'Username'|@translate}{'Number of rates'|@translate}{'Average rate'|@translate}{'Variation'|@translate}{'Consensus deviation'|@translate|@replace:' ':'
'}
{'Username'|@translate}{'Number of rates'|@translate}{'Average rate'|@translate}{'Variation'|@translate}{'Consensus deviation'|@translate|@replace:' ':'
'}
{$rate}{$rate}
{$user}[{'Delete'|@translate}]
diff --git a/include/ws_functions/pwg.php b/include/ws_functions/pwg.php index 0def2031f..5f3772aff 100644 --- a/include/ws_functions/pwg.php +++ b/include/ws_functions/pwg.php @@ -271,6 +271,10 @@ DELETE FROM '. RATE_TABLE .' { $query .= ' AND anonymous_id=\''.$params['anonymous_id'].'\''; } + if (!empty($params['image_id'])) + { + $query .= ' AND element_id='.$params['image_id']; + } $changes = pwg_db_changes(pwg_query($query)); if ($changes) diff --git a/ws.php b/ws.php index 5551c87df..fe81decf3 100644 --- a/ws.php +++ b/ws.php @@ -307,6 +307,7 @@ function ws_addDefaultMethods( $arr ) array( 'user_id' => array('type'=>WS_TYPE_ID), 'anonymous_id' => array('default'=>null), + 'image_id' => array('flags'=>WS_PARAM_OPTIONAL, 'type'=>WS_TYPE_ID), ), 'Deletes all rates for a user.', $ws_functions_root . 'pwg.php', -- cgit v1.2.3