Items.EditablePinnedList(..) seems to be done... (needs more testing)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-02-02 03:25:58 +03:00
parent 226a397f3b
commit 466b52ccf1
2 changed files with 66 additions and 35 deletions

View File

@ -1732,6 +1732,9 @@ var WidgetTestActions = actions.Actions({
// NOTE: this is not a dialog event, it is defined by the // NOTE: this is not a dialog event, it is defined by the
// container to notify us that we are closing... // container to notify us that we are closing...
.on('close', function(){ .on('close', function(){
console.log(core.doc`Lists:
- Pins: ${pins.join(', ')}
- Letters: ${letters.join(', ')}`)
}) })
})], })],

View File

@ -361,11 +361,12 @@ function(text, options){
// //
// options format: // options format:
// { // {
// // pattern used to match and disable items... // // test if item is disabled...
// // // //
// // NOTE: this is used via .replace(..) so the match will get // // NOTE: if this is a string or regexp, this is used via
// // removed from the item text, unless prevented via regexp. // // .replace(..) so the match will get removed from the item
// disableItemPattern: <pattern>, // // text, unless prevented via regexp.
// isItemDisabled: <pattern> | <function>,
// //
// // if true, disabled items will not get created... // // if true, disabled items will not get created...
// skipDisabledItems: false, // skipDisabledItems: false,
@ -383,19 +384,30 @@ function(data, options){
var res = [] var res = []
var keys = data instanceof Array ? data : Object.keys(data) var keys = data instanceof Array ? data : Object.keys(data)
options = options || {} options = options || {}
var pattern = options.disableItemPattern var test = typeof(options.isItemDisabled) == typeof('str') ?
&& RegExp(options.disableItemPattern) RegExp(options.isItemDisabled)
: options.isItemDisabled
keys.forEach(function(k){ keys.forEach(function(k){
var txt = k var txt = k
var opts = Object.create(options) var opts = Object.create(options)
if(pattern){ if(test){
txt = k instanceof Array ? k[0] : k txt = k instanceof Array ? k[0] : k
// item matches disabled pattern... // item passes disabled predicate...
if(pattern.test(txt)){ if(test instanceof Function
var t = txt.replace(pattern, '') && test(txt)){
opts.disabled = true
if(options.skipDisabledItems){
return
}
// item matches disabled test...
} else if(test instanceof RegExp
&& test.test(txt)){
var t = txt.replace(test, '')
opts.disabled = true opts.disabled = true
@ -867,6 +879,20 @@ function(list, options){
//
// Format:
// {
// // equivalent to .length_limit option in .List(..) but applies
// // only to pins...
// pins_length_limit: .. ,
//
// // equivalent to .sortable option in .List(..) but applies only
// // to pins...
// pins_sortable: .. ,
//
// ...
// }
//
// XXX should this be a single list or two lists??? // 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... // ...with a single list it's simpler to play with items w/o full updates...
// XXX add a fast redraw mode to .update(..) // XXX add a fast redraw mode to .update(..)
@ -885,13 +911,20 @@ function(list, pins, options){
var pins_id = id + '-pins' var pins_id = id + '-pins'
var dialog = this.dialog var dialog = this.dialog
// prepare the cache...
if(dialog.__list){ if(dialog.__list){
pins = dialog.__list[pins_id] || pins pins = dialog.__list[pins_id] || pins
} }
// link the to_remove lists of pins and the main list...
dialog.__to_remove = dialog.__to_remove || {}
if(dialog.__to_remove[id] == null){
dialog.__to_remove[id] = dialog.__to_remove[pins_id] = []
}
//------------------------------------ setup options: main/pins ---
// buttons... // buttons...
var buttons = options.buttons = (options.buttons || []).slice() var buttons = options.buttons = (options.buttons || []).slice()
// XXX pin/unpin button... // pin/unpin button...
var pin = [ var pin = [
'<span class="pin-set">&#9679;</span>' '<span class="pin-set">&#9679;</span>'
+'<span class="pin-unset">&#9675;</span>', +'<span class="pin-unset">&#9675;</span>',
@ -906,17 +939,11 @@ function(list, pins, options){
pins.sort(options.sort) pins.sort(options.sort)
: pins.sortAs(list)) : pins.sortAs(list))
// XXX pin event???
// unpin... // unpin...
} else { } else {
pins.splice(pins.indexOf(p), 1) pins.splice(pins.indexOf(p), 1)
// XXX unpin event???
} }
// XXX redraw...
// XXX this is slow... // XXX this is slow...
that.dialog.update() that.dialog.update()
}] }]
@ -924,33 +951,34 @@ function(list, pins, options){
i < 0 ? i < 0 ?
buttons.push(pin) buttons.push(pin)
: (buttons[i] = pin) : (buttons[i] = pin)
options.isItemDisabled = function(e){ return pins.indexOf(e) >= 0 }
options.skipDisabledItems = options.skipDisabledItems !== false ? true : false
// options for pins... //----------------------------------------- setup options: pins ---
var pins_options = { var pins_options = {
list_id: pins_id, list_id: pins_id,
//cls: (options.cls || '') + ' pinned',
new_item: false, new_item: false,
length_limit: options.pins_lenght_limit || 10, length_limit: options.pins_length_limit || 10,
isItemDisabled: null,
} }
pins_options.__proto__ = options pins_options.__proto__ = options
var sortable = pins_options.sortable = options.pins_sortable !== false || true var sortable = pins_options.sortable = options.pins_sortable !== false || true
sortable sortable
|| (options.sort instanceof Function ? || (options.sort instanceof Function ?
pins.sort(options.sort) pins.sort(options.sort)
: pins.sortAs(list)) : pins.sortAs(list))
// build the list... //---------------------------------------------- build the list ---
var res = this.EditableList(pins, pins_options) var res = this.EditableList(pins, pins_options)
.addClass('pinned') .addClass('pinned')
.toArray() .toArray()
res.push(this.Separator()) res.push(this.Separator()[0])
res.concat(this.EditableList( res.concat(this.EditableList(
// remove pinned from list... // remove pinned from list...
// XXX should these be removed or hidden??? list,
list.filter(function(e){ return pins.indexOf(e) < 0 }),
options) options)
.toArray()) .toArray())
@ -3547,7 +3575,7 @@ ListerPrototype.options = {
// XXX not sure if we need these... // XXX not sure if we need these...
skipDisabledItems: false, skipDisabledItems: false,
// NOTE: to disable this set it to false or null // NOTE: to disable this set it to false or null
disableItemPattern: '^- ', isItemDisabled: '^- ',
} }
// XXX should we inherit or copy options??? // XXX should we inherit or copy options???
// ...inheriting might pose problems with deleting values reverting // ...inheriting might pose problems with deleting values reverting
@ -3592,7 +3620,7 @@ module.makeLister = function(elem, lister, options){
// ] // ]
// //
// If <option-test> starts with a '- ' then it will be added disabled, // If <option-test> starts with a '- ' then it will be added disabled,
// to control the pattern use the .disableItemPattern option, and to // to control the pattern use the .isItemDisabled option, and to
// disable this feature set it to false|null. // disable this feature set it to false|null.
// //
// NOTE: this essentially a different default configuration of Browser... // NOTE: this essentially a different default configuration of Browser...
@ -3608,7 +3636,7 @@ ListPrototype.options = {
// XXX not sure if we need these... // XXX not sure if we need these...
skipDisabledItems: false, skipDisabledItems: false,
// NOTE: to disable this set it to false or null // NOTE: to disable this set it to false or null
disableItemPattern: '^- ', isItemDisabled: '^- ',
list: function(path, make){ list: function(path, make){
var that = this var that = this
@ -3626,7 +3654,7 @@ ListPrototype.options = {
// build the list... // build the list...
_make _make
.List(data, { .List(data, {
disableItemPattern: this.options.disableItemPattern, isItemDisabled: this.options.isItemDisabled,
skipDisabledItems: this.options.skipDisabledItems, skipDisabledItems: this.options.skipDisabledItems,
}) })
@ -3717,7 +3745,7 @@ module.makeList = makeBrowserMaker(List)
// the one used is the longest match. // the one used is the longest match.
// NOTE: if path is receded with '- ' ('- a|b/c') then the basename of // NOTE: if path is receded with '- ' ('- a|b/c') then the basename of
// that path will be disabled, to control the pattern use // that path will be disabled, to control the pattern use
// .disableItemPattern and to disable this feature set it to false. // .isItemDisabled and to disable this feature set it to false.
// //
// //
// Handler format: // Handler format:
@ -3752,14 +3780,14 @@ PathListPrototype.options = {
// XXX not sure if we need these... // XXX not sure if we need these...
skipDisabledItems: false, skipDisabledItems: false,
// NOTE: to disable this set it to false or null // NOTE: to disable this set it to false or null
disableItemPattern: '^- ', isItemDisabled: '^- ',
list: function(path, make){ list: function(path, make){
var that = this var that = this
var data = this.options.data var data = this.options.data
var keys = data.constructor == Array ? data : Object.keys(data) var keys = data.constructor == Array ? data : Object.keys(data)
var pattern = this.options.disableItemPattern var pattern = this.options.isItemDisabled
&& RegExp(this.options.disableItemPattern) && RegExp(this.options.isItemDisabled)
if(pattern && this.options.skipDisabledItems){ if(pattern && this.options.skipDisabledItems){
keys = keys.filter(function(k){ return !pattern.test(k) }) keys = keys.filter(function(k){ return !pattern.test(k) })