import jQ from "jquery";
import BaseComponent from "../../../base-component";
import Class from "../../../../helpers/class";
import Utils from "../../../../helpers/utils";
import PageItemList from "./page-item-list";
/**
* Collection item component
* @extends BaseComponent
*/
class PageItem extends BaseComponent {
/**
* @constructs
*/
constructor() {
super();
this.data = null;
this.id = null;
this.index = 0;
this.$element = null;
this.displayImage = true;
}
compileTemplate() {
var pageUrl = this.data.hasOwnProperty('url')? this.data.url : '#';
var itemThumb = '';
var itemThumbSrc = '';
if (this.displayImage) {
// Get the page thumbnail url
if (this.data.image && this.data.image.hasOwnProperty('src') && this.data.image.src !== '') {
itemThumbSrc = Utils.optimizeImage(this.data.image.src, '200x');
}
// Build the page thumbnail
if (itemThumbSrc.length > 0) {
itemThumb = this.getTemplate(PageItemList.Enum.tempType.IMAGE);
}
}
return this.getTemplate()
.replace(/{{itemThumbnail}}/g, itemThumb)
.replace(/{{itemThumbSrc}}/g, itemThumbSrc)
.replace(/{{class.filterResultItem}}/g, Class.filterResultItem)
.replace(/{{itemUrl}}/g, pageUrl)
.replace(/{{itemTitle}}/g, Utils.escape(this.data.title));
}
render() {
this.$element = jQ(this.compileTemplate());
}
setData(data, index) {
this.data = data;
this.id = data.id;
this.index = index;
this.displayImage = this.parent.panelData.hasOwnProperty('displayImage') && this.parent.panelData.displayImage;
}
}
export default PageItem