Changeset 28542
- Timestamp:
- May 27, 2014, 12:03:57 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/batch_manager_global.php
r28533 r28542 520 520 } 521 521 522 $template->assign( 'filter_category_selected', $selected_category); 523 524 // Dissociate from a category : categories listed for dissociation can only 525 // represent virtual links. We can't create orphans. Links to physical 526 // categories can't be broken. 527 if (count($page['cat_elements_id']) > 0) 528 { 529 $query = ' 530 SELECT 531 DISTINCT(category_id) AS id, 532 c.name, 533 c.uppercats, 534 c.global_rank 535 FROM '.IMAGE_CATEGORY_TABLE.' AS ic 536 JOIN '.CATEGORIES_TABLE.' AS c ON c.id = ic.category_id 537 JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id 538 WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') 539 AND ( 540 ic.category_id != i.storage_category_id 541 OR i.storage_category_id IS NULL 542 ) 543 ;'; 544 display_select_cat_wrapper($query, array(), 'dissociate_options', true); 545 } 522 $template->assign('filter_category_selected', $selected_category); 523 546 524 547 525 if (count($page['cat_elements_id']) > 0) -
trunk/admin/picture_modify.php
r28532 r28542 43 43 WHERE representative_picture_id = '.$_GET['image_id'].' 44 44 ;'; 45 $represent _options_selected= query2array($query, null, 'id');45 $represented_albums = query2array($query, null, 'id'); 46 46 47 47 // +-----------------------------------------------------------------------+ … … 166 166 } 167 167 168 $no_longer_thumbnail_for = array_diff($represent _options_selected, $_POST['represent']);168 $no_longer_thumbnail_for = array_diff($represented_albums, $_POST['represent']); 169 169 if (count($no_longer_thumbnail_for) > 0) 170 170 { … … 172 172 } 173 173 174 $new_thumbnail_for = array_diff($_POST['represent'], $represent _options_selected);174 $new_thumbnail_for = array_diff($_POST['represent'], $represented_albums); 175 175 if (count($new_thumbnail_for) > 0) 176 176 { … … 183 183 } 184 184 185 $represent _options_selected= $_POST['represent'];185 $represented_albums = $_POST['represent']; 186 186 187 187 $page['infos'][] = l10n('Photo informations updated'); … … 407 407 WHERE image_id = '.$_GET['image_id'].' 408 408 ;'; 409 $associate _options_selected= query2array($query, null, 'id');409 $associated_albums = query2array($query, null, 'id'); 410 410 411 411 $template->assign(array( 412 'associate_options_selected' => $associate_options_selected, 413 'represent_options_selected' => $represent_options_selected, 412 'associated_albums' => $associated_albums, 413 'represented_albums' => $represented_albums, 414 'STORAGE_ALBUM' => $storage_category_id, 414 415 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories')), 415 416 )); -
trunk/admin/themes/default/js/LocalStorageCache.js
r28540 r28542 1 /** 2 * Base LocalStorage cache 3 * 4 * @param options {object} 5 * - key (required) identifier of the collection 6 * - serverId (recommended) identifier of the Piwigo instance 7 * - serverKey (required) state of collection server-side 8 * - lifetime (optional) cache lifetime in seconds 9 * - loader (required) function called to fetch data, takes a callback as first argument 10 * which must be called with the loaded date 11 */ 1 12 var LocalStorageCache = function(options) { 13 this._init(options); 14 }; 15 16 /* 17 * Constructor (deported for easy inheritance) 18 */ 19 LocalStorageCache.prototype._init = function(options) { 2 20 this.key = options.key + '_' + options.serverId; 3 21 this.serverKey = options.serverKey; … … 9 27 }; 10 28 29 /* 30 * Get the cache content 31 * @param callback {function} called with the data as first parameter 32 */ 11 33 LocalStorageCache.prototype.get = function(callback) { 12 34 var now = new Date().getTime(), … … 28 50 }; 29 51 52 /* 53 * Manually set the cache content 54 * @param data {mixed} 55 */ 30 56 LocalStorageCache.prototype.set = function(data) { 31 57 if (this.ready) { … … 38 64 }; 39 65 66 /* 67 * Manually clear the cache 68 */ 40 69 LocalStorageCache.prototype.clear = function() { 41 70 if (this.ready) { … … 43 72 } 44 73 }; 74 75 76 /** 77 * Special LocalStorage for admin categories list 78 * 79 * @param options {object} 80 * - serverId (recommended) identifier of the Piwigo instance 81 * - serverKey (required) state of collection server-side 82 * - rootUrl (required) used for WS call 83 */ 84 var CategoriesCache = function(options) { 85 options.key = 'categoriesAdminList'; 86 87 options.loader = function(callback) { 88 jQuery.getJSON(options.rootUrl + 'ws.php?format=json&method=pwg.categories.getAdminList', function(data) { 89 callback(data.result.categories); 90 }); 91 }; 92 93 this._init(options); 94 }; 95 96 CategoriesCache.prototype = new LocalStorageCache({}); 97 98 /* 99 * Init Selectize with cache content 100 * @param $target {jQuery} 101 * @param options {object} 102 * - default (optional) default value which will be forced if the select is emptyed 103 * - filter (optional) function called for each select before applying the data 104 * takes two parameters: cache data, options 105 * must return new data 106 */ 107 CategoriesCache.prototype.selectize = function($target, options) { 108 options = options || {}; 109 110 $target.selectize({ 111 valueField: 'id', 112 labelField: 'fullname', 113 sortField: 'global_rank', 114 searchField: ['fullname'], 115 plugins: ['remove_button'] 116 }); 117 118 this.get(function(categories) { 119 $target.each(function() { 120 var data; 121 if (options.filter != undefined) { 122 data = options.filter.call(this, categories, options); 123 } 124 else { 125 data = categories; 126 } 127 128 this.selectize.load(function(callback) { 129 callback(data); 130 }); 131 132 if (jQuery(this).data('value')) { 133 jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) { 134 this.selectize.addItem(id); 135 }, this)); 136 } 137 138 if (options.default != undefined) { 139 if (this.selectize.getValue() == '') { 140 this.selectize.addItem(options.default); 141 } 142 143 // if multiple: prevent item deletion 144 if (this.multiple) { 145 this.selectize.getItem(options.default).find('.remove').hide(); 146 147 this.selectize.on('item_remove', function(id) { 148 if (id == options.default) { 149 this.addItem(id); 150 this.getItem(id).find('.remove').hide(); 151 } 152 }); 153 } 154 // if single: restore default on blur 155 else { 156 this.selectize.on('dropdown_close', function() { 157 if (this.getValue() == '') { 158 this.addItem(options.default); 159 } 160 }); 161 } 162 } 163 }); 164 }); 165 }; -
trunk/admin/themes/default/template/batch_manager_global.tpl
r28540 r28542 120 120 121 121 {* <!-- CATEGORIES --> *} 122 var categoriesCache = new LocalStorageCache({ 123 key: 'categoriesAdminList', 122 var categoriesCache = new CategoriesCache({ 124 123 serverKey: '{$CACHE_KEYS.categories}', 125 124 serverId: '{$CACHE_KEYS._hash}', 126 127 loader: function(callback) { 128 jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { 129 callback(data.result.categories); 130 }); 131 } 125 rootUrl: '{$ROOT_URL}' 132 126 }); 133 127 134 jQuery('[data-selectize=categories]').selectize({ 135 valueField: 'id', 136 labelField: 'fullname', 137 sortField: 'global_rank', 138 searchField: ['fullname'], 139 plugins: ['remove_button'] 140 }); 141 142 categoriesCache.get(function(categories) { 143 jQuery('[data-selectize=categories]').each(function() { 144 this.selectize.load(function(callback) { 145 callback(categories); 146 }); 147 148 if (jQuery(this).data('value')) { 149 this.selectize.setValue(jQuery(this).data('value')[0]); 128 categoriesCache.selectize(jQuery('[data-selectize=categories]'), { 129 filter: function(categories, options) { 130 if (this.name == 'dissociate') { 131 var filtered = jQuery.grep(categories, function(cat) { 132 return !cat.dir; 133 }); 134 135 if (filtered.length > 0) { 136 jQuery('.albumDissociate').show(); 137 options.default = filtered[0].id; 138 } 139 140 return filtered; 150 141 } 151 152 // prevent empty value 153 if (this.selectize.getValue() == '') { 154 this.selectize.setValue(categories[0].id); 142 else { 143 options.default = categories[0].id; 144 return categories; 155 145 } 156 this.selectize.on('dropdown_close', function() { 157 if (this.getValue() == '') { 158 this.setValue(categories[0].id); 159 } 160 }); 161 }); 146 } 162 147 }); 163 148 … … 838 823 <option value="associate">{'Associate to album'|@translate}</option> 839 824 <option value="move">{'Move to album'|@translate}</option> 840 {if !empty($dissociate_options)} 841 <option value="dissociate">{'Dissociate from album'|@translate}</option> 842 {/if} 825 <option value="dissociate" class="albumDissociate" style="display:none">{'Dissociate from album'|@translate}</option> 843 826 <option value="add_tags">{'Add tags'|@translate}</option> 844 827 {if !empty($associated_tags)} … … 885 868 886 869 <!-- dissociate --> 887 <div id="action_dissociate" class="bulkAction ">870 <div id="action_dissociate" class="bulkAction albumDissociate" style="display:none"> 888 871 <select data-selectize="categories" name="dissociate" style="width:400px"></select> 889 872 </div> -
trunk/admin/themes/default/template/cat_modify.tpl
r28540 r28542 6 6 {footer_script} 7 7 {* <!-- CATEGORIES --> *} 8 var categoriesCache = new LocalStorageCache({ 9 key: 'categoriesAdminList', 8 var categoriesCache = new CategoriesCache({ 10 9 serverKey: '{$CACHE_KEYS.categories}', 11 10 serverId: '{$CACHE_KEYS._hash}', 12 13 loader: function(callback) { 14 jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { 15 callback(data.result.categories); 16 }); 17 } 11 rootUrl: '{$ROOT_URL}' 18 12 }); 19 13 20 jQuery('[data-selectize=categories]').selectize({ 21 valueField: 'id', 22 labelField: 'fullname', 23 sortField: 'global_rank', 24 searchField: ['fullname'], 25 plugins: ['remove_button'] 26 }); 27 28 categoriesCache.get(function(categories) { 29 categories.push({ 30 id: 0, 31 fullname: '------------', 32 global_rank: 0 33 }); 34 35 // remove itself and children 36 categories = jQuery.grep(categories, function(cat) { 37 return !(/\b{$CAT_ID}\b/.test(cat.uppercats)); 38 }); 39 40 jQuery('[data-selectize=categories]').each(function() { 41 this.selectize.load(function(callback) { 42 callback(categories); 14 categoriesCache.selectize(jQuery('[data-selectize=categories]'), { 15 default: 0, 16 filter: function(categories, options) { 17 // remove itself and children 18 var filtered = jQuery.grep(categories, function(cat) { 19 return !(/\b{$CAT_ID}\b/.test(cat.uppercats)); 43 20 }); 44 45 if (jQuery(this).data('value')) {46 this.selectize.setValue(jQuery(this).data('value')[0]);47 }48 21 49 // prevent empty value 50 if (this.selectize.getValue() == '') { 51 this.selectize.setValue(0); 52 } 53 this.selectize.on('dropdown_close', function() { 54 if (this.getValue() == '') { 55 this.setValue(0); 56 } 22 filtered.push({ 23 id: 0, 24 fullname: '------------', 25 global_rank: 0 57 26 }); 58 }); 27 28 return filtered; 29 } 59 30 }); 60 31 {/footer_script} -
trunk/admin/themes/default/template/photos_add_direct.tpl
r28540 r28542 17 17 {footer_script} 18 18 {* <!-- CATEGORIES --> *} 19 var categoriesCache = new LocalStorageCache({ 20 key: 'categoriesAdminList', 19 var categoriesCache = new CategoriesCache({ 21 20 serverKey: '{$CACHE_KEYS.categories}', 22 21 serverId: '{$CACHE_KEYS._hash}', 23 24 loader: function(callback) { 25 jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { 26 callback(data.result.categories); 27 }); 22 rootUrl: '{$ROOT_URL}' 23 }); 24 25 categoriesCache.selectize(jQuery('[data-selectize=categories]'), { 26 filter: function(categories, options) { 27 if (categories.length > 0) { 28 jQuery("#albumSelection").show(); 29 options.default = categories[0].id; 30 } 31 32 return categories; 28 33 } 29 });30 31 jQuery('[data-selectize=categories]').selectize({32 valueField: 'id',33 labelField: 'fullname',34 sortField: 'global_rank',35 searchField: ['fullname'],36 plugins: ['remove_button']37 });38 39 categoriesCache.get(function(categories) {40 if (categories.length > 0) {41 jQuery("#albumSelection").show();42 }43 44 jQuery('[data-selectize=categories]').each(function() {45 this.selectize.load(function(callback) {46 callback(categories);47 });48 49 if (jQuery(this).data('value')) {50 this.selectize.setValue(jQuery(this).data('value')[0]);51 }52 53 // prevent empty value54 if (this.selectize.getValue() == '') {55 this.selectize.setValue(categories[0].id);56 }57 this.selectize.on('dropdown_close', function() {58 if (this.getValue() == '') {59 this.setValue(categories[0].id);60 }61 });62 });63 34 }); 64 35 -
trunk/admin/themes/default/template/picture_modify.tpl
r28540 r28542 11 11 (function(){ 12 12 {* <!-- CATEGORIES --> *} 13 var categoriesCache = new LocalStorageCache({ 14 key: 'categoriesAdminList', 13 var categoriesCache = new CategoriesCache({ 15 14 serverKey: '{$CACHE_KEYS.categories}', 16 15 serverId: '{$CACHE_KEYS._hash}', 17 18 loader: function(callback) { 19 jQuery.getJSON('{$ROOT_URL}ws.php?format=json&method=pwg.categories.getAdminList', function(data) { 20 callback(data.result.categories); 21 }); 22 } 16 rootUrl: '{$ROOT_URL}' 23 17 }); 24 18 25 jQuery('[data-selectize=categories]').selectize({ 26 valueField: 'id', 27 labelField: 'fullname', 28 sortField: 'global_rank', 29 searchField: ['fullname'], 30 plugins: ['remove_button'] 31 }); 32 33 categoriesCache.get(function(categories) { 34 jQuery('[data-selectize=categories]').each(function() { 35 this.selectize.load(function(callback) { 36 callback(categories); 37 }); 38 39 jQuery.each(jQuery(this).data('value'), jQuery.proxy(function(i, id) { 40 this.selectize.addItem(id); 41 }, this)); 42 }); 43 }); 19 categoriesCache.selectize(jQuery('[data-selectize=categories]'), { {if $STORAGE_ALBUM} 20 filter: function(categories, options) { 21 options.default = (this.name == 'associate[]') ? {$STORAGE_ALBUM} : undefined; 22 return categories; 23 } 24 {/if} }); 44 25 45 26 {* <!-- TAGS --> *} … … 158 139 <strong>{'Linked albums'|@translate}</strong> 159 140 <br> 160 <select data-selectize="categories" data-value="{$associate _options_selected|@json_encode|escape:html}"141 <select data-selectize="categories" data-value="{$associated_albums|@json_encode|escape:html}" 161 142 name="associate[]" multiple style="width:600px;" ></select> 162 143 </p> … … 165 146 <strong>{'Representation of albums'|@translate}</strong> 166 147 <br> 167 <select data-selectize="categories" data-value="{$represent _options_selected|@json_encode|escape:html}"148 <select data-selectize="categories" data-value="{$represented_albums|@json_encode|escape:html}" 168 149 name="represent[]" multiple style="width:600px;" ></select> 169 150 </p> -
trunk/include/ws_functions/pwg.categories.php
r28494 r28542 490 490 491 491 $query = ' 492 SELECT id, name, comment, uppercats, global_rank 492 SELECT id, name, comment, uppercats, global_rank, dir 493 493 FROM '. CATEGORIES_TABLE .' 494 494 ;';
Note: See TracChangeset
for help on using the changeset viewer.