Various fixes plus support for defaultPath selection when async data

This commit is contained in:
Djamil Legato
2019-06-05 22:07:07 -07:00
parent 0ef89856fb
commit aa56662aa2
4 changed files with 21 additions and 35 deletions

View File

@@ -1504,6 +1504,7 @@ class AdminController extends AdminBaseController
$payload = [
'name' => $file_page ? $file_page->title() : $fileInfo->getFilename(),
'value' => $file_page ? $file_page->route() : $file_path,
'item-key' => basename($file_page ? $file_page->route() : $file_path),
'filename' => $fileInfo->getFilename(),
'extension' => $type === 'dir' ? '' : $fileInfo->getExtension(),
'type' => $type,

View File

@@ -19,31 +19,13 @@ export class Parents {
},
{
labelKey: 'name',
// defaultPath: this.field.val(),
defaultPath: this.field.val(),
createItemContent: function(item) {
return Parents.createItemContent(this.config, item);
}
}
);
/*
this.finder = finder(
this.container[0],
function(parent, config, callback) {
return dataLoad(parent, config, callback);
},
{
labelKey: 'name',
// defaultPath: this.field.val(),
createItemContent: (config, item) => Parents.createItemContent(config, item)
}
);
*/
/* this.finder.on('leaf-selected', (item) => {
this.finder.emit('create-column', () => this.createSimpleColumn(item));
});
*/
this.finder.$emitter.on('leaf-selected', (item) => {
this.finder.emit('create-column', () => this.createSimpleColumn(item));
});
@@ -110,8 +92,6 @@ export class Parents {
createSimpleColumn(item) {}
dataLoad(parent, callback) {
console.log(this, parent, callback);
if (!parent) {
return callback(this.data);
}

View File

@@ -14,6 +14,7 @@ export const DEFAULTS = {
valueKey: 'value', // new
childKey: 'children',
iconKey: 'icon', // new
itemKey: 'item-key', // new
className: {
container: 'fjs-container',
col: 'fjs-col',
@@ -58,7 +59,6 @@ class Finder {
createColumn(data, parent) {
const callback = (data) => this.createColumn(data, parent);
console.log(typeof data);
if (typeof data === 'function') {
data.call(this, parent, callback);
} else if (Array.isArray(data) || typeof data === 'object') {
@@ -174,16 +174,21 @@ class Finder {
path = Array.isArray(path) ? path : path.split('/').map(bit => bit.trim()).filter(Boolean);
if (path.length) {
this.container.children().each((index, child) => $(child).remove);
this.container.children().each((index, child) => $(child).remove());
}
if (typeof data === 'function') {
data.call(this, null, (data) => this.selectPath(path, data));
} else {
this.selectPath(path, data);
}
}
selectPath(path, data, column) {
column = column || this.createColumn(data);
const current = path[0];
const children = data.find((item) => item[this.config.labelKey] === current);
const children = data.find((item) => item[this.config.itemKey] === current);
const newColumn = this.itemSelected({
column,
item: column.find(`[data-fjs-item="${current}"]`).first()
@@ -244,7 +249,7 @@ class Finder {
listItem.addClass(listItemClasses.join(' '));
listItem.append(link)
.attr('data-fjs-item', item[this.config.labelKey]);
.attr('data-fjs-item', item[this.config.itemKey]);
listItem[0]._item = item;

File diff suppressed because one or more lines are too long