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

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

Login BO
visu sous-menus

File size: 9.0 KB
Line 
1/* ************************************************* */
2/* ****************** LIST ************************* */
3/* ************************************************* */
4var ListItem = Class.create( {
5
6    initialize: function( jsonElements, objectParameter )
7    {
8        this.array = [];
9        jQuery.each( jsonElements, jQuery.proxy( function( i, jsonElement )
10        {
11            this.addItem( jsonElement, objectParameter );
12        }, this ) );
13    },
14
15    addItem:function( jsonElement, objectParameter )
16    {
17        var divItem = false;
18
19        var newObjectItem = new Object();
20        newObjectItem.jsonElement = jsonElement;
21        newObjectItem.divItem = this.createItemDiv( newObjectItem.jsonElement, objectParameter );
22
23        this.array.push( newObjectItem );
24    },
25
26    addOpenListener : function( func )
27    {
28        jQuery.each( this.array, function( i, objectItem )
29        {
30            objectItem.divItem.addOpenListener( func );
31        } );
32    },
33
34    displayNoItem: function( parentNode, idIfNoItem, textIfNoItem )
35    {
36        var divNoItem = $( document.createElement( "div" ) );
37        divNoItem.id = idIfNoItem;
38        divNoItem.textContent = textIfNoItem;
39        parentNode.append( divNoItem );
40    },
41
42    display : function( parentNode, idIfNoItem, textIfNoItem, className )
43    {
44        parentNode.empty();
45        if( 0 >= this.array.length )
46            this.displayNoItem( parentNode, idIfNoItem, textIfNoItem );
47        else
48            jQuery.each( this.array, function( i, item )
49            {
50                if( className )
51                    item.divItem.display( parentNode, className );
52                else
53                    item.divItem.display( parentNode );
54            } );
55    },
56
57    displayWithPairImpair : function( parentNode, idIfNoItem, textIfNoItem )
58    {
59        parentNode.empty();
60        if( 0 >= this.array.length )
61            this.displayNoItem( parentNode, idIfNoItem, textIfNoItem );
62        else
63        {
64            jQuery.each( this.array, function( i, item )
65            {
66                if( 0 == i % 2 )
67                    item.divItem.display( parentNode, "pair" );
68                else
69                    item.divItem.display( parentNode, "impair" );
70            } );
71        }
72    },
73
74    getItemById: function( itemId )
75    {
76        var returnObj = false;
77        jQuery.each( this.array, jQuery.proxy( function( i, objItem )
78        {
79            if( objItem.jsonElement.id == itemId )
80                returnObj = objItem;
81        }, this ) );
82
83        return returnObj;
84    }
85
86} );
87
88/* ************************************************* */
89/* ****************** ITEM ************************* */
90/* ************************************************* */
91var Item = Class.create( {
92
93    initialize: function( jsonElement, objectParameter )
94    {
95        this.jsonElement = jsonElement;
96        this.listeners = [];
97
98        if( objectParameter )
99        {
100            this.language = objectParameter.language || "fr";
101            this.onMouseOverContainer = objectParameter.onMouseOverContainer ? objectParameter.onMouseOverContainer : false;
102            this.onMouseOutContainer = objectParameter.onMouseOutContainer ? objectParameter.onMouseOutContainer : false;
103        }
104    },
105
106    getId : function()
107    {
108        if( jQuery.isArray( this.jsonElement ) )
109            return this.jsonElement[0].id;
110        else
111            return this.jsonElement.id;
112    },
113
114    getName: function ()
115    {
116        if( jQuery.isArray( this.jsonElement ) )
117            return this.jsonElement[0].name;
118        else
119            return this.jsonElement.name;
120    },
121
122    getNameWithCode: function ()
123    {
124        if( jQuery.isArray( this.jsonElement ) )
125            return this.jsonElement[0].name + " (" + this.jsonElement[0].code + ")";
126        else
127            return this.jsonElement.name + " (" + this.jsonElement.code + ")";
128    },
129
130    getContentType: function()
131    {
132        return this.jsonElement.contentType;
133    },
134
135    createContainer: function ( containerName, classNameValue )
136    {
137        this.divContainer = $( document.createElement( "div" ) );
138        this.divContainer.item = this;
139        if( classNameValue )
140            this.divContainer.addClass( classNameValue );
141        if( jQuery.isArray( this.jsonElement ) && 1 < this.jsonElement.length )
142            this.divContainer.attr( {id:containerName + "_MENU"} );
143        else
144            this.divContainer.attr( {id:containerName + "_" + this.getId()} );
145    },
146
147    appendContainer: function ( parentNode )
148    {
149        this.parentNode = parentNode;
150        parentNode.append( this.divContainer );
151    },
152
153    onHoverContainer: function( event )
154    {
155        var contextEvent = event.data;
156        if( !event || (event.detail == undefined || 1 == event.detail) )
157            contextEvent.executeListenersFunction();
158    },
159
160    onClickContainer: function( event )
161    {
162        var contextEvent = event.data;
163        if( !event || (event.detail == undefined || 1 == event.detail) )
164            contextEvent.executeListenersFunction();
165    },
166
167    selectWithParameter: function( classNameValue )
168    {
169        if( classNameValue )
170            this.divContainer.addClass( classNameValue );
171    },
172
173    unselectWithParameter: function( classNameValue )
174    {
175        if( classNameValue )
176            this.divContainer.removeClass( classNameValue );
177    },
178
179    executeListenersFunction: function()
180    {
181        jQuery.each( this.listeners, jQuery.proxy( function ( i, func )
182        {
183            func( this );
184        }, this ) );
185    },
186
187    addObservers: function ()
188    {
189        if( this.divContainer )
190            this.divContainer.bind( 'click', this, this.onClickContainer );
191        if( this.divContainer && this.onMouseOverContainer )
192            this.divContainer.bind( 'mouseover', this, this.onMouseOverContainer );
193        if( this.divContainer && this.onMouseOutContainer )
194            this.divContainer.bind( 'mouseout', this, this.onMouseOutContainer );
195    },
196
197    addOpenListener: function( func )
198    {
199        this.listeners.push( func );
200    },
201
202    addName: function ( classNameValue )
203    {
204        if( !this.divContainer )
205            return;
206
207        var divName = $( document.createElement( "div" ) );
208        divName.addClass( classNameValue );
209        divName.html( this.getName() );
210
211        this.divContainer.append( divName );
212    },
213
214    addNameWithMenus: function ( classNameValue )
215    {
216        if( !this.divContainer )
217            return;
218
219        if( 1 < this.jsonElement.length )
220        {
221            var divMenu_name = $( document.createElement( "div" ) );
222            divMenu_name.addClass( classNameValue );
223            divMenu_name.html( this.getName() );
224            this.divContainer.append( divMenu_name );
225
226            var divMenu_arrow = $( document.createElement( "div" ) );
227            divMenu_arrow.attr( {id:"divMenu_arrow_" + this.getId(), class:"divMenu_arrow" } );
228            this.divContainer.append( divMenu_arrow );
229
230            this.divHiddenElements = $( document.createElement( "div" ) );
231            this.divHiddenElements.attr( {class:"divMenu_content" } );
232
233            jQuery.each( this.jsonElement, jQuery.proxy( function ( i, element )
234            {
235                var divSubMenu_name = $( document.createElement( "div" ) );
236                divSubMenu_name.addClass( classNameValue + "_subMenu" );
237                divSubMenu_name.addClass( "parameter_menu_" + element.id );
238                divSubMenu_name.html( element.code );
239                divSubMenu_name.bind( 'click', {divContainer:this.divContainer, jsonElement:[element]}, this.onClickMenu );
240                this.divHiddenElements.append( divSubMenu_name );
241            }, this ) );
242
243            this.divContainer.append( this.divHiddenElements );
244
245            divMenu_name.toggle(
246                    jQuery.proxy( function ()
247                    {
248                        $( "#divMenu_arrow_" + this.getId() ).addClass( "deployed" );
249                        this.divHiddenElements.animate( {height:"toggle"}, 100 );
250                    }, this ),
251                    jQuery.proxy( function ()
252                    {
253                        $( "#divMenu_arrow_" + this.getId() ).removeClass( "deployed" );
254                        this.divHiddenElements.animate( {height:"toggle"}, 100 );
255                    }, this ) );
256
257            divMenu_arrow.toggle(
258                    jQuery.proxy( function ()
259                    {
260                        $( "#divMenu_arrow_" + this.getId() ).addClass( "deployed" );
261                        this.divHiddenElements.animate( {width:"toggle"}, 100 );
262                    }, this ),
263                    jQuery.proxy( function ()
264                    {
265                        $( "#divMenu_arrow_" + this.getId() ).removeClass( "deployed" );
266                        this.divHiddenElements.animate( {width:"toggle"}, 100 );
267                    }, this ) );
268        }
269        else
270            this.addName( classNameValue );
271    },
272
273    onClickMenu: function( event )
274    {
275        event.data.divContainer.item.jsonElement = event.data.jsonElement;
276    }
277
278} );
Note: See TracBrowser for help on using the repository browser.