//= require spotlight/admin/blocks/resources_block
SirTrevor.Blocks.SolrDocumentsBase = (function(){
return Spotlight.Block.Resources.extend({
plustextable: true,
autocomplete_url: function() { return this.$instance().closest('form[data-autocomplete-exhibit-catalog-path]').data('autocomplete-exhibit-catalog-path').replace("%25QUERY", "%QUERY"); },
autocomplete_template: function() { return '
{{#if thumbnail}}
{{/if}}
{{title}} {{description}} ' },
transform_autocomplete_results: function(response) {
return $.map(response['docs'], function(doc) {
return doc;
})
},
caption_option_values: function() {
var fields = $('[data-blacklight-configuration-index-fields]').data('blacklight-configuration-index-fields');
return $.map(fields, function(field) {
return $('').val(field.key).text(field.label)[0].outerHTML;
}).join("\n");
},
item_options: function() { return this.caption_options(); },
caption_options: function() { return [
'',
'',
'',
'',
'',
'
',
'',
'',
'',
'',
'',
'
',
].join("\n") },
_itemPanelIiifFields: function(index, data) {
return [
// '',
// for legacy compatiblity:
'',
'',
'',
'',
'',
'',
].join("\n");
},
setIiifFields: function(panel, data, initialize) {
var legacyThumbnailField = $(panel).find('[name$="[thumbnail_image_url]"]')
var legacyFullField = $(panel).find('[name$="[full_image_url]"]')
if (initialize && legacyThumbnailField.val().length > 0) {
return;
}
legacyThumbnailField.val("");
legacyFullField.val("");
$(panel).find('[name$="[iiif_image_id]"]').val(data.imageId);
$(panel).find('[name$="[iiif_tilesource]"]').val(data.tilesource);
$(panel).find('[name$="[iiif_manifest_url]"]').val(data.manifest);
$(panel).find('[name$="[iiif_canvas_id]"]').val(data.canvasId);
$(panel).find('img.img-thumbnail').attr('src', data.thumbnail_image_url || data.tilesource.replace("/info.json", "/full/100,100/0/default.jpg"));
},
afterPanelRender: function(data, panel) {
var context = this;
var manifestUrl = data.iiif_manifest || data.iiif_manifest_url;
if (!manifestUrl) {
$(panel).find('[name$="[thumbnail_image_url]"]').val(data.thumbnail_image_url || data.thumbnail);
$(panel).find('[name$="[full_image_url]"]').val(data.full_image_url);
return;
}
$.ajax(manifestUrl).done(
function(manifest) {
var Iiif = require('spotlight/admin/iiif');
var iiifManifest = new Iiif(manifestUrl, manifest);
var thumbs = iiifManifest.imagesArray();
if (!data.iiif_image_id) {
context.setIiifFields(panel, thumbs[0], !!data.iiif_manifest_url);
}
if(thumbs.length > 1) {
panel.multiImageSelector(thumbs, function(selectorImage) {
context.setIiifFields(panel, selectorImage, false);
}, data.iiif_image_id);
}
}
);
}
});
})();