Changeset 27564 for extensions/rv_autocomplete
- Timestamp:
- Mar 5, 2014, 10:44:34 PM (11 years ago)
- Location:
- extensions/rv_autocomplete
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/rv_autocomplete/admin/custom.php
r22201 r27564 5 5 ORDER BY name'; 6 6 7 $suggestions = array_from_query($query);7 $suggestions = query2array($query); 8 8 9 9 $roots = rvac_get_url_roots(); … … 12 12 13 13 $template->assign('suggestions', $suggestions); 14 foreach ($conf['available_permission_levels'] as $level) 15 { 16 if (0 == $level) 17 $label = l10n('Everybody'); 18 else 19 $label = l10n( sprintf('Level %d', $level) ); 20 $options[$level] = $label; 21 } 22 $template->assign('available_permission_levels', $options); 23 14 24 $template->assign('RVAC_ID', RVAC_ID); 15 25 ?> -
extensions/rv_autocomplete/admin/custom.tpl
r25546 r27564 28 28 <td> 29 29 <input id="ac_counter" type="text" size="3"> 30 </td> 31 </tr> 32 33 <tr> 34 <td> 35 <label for=ac_level>{'Privacy level'|@translate}:</label> 36 </td> 37 <td> 38 <select id="ac_level"> 39 {foreach $available_permission_levels as $level=>$label} 40 <option value="{$level}">{$label}</option> 41 {/foreach} 42 </select> 30 43 </td> 31 44 </tr> … … 54 67 <thead> 55 68 <tr class="throw"> 56 <th>{'Name'|@translate}</th> 57 <th>{'Weight'|@translate}</th> 58 <th>{'URL'|@translate}</th> 59 <th>{'Actions'|@translate}</th> 69 <th class="dtc_Name">{'Name'|@translate}</th> 70 <th class="dtc_Weight">{'Weight'|@translate}</th> 71 <th class="dtc_Level">{'Privacy level'|@translate}</th> 72 <th class="dtc_Url">{'URL'|@translate}</th> 73 <th class="dtc_Actions">{'Actions'|@translate}</th> 60 74 </tr> 61 75 </thead> … … 110 124 111 125 {footer_script} 112 var iniDatas = [ 113 {foreach from=$suggestions item=s name=sloop} 114 {ldelim}id:{$s.id},name:"{$s.name|@escape:javascript}",counter:{$s.counter},url:"{$s.url|@escape:javascript}",U_LINK:"{$s.U_LINK|@escape:javascript}"{rdelim}{if !$smarty.foreach.sloop.last},{/if} 115 {/foreach} 116 ]; 117 var SHelper = {ldelim} 118 {literal} 119 120 buildRowData: function(item) { 121 var rowData = []; 122 rowData.push(item.name); 123 rowData.push(item.counter); 124 rowData.push( "<a href=\""+item.U_LINK+"\" onclick=\"return SHelper.zoom(this.href)\">" 125 + (item.url ? item.url : "show" ) 126 + "</a>" 127 ); 128 rowData.push("<a href=\"\" onclick=\"return SHelper.del(this)\">Delete</a>" 129 + " <a href=\"\" onclick=\"return SHelper.edit(this)\">Edit</a>" 130 ); 131 return rowData; 132 }, 133 134 buildRow: function(item) { 135 var rd = SHelper.buildRowData(item) 136 , row = "<tr>"; 137 138 for (var i =0; i<rd.length; i++) 139 row += "<td>"+rd[i]+"</td>"; 140 141 row += "</tr>"; 142 143 return $(row).data("ac", item) 144 }, 126 var SHelper = { 145 127 146 128 rowFromNode: function(node) { … … 160 142 if (!confirm("Are you sure?")) return false; 161 143 var row = SHelper.rowFromNode(node) 162 , item= row.data("ac");144 , item=dataTable.fnGetData(row[0]); 163 145 164 146 row.fadeTo(500, 0.4); 165 147 (new PwgWS("")).callService( 166 "rvac.delCustom", { id: item.id},148 "rvac.delCustom", { id: item.id}, 167 149 { 168 150 method: "POST", 169 151 onFailure: function(num, text) { row.stop(); row.fadeTo(0,1); alert(num + " " + text); }, 170 152 onSuccess: function(result) { 171 // row.remove();172 153 dataTable.fnDeleteRow( row[0] ); 173 154 } … … 180 161 add: function() { 181 162 $("#ac_name,#ac_counter,#ac_url").val( "" ); 163 $("#ac_level").val("0"); 182 164 $("#acFormContainer") 183 .dialog("option", "buttons", [{ text: "Create", click: function() {165 .dialog("option", "buttons", [{ text: "Create", click: function() { 184 166 (new PwgWS("")).callService( 185 "rvac.addCustom", { name:$("#ac_name").val(), counter:$("#ac_counter").val(), url:$("#ac_url").val() },167 "rvac.addCustom", { name:$("#ac_name").val(), counter:$("#ac_counter").val(), level:$("#ac_level").val(), url:$("#ac_url").val() }, 186 168 { 187 169 method: "POST", … … 190 172 }, 191 173 onSuccess: function(result) { 192 //$("#csTable").append( SHelper.buildRow(result) ); 193 var rd = SHelper.buildRowData(result); 194 var node = dataTable.fnGetNodes( dataTable.fnAddData(rd)[0] ); 195 $(node).data("ac", result); 196 174 dataTable.fnAddData(result); 197 175 $("#ac_name,#ac_counter,#ac_url").val( "" ); 198 176 } … … 206 184 edit: function(node) { 207 185 var row = SHelper.rowFromNode(node) 208 , item= row.data("ac");186 , item=dataTable.fnGetData(row[0]); 209 187 210 188 $("#ac_name").val( item.name ); 211 189 $("#ac_counter").val( item.counter ); 190 $("#ac_level").val( item.level ); 212 191 $("#ac_url").val( item.url ); 213 192 214 193 $("#acFormContainer") 215 .dialog("option", "buttons", [{ text: "Modify", click: function() {194 .dialog("option", "buttons", [{ text: "Modify", click: function() { 216 195 (new PwgWS("")).callService( 217 "rvac.modCustom", { id: item.id, name:$("#ac_name").val(), counter:$("#ac_counter").val(), url:$("#ac_url").val() },196 "rvac.modCustom", { id: item.id, name:$("#ac_name").val(), counter:$("#ac_counter").val(), level:$("#ac_level").val(), url:$("#ac_url").val() }, 218 197 { 219 198 method: "POST", … … 222 201 }, 223 202 onSuccess: function(result) { 224 /*row.after( SHelper.buildRow(result) ) 225 .remove();*/ 226 227 dataTable.fnUpdate(SHelper.buildRowData(result), row[0]); 228 row.data("ac", result); 229 203 dataTable.fnUpdate(result, row[0]); 230 204 $("#acFormContainer").dialog("close"); 231 205 } … … 242 216 $().ready( function() { 243 217 var table = $("#csTable"); 244 $.each(iniDatas, function(i, item) {245 table.append( SHelper.buildRow(item) );246 });247 218 dataTable = table.dataTable( { 248 219 sDom : '<"dtBar"filp>rt<"dtBar"ilp>', 249 220 iDisplayLength: 100, 250 aoColumnDefs: [ 251 { bSearchable: false, aTargets: [1,3] }, 252 { bSortable: false, aTargets: [3] } 221 aaData: [{foreach from=$suggestions item=s name=sloop} 222 {ldelim}id:{$s.id},name:"{$s.name|@escape:javascript}",counter:{$s.counter},level:{$s.level},url:"{$s.url|@escape:javascript}",U_LINK:"{$s.U_LINK|@escape:javascript}"{rdelim}{if !$smarty.foreach.sloop.last},{/if} 223 {/foreach} 224 ], 225 aoColumnDefs: [ { 226 aTargets: ["dtc_Name"], 227 mData: function(item) { 228 return item.name; 229 } 230 },{ 231 aTargets: ["dtc_Weight"], 232 bSearchable: false, 233 mData: function(item) { 234 return item.counter; 235 } 236 },{ 237 aTargets: ["dtc_Level"], 238 mData: function(item, type) { 239 if ("sort"===type) 240 return item.level; 241 switch (item.level) { 242 {foreach $available_permission_levels as $level=>$label} 243 case {$level}: 244 case "{$level}": 245 return "{$label|escape:'javascript'}"; 246 {/foreach} 247 } 248 return item.level; 249 } 250 },{ 251 aTargets: ["dtc_Url"], 252 bSearchable: false, 253 mData: function(item) { 254 return "<a href=\""+item.U_LINK+"\" onclick=\"return SHelper.zoom(this.href)\">" 255 + (item.url ? item.url : "show" ) 256 + "</a>" 257 } 258 },{ 259 aTargets: ["dtc_Actions"], 260 bSearchable: false, 261 bSortable: false, 262 mData: function(item) { 263 return "<a href=\"\" onclick=\"return SHelper.del(this)\">Delete</a>" 264 + " <a href=\"\" onclick=\"return SHelper.edit(this)\">Edit</a>" 265 } 266 } 253 267 ], 254 268 asStripeClasses: ["row1", "row2"], … … 273 287 ); 274 288 }); 275 {/literal}276 289 {/footer_script} -
extensions/rv_autocomplete/admin/exclude.php
r22214 r27564 29 29 GROUP BY id 30 30 ORDER BY global_rank'; 31 $albums = array_from_query($query);31 $albums = query2array($query); 32 32 usort($albums, 'global_rank_compare'); 33 33 … … 40 40 GROUP BY id 41 41 ORDER BY url_name'; 42 $tags = array_from_query($query);42 $tags = query2array($query); 43 43 $tags_select = array(); 44 44 foreach($tags as $tag) -
extensions/rv_autocomplete/admin/functions.inc.php
r22201 r27564 48 48 function rvac_ws_add_methods($srv_arr) 49 49 { 50 global $conf; 50 51 $srv = $srv_arr[0]; 51 52 include_once( dirname(__FILE__).'/../functions.inc.php' ); 52 53 $srv->addMethod('rvac.addCustom', 'rv_ac_ws_add_custom_suggestion', 53 54 array( 54 'name' => array(), 55 'counter' => array('default'=>0), 56 'url' => array('default'=>''), 55 'name' => array(), 56 'counter' => array('default'=>0), 57 'url' => array('default'=>''), 58 'level' => array('default'=>min($conf['available_permission_levels']), 'maxValue'=>max($conf['available_permission_levels']),'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE), 57 59 ), 58 '' );60 '','', array('admin_only'=>true, 'post_only'=>true)); 59 61 60 62 $srv->addMethod('rvac.modCustom', 'rv_ac_ws_mod_custom_suggestion', … … 64 66 'counter' => array('flags' => WS_PARAM_OPTIONAL), 65 67 'url' => array('flags' => WS_PARAM_OPTIONAL), 68 'level' => array('flags' => WS_PARAM_OPTIONAL, 'maxValue'=>max($conf['available_permission_levels']),'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE), 66 69 ), 67 '' );70 '','', array('admin_only'=>true, 'post_only'=>true)); 68 71 69 72 $srv->addMethod('rvac.delCustom', 'rv_ac_ws_del_custom_suggestion', 70 73 array('id'), 71 '' );74 '','', array('admin_only'=>true, 'post_only'=>true)); 72 75 } 73 76 74 77 function rv_ac_ws_add_custom_suggestion($params, $service) 75 78 { 76 global $conf;77 if (!is_admin() || !$service->isPost())78 return new PwgError(403, 'post admin');79 80 79 $name = trim($params['name']); 81 80 if (empty($name)) … … 88 87 if ( !empty($params['url']) ) 89 88 $insert['url'] = $params['url']; 89 if ( isset($params['level']) ) 90 $insert['level'] = $params['level']; 90 91 91 92 mass_inserts(RVAC_SUGGESTIONS, array_keys($insert), array($insert)); … … 100 101 function rv_ac_ws_mod_custom_suggestion($params, $service) 101 102 { 102 global $conf;103 if (!is_admin() || !$service->isPost())104 return new PwgError(403, 'post admin');105 103 $id = intval($params['id']); 106 104 $update = array(); … … 112 110 if (isset($params['url'])) 113 111 $update['url'] = $params['url']; 112 if ( isset($params['level']) ) 113 $update['level'] = $params['level']; 114 114 115 115 single_update(RVAC_SUGGESTIONS, … … 129 129 function rv_ac_ws_del_custom_suggestion($params, $service) 130 130 { 131 global $conf;132 if (!is_admin() || !$service->isPost())133 return new PwgError(403, 'post admin');134 135 131 $id = intval($params['id']); 136 132 $q = 'DELETE FROM '.RVAC_SUGGESTIONS.' WHERE id='.$id; -
extensions/rv_autocomplete/functions.inc.php
r22246 r27564 76 76 if ( !empty($rvac_conf['excluded_tags']) ) 77 77 $query .= ' WHERE id NOT IN ('.implode(',',$rvac_conf['excluded_tags']).')'; 78 $tag_names = simple_hash_from_query($query, 'id','name');78 $tag_names = query2array($query, 'id','name'); 79 79 80 80 $url_len = strlen( $roots['t'] ); … … 105 105 } 106 106 107 $query = 'SELECT name,counter,url FROM '.RVAC_SUGGESTIONS ;107 $query = 'SELECT name,counter,url FROM '.RVAC_SUGGESTIONS.' WHERE level<='.$user['level']; 108 108 $result = pwg_query($query); 109 109 while ($row = pwg_db_fetch_assoc($result)) -
extensions/rv_autocomplete/main.inc.php
r25546 r27564 1 1 <?php /* 2 2 Plugin Name: RV autocomplete 3 Version: 2.6. a3 Version: 2.6.b 4 4 Description: Autocompletes the quick search with albums, tags or custom suggestions 5 5 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=694
Note: See TracChangeset
for help on using the changeset viewer.