From 0ebd50450f17fafa4b5bc8452315e73be8471979 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 13 Feb 2015 10:50:28 +0000 Subject: [PATCH] documents panel: add entities array input --- static/js/documentsPanel.js | 61 +++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/static/js/documentsPanel.js b/static/js/documentsPanel.js index 872c11c4..4936551d 100644 --- a/static/js/documentsPanel.js +++ b/static/js/documentsPanel.js @@ -525,7 +525,7 @@ pandora.ui.documentsPanel = function(options) { } function renderData() { - var $name, $description, + var $name, $description, $input, item = $list.value($list.options('selected')[0]), editable = item.user == pandora.user.username || pandora.site.capabilities.canEditDocuments[pandora.user.level] @@ -673,7 +673,64 @@ pandora.ui.documentsPanel = function(options) { value: item.description, width: width }) - ], + ].concat( + pandora.site.entities && pandora.site.entities.length + ? Ox.ArrayInput({ + getInput: function(width) { + $input = Ox.FormElementGroup({ + elements: [ + Ox.Select({ + items: pandora.site.entities.map(function(entity) { + return { + id: entity.id, + title: entity.title + }; + }), + overlap: 'right', + width: labelWidth + }) + .bindEvent({ + change: function() { + $input.value($input.value()[0], ''); + } + }), + Ox.Input({ + autocomplete: function(value, callback) { + pandora.api.autocompleteEntities({ + key: $input.value()[0], + operator: '=', + range: [0, 10], + value: value + }, function(result) { + callback(result.data.items); + }); + }, + autocompleteReplace: true, + autocompleteSelect: true, + autocompleteSelectSubmit: true, + width: width - labelWidth + }) + ], + width: width + }); + return $input; + }, + label: Ox._('Entities'), + setWidth: function(width) { + $input.options('elements')[1].options({ + width: width - labelWidth + }); + }, + value: item.entities, + width: width + }) + .bindEvent({ + add: function() { + $item[0].scrollTop = 1000000; + } + }) + : [] + ), width: 240 }) .css({margin: '12px 8px 8px 8px'})