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

View File

@ -506,7 +506,7 @@ var makeDrawer = function(direction){
// XXX should these replace the makeConfigListEditor/makeNestedConfigListEditor??? // XXX should these replace the makeConfigListEditor/makeNestedConfigListEditor???
var makeListEditorDialog = var makeListEditorDialog =
module.makeListEditorDialog = module.makeListEditorDialog =
function makeConfigListEditorDialog(list, options){ function makeListEditorDialog(list, options){
options = options || {} options = options || {}
return makeUIDialog(function(){ return makeUIDialog(function(){
@ -724,6 +724,21 @@ var DialogsActions = actions.Actions({
`, `,
makeUIDialog(function(list, options){ makeUIDialog(function(list, options){
return browse.makeList(null, 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/', showActionList: ['- Interface/',
core.doc`Show list of actions dialog... core.doc`Show list of actions dialog...

View File

@ -611,6 +611,15 @@ function(data, options){
// // internally // // internally
// to_remove: null | <list>, // 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... // // Special buttons...
// // // //
// // NOTE: these can be used only if .sort if not set. // // 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 // overwrite the .__list[id] cache, with the input list, this may
// result in losing the edited state if the lists were not synced // result in losing the edited state if the lists were not synced
// properly... // 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 = Items.EditableList =
function(list, options){ function(list, options){
var make = this var make = this
@ -722,8 +733,16 @@ function(list, options){
} }
options = opts options = opts
var lst = list instanceof Function ? var lst =
list() // 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 : list
var editable = dialog.__editable[id] = lst instanceof Array var editable = dialog.__editable[id] = lst instanceof Array
// NOTE: we .slice() here to make the changes a bit better packaged // NOTE: we .slice() here to make the changes a bit better packaged
@ -982,8 +1001,8 @@ function(list, options){
: undefined) : 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... // update list and select new value...
dialog.update() dialog.update()