some refactoring and generalization...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-09-09 04:46:59 +03:00
parent 754094e6b3
commit 24f8cbbcec
2 changed files with 94 additions and 24 deletions

View File

@ -1274,7 +1274,6 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
// XXX show collections in image metadata... (???)
var UICollectionActions = actions.Actions({
config: {
// Global default collections...
//
// NOTE: delete or set to null for none...
@ -1282,15 +1281,11 @@ var UICollectionActions = actions.Actions({
},
editDefaultCollections: ['Interface/Edit default collections...',
widgets.makeUIDialog(function(action){
var defaults =
this.config['default-collections'] =
(this.config['default-collections'] || []).slice()
return browse.makeLister(null,
function(path, make){
make.EditableList(defaults,
widgets.makeConfigListEditorDialog(
'default-collections',
{
cls: 'collection-list',
unique: true,
sortable: 'y',
@ -1299,10 +1294,6 @@ var UICollectionActions = actions.Actions({
check: function(title){
return title.length > 0
&& title != MAIN_COLLECTION_TITLE },
})
}, {
cls: 'collection-list',
})
})],
browseCollections: ['Collections/$Collec$tions...',

View File

@ -324,8 +324,6 @@ function(actions, list, list_key, value_key, options){
/*********************************************************************/
// Dialogs and containers...
@ -458,7 +456,6 @@ module.makeUIDialog = function(a, b){
})
}
var makeDrawer = function(direction){
return makeUIContainer(function(dialog, options){
var that = this
@ -485,6 +482,88 @@ var makeDrawer = function(direction){
})
}
//---------------------------------------------------------------------
// Higher level dialog action constructors...
// Make list editor dialog...
//
// makeListEditorDialog(list[, options])
// -> action
//
// makeListEditorDialog(function[, options])
// -> action
//
//
// Example:
// someAction: [
// makeListEditorDialog(
// // list of items to edit or list getter function...
// // NOTE: this is edited in place...
// [ 'item', .. ] | function(){ .. },
// // options compatible with browse's Items.EditableList(..)
// { .. })],
//
// XXX should these replace the makeConfigListEditor/makeNestedConfigListEditor???
var makeListEditorDialog =
module.makeListEditorDialog =
function makeConfigListEditorDialog(list, options){
options = options || {}
return makeUIDialog(function(){
var lst = list instanceof Function ?
list.call(this)
: list
// NOTE: this will edit the list in place...
return browse.makeLister(null,
function(_, make){
make.EditableList(lst, options)
}, {
cls: options.cls,
})
})
}
// Make .config list editor dialog...
//
// makeConfigListEditorDialog(path[, options])
// -> action
//
//
// Example:
// someAction: [
// makeConfigListEditorDialog(
// // path to list in .config
// 'path.to.list',
// // options compatible with browse's Items.EditableList(..)
// { .. })],
//
// NOTE: see collections.editDefaultCollections(..) for a live example.
var makeConfigListEditorDialog =
module.makeConfigListEditorDialog =
function makeConfigListEditorDialog(path, options){
path = path.split('.')
var key = path.pop()
return makeListEditorDialog(function(){
var p = path.slice()
// get the path...
var cur = this.config
while(p.length > 0){
var k = p.shift()
cur = cur[k] = cur[k] || {}
}
// the actual list we'll be editing...
var list =
cur[key] =
(cur[key] || []).slice()
return list
}, options)
}
//---------------------------------------------------------------------