/* global MediaUtils,Sanitizer,ThumbnailItem,IntlHelper */ /** * ThumbnailDateGroup is a grouping mechanism supported in video app. It * groups video data by its year and month, see bug 908380. The grouping * identity is based on the groupID. Once the groupID is different, we view * two groups as different groups. ThumbnailDateGroup also sorts the added video * data descendant. We can just put a item into group and let it sort the list. * * The sanitizer.js library is used to escape HTML within the view method. * It is used when rendering group header, the HTML DOM node of this object. * * The HTML Node of this object contains all UI of its children. If we move it, * all items under this group are also moved. * * CONSTRUCTOR: * To create a group, we need to supply one argument: * item: the first data object for this group. It will be used for * rendering the information about this group. * * API: * addItem(): add a new item to this group. ThumbnailDateGroup will create a * ThumbnailItem for the supplied video data and insert it to UI. * args: * item: the video data object. * return: ThumbnailItem object * removeItem(): remove a ThumbnailItem from this group. It also removes the * UI from this group. * thumbnail: ThumbnailItem object to remove. * getCount(): returns the total items in this group * * Properties: * htmlNode: the HTML DOM node of this group. * groupID: the ID of this group. * thumbnails: all ThumbnailItem objects under this group. * * Static API: * getGroupID: calculate the group id for video object. * item: the video data object. * return: an id string. * compareGroupID * */ 'use strict'; function ThumbnailDateGroup(item) { if (!item) { throw new Error('item should not be null or undefined.'); } this.thumbnails = []; this.groupID = ThumbnailDateGroup.getGroupID(item); this.date = item.date; var wrappedHtmlText = ThumbnailDateGroup.view(); // create dummy node for converting to DOM node. var dummyDiv = document.createElement('DIV'); dummyDiv.innerHTML = Sanitizer.unwrapSafeHTML(wrappedHtmlText); var domNode = dummyDiv.firstElementChild; if (!domNode) { throw new Error('the template is empty'); } this.htmlNode = domNode; this.container = domNode.querySelector('.thumbnail-group-container'); this.header = domNode.querySelector('.thumbnail-group-header'); this.localize(); } // static functions ThumbnailDateGroup.view = function() { return Sanitizer.createSafeHTML `