From ff35e6efabdba812e9c805d33f9dbe8782b4bac4 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Mon, 10 Jun 2013 21:54:53 +0100 Subject: [PATCH] webui: move idnode tree to idnode.js and update to handle 2 types of enum --- src/webui/static/app/idnode.js | 80 +++++++++++++++++++- src/webui/static/app/tvadapters.js | 117 +---------------------------- 2 files changed, 78 insertions(+), 119 deletions(-) diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 20b32437..62fa93b2 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -21,6 +21,13 @@ tvheadend.idnode_editor_field = function(f, create) switch(f.type) { case 'str': if (f.enum) { + var store = f.enum; + if (f.enum.length > 0 && f.enum[0] instanceof Object) + store = new Ext.data.JsonStore({ + id : 'key', + fields : [ 'key', 'val' ], + data : f.enum, + }); return new Ext.form.ComboBox({ fieldLabel : f.caption, name : f.id, @@ -28,7 +35,9 @@ tvheadend.idnode_editor_field = function(f, create) disabled : d, width : 300, mode : 'local', - store : f.enum, + valueField : 'key', + displayField : 'val', + store : store, typeAhead : true, forceSelection : true, triggerAction : 'all', @@ -76,7 +85,7 @@ tvheadend.idnode_editor_field = function(f, create) /* * ID node editor panel */ -tvheadend.idnode_editor = function(item) +tvheadend.idnode_editor = function(item, conf) { var fields = [] @@ -87,13 +96,14 @@ tvheadend.idnode_editor = function(item) } var panel = new Ext.FormPanel({ + title : conf.title || null, frame : true, border : true, bodyStyle : 'padding: 5px', labelAlign : 'left', labelWidth : 200, autoWidth : true, - autoHeight : true, + autoHeight : !conf.fixedHeight, defaultType : 'textfield', buttonAlign : 'left', items : fields, @@ -371,7 +381,7 @@ tvheadend.idnode_grid = function(panel, conf) success : function(d) { d = json_decode(d); - p = tvheadend.idnode_editor(d[0]); + p = tvheadend.idnode_editor(d[0], {}); w = new Ext.Window({ title : 'Add ' + conf.titleS, layout : 'fit', @@ -437,3 +447,65 @@ tvheadend.idnode_grid = function(panel, conf) build(conf.fields); } } + +tvheadend.idnode_tree = function (conf) +{ + var current = null; + + var loader = new Ext.tree.TreeLoader({ + dataUrl : conf.url + }); + + var tree = new Ext.tree.TreePanel({ + loader : loader, + flex : 1, + border : false, + root : new Ext.tree.AsyncTreeNode({ + id : 'root', + text : conf.title + }), + listeners : { + click: function(n) { + if(current) + panel.remove(current); + if(!n.isRoot) + current = panel.add(new tvheadend.idnode_editor(n.attributes, {title: 'Parameters', fixedHeight: true})); + panel.doLayout(); + } + } + }); + + tvheadend.comet.on('idnodeNameChanged', function(o) { + var n = tree.getNodeById(o.id); + if(n) { + n.setText(o.text); + } + }); + + tvheadend.comet.on('idnodeParamsChanged', function(o) { + var n = tree.getNodeById(o.id); + if(n) { + n.attributes.params = o.params; + } + }); + + + var panel = new Ext.Panel({ + title : conf.title, + layout : 'hbox', + flex : 1, + padding : 5, + border : false, + layoutConfig : { + align : 'stretch' + }, + items: [ tree ] + }); + + + tree.on('render', function() { + tree.getRootNode().expand(); + }); + + return panel; +} diff --git a/src/webui/static/app/tvadapters.js b/src/webui/static/app/tvadapters.js index c13e209f..010d2e40 100644 --- a/src/webui/static/app/tvadapters.js +++ b/src/webui/static/app/tvadapters.js @@ -1,117 +1,4 @@ -/** - * Datastore for adapters - */ -/* -tvheadend.tvAdapterStore = new Ext.data.JsonStore({ - root : 'entries', - id : 'identifier', - fields : [ 'identifier', 'type', 'name', 'path', 'devicename', - 'hostconnection', 'currentMux', 'services', 'muxes', 'initialMuxes', - 'satConf', 'deliverySystem', 'freqMin', 'freqMax', 'freqStep', - 'symrateMin', 'symrateMax', 'signal', 'snr', 'ber', 'unc', 'uncavg', 'bw', 'reason'], - autoLoad : true, - url : 'tv/adapter' -}); - -tvheadend.comet.on('tvAdapter', function(m) { - idx = tvheadend.tvAdapterStore.find('identifier', m.identifier); - if (idx == -1) - return; - r = tvheadend.tvAdapterStore.getAt(idx); - r.beginEdit(); - for (key in m) - r.set(key, m[key]); - r.endEdit(); - tvheadend.tvAdapterStore.commitChanges(); -}); - tvheadend.tvadapters = function() { - tvheadend.tvAdapterStore.load(); - - var adapterSelection = new Ext.form.ComboBox({ - loadingText : 'Loading...', - width : 300, - displayField : 'name', - store : tvheadend.tvAdapterStore, - mode : 'remote', - editable : false, - triggerAction : 'all', - emptyText : 'Select TV adapter...' - }); - - var dummyadapter = new Ext.Panel({ - region : 'center', - layout : 'fit', - items : [ { - border : false - } ] - }); - - var panel = new Ext.Panel({ - title : 'TV Adapters', - iconCls : 'hardware', - layout : 'fit', - tbar : [ adapterSelection, '->', { - text : 'Help', - handler : function() { - new tvheadend.help('DVB', 'config_dvb.html'); - } - } ], - - items : [ dummyadapter ] - }); - - adapterSelection.on('select', function(c, r) { - panel.removeAll(false); - - if (r.data.type == 'dvb') - panel.add(new tvheadend.dvb_adapter(r.data)); - else - panel.add(new tvheadend.v4l_adapter(r.data)); - - panel.doLayout(); - }); - - return panel; -} -*/ -/** - * - */ -/* -tvheadend.showTransportDetails = function(data) { - html = ''; - - html += '
'; - html += 'PID '; - html += 'Type'; - html += 'Details'; - html += '
'; - - for (i = 0; i < data.streams.length; i++) { - s = data.streams[i]; - - html += '
'; - html += '' + s.pid + ''; - html += '' + s.type + ''; - html += '' + (s.details.length > 0 ? s.details : ' ') - + ''; - html += '
'; - } - - win = new Ext.Window({ - title : 'Service details for ' + data.title, - layout : 'fit', - width : 400, - height : 400, - plain : true, - bodyStyle : 'padding: 5px', - html : html - }); - win.show(); -} -*/ - -tvheadend.tvadapters = function() { - return tvheadend.item_browser('tvadapters', 'TV Adapters'); +// return tvheadend.item_browser('tvadapters', 'TV Adapters'); + return tvheadend.idnode_tree({ url: 'tvadapters', title: 'TV adapters'}); }