source: ether_megapoli/trunk/web/resources/js/classesForJQuery/etherClasses.js @ 236

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

jQuery

  • calendrier ok
  • window ok
File size: 5.8 KB
Line 
1/* ************************************************* */
2/* ****************** LIST ************************* */
3/* ************************************************* */
4var ListItem = Class.create( {
5
6    initialize: function( plateforms, objectParameter )
7    {
8        this.array = [];
9        jQuery.each( plateforms,
10                jQuery.proxy( function( i, jsonObject )
11                {
12                    this.addItem( jsonObject, objectParameter );
13                }, this ) );
14    },
15
16    addItem:function( jsonElement, objectParameter )
17    {
18        var divItem = false;
19
20        var objectItemNew = new Object();
21        objectItemNew.jsonElement = jsonElement;
22        objectItemNew.divItem = this.createItemDiv( objectItemNew.jsonElement, objectParameter );
23
24        this.array.push( objectItemNew );
25    },
26
27    createItemDiv: function( itemHash, objectParameter )
28    {
29        return new Plateform( itemHash, objectParameter );
30    },
31
32    addOpenListener : function( func )
33    {
34        jQuery.each( this.array, function( i, objectItem )
35        {
36            objectItem.divItem.addOpenListener( func );
37        } );
38    },
39
40    display : function( parentNode, idIfNoItem, textIfNoItem )
41    {
42        if( 0 >= this.array.size() )
43        {
44            var divNoItem = $( document.createElement( "div" ) );
45            divNoItem.id = idIfNoItem;
46            divNoItem.textContent = textIfNoItem;
47            parentNode.append( divNoItem );
48        }
49        else
50            jQuery.each( this.array, function( item )
51            {
52                item.divItem.display( parentNode );
53            } );
54    },
55
56    displayWithPairImpair : function( parentNode, idIfNoItem, textIfNoItem )
57    {
58        parentNode.empty();
59        if( 0 >= this.array.length )
60        {
61            var divNoItem = $( document.createElement( "div" ) );
62            divNoItem.id = idIfNoItem;
63            divNoItem.textContent = textIfNoItem;
64            parentNode.append( divNoItem );
65        }
66        else
67        {
68            var rowNumber = 0;
69            jQuery.each( this.array, function( i, item )
70            {
71                if( rowNumber % 2 == 0 )
72                    item.divItem.display( parentNode, "pair" );
73                else
74                    item.divItem.display( parentNode, "impair" );
75                rowNumber++;
76            } );
77        }
78    },
79
80    getItemById: function( itemId )
81    {
82        var returnObj = false;
83        jQuery.each( this.array, jQuery.proxy( function( i, objItem )
84        {
85            if( objItem.jsonElement.id == itemId )
86                returnObj = objItem;
87        }, this ) );
88
89        return returnObj;
90    }
91
92} );
93
94/* ************************************************* */
95/* ****************** ITEM ************************* */
96/* ************************************************* */
97var Item = Class.create( {
98
99    initialize: function( jsonElement, objectParameter )
100    {
101        this.jsonElement = jsonElement;
102        this.listeners = [];
103
104        if( objectParameter )
105        {
106            this.language = objectParameter.language || "fr";
107            this.onMouseOverContainer = objectParameter.onMouseOverContainer ? objectParameter.onMouseOverContainer : false;
108            this.onMouseOutContainer = objectParameter.onMouseOutContainer ? objectParameter.onMouseOutContainer : false;
109        }
110    },
111
112    getId : function()
113    {
114        return this.jsonElement.id;
115    },
116
117    getContentType: function()
118    {
119        return this.jsonElement.contentType;
120    },
121
122    createContainer: function ( containerName, classNameValue )
123    {
124        this.divContainer = $( document.createElement( "div" ) );
125        this.divContainer.item = this;
126        if( classNameValue )
127            this.divContainer.addClass( classNameValue );
128        this.divContainer.attr( {id:containerName + "_" + this.jsonElement.id} );
129    },
130
131    appendContainer: function ( parentNode )
132    {
133        this.parentNode = parentNode;
134        parentNode.append( this.divContainer );
135    },
136
137    onHoverContainer: function( event )
138    {
139        var contextEvent = event.data;
140        if( !event || (event.detail == undefined || 1 == event.detail) )
141            contextEvent.executeListenersFunction();
142    },
143
144    onClickContainer: function( event )
145    {
146        var contextEvent = event.data;
147        if( !event || (event.detail == undefined || 1 == event.detail) )
148            contextEvent.executeListenersFunction();
149    },
150
151    selectWithParameter: function( classNameValue )
152    {
153        if( classNameValue )
154            this.divContainer.addClass( classNameValue );
155    },
156
157    unselectWithParameter: function( classNameValue )
158    {
159        if( classNameValue )
160            this.divContainer.removeClass( classNameValue );
161    },
162
163    executeListenersFunction: function()
164    {
165        jQuery.each( this.listeners, jQuery.proxy( function ( i, func )
166        {
167            func( this );
168        }, this ) );
169    },
170
171    addObservers: function ()
172    {
173        if( this.divContainer )
174            this.divContainer.bind( 'click', this, this.onClickContainer );
175        if( this.divContainer && this.onMouseOverContainer )
176            this.divContainer.bind( 'mouseover', this, this.onMouseOverContainer );
177        if( this.divContainer && this.onMouseOutContainer )
178            this.divContainer.bind( 'mouseout', this, this.onMouseOutContainer );
179    },
180
181    addOpenListener: function( func )
182    {
183        this.listeners.push( func );
184    },
185
186    addName: function ( classNameValue )
187    {
188        if( !this.divContainer )
189            return;
190
191        this.divName = $( document.createElement( "div" ) );
192        this.divName.addClass( classNameValue );
193        this.divName.html( this.jsonElement.name );
194
195        this.divContainer.append( this.divName );
196    },
197
198    getName: function ()
199    {
200        return this.jsonElement.name;
201    }
202
203} );
Note: See TracBrowser for help on using the repository browser.