diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index ffc377be..eeb63375 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -1800,6 +1800,7 @@ module.CropActions = actions.Actions({ this.crop(this.data[selector](tags), flatten) }], + // crop edit actions... // XXX BUG? order does odd things... addToCrop: ['- Crop/', @@ -1883,21 +1884,7 @@ module.CropActions = actions.Actions({ { browseMode: 'uncrop', getUndoState: function(d){ - d.placements = (d.args[0] instanceof Array ? d.args[0] : [d.args[0]] - || [d.current]) - .map(function(g){ return [ - g == null ? - d.current - // get the images... - // NOTE: we store the list if gids and not the - // ribbon as when undoing we have no info - // on ribbon content... - : this.data.ribbons[g] ? this.data.getImages(g) : g, - // get ribbon and ribbon order... - [this.data.getRibbon(g), this.data.getRibbonOrder(g)], - // XXX this is not needed here but is used by .uncollect.undo(..) - this.data.order.indexOf(g), - ] }.bind(this)) }, + d.placements = this.data.getImagePositions(d.args[0]) }, undo: function(d){ (d.placements || []) .forEach(function(e){ diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index 94158f7e..076cc3c4 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -977,17 +977,14 @@ var CollectionActions = actions.Actions({ `, { browseMode: function(){ return !this.collection && 'disabled' }, - /*/ XXX two ways to go: + // XXX two ways to go: // - .collect(..) + .data.placeImage(..) // - rewrite .collect(..) to use .data.placeImage(..) (like: .addToCrop(..)) - //getUndoState: 'removeFromCrop', getUndoState: function(d){ - var base = this.getActionAttr('removeFromCrop', 'getUndoState') - base && base.call(this, d) + d.placements = this.data.getImagePositions(d.args[0]) }, d.collection = d.args[1] || this.collection }, - // XXX this does not work yet... - // XXX this use + /*/ XXX this does not work yet... undo: function(d){ var that = this var gids = d.args[0] || [d.current] diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index 5d24afde..6a488112 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -1213,6 +1213,58 @@ var DataPrototype = { return res }, + // Get image positions... + // + // Get current image position... + // .getImagePositions() + // -> positions + // + // Get positions of gid(s)... + // .getImagePositions(gid) + // .getImagePositions(gid, ...) + // .getImagePositions([gid, ...]) + // -> positions + // + // The resulting positions will be sorted to .order, ribbon gids + // are pushed to the end of the list and also sorted to .ribbon_order + // + // Returns: + // [ + // [, + // [, ]], + // ], + // ... + // ] + // + // NOTE: if a ribbon gid is encountered it will be expanded to a + // list of image gids... + getImagePositions: function(gids){ + gids = arguments.length > 1 ? + [].slice.call(arguments) + : (gids || this.current) + gids = (gids instanceof Array ? gids : [gids]) + // sort ribbon gids to .ribbon_order + .concat(this.ribbon_order + .filter(function(g){ + var i = gids.indexOf(g) + return i >= 0 ? !!gids.splice(i, 1) : false })) + return this + // sort list... + // NOTE: ribbon gids will get pushed to the end... + .makeSparseImages(gids) + .map(function(g){ return [ + // get the images... + this.ribbons[g] ? this.getImages(g) : g, + // get ribbon and ribbon order... + [this.getRibbon(g), this.getRibbonOrder(g)], + // global order... + this.order.indexOf(g), + ] }.bind(this)) + // XXX do we need this??? + // ...removing this would also encode order... + .compact() + }, + // Get ribbon... // // Get current ribbon: