From f995891a52e73fac67d6b9571dd2918d4e4bad80 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 2 Feb 2017 07:26:39 +0300 Subject: [PATCH] some refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/lib/util.js | 12 ++-- ui (gen4)/lib/widget/browse.js | 107 ++++++++++++++++++++++----------- 2 files changed, 80 insertions(+), 39 deletions(-) diff --git a/ui (gen4)/lib/util.js b/ui (gen4)/lib/util.js index 1fea4eaa..c73f7159 100755 --- a/ui (gen4)/lib/util.js +++ b/ui (gen4)/lib/util.js @@ -390,19 +390,21 @@ if(typeof(jQuery) != typeof(undefined)){ // // clear element value on edit... // clear_on_edit: false, // - // // reset value on abort... + // // reset value on commit/abort... + // // XXX revise default... + // reset_on_commit: true, // reset_on_abort: true, // - // // blur element on abort/commit... - // blur_on_abort: false, + // // blur element on commit/abort... // blur_on_commit: false, + // blur_on_abort: false, // // // restore focus before disabling the editor... // keep_focus_on_parent: true, // - // // clear selection on abort/commit... - // clear_selection_on_abort: true, + // // clear selection on commit/abort... // clear_selection_on_commit: true, + // clear_selection_on_abort: true, // // // If false unhandled key events will not be propagated to // // parents... diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 1f62dd7d..e5f4dba1 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -317,7 +317,7 @@ function(text, options){ start_on == 'select' && editable .on('edit-abort', function(){ dialog.select(null) }) - + // edit event handlers... options.editaborted && editable.on('edit-abort', options.editaborted) @@ -339,6 +339,39 @@ function(text, options){ } + +//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// Group items... +// +// .Group([, ...]) +// -> +// +// This will return a group element, to get the items use .children() +// +// +// Usage example: +// make.Group([ +// make.Heading('Group'), +// make('---'), +// make('Group item'), +// ]) +// +Items.Group = +function(list){ + var res = [] + list.forEach(function(e){ + e instanceof jQuery ? (res = res.concat(e.toArray())) + : e instanceof Array ? (res = res.concat(e)) + : res.push(e) + }) + var group = $('
') + .addClass('item-group') + .appendTo($(res).parent()) + .append($(res)) + return group +} + + // List of elements... // // @@ -433,13 +466,9 @@ function(data, options){ res.push(elem[0]) }) - options.groupList - && $(res).parent() - .append($('
') - .addClass('item-group') - .append($(res))) - - return $(res) + return options.groupList ? + make.Group(res).children() + : $(res) } @@ -585,6 +614,7 @@ function(data, options){ // info. // NOTE: the list must contain strings. // +// XXX should id be the first argument?? Items.EditableList = function(list, options){ var make = this @@ -879,6 +909,11 @@ function(list, options){ +// Editable list of pinnable elements... +// +// This is like .EditableList(..) but adds the ability to pin items to +// the top sub-list and maintain that sub-list order independently or +// keep it the same as the main list... // // Format: // { @@ -893,16 +928,9 @@ function(list, options){ // ... // } // +// XXX should id be the first argument?? // XXX should this be a single list or two lists??? // ...with a single list it's simpler to play with items w/o full updates... -// XXX add a fast redraw mode to .update(..) -// - do not clear items -// - if args did not change: -// - check if cur item is the same -// ...same text, options, signature to make(..)??? -// - if the same, keep the element -// - if different find and place -// - if nothing found, create Items.EditablePinnedList = function(list, pins, options){ var that = this @@ -924,6 +952,11 @@ function(list, pins, options){ dialog.__to_remove[id] = dialog.__to_remove[pins_id] = [] } + // XXX redraw.... + // - sort - within one list this is trivial (history.js) + // - pin/unpin - remove item from one list and update the + // other... (can we update a sub-list?) + //------------------------------------ setup options: main/pins --- // buttons... var buttons = options.buttons = (options.buttons || []).slice() @@ -1162,6 +1195,14 @@ var BrowserClassPrototype = { // - navigation (mouse/keyboard) // - search/filtering // - buttons +// XXX add a fast redraw mode to .update(..) (???) +// - do not clear items +// - if args did not change: +// - check if cur item is the same +// ...same text, options, signature to make(..)??? +// - if the same, keep the element +// - if different find and place +// - if nothing found, create var BrowserPrototype = { dom: null, @@ -3687,6 +3728,22 @@ module.makeList = makeBrowserMaker(List) +/*********************************************************************/ + +// Make an list/Array editor... +// +// +// For options format see: Items.EditableList(..) +var makeListEditor = +module.makeListEditor = +function(list, options){ + return makeLister(null, + function(path, make){ + make.EditableList(list, options) }, + options) } + + + /*********************************************************************/ // This is similar to List(..) but will parse paths in keys... @@ -3932,24 +3989,6 @@ module.makePathList = makeBrowserMaker(PathList) -/*********************************************************************/ - -// Make an list/Array editor... -// -// -// For options format see: List.EditableList(..) -var makeListEditor = -module.makeListEditor = -function(list, options){ - return makeLister(null, - function(path, make){ - make.EditableList(list, options) - }, - options) -} - - - /********************************************************************** * vim:set ts=4 sw=4 : */ return module })