/* ************************************************* */ /* ****************** LIST ************************* */ /* ************************************************* */ var ListItem = Class.create({ initialize: function( plateforms, objectParameter ) { this.array = $A(); $A(plateforms).each(function( jsonObject ) { this.addItem(jsonObject, objectParameter); }.bind(this)); }, addItem:function( jsonElement, objectParameter ) { var divItem = false; var objectItemNew = new Object(); objectItemNew.jsonElement = jsonElement; objectItemNew.divItem = this.createItemDiv(objectItemNew.jsonElement, objectParameter); this.array.push(objectItemNew); }, createItemDiv: function( itemHash, objectParameter ) { return new Plateform(itemHash, objectParameter); }, addOpenListener : function( func ) { this.array.each(function( objectItem ) { objectItem.divItem.addOpenListener(func); }); }, display : function( parentNode, idIfNoItem, textIfNoItem ) { if( 0 >= this.array.size() ) { var divNoItem = $(document.createElement("div")); divNoItem.id = idIfNoItem; divNoItem.textContent = textIfNoItem; parentNode.appendChild(divNoItem); } else this.array.each(function( item ) { item.divItem.display(parentNode); }); }, displayWithPairImpair : function( parentNode, idIfNoItem, textIfNoItem ) { Dom.clearContainer(parentNode); if( 0 >= this.array.size() ) { var divNoItem = $(document.createElement("div")); divNoItem.id = idIfNoItem; divNoItem.textContent = textIfNoItem; parentNode.appendChild(divNoItem); } else { var rowNumber = 0; this.array.each(function( item ) { if(rowNumber % 2 == 0) item.divItem.display(parentNode,"pair"); else item.divItem.display(parentNode,"impair"); rowNumber++; }); } }, getItemById: function( itemId ) { var returnObj = false; this.array.each(function( objItem ) { if( objItem.jsonElement.id == itemId ) returnObj = objItem; }.bind(this)); return returnObj; } }); /* ************************************************* */ /* ****************** ITEM ************************* */ /* ************************************************* */ var Item = Class.create({ initialize: function( jsonElement, objectParameter ) { this.jsonElement = Object.clone(jsonElement); // Warning: This is only a shallow copy this.listeners = $A(); // HACK: No deep copy in Javascript if( objectParameter ) { this.language = objectParameter.language || "fr"; if( objectParameter.currentTitleId ) this.currentTitleId = objectParameter.currentTitleId; if( objectParameter.isExpiredTitle ) this.isExpiredTitle = objectParameter.isExpiredTitle; } }, getId : function() { return this.jsonElement.id; }, getContentType: function() { return this.jsonElement.contentType; }, createContainer: function ( containerName, classNameValue ) { this.divContainer = $(document.createElement("div")); this.divContainer.item = this; if(classNameValue) this.divContainer.className = classNameValue; this.divContainer.id = containerName + "_" + this.jsonElement.id; }, appendContainer: function ( parentNode ) { this.parentNode = parentNode; parentNode.appendChild(this.divContainer); }, onClickContainer: function( event ) { if( !event || (event.detail == undefined || 1 == event.detail) ) this.executeListenersFunction(); }, selectWithParameter: function( classNameValue ) { if( classNameValue ) this.divContainer.addClassName(classNameValue); }, unselectWithParameter: function( classNameValue ) { if( classNameValue ) this.divContainer.removeClassName(classNameValue); }, executeListenersFunction: function() { this.listeners.each(function ( func ) { func(this); }.bind(this)); }, addObservers: function () { if( this.divContainer ) Event.observe(this.divContainer, 'click', this.onClickContainer.bindAsEventListener(this)); }, addOpenListener: function( func ) { this.listeners.push(func); }, addName: function ( classNameValue ) { if( !this.divContainer ) return; this.divName = $(document.createElement("div")); this.divName.className = classNameValue; this.divName.innerHTML = this.jsonElement.name; this.divContainer.appendChild(this.divName); } });