', {
- 'class': 'cp-modal-close fa fa-times',
- 'title': Messages.filePicker_close
- }).click(hide).appendTo($block);
- $body.click(hide);
- $block.click(function (e) {
- e.stopPropagation();
- });
- $body.keydown(function (e) {
- if (e.which === 27) {
- hide();
- }
- });
- return $blockContainer;
- };
- common.createFileDialog = function (cfg) {
- var $blockContainer = common.createModal({
- id: 'fileDialog',
- $body: cfg.$body
- });
- var $block = $blockContainer.find('.cp-modal');
- var $description = $('').text(Messages.filePicker_description);
- $block.append($description);
- var $filter = $('
', {'class': 'cp-modal-form'}).appendTo($block);
- var $container = $('', {'class': 'fileContainer'}).appendTo($block);
- var updateContainer = function () {
- $container.html('');
- var filter = $filter.find('.filter').val().trim();
- var list = common.getUserFilesList();
- var fo = common.getFO();
- list.forEach(function (id) {
- var data = fo.getFileData(id);
- var name = fo.getTitle(id);
- if (filter && name.toLowerCase().indexOf(filter.toLowerCase()) === -1) {
- return;
- }
- var $span = $('', {
- 'class': 'element',
- 'title': name,
- }).appendTo($container);
- $span.append(getFileIcon(data));
- $span.append(name);
- $span.click(function () {
- if (typeof cfg.onSelect === "function") { cfg.onSelect(data.href); }
- $blockContainer.hide();
- });
- });
- };
- var to;
- $('', {
- type: 'text',
- 'class': 'filter',
- 'placeholder': Messages.filePicker_filter
- }).appendTo($filter).on('keypress', function () {
- if (to) { window.clearTimeout(to); }
- to = window.setTimeout(updateContainer, 300);
- });
- //$filter.append(' '+Messages.or+' ');
- var data = {FM: cfg.data.FM};
- $filter.append(common.createButton('upload', false, data, function () {
- $blockContainer.hide();
- }));
- updateContainer();
- $blockContainer.show();
- };
-
-
-
-
- // Create a button with a dropdown menu
- // input is a config object with parameters:
- // - container (optional): the dropdown container (span)
- // - text (optional): the button text value
- // - options: array of {tag: "", attributes: {}, content: "string"}
- //
- // allowed options tags: ['a', 'hr', 'p']
- var createDropdown = common.createDropdown = function (config) {
- if (typeof config !== "object" || !Array.isArray(config.options)) { return; }
-
- var allowedTags = ['a', 'p', 'hr'];
- var isValidOption = function (o) {
- if (typeof o !== "object") { return false; }
- if (!o.tag || allowedTags.indexOf(o.tag) === -1) { return false; }
- return true;
- };
-
- // Container
- var $container = $(config.container);
- var containerConfig = {
- 'class': 'cp-dropdown-container'
- };
- if (config.buttonTitle) {
- containerConfig.title = config.buttonTitle;
- }
-
- if (!config.container) {
- $container = $('', containerConfig);
- }
-
- // Button
- var $button = $('