made browse.Items.EditableList(..) more uniform (changes the input on exit only) + added state merge handling + some fixes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-09-16 18:11:07 +03:00
parent b1ecd237cb
commit 3b7beab501
3 changed files with 48 additions and 12 deletions

View File

@ -136,10 +136,11 @@ var UIAliasActions = actions.Actions({
new_item: false,
to_remove: to_remove,
itemopen: function(name){
update_merge: 'drop_changes',
itemopen: function(_, name){
that.editAlias(name)
.on('close', function(){ dialog.update() })
dialog.close()
},
each: function(name, elem){
@ -148,17 +149,18 @@ var UIAliasActions = actions.Actions({
keys: getKeys(name),
action: name,
})
}
},
})
: make.Empty()
make('---')
make('New...')
.on('open', function(){
make('New...', { events: {
open: function(){
that.editAlias()
.on('close', function(){ dialog.update() })
})
},
} })
}, {
cls: 'table-view show-keys',
})

View File

@ -506,7 +506,7 @@ var makeDrawer = function(direction){
// XXX should these replace the makeConfigListEditor/makeNestedConfigListEditor???
var makeListEditorDialog =
module.makeListEditorDialog =
function makeConfigListEditorDialog(list, options){
function makeListEditorDialog(list, options){
options = options || {}
return makeUIDialog(function(){
@ -724,6 +724,21 @@ var DialogsActions = actions.Actions({
`,
makeUIDialog(function(list, options){
return browse.makeList(null, list, options) })],
// XXX do we need to split the options???
showEditableList: ['- Interface/',
core.doc`Show editable list dialog...
.showEditableList(<list>, <options>)
-> dialog
See browse.Items.EditableList(..) for more info.
`,
makeUIDialog(function(list, options){
return browse.makeLister(null,
function(path, make){
make.EditableList(list, options)
},
options) })],
showActionList: ['- Interface/',
core.doc`Show list of actions dialog...

View File

@ -611,6 +611,15 @@ function(data, options){
// // internally
// to_remove: null | <list>,
//
// // Merge list state and external list mode on update...
// //
// // This can be:
// // null - keep dialog state, ignore external state (default)
// // 'drop_changes' - load external state
// // <function> - merge the changes
// //
// update_merge: null | 'drop_changes' | <function>,
//
// // Special buttons...
// //
// // NOTE: these can be used only if .sort if not set.
@ -680,6 +689,8 @@ function(data, options){
// overwrite the .__list[id] cache, with the input list, this may
// result in losing the edited state if the lists were not synced
// properly...
// XXX the problem with this is that it adds elements live while removing
// elements on close, either both should be live or both on close...
Items.EditableList =
function(list, options){
var make = this
@ -722,8 +733,16 @@ function(list, options){
}
options = opts
var lst = list instanceof Function ?
list()
var lst =
// load dialog state...
(options.update_merge != 'drop_changes' && dialog.__list[id]) ?
dialog.__list[id]
// merge states...
: (options.update_merge instanceof Function && dialog.__list[id]) ?
options.update_merge(dialog.__list[id])
// initial state...
: list instanceof Function ?
list()
: list
var editable = dialog.__editable[id] = lst instanceof Array
// NOTE: we .slice() here to make the changes a bit better packaged
@ -982,9 +1001,9 @@ function(list, options){
: undefined)
}
lst = dialog.__list[id] = write(list, lst)
// XXX should this be done here???
//lst = dialog.__list[id] = write(list, lst)
// update list and select new value...
dialog.update()
.done(function(){