now new collections are added to top of list by default (+option)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-02-25 16:03:33 +03:00
parent 83404e9714
commit 3e3cd7665f
2 changed files with 56 additions and 50 deletions

View File

@ -146,13 +146,12 @@ var CollectionActions = actions.Actions({
var order = this.__collection_order = this.__collection_order || []
// add unsorted things to the head of the list...
var res = keys
.concat(order)
.reverse()
.unique()
.reverse()
var res = [
...keys,
...order,
].tailUnique()
// XXX defaults...
// defaults...
res = res.concat(defaults).unique()
// keep MAIN_COLLECTION_TITLE out of the collection order...
@ -574,6 +573,8 @@ var CollectionActions = actions.Actions({
&& collection != MAIN_COLLECTION_TITLE
// save the data...
// XXX would be nice to be able to add new collections both
// to the start and end of list...
var state = collections[collection] =
collections[collection]
|| {}
@ -2249,6 +2250,13 @@ var UICollectionActions = actions.Actions({
// This will be auto-selected in .browseCollections(..) on next
// add/edit operation...
//'collection-last-used': null,
// can be:
// 'end' | null - place new items at end of list
// 'start' - place new items at start of list
//
// XXX make this configurable???
'collection-ui-place-new': 'start',
},
// UI...
@ -2375,6 +2383,7 @@ var UICollectionActions = actions.Actions({
i && $(this).attr('count', i) }
// update collection list if changed externally...
/* XXX
collections.splice.apply(collections,
// NOTE: if the length calculation here looks a "bit"
// convoluted, that's because it is, this fixes
@ -2387,6 +2396,15 @@ var UICollectionActions = actions.Actions({
.concat(collections
.concat(that.collection_order || [])
.unique()))
/*/
console.log('>>>>', that.collection_order)
collections
.splice(0, collections.length,
...[
...collections,
...(that.collection_order || []),
].tailUnique())
//*/
// main collection...
var main = typeof(show_main) == 'function' ?
@ -2429,6 +2447,7 @@ var UICollectionActions = actions.Actions({
: action ?
'$New...'
: '$New from current state...',
place_new_item: that.config['collection-ui-place-new'],
unique: true,
sortable: 'y',

View File

@ -568,6 +568,8 @@ function(data, options){
// // it as item text...
// new_item: <text>|<bool>,
//
// place_new_item: null | 'end' | 'start',
//
// // If true (default), enable direct editing of items...
// //
// editable_items: <bool>,
@ -755,8 +757,7 @@ function(list, options){
// save item to lst...
var saveItem = function(txt, replace){
if(txt == replace || txt.trim() == ''){
return txt
}
return txt }
txt = options.normalize ?
options.normalize(txt)
: txt
@ -770,8 +771,7 @@ function(list, options){
// invalid format...
if(options.check && !options.check(txt)){
dialog.update()
return
}
return }
lst = dialog.__list[id]
var normalized = lst.map(function(e){
@ -784,13 +784,11 @@ function(list, options){
options.overflow
&& options.overflow.call(dialog, txt)
return
}
return }
// prevent editing non-arrays...
if(!editable || !lst){
return
}
return }
// check if item pre-existed...
var preexisted = utxt ?
@ -802,9 +800,12 @@ function(list, options){
|| normalized.indexOf(ntxt) >= 0)
// add new value and sort list...
// XXX add option to append/prepend item to list...
;(replace && lst.indexOf(replace) >= 0) ?
lst[lst.indexOf(replace)] = txt
: lst.push(txt)
: options.place_new_item == 'start' ?
lst.unshift(txt)
: lst.push(txt)
// unique...
if(options.unique == null || options.unique === true){
@ -813,8 +814,7 @@ function(list, options){
// unique filter...
} else if(options.unique instanceof Function){
lst = lst.unique(options.unique)
}
lst = lst.unique(options.unique) }
// itemadded handler...
options.itemadded
@ -827,8 +827,7 @@ function(list, options){
lst = lst
.sort(options.sort instanceof Function ?
options.sort
: undefined)
}
: undefined) }
lst = write(dialog.__list[id], lst)
@ -1101,16 +1100,14 @@ function(list, options){
.toArray()
var l = dialog.__list[id]
l.splice.apply(l, [0, l.length].concat(order))
dialog.updateItemNumbers()
},
})
}
dialog.updateItemNumbers() },
}) }
// mark items for removal -- if a list is given by user...
to_remove.forEach(function(e){
dialog.filter('"'+ e +'"')
.addClass('strike-out')
})
to_remove
.forEach(function(e){
dialog.filter('"'+ e +'"')
.addClass('strike-out') })
options.itemopen
&& res.on('open', function(evt){
@ -1122,8 +1119,7 @@ function(list, options){
if(options.editable_items !== false){
var trigger_edit = function(){
dialog.select('!')
.trigger('itemedit')
}
.trigger('itemedit') }
$(res)
.on('itemedit', function(){ editItem($(this)) })
;(options.item_edit_keys || ['F2'])
@ -1133,8 +1129,7 @@ function(list, options){
options.item_edit_events != false
&& options.item_edit_events != ''
&& $(res).on(options.item_edit_events || 'menu',
function(){ $(this).trigger('itemedit') })
}
function(){ $(this).trigger('itemedit') }) }
// new item...
if(options.new_item !== false){
@ -1150,15 +1145,12 @@ function(list, options){
.on('edit-commit', function(evt, txt){
if(txt.trim() != ''){
txt = saveItem(txt)
dialog.update()
.done(function(){
//dialog.select('"'+txt+'"')
txt
&& dialog.select('"'+txt.replace(/\$/g, '')+'"') })
}
}))
}
&& dialog
.select('"'+txt.replace(/\$/g, '')+'"') }) } })) }
// dialog handlers...
// NOTE: we bind these only once per dialog...
@ -1169,15 +1161,12 @@ function(list, options){
.on('update', function(){
to_remove.forEach(function(e){
dialog.filter('"'+ e +'"')
.addClass('strike-out')
})
})
.addClass('strike-out') }) })
// clear the to_remove items + save list...
.on('close', function(){
// prevent editing non-arrays...
if(!editable){
return
}
return }
lst = dialog.__list[id]
@ -1188,20 +1177,18 @@ function(list, options){
.forEach(function(e){
var i = lst.indexOf(e)
i >= 0
&& lst.splice(i, 1)
})
&& lst.splice(i, 1) })
// sort...
if(options.sort){
lst.sort(options.sort !== true ? options.sort : undefined)
}
lst.sort(
options.sort !== true ?
options.sort
: undefined) }
write(list, lst)
})
}
write(list, lst) }) }
return $(res)
}
return $(res) }