|
|
@@ -5,9 +5,10 @@ import _ from 'lodash';
|
|
|
|
|
|
export class FolderPickerCtrl {
|
|
|
initialTitle: string;
|
|
|
- initialFolderId: number;
|
|
|
+ initialFolderId?: number;
|
|
|
labelClass: string;
|
|
|
onChange: any;
|
|
|
+ onLoad: any;
|
|
|
rootName = 'Root';
|
|
|
folder: any;
|
|
|
|
|
|
@@ -17,12 +18,19 @@ export class FolderPickerCtrl {
|
|
|
this.labelClass = "width-7";
|
|
|
}
|
|
|
|
|
|
- if (this.initialFolderId > 0) {
|
|
|
+ if (this.initialFolderId && this.initialFolderId > 0) {
|
|
|
this.getOptions('').then(result => {
|
|
|
this.folder = _.find(result, {value: this.initialFolderId});
|
|
|
+ this.onFolderLoad();
|
|
|
});
|
|
|
} else {
|
|
|
- this.folder = {text: this.initialTitle, value: null};
|
|
|
+ if (this.initialTitle) {
|
|
|
+ this.folder = {text: this.initialTitle, value: null};
|
|
|
+ } else {
|
|
|
+ this.folder = {text: this.rootName, value: 0};
|
|
|
+ }
|
|
|
+
|
|
|
+ this.onFolderLoad();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -33,8 +41,12 @@ export class FolderPickerCtrl {
|
|
|
};
|
|
|
|
|
|
return this.backendSrv.search(params).then(result => {
|
|
|
- if (query === "") {
|
|
|
- result.unshift({title: this.rootName, value: 0});
|
|
|
+ if (query === '' ||
|
|
|
+ query.toLowerCase() === "r" ||
|
|
|
+ query.toLowerCase() === "ro" ||
|
|
|
+ query.toLowerCase() === "roo" ||
|
|
|
+ query.toLowerCase() === "root") {
|
|
|
+ result.unshift({title: this.rootName, id: 0});
|
|
|
}
|
|
|
|
|
|
return _.map(result, item => {
|
|
|
@@ -43,6 +55,12 @@ export class FolderPickerCtrl {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ onFolderLoad() {
|
|
|
+ if (this.onLoad) {
|
|
|
+ this.onLoad({$folder: {id: this.folder.value, title: this.folder.text}});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
onFolderChange(option) {
|
|
|
this.onChange({$folder: {id: option.value, title: option.text}});
|
|
|
}
|
|
|
@@ -69,11 +87,12 @@ export function folderPicker() {
|
|
|
bindToController: true,
|
|
|
controllerAs: 'ctrl',
|
|
|
scope: {
|
|
|
- initialTitle: "<",
|
|
|
+ initialTitle: '<',
|
|
|
initialFolderId: '<',
|
|
|
labelClass: '@',
|
|
|
rootName: '@',
|
|
|
- onChange: '&'
|
|
|
+ onChange: '&',
|
|
|
+ onLoad: '&'
|
|
|
}
|
|
|
};
|
|
|
}
|