openmedialibrary/static/js/selectFolder.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-01-23 08:07:03 +00:00
'use strict';
oml.ui.selectFolder = function(options, self) {
2019-01-24 07:17:00 +00:00
var inputOptions = {
style: options.style,
placeholder: options.placeholder,
width: options.width - options.labelWidth - 4,
value: options.title,
autocomplete: function(value, callback) {
oml.api.autocompleteFolder({path: value}, function(result) {
callback(result.data.items);
});
},
autocompleteSelect: true,
changeOnKeypress: true,
},
buttonOptions = {
overlap: 'left',
tooltip: Ox._('Select Folder'),
style: options.style,
title: 'directory',
type: 'image'
};
var $button = Ox.Button(buttonOptions).bindEvent({
2019-01-23 08:07:03 +00:00
click: function(event) {
oml.api.selectFolder({
2019-01-24 07:17:00 +00:00
base: $input.value()
2019-01-23 08:07:03 +00:00
}, function(result) {
if (result.data.path) {
2019-01-24 07:17:00 +00:00
$input.value(result.data.path);
that.triggerEvent('change', result.data.path);
2019-01-23 08:07:03 +00:00
}
})
}
2019-01-24 07:17:00 +00:00
}).css({
'padding-left': '4px'
2019-01-23 08:07:03 +00:00
}),
2019-01-24 07:17:00 +00:00
$input = Ox.Input(inputOptions),
2019-01-23 08:07:03 +00:00
that = Ox.FormElementGroup({
id: options.id,
elements: [
Ox.Label({
style: options.style,
textAlign: 'right',
overlap: 'right',
title: options.label,
width: options.labelWidth
}),
2019-01-24 07:17:00 +00:00
$input,
2019-01-23 08:07:03 +00:00
$button
],
}, self);
that.value = function() {
2019-01-24 07:17:00 +00:00
return $input.value()
2019-01-23 08:07:03 +00:00
}
if (options.title && options.title != '...') {
$button.value(options.title)
}
return that;
}