[382] | 1 | /* ************************************************* */ |
---|
| 2 | /* ****************** LIST ************************* */ |
---|
| 3 | /* ************************************************* */ |
---|
| 4 | var 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.attr( {id:idIfNoItem} ); |
---|
| 38 | divNoItem.html( 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 | /* ************************************************* */ |
---|
| 91 | var 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, isArrowFirst ) |
---|
| 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 + " divMenu_parameter_name" ); |
---|
| 223 | divMenu_name.html( this.getName() ); |
---|
| 224 | |
---|
| 225 | var divMenu_arrow = $( document.createElement( "div" ) ); |
---|
| 226 | divMenu_arrow.attr( {id:"divMenu_arrow_" + this.getId()} ); |
---|
| 227 | |
---|
| 228 | if( isArrowFirst ) |
---|
| 229 | { |
---|
| 230 | divMenu_arrow.addClass( "divMenu_arrow_left" ); |
---|
| 231 | this.divContainer.append( divMenu_arrow ); |
---|
| 232 | this.divContainer.append( divMenu_name ); |
---|
| 233 | } |
---|
| 234 | else |
---|
| 235 | { |
---|
| 236 | divMenu_arrow.addClass( "divMenu_arrow" ); |
---|
| 237 | this.divContainer.append( divMenu_name ); |
---|
| 238 | this.divContainer.append( divMenu_arrow ); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | this.divHiddenElements = $( document.createElement( "div" ) ); |
---|
| 242 | this.divHiddenElements.attr( {class:"divMenu_content" } ); |
---|
| 243 | |
---|
| 244 | jQuery.each( this.jsonElement, jQuery.proxy( function ( i, element ) |
---|
| 245 | { |
---|
| 246 | var divSubMenu_name = $( document.createElement( "div" ) ); |
---|
| 247 | divSubMenu_name.addClass( classNameValue + "_subMenu" ); |
---|
| 248 | divSubMenu_name.addClass( "parameter_menu_" + element.id ); |
---|
| 249 | divSubMenu_name.html( element.code ); |
---|
| 250 | divSubMenu_name.bind( 'click', {divContainer:this.divContainer, jsonElement:[element]}, this.onClickMenu ); |
---|
| 251 | this.divHiddenElements.append( divSubMenu_name ); |
---|
| 252 | }, this ) ); |
---|
| 253 | |
---|
| 254 | this.divContainer.append( this.divHiddenElements ); |
---|
| 255 | |
---|
| 256 | divMenu_name.toggle( |
---|
| 257 | jQuery.proxy( function () |
---|
| 258 | { |
---|
| 259 | $( "#divMenu_arrow_" + this.getId() ).addClass( "deployed" ); |
---|
| 260 | this.divHiddenElements.animate( {height:"toggle"}, 100 ); |
---|
| 261 | }, this ), |
---|
| 262 | jQuery.proxy( function () |
---|
| 263 | { |
---|
| 264 | $( "#divMenu_arrow_" + this.getId() ).removeClass( "deployed" ); |
---|
| 265 | this.divHiddenElements.animate( {height:"toggle"}, 100 ); |
---|
| 266 | }, this ) ); |
---|
| 267 | |
---|
| 268 | divMenu_arrow.toggle( |
---|
| 269 | jQuery.proxy( function () |
---|
| 270 | { |
---|
| 271 | $( "#divMenu_arrow_" + this.getId() ).addClass( "deployed" ); |
---|
| 272 | this.divHiddenElements.animate( {width:"toggle"}, 100 ); |
---|
| 273 | }, this ), |
---|
| 274 | jQuery.proxy( function () |
---|
| 275 | { |
---|
| 276 | $( "#divMenu_arrow_" + this.getId() ).removeClass( "deployed" ); |
---|
| 277 | this.divHiddenElements.animate( {width:"toggle"}, 100 ); |
---|
| 278 | }, this ) ); |
---|
| 279 | } |
---|
| 280 | else |
---|
| 281 | this.addName( classNameValue ); |
---|
| 282 | }, |
---|
| 283 | |
---|
| 284 | onClickMenu: function( event ) |
---|
| 285 | { |
---|
| 286 | event.data.divContainer.item.jsonElement = event.data.jsonElement; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | } ); |
---|