source: ether_megapoli/trunk/web/resources/js/etherClasses.js @ 200

Last change on this file since 200 was 172, checked in by vmipsl, 13 years ago

Interface _ plusieurs graphs possible sur le même quicklook

File size: 6.0 KB
Line 
1/* ************************************************* */
2/* ****************** LIST ************************* */
3/* ************************************************* */
4var 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/* ************************************************* */
96var 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            this.onMouseOverContainer = objectParameter.onMouseOverContainer ? objectParameter.onMouseOverContainer : false;
112            this.onMouseOutContainer = objectParameter.onMouseOutContainer ? objectParameter.onMouseOutContainer : false;
113        }
114    },
115
116    getId : function()
117    {
118        return this.jsonElement.id;
119    },
120
121    getContentType: function()
122    {
123        return this.jsonElement.contentType;
124    },
125
126    createContainer: function ( containerName, classNameValue )
127    {
128        this.divContainer = $( document.createElement( "div" ) );
129        this.divContainer.item = this;
130        if( classNameValue )
131            this.divContainer.className = classNameValue;
132        this.divContainer.id = containerName + "_" + this.jsonElement.id;
133    },
134
135    appendContainer: function ( parentNode )
136    {
137        this.parentNode = parentNode;
138        parentNode.appendChild( this.divContainer );
139    },
140
141    onHoverContainer: function( event )
142    {
143        if( !event || (event.detail == undefined || 1 == event.detail) )
144            this.executeListenersFunction();
145    },
146
147    onClickContainer: function( event )
148    {
149        if( !event || (event.detail == undefined || 1 == event.detail) )
150            this.executeListenersFunction();
151    },
152
153    selectWithParameter: function( classNameValue )
154    {
155        if( classNameValue )
156            this.divContainer.addClassName( classNameValue );
157    },
158
159    unselectWithParameter: function( classNameValue )
160    {
161        if( classNameValue )
162            this.divContainer.removeClassName( classNameValue );
163    },
164
165    executeListenersFunction: function()
166    {
167        this.listeners.each( function ( func )
168        {
169            func( this );
170        }.bind( this ) );
171    },
172
173    addObservers: function ()
174    {
175        if( this.divContainer )
176            Event.observe( this.divContainer, 'click', this.onClickContainer.bindAsEventListener( this ) );
177        if( this.divContainer && this.onMouseOverContainer )
178            Event.observe( this.divContainer, 'mouseover', this.onMouseOverContainer.bindAsEventListener( this ) );
179        if( this.divContainer && this.onMouseOutContainer )
180            Event.observe( this.divContainer, 'mouseout', this.onMouseOutContainer.bindAsEventListener( this ) );
181    },
182
183    addOpenListener: function( func )
184    {
185        this.listeners.push( func );
186    },
187
188    addName: function ( classNameValue )
189    {
190        if( !this.divContainer )
191            return;
192
193        this.divName = $( document.createElement( "div" ) );
194        this.divName.className = classNameValue;
195        this.divName.innerHTML = this.jsonElement.name;
196
197        this.divContainer.appendChild( this.divName );
198    },
199
200    getName: function ()
201    {
202        return this.jsonElement.name;
203    }
204
205} );
Note: See TracBrowser for help on using the repository browser.