1717 * Copyright (C) 2011 Simon Newton
1818 */
1919
20+ goog . provide ( 'app.setup' ) ;
21+
22+ goog . require ( 'app.displayCommand' ) ;
2023goog . require ( 'goog.dom' ) ;
2124goog . require ( 'goog.events' ) ;
2225goog . require ( 'goog.ui.Component' ) ;
2326goog . require ( 'goog.ui.TableSorter' ) ;
24- goog . require ( 'app.MessageStructure' ) ;
25-
26- goog . provide ( 'app.setup' ) ;
2727
28- var app = app || { }
2928
30- // Empty list, this is populated in the page
31- app . SOFTWARE_VERSIONS = [ ]
29+ // These are populated in the page
30+ app . SOFTWARE_VERSIONS = [ ] ;
31+ app . OPEN_FIXTURE_LIBRARY_MODEL_URL = null ;
3232
3333/**
3434 * Sort hex values
@@ -37,7 +37,7 @@ app.SOFTWARE_VERSIONS = []
3737 * @return {number } Negative if a < b, 0 if a = b, and positive if a > b.
3838 */
3939app . hexSort = function ( a , b ) {
40- return parseInt ( a ) - parseInt ( b ) ;
40+ return parseInt ( a , 16 ) - parseInt ( b , 16 ) ;
4141} ;
4242
4343
@@ -61,45 +61,52 @@ app.toHex = function(n, padding) {
6161
6262/**
6363 * Hide a node.
64+ * @param {!Element } node The HTML element to hide.
6465 */
6566app . hideNode = function ( node ) {
6667 node . style . display = 'none' ;
67- }
68+ } ;
6869
6970/**
7071 * Show a block node
72+ * @param {!Element } node The HTML element to show as a block.
7173 */
7274app . showBlock = function ( node ) {
7375 node . style . display = 'block' ;
74- }
76+ } ;
7577
7678/**
7779 * Show a inline node
80+ * @param {!Element } node The HTML element to show inline.
7881 */
7982app . showInline = function ( node ) {
8083 node . style . display = 'inline' ;
81- }
84+ } ;
8285
8386/**
8487 * Show a table row
88+ * @param {!Element } row The HTML element to show as a table row.
8589 */
8690app . showRow = function ( row ) {
8791 row . style . display = 'table-row' ;
88- }
92+ } ;
8993
9094
9195/**
9296 * Create a TD node and set the innerHTML property
97+ * @param {!string } text Inner HTML for the new table cell.
98+ * @return {!Element } The created TD element.
9399 */
94100app . newTD = function ( text ) {
95101 var td = goog . dom . createDom ( 'td' ) ;
96102 td . innerHTML = text ;
97103 return td ;
98- }
104+ } ;
99105
100106
101107/**
102108 * Make the model table sortable
109+ * @param {!string } table_id
103110 */
104111app . makeModelTable = function ( table_id ) {
105112 var table = new goog . ui . TableSorter ( ) ;
@@ -114,15 +121,28 @@ goog.exportSymbol('app.makeModelTable', app.makeModelTable);
114121
115122/**
116123 * Set the software versions
124+ * @param {!Array.<Object> } version_info The software versions.
117125 */
118126app . setSoftwareVersions = function ( version_info ) {
119127 app . SOFTWARE_VERSIONS = version_info ;
120128} ;
121129goog . exportSymbol ( 'app.setSoftwareVersions' , app . setSoftwareVersions ) ;
122130
123131
132+ /**
133+ * Set the URL of the RDM lookup page in the Open Fixture library with the RDM IDs
134+ * of this model so we can use it to link every personality.
135+ * @param {!string } url The URL with query parameters for RDM manufacturer ID and RDM model ID.
136+ */
137+ app . setOpenFixtureLibraryModelUrl = function ( url ) {
138+ app . OPEN_FIXTURE_LIBRARY_MODEL_URL = url ;
139+ } ;
140+ goog . exportSymbol ( 'app.setOpenFixtureLibraryModelUrl' , app . setOpenFixtureLibraryModelUrl ) ;
141+
142+
124143/**
125144 * Display info for the currently selected software version
145+ * @param {?Element= } element
126146 */
127147app . changeSoftwareVersion = function ( element ) {
128148 // default to displaying the first version
@@ -138,87 +158,97 @@ app.changeSoftwareVersion = function(element) {
138158 // DMX Personalities
139159 var personalities = software_version [ 'personalities' ] ;
140160 var personality_fieldset = goog . dom . $ ( 'model_personality_fieldset' ) ;
141- if ( personalities && personalities . length ) {
142- var tbody = goog . dom . $ ( 'model_personality_tbody' ) ;
143- goog . dom . removeChildren ( tbody ) ;
144- for ( var i = 0 ; i < personalities . length ; ++ i ) {
145- var personality = personalities [ i ] ;
146- var tr = goog . dom . createDom ( 'tr' ) ;
147- // add the cells
148- goog . dom . appendChild ( tr , app . newTD ( personality [ 'index' ] ) ) ;
149- if ( 'slot_count' in personality ) {
150- goog . dom . appendChild ( tr , app . newTD ( personality [ 'slot_count' ] ) ) ;
151- } else {
152- goog . dom . appendChild ( tr , app . newTD ( 'Unknown' ) ) ;
161+ if ( personality_fieldset ) {
162+ if ( personalities && personalities . length ) {
163+ var tbody = goog . dom . $ ( 'model_personality_tbody' ) ;
164+ goog . dom . removeChildren ( tbody ) ;
165+ for ( var i = 0 ; i < personalities . length ; ++ i ) {
166+ var personality = personalities [ i ] ;
167+ var oflLink = app . OPEN_FIXTURE_LIBRARY_MODEL_URL + '&personalityIndex=' + personality [ 'index' ] ;
168+
169+ var tr = goog . dom . createDom ( 'tr' ) ;
170+ // add the cells
171+ goog . dom . appendChild ( tr , app . newTD ( personality [ 'index' ] ) ) ;
172+ if ( 'slot_count' in personality ) {
173+ goog . dom . appendChild ( tr , app . newTD ( personality [ 'slot_count' ] ) ) ;
174+ } else {
175+ goog . dom . appendChild ( tr , app . newTD ( 'Unknown' ) ) ;
176+ }
177+ goog . dom . appendChild ( tr , app . newTD ( personality [ 'description' ] ) ) ;
178+ goog . dom . appendChild ( tr , app . newTD ( '<a href="' + oflLink + '">View in Open Fixture Library</a>' ) ) ;
179+ goog . dom . appendChild ( tbody , tr ) ;
153180 }
154- goog . dom . appendChild ( tr , app . newTD ( personality [ 'description' ] ) ) ;
155- goog . dom . appendChild ( tbody , tr ) ;
181+ app . showBlock ( personality_fieldset ) ;
182+ } else {
183+ app . hideNode ( personality_fieldset ) ;
156184 }
157- app . showBlock ( personality_fieldset ) ;
158- } else {
159- app . hideNode ( personality_fieldset ) ;
160185 }
161186
162187 // Sensors
163188 var sensors = software_version [ 'sensors' ] ;
164189 var sensor_fieldset = goog . dom . $ ( 'model_sensor_fieldset' ) ;
165- if ( sensors && sensors . length ) {
166- var tbody = goog . dom . $ ( 'model_sensor_tbody' ) ;
167- goog . dom . removeChildren ( tbody ) ;
168- for ( var i = 0 ; i < sensors . length ; ++ i ) {
169- var sensor = sensors [ i ] ;
170- var tr = goog . dom . createDom ( 'tr' ) ;
171- // add the cells
172- goog . dom . appendChild ( tr , app . newTD ( sensor [ 'index' ] ) ) ;
173- goog . dom . appendChild ( tr , app . newTD ( sensor [ 'description' ] ) ) ;
174- var type_str = sensor [ 'type_str' ] ;
175- var sensor_type = '' ;
176- if ( type_str ) {
177- sensor_type = type_str + ' (0x' + app . toHex ( sensor [ 'type' ] , 2 ) + ')' ;
178- } else {
179- sensor_type = app . toHex ( sensor [ 'type' ] , 2 )
190+ if ( sensor_fieldset ) {
191+ if ( sensors && sensors . length ) {
192+ var tbody = goog . dom . $ ( 'model_sensor_tbody' ) ;
193+ goog . dom . removeChildren ( tbody ) ;
194+ for ( var i = 0 ; i < sensors . length ; ++ i ) {
195+ var sensor = sensors [ i ] ;
196+ var tr = goog . dom . createDom ( 'tr' ) ;
197+ // add the cells
198+ goog . dom . appendChild ( tr , app . newTD ( sensor [ 'index' ] ) ) ;
199+ goog . dom . appendChild ( tr , app . newTD ( sensor [ 'description' ] ) ) ;
200+ var type_str = sensor [ 'type_str' ] ;
201+ var sensor_type = '' ;
202+ if ( type_str ) {
203+ sensor_type = type_str + ' (0x' + app . toHex ( sensor [ 'type' ] , 2 ) + ')' ;
204+ } else {
205+ sensor_type = app . toHex ( sensor [ 'type' ] , 2 ) ;
206+ }
207+ goog . dom . appendChild ( tr , app . newTD ( sensor_type ) ) ;
208+ goog . dom . appendChild ( tr , app . newTD ( sensor [ 'supports_recording' ] ) ) ;
209+ goog . dom . appendChild ( tr , app . newTD ( sensor [ 'supports_min_max' ] ) ) ;
210+ goog . dom . appendChild ( tbody , tr ) ;
180211 }
181- goog . dom . appendChild ( tr , app . newTD ( sensor_type ) ) ;
182- goog . dom . appendChild ( tr , app . newTD ( sensor [ 'supports_recording' ] ) ) ;
183- goog . dom . appendChild ( tr , app . newTD ( sensor [ 'supports_min_max' ] ) ) ;
184- goog . dom . appendChild ( tbody , tr ) ;
212+ app . showBlock ( sensor_fieldset ) ;
213+ } else {
214+ app . hideNode ( sensor_fieldset ) ;
185215 }
186- app . showBlock ( sensor_fieldset ) ;
187- } else {
188- app . hideNode ( sensor_fieldset ) ;
189216 }
190217
191218 // supported params
192219 var supported_params = software_version [ 'supported_parameters' ] ;
193220 var supported_params_fieldset = goog . dom . $ ( 'model_params_fieldset' ) ;
194- if ( supported_params && supported_params . length ) {
195- var supported_params_list = goog . dom . $ ( 'model_params_list' ) ;
196- goog . dom . removeChildren ( supported_params_list ) ;
197- for ( var i = 0 ; i < supported_params . length ; ++ i ) {
198- var param = supported_params [ i ] ;
199- var param_name = param [ 'name' ] ;
200- var li = goog . dom . createDom ( 'li' ) ;
201- if ( param_name ) {
202- var a = goog . dom . createDom ( 'a' ) ;
203- a . innerHTML = param_name + ' (0x' + app . toHex ( param [ 'id' ] , 4 ) + ')' ;
204- a . href = ( '/pid/display?manufacturer=' + param [ 'manufacturer_id' ] +
205- '&pid=' + param [ 'id' ] ) ;
206- goog . dom . appendChild ( li , a )
207- } else {
208- li . innerHTML = '0x' + app . toHex ( param [ 'id' ] , 4 ) ;
221+ if ( supported_params_fieldset ) {
222+ if ( supported_params && supported_params . length ) {
223+ var supported_params_list = goog . dom . $ ( 'model_params_list' ) ;
224+ goog . dom . removeChildren ( supported_params_list ) ;
225+ for ( var i = 0 ; i < supported_params . length ; ++ i ) {
226+ var param = supported_params [ i ] ;
227+ var param_name = param [ 'name' ] ;
228+ var li = goog . dom . createDom ( 'li' ) ;
229+ if ( param_name ) {
230+ var a = goog . dom . createDom ( 'a' ) ;
231+ a . innerHTML = param_name + ' (0x' + app . toHex ( param [ 'id' ] , 4 ) + ')' ;
232+ a . href = ( '/pid/display?manufacturer=' + param [ 'manufacturer_id' ] +
233+ '&pid=' + param [ 'id' ] ) ;
234+ goog . dom . appendChild ( li , a ) ;
235+ } else {
236+ li . innerHTML = '0x' + app . toHex ( param [ 'id' ] , 4 ) ;
237+ }
238+ goog . dom . appendChild ( supported_params_list , li ) ;
209239 }
210- goog . dom . appendChild ( supported_params_list , li ) ;
240+ app . showBlock ( supported_params_fieldset ) ;
241+ } else {
242+ app . hideNode ( supported_params_fieldset ) ;
211243 }
212- app . showBlock ( supported_params_fieldset ) ;
213- } else {
214- app . hideNode ( supported_params_fieldset ) ;
215244 }
216245} ;
217246goog . exportSymbol ( 'app.changeSoftwareVersion' , app . changeSoftwareVersion ) ;
218247
219248
220249/**
221250 * Display the latest version for the element.
251+ * @param {!Element } element
222252 */
223253app . setLatestVersion = function ( element ) {
224254 var index = 0 ;
@@ -232,12 +262,13 @@ app.setLatestVersion = function(element) {
232262 }
233263 element . selectedIndex = index ;
234264 app . changeSoftwareVersion ( element ) ;
235- }
265+ } ;
236266goog . exportSymbol ( 'app.setLatestVersion' , app . setLatestVersion ) ;
237267
238268
239269/**
240270 * Make the pid table sortable
271+ * @param {!string } table_id
241272 */
242273app . makePIDTable = function ( table_id ) {
243274 var table = new goog . ui . TableSorter ( ) ;
@@ -251,14 +282,3 @@ app.makePIDTable = function(table_id) {
251282 table . setSortFunction ( 5 , goog . ui . TableSorter . alphaSort ) ;
252283} ;
253284goog . exportSymbol ( 'app.makePIDTable' , app . makePIDTable ) ;
254-
255-
256- /**
257- * Display a pid command
258- */
259- app . displayCommand = function ( json , element_id ) {
260- var msg_structure = new app . MessageStructure ( ) ;
261- msg_structure . decorate ( goog . dom . $ ( element_id ) ) ;
262- msg_structure . update ( json [ 'items' ] ) ;
263- } ;
264- goog . exportSymbol ( 'app.displayCommand' , app . displayCommand ) ;
0 commit comments