1 | /* ************************************************* */ |
---|
2 | /* ****************** LIST ************************* */ |
---|
3 | /* ************************************************* */ |
---|
4 | var ListItem = Class.create({ |
---|
5 | |
---|
6 | initialize: function( plateforms, objectParameter ) |
---|
7 | { |
---|
8 | this.array = $A(); |
---|
9 | $A(plateforms).each(function( jsonObject ) |
---|
10 | { |
---|
11 | this.addItem(jsonObject, objectParameter); |
---|
12 | }.bind(this)); |
---|
13 | }, |
---|
14 | |
---|
15 | addItem:function( jsonElement, objectParameter ) |
---|
16 | { |
---|
17 | var divItem = false; |
---|
18 | |
---|
19 | var objectItemNew = new Object(); |
---|
20 | objectItemNew.jsonElement = jsonElement; |
---|
21 | objectItemNew.divItem = this.createItemDiv(objectItemNew.jsonElement, objectParameter); |
---|
22 | |
---|
23 | this.array.push(objectItemNew); |
---|
24 | }, |
---|
25 | |
---|
26 | createItemDiv: function( itemHash, objectParameter ) |
---|
27 | { |
---|
28 | return new Plateform(itemHash, objectParameter); |
---|
29 | }, |
---|
30 | |
---|
31 | addOpenListener : function( func ) |
---|
32 | { |
---|
33 | this.array.each(function( objectItem ) |
---|
34 | { |
---|
35 | objectItem.divItem.addOpenListener(func); |
---|
36 | }); |
---|
37 | }, |
---|
38 | |
---|
39 | display : function( parentNode, idIfNoItem, textIfNoItem ) |
---|
40 | { |
---|
41 | if( 0 >= this.array.size() ) |
---|
42 | { |
---|
43 | var divNoItem = $(document.createElement("div")); |
---|
44 | divNoItem.id = idIfNoItem; |
---|
45 | divNoItem.textContent = textIfNoItem; |
---|
46 | parentNode.appendChild(divNoItem); |
---|
47 | } |
---|
48 | else |
---|
49 | this.array.each(function( item ) |
---|
50 | { |
---|
51 | item.divItem.display(parentNode); |
---|
52 | }); |
---|
53 | }, |
---|
54 | |
---|
55 | displayWithPairImpair : function( parentNode, idIfNoItem, textIfNoItem ) |
---|
56 | { |
---|
57 | Dom.clearContainer(parentNode); |
---|
58 | if( 0 >= this.array.size() ) |
---|
59 | { |
---|
60 | var divNoItem = $(document.createElement("div")); |
---|
61 | divNoItem.id = idIfNoItem; |
---|
62 | divNoItem.textContent = textIfNoItem; |
---|
63 | parentNode.appendChild(divNoItem); |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | var rowNumber = 0; |
---|
68 | this.array.each(function( item ) |
---|
69 | { |
---|
70 | if(rowNumber % 2 == 0) |
---|
71 | item.divItem.display(parentNode,"pair"); |
---|
72 | else |
---|
73 | item.divItem.display(parentNode,"impair"); |
---|
74 | rowNumber++; |
---|
75 | }); |
---|
76 | } |
---|
77 | }, |
---|
78 | |
---|
79 | getItemById: function( itemId ) |
---|
80 | { |
---|
81 | var returnObj = false; |
---|
82 | this.array.each(function( objItem ) |
---|
83 | { |
---|
84 | if( objItem.jsonElement.id == itemId ) |
---|
85 | returnObj = objItem; |
---|
86 | }.bind(this)); |
---|
87 | |
---|
88 | return returnObj; |
---|
89 | } |
---|
90 | |
---|
91 | }); |
---|
92 | |
---|
93 | /* ************************************************* */ |
---|
94 | /* ****************** ITEM ************************* */ |
---|
95 | /* ************************************************* */ |
---|
96 | var Item = Class.create({ |
---|
97 | |
---|
98 | initialize: function( jsonElement, objectParameter ) |
---|
99 | { |
---|
100 | this.jsonElement = Object.clone(jsonElement); // Warning: This is only a shallow copy |
---|
101 | this.listeners = $A(); |
---|
102 | |
---|
103 | // HACK: No deep copy in Javascript |
---|
104 | if( objectParameter ) |
---|
105 | { |
---|
106 | this.language = objectParameter.language || "fr"; |
---|
107 | if( objectParameter.currentTitleId ) |
---|
108 | this.currentTitleId = objectParameter.currentTitleId; |
---|
109 | if( objectParameter.isExpiredTitle ) |
---|
110 | this.isExpiredTitle = objectParameter.isExpiredTitle; |
---|
111 | } |
---|
112 | }, |
---|
113 | |
---|
114 | getId : function() |
---|
115 | { |
---|
116 | return this.jsonElement.id; |
---|
117 | }, |
---|
118 | |
---|
119 | getContentType: function() |
---|
120 | { |
---|
121 | return this.jsonElement.contentType; |
---|
122 | }, |
---|
123 | |
---|
124 | createContainer: function ( containerName, classNameValue ) |
---|
125 | { |
---|
126 | this.divContainer = $(document.createElement("div")); |
---|
127 | this.divContainer.item = this; |
---|
128 | if(classNameValue) |
---|
129 | this.divContainer.className = classNameValue; |
---|
130 | this.divContainer.id = containerName + "_" + this.jsonElement.id; |
---|
131 | }, |
---|
132 | |
---|
133 | appendContainer: function ( parentNode ) |
---|
134 | { |
---|
135 | this.parentNode = parentNode; |
---|
136 | parentNode.appendChild(this.divContainer); |
---|
137 | }, |
---|
138 | |
---|
139 | onClickContainer: function( event ) |
---|
140 | { |
---|
141 | if( !event || (event.detail == undefined || 1 == event.detail) ) |
---|
142 | this.executeListenersFunction(); |
---|
143 | }, |
---|
144 | |
---|
145 | selectWithParameter: function( classNameValue ) |
---|
146 | { |
---|
147 | if( classNameValue ) |
---|
148 | this.divContainer.addClassName(classNameValue); |
---|
149 | }, |
---|
150 | |
---|
151 | unselectWithParameter: function( classNameValue ) |
---|
152 | { |
---|
153 | if( classNameValue ) |
---|
154 | this.divContainer.removeClassName(classNameValue); |
---|
155 | }, |
---|
156 | |
---|
157 | executeListenersFunction: function() |
---|
158 | { |
---|
159 | this.listeners.each(function ( func ) |
---|
160 | { |
---|
161 | func(this); |
---|
162 | }.bind(this)); |
---|
163 | }, |
---|
164 | |
---|
165 | addObservers: function () |
---|
166 | { |
---|
167 | if( this.divContainer ) |
---|
168 | Event.observe(this.divContainer, 'click', this.onClickContainer.bindAsEventListener(this)); |
---|
169 | }, |
---|
170 | |
---|
171 | addOpenListener: function( func ) |
---|
172 | { |
---|
173 | this.listeners.push(func); |
---|
174 | }, |
---|
175 | |
---|
176 | addName: function ( classNameValue ) |
---|
177 | { |
---|
178 | if( !this.divContainer ) |
---|
179 | return; |
---|
180 | |
---|
181 | this.divName = $(document.createElement("div")); |
---|
182 | this.divName.className = classNameValue; |
---|
183 | this.divName.innerHTML = this.jsonElement.name; |
---|
184 | |
---|
185 | this.divContainer.appendChild(this.divName); |
---|
186 | } |
---|
187 | }); |
---|