diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index d5f3bbe4..8a823570 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -47,6 +47,7 @@ var widgets = require('features/ui-widgets') // var MAIN_COLLECTION_TITLE = '$ALL' +var MAIN_COLLECTION_GID = '0' // XXX undo... var CollectionActions = actions.Actions({ @@ -96,7 +97,8 @@ var CollectionActions = actions.Actions({ set collection(value){ this.loadCollection(value) }, get collectionGID(){ - return ((this.collections || {})[this.collection] || {}).gid }, + return ((this.collections || {})[this.collection] || {}).gid + || MAIN_COLLECTION_GID }, set collectionGID(value){ this.collection = value }, @@ -476,8 +478,10 @@ var CollectionActions = actions.Actions({ var state = collections[collection] = collections[collection] || {} state.title = state.title || collection state.gid = state.gid - // maintain the GID of MAIN_COLLECTION_TITLE as '0'... - || (collection == MAIN_COLLECTION_TITLE ? '0' : this.data.newGID()) + // maintain the GID of MAIN_COLLECTION_TITLE as MAIN_COLLECTION_GID... + || (collection == MAIN_COLLECTION_TITLE ? + MAIN_COLLECTION_GID + : this.data.newGID()) // NOTE: we do not need to care about tags here as they // will get overwritten on load... state.data = (mode == 'empty' ? @@ -1046,7 +1050,7 @@ module.Collection = core.ImageGridFeatures.Feature({ : [] var from_id = 'collection: ' +JSON.stringify(from == MAIN_COLLECTION_TITLE ? - '0' + MAIN_COLLECTION_GID : this.collections[from].gid || from) // everything has changed, no need to bother with details... @@ -1570,7 +1574,6 @@ module.AutoCollections = core.ImageGridFeatures.Feature({ //--------------------------------------------------------------------- // XXX show collections in image metadata... (???) -// XXX mark unsaved (*) collections... var UICollectionActions = actions.Actions({ config: { // Global default collections... @@ -1595,8 +1598,7 @@ var UICollectionActions = actions.Actions({ && title != MAIN_COLLECTION_TITLE }, })], - // XXX need .changes format... - // XXX BUG: adding a new collections kills sort... + // XXX edit collection title here??? browseCollections: ['Collections/$Collec$tions...', core.doc`Collection list... @@ -1639,12 +1641,21 @@ var UICollectionActions = actions.Actions({ dialog.close() } var setItemState = function(title){ + var gid = ((that.collections || {})[title] || {}).gid || title + // handle main collection changes... + gid = title == MAIN_COLLECTION_TITLE ? + MAIN_COLLECTION_GID + : gid + var text = this.find('.text').last() // saved state... - // XXX need changes format... - var unsaved = this.changes === true - || (this.changes || {})['collections: '+ JSON.stringify(title)] + var unsaved = that.changes === true + || (that.changes || {})['collection: '+ JSON.stringify(gid)] + || (that.collectionGID == gid + && (that.config['collection-transfer-changes'] || []) + .filter(function(a){ + return !!(that.changes || {})[a] }).length > 0) unsaved && text.attr('unsaved', true) @@ -1659,8 +1670,12 @@ var UICollectionActions = actions.Actions({ && text.attr('cropped', cs.length) } - // XXX should we update collections if they changed outside??? - // XXX + // update collection list if changed externally... + // XXX do we need this??? + collections.splice.apply(collections, [0, collections.length].concat( + collections + .concat(this.collection_order || []) + .unique())) // main collection... !action @@ -1678,7 +1693,8 @@ var UICollectionActions = actions.Actions({ .addClass('sort-handle') .html('☰')) setItemState - .call($(this), title) + //.call($(this), title) + .call($(this), $(this).find('.text').attr('text')) }, open: openHandler, }}) @@ -1709,20 +1725,18 @@ var UICollectionActions = actions.Actions({ }, { cls: 'collection-list', // focus current collection... - selected: that.collection || MAIN_COLLECTION_TITLE, + selected: JSON.stringify( + (that.collection || MAIN_COLLECTION_TITLE) + // XXX not sure it is good that we have to do this... + .replace(/\$/g, '')), }) .close(function(){ - // XXX for some reason when an item is added collections - // reverts to the pre-sorted state and all - // consecutive sorts are ignored... - console.log('>>>', collections) that.collection_order = collections to_remove .forEach(function(title){ that.removeCollection(title) }) }) })], - // XXX mark unsaved (*) collections... browseImageCollections: ['Collections|Image/Image $collections...', widgets.makeUIDialog(function(gid){ var that = this diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 28dcde97..a4bbd2a2 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -683,6 +683,7 @@ function(data, options){ // NOTE: this uses .List(..) internally, see it's doc for additional // info. // NOTE: the list must contain strings. +// NOTE: this accounts for '$' as a key binding marker in item text... // // XXX should id be the first argument?? // XXX TEST: potential problem: when reloading the list this will @@ -952,6 +953,8 @@ function(list, options){ txt = options.normalize ? options.normalize(txt) : txt + // account for '$' as key binding marker... + var ntxt = txt.replace(/\$/g, '') // invalid format... if(options.check && !options.check(txt)){ @@ -960,6 +963,8 @@ function(list, options){ } lst = dialog.__list[id] + var normalized = lst.map(function(e){ + return e.replace(/\$/g, '') }) // list length limit if(options.length_limit @@ -977,25 +982,32 @@ function(list, options){ } // check if item pre-existed... - var preexisted = lst.indexOf(options.unique instanceof Function ? - options.unique(txt) - : txt) >= 0 + var preexisted = options.unique instanceof Function ? + //lst.indexOf(options.unique(txt)) >= 0 + (lst.indexOf(options.unique(txt)) >= 0 + // account for '$' as key binding marker... (XXX ???) + || normalized.indexOf(options.unique(txt).replace(/\$/g, ''))) + : (lst.indexOf(txt) >= 0 + || normalized.indexOf(ntxt) >= 0) // add new value and sort list... lst.push(txt) // unique... if(options.unique == null || options.unique === true){ - lst = lst.unique() + // account for '$' as key binding marker... + lst = lst.unique(function(e){ return e.replace(/\$/g, '') }) // unique normalized... } else if(options.unique instanceof Function){ lst = lst.unique(options.unique) } + // itemadded handler... options.itemadded && !(options.unique && preexisted) - && options.itemadded.call(dialog, txt) + && options + .itemadded.call(dialog, txt) // sort... if(options.sort){ @@ -1005,8 +1017,7 @@ function(list, options){ : undefined) } - // XXX should this be done here??? - //lst = dialog.__list[id] = write(list, lst) + lst = write(dialog.__list[id], lst) // update list and select new value... dialog.update()