3 saveScrollTop: function()
5 this._scroll_top
= $(document
).scrollTop();
8 restoreScrollTop: function()
10 if (typeof(this._scroll_top
) == 'undefined')
13 $(document
).scrollTop(this._scroll_top
);
15 delete this._scroll_top
;
18 loading: function(enable
)
23 var state
= this._loading
|| (this._loading
= {
26 .addClass('modal fade')
28 .addClass('modal-dialog')
30 .addClass('modal-content luci2-modal-loader')
32 .addClass('modal-body')
33 .text(L
.tr('Loading data…')))))
41 state
.modal
.modal(enable
? 'show' : 'hide');
44 dialog: function(title
, content
, options
)
50 var state
= this._dialog
|| (this._dialog
= {
52 .addClass('modal fade')
54 .addClass('modal-dialog')
56 .addClass('modal-content')
58 .addClass('modal-header')
60 .addClass('modal-title'))
62 .addClass('modal-body'))
64 .addClass('modal-footer')
65 .append(self
.button(L
.tr('Close'), 'primary')
67 $(this).parents('div.modal').modal('hide');
72 if (typeof(options
) != 'object')
77 state
.dialog
.modal('hide');
82 var cnt
= state
.dialog
.children().children().children('div.modal-body');
83 var ftr
= state
.dialog
.children().children().children('div.modal-footer');
87 if (options
.style
== 'confirm')
89 ftr
.append(L
.ui
.button(L
.tr('Ok'), 'primary')
90 .click(options
.confirm
|| function() { L
.ui
.dialog(false) }));
92 ftr
.append(L
.ui
.button(L
.tr('Cancel'), 'default')
93 .click(options
.cancel
|| function() { L
.ui
.dialog(false) }));
95 else if (options
.style
== 'close')
97 ftr
.append(L
.ui
.button(L
.tr('Close'), 'primary')
98 .click(options
.close
|| function() { L
.ui
.dialog(false) }));
100 else if (options
.style
== 'wait')
102 ftr
.append(L
.ui
.button(L
.tr('Close'), 'primary')
103 .attr('disabled', true));
108 state
.dialog
.addClass('wide');
112 state
.dialog
.removeClass('wide');
115 state
.dialog
.find('h4:first').text(title
);
116 state
.dialog
.modal('show');
118 cnt
.empty().append(content
);
123 upload: function(title
, content
, options
)
125 var state
= L
.ui
._upload
|| (L
.ui
._upload
= {
127 .attr('method', 'post')
128 .attr('action', '/cgi-bin/luci-upload')
129 .attr('enctype', 'multipart/form-data')
130 .attr('target', 'cbi-fileupload-frame')
132 .append($('<input />')
133 .attr('type', 'hidden')
134 .attr('name', 'sessionid'))
135 .append($('<input />')
136 .attr('type', 'hidden')
137 .attr('name', 'filename'))
138 .append($('<input />')
139 .attr('type', 'file')
140 .attr('name', 'filedata')
141 .addClass('cbi-input-file'))
143 .css('width', '100%')
144 .addClass('progress progress-striped active')
146 .addClass('progress-bar')
147 .css('width', '100%')))
148 .append($('<iframe />')
149 .addClass('pull-right')
150 .attr('name', 'cbi-fileupload-frame')
152 .css('height', '1px')
153 .css('visibility', 'hidden')),
155 finish_cb: function(ev
) {
158 var body
= (this.contentDocument
|| this.contentWindow
.document
).body
;
159 if (body
.firstChild
.tagName
.toLowerCase() == 'pre')
160 body
= body
.firstChild
;
164 json
= $.parseJSON(body
.innerHTML
);
167 message
: L
.tr('Invalid server response received'),
168 error
: [ -1, L
.tr('Invalid data') ]
174 L
.ui
.dialog(L
.tr('File upload'), [
175 $('<p />').text(L
.tr('The file upload failed with the server response below:')),
176 $('<pre />').addClass('alert-message').text(json
.message
|| json
.error
[1]),
177 $('<p />').text(L
.tr('In case of network problems try uploading the file again.'))
178 ], { style
: 'close' });
180 else if (typeof(state
.success_cb
) == 'function')
182 state
.success_cb(json
);
186 confirm_cb: function() {
187 var f
= state
.form
.find('.cbi-input-file');
188 var b
= state
.form
.find('.progress');
189 var p
= state
.form
.find('p');
194 state
.form
.find('iframe').on('load', state
.finish_cb
);
199 p
.text(L
.tr('File upload in progress …'));
201 state
.form
.parent().parent().find('button').prop('disabled', true);
205 state
.form
.find('.progress').hide();
206 state
.form
.find('.cbi-input-file').val('').show();
207 state
.form
.find('p').text(content
|| L
.tr('Select the file to upload and press "%s" to proceed.').format(L
.tr('Ok')));
209 state
.form
.find('[name=sessionid]').val(L
.globals
.sid
);
210 state
.form
.find('[name=filename]').val(options
.filename
);
212 state
.success_cb
= options
.success
;
214 L
.ui
.dialog(title
|| L
.tr('File upload'), state
.form
, {
216 confirm
: state
.confirm_cb
220 reconnect: function()
222 var protocols
= (location
.protocol
== 'https:') ? [ 'http', 'https' ] : [ 'http' ];
223 var ports
= (location
.protocol
== 'https:') ? [ 80, location
.port
|| 443 ] : [ location
.port
|| 80 ];
224 var address
= location
.hostname
.match(/^[A-Fa-f0-9]*:[A-Fa-f0-9:]+$/) ? '[' + location
.hostname
+ ']' : location
.hostname
;
226 var interval
, timeout
;
229 L
.tr('Waiting for device'), [
230 $('<p />').text(L
.tr('Please stand by while the device is reconfiguring …')),
232 .css('width', '100%')
233 .addClass('progressbar')
234 .addClass('intermediate')
236 .css('width', '100%'))
240 for (var i
= 0; i
< protocols
.length
; i
++)
241 images
= images
.add($('<img />').attr('url', protocols
[i
] + '://' + address
+ ':' + ports
[i
]));
243 //L.network.getNetworkStatus(function(s) {
244 // for (var i = 0; i < protocols.length; i++)
246 // for (var j = 0; j < s.length; j++)
248 // for (var k = 0; k < s[j]['ipv4-address'].length; k++)
249 // images = images.add($('<img />').attr('url', protocols[i] + '://' + s[j]['ipv4-address'][k].address + ':' + ports[i]));
251 // for (var l = 0; l < s[j]['ipv6-address'].length; l++)
252 // images = images.add($('<img />').attr('url', protocols[i] + '://[' + s[j]['ipv6-address'][l].address + ']:' + ports[i]));
255 //}).then(function() {
256 images
.on('load', function() {
257 var url
= this.getAttribute('url');
258 L
.session
.isAlive().then(function(access
) {
261 window
.clearTimeout(timeout
);
262 window
.clearInterval(interval
);
273 interval
= window
.setInterval(function() {
274 images
.each(function() {
275 this.setAttribute('src', this.getAttribute('url') + L
.globals
.resource
+ '/icons/loading.gif?r=' + Math
.random());
279 timeout
= window
.setTimeout(function() {
280 window
.clearInterval(interval
);
284 L
.tr('Device not responding'),
285 L
.tr('The device was not responding within 180 seconds, you might need to manually reconnect your computer or use SSH to regain access.'),
292 login: function(invalid
)
294 var state
= L
.ui
._login
|| (L
.ui
._login
= {
297 .attr('method', 'post')
299 .addClass('alert alert-danger')
300 .text(L
.tr('Wrong username or password given!')))
302 .append($('<label />')
303 .text(L
.tr('Username'))
305 .append($('<input />')
306 .attr('type', 'text')
307 .attr('name', 'username')
308 .attr('value', 'root')
309 .addClass('form-control')
310 .keypress(function(ev
) {
311 if (ev
.which
== 10 || ev
.which
== 13)
315 .append($('<label />')
316 .text(L
.tr('Password'))
318 .append($('<input />')
319 .attr('type', 'password')
320 .attr('name', 'password')
321 .addClass('form-control')
322 .keypress(function(ev
) {
323 if (ev
.which
== 10 || ev
.which
== 13)
327 .text(L
.tr('Enter your username and password above, then click "%s" to proceed.').format(L
.tr('Ok')))),
329 response_cb: function(response
) {
330 if (!response
.ubus_rpc_session
)
336 L
.globals
.sid
= response
.ubus_rpc_session
;
337 L
.setHash('id', L
.globals
.sid
);
338 L
.session
.startHeartbeat();
340 state
.deferred
.resolve();
344 confirm_cb: function() {
345 var u
= state
.form
.find('[name=username]').val();
346 var p
= state
.form
.find('[name=password]').val();
352 L
.tr('Logging in'), [
353 $('<p />').text(L
.tr('Log in in progress …')),
355 .css('width', '100%')
356 .addClass('progressbar')
357 .addClass('intermediate')
359 .css('width', '100%'))
363 L
.globals
.sid
= '00000000000000000000000000000000';
364 L
.session
.login(u
, p
).then(state
.response_cb
);
368 if (!state
.deferred
|| state
.deferred
.state() != 'pending')
369 state
.deferred
= $.Deferred();
371 /* try to find sid from hash */
372 var sid
= L
.getHash('id');
373 if (sid
&& sid
.match(/^[a-f0-9]{32}$/))
376 L
.session
.isAlive().then(function(access
) {
379 L
.session
.startHeartbeat();
380 state
.deferred
.resolve();
384 L
.setHash('id', undefined);
389 return state
.deferred
;
393 state
.form
.find('.alert-message').show();
395 state
.form
.find('.alert-message').hide();
397 L
.ui
.dialog(L
.tr('Authorization Required'), state
.form
, {
399 confirm
: state
.confirm_cb
402 state
.form
.find('[name=password]').focus();
404 return state
.deferred
;
407 cryptPassword
: L
.rpc
.declare({
411 expect
: { crypt
: '' }
415 mergeACLScope: function(acl_scope
, scope
)
417 if ($.isArray(scope
))
419 for (var i
= 0; i
< scope
.length
; i
++)
420 acl_scope
[scope
[i
]] = true;
422 else if ($.isPlainObject(scope
))
424 for (var object_name
in scope
)
426 if (!$.isArray(scope
[object_name
]))
429 var acl_object
= acl_scope
[object_name
] || (acl_scope
[object_name
] = { });
431 for (var i
= 0; i
< scope
[object_name
].length
; i
++)
432 acl_object
[scope
[object_name
][i
]] = true;
437 mergeACLPermission: function(acl_perm
, perm
)
439 if ($.isPlainObject(perm
))
441 for (var scope_name
in perm
)
443 var acl_scope
= acl_perm
[scope_name
] || (acl_perm
[scope_name
] = { });
444 L
.ui
.mergeACLScope(acl_scope
, perm
[scope_name
]);
449 mergeACLGroup: function(acl_group
, group
)
451 if ($.isPlainObject(group
))
453 if (!acl_group
.description
)
454 acl_group
.description
= group
.description
;
458 var acl_perm
= acl_group
.read
|| (acl_group
.read
= { });
459 L
.ui
.mergeACLPermission(acl_perm
, group
.read
);
464 var acl_perm
= acl_group
.write
|| (acl_group
.write
= { });
465 L
.ui
.mergeACLPermission(acl_perm
, group
.write
);
470 callACLsCallback: function(trees
)
474 for (var i
= 0; i
< trees
.length
; i
++)
476 if (!$.isPlainObject(trees
[i
]))
479 for (var group_name
in trees
[i
])
481 var acl_group
= acl_tree
[group_name
] || (acl_tree
[group_name
] = { });
482 L
.ui
.mergeACLGroup(acl_group
, trees
[i
][group_name
]);
489 callACLs
: L
.rpc
.declare({
492 expect
: { acls
: [ ] }
495 getAvailableACLs: function()
497 return this.callACLs().then(this.callACLsCallback
);
500 renderChangeIndicator: function()
503 .addClass('nav navbar-nav navbar-right')
506 .attr('id', 'changes')
508 .append($('<span />')
509 .addClass('label label-info'))));
512 callMenuCallback: function(entries
)
514 L
.globals
.mainMenu
= new L
.ui
.menu();
515 L
.globals
.mainMenu
.entries(entries
);
519 .append(L
.globals
.mainMenu
.render(0, 1))
520 .append(L
.ui
.renderChangeIndicator());
523 callMenu
: L
.rpc
.declare({
526 expect
: { menu
: { } }
529 renderMainMenu: function()
531 return this.callMenu().then(this.callMenuCallback
);
534 renderViewMenu: function()
538 .append(L
.globals
.mainMenu
.render(2, 900));
541 renderView: function()
543 var node
= arguments
[0];
544 var name
= node
.view
.split(/\//).join('.');
545 var cname
= L
.toClassName(name
);
546 var views
= L
.views
|| (L
.views
= { });
549 for (var i
= 1; i
< arguments
.length
; i
++)
550 args
.push(arguments
[i
]);
552 if (L
.globals
.currentView
)
553 L
.globals
.currentView
.finish();
555 L
.ui
.renderViewMenu();
556 L
.setHash('view', node
.view
);
558 if (views
[cname
] instanceof L
.ui
.view
)
560 L
.globals
.currentView
= views
[cname
];
561 return views
[cname
].render
.apply(views
[cname
], args
);
564 var url
= L
.globals
.resource
+ '/view/' + name
+ '.js';
570 }).then(function(data
) {
572 var viewConstructorSource
= (
573 '(function(L, $) { ' +
579 var viewConstructor
= eval(viewConstructorSource
);
581 views
[cname
] = new viewConstructor({
583 acls
: node
.write
|| { }
586 L
.globals
.currentView
= views
[cname
];
587 return views
[cname
].render
.apply(views
[cname
], args
);
590 alert('Unable to instantiate view "%s": %s'.format(url
, e
));
593 return $.Deferred().resolve();
597 changeView: function()
599 var name
= L
.getHash('view');
600 var node
= L
.globals
.defaultNode
;
602 if (name
&& L
.globals
.mainMenu
)
603 node
= L
.globals
.mainMenu
.getNode(name
);
608 L
.ui
.renderView(node
).then(function() {
614 updateHostname: function()
616 return L
.system
.getBoardInfo().then(function(info
) {
618 $('#hostname').text(info
.hostname
);
622 updateChanges: function()
624 return L
.uci
.changes().then(function(changes
) {
628 for (var config
in changes
)
632 for (var i
= 0; i
< changes
[config
].length
; i
++)
634 var c
= changes
[config
][i
];
639 log
.push('uci reorder %s.<ins>%s=<strong>%s</strong></ins>'.format(config
, c
[1], c
[2]));
644 log
.push('uci delete %s.<del>%s</del>'.format(config
, c
[1]));
646 log
.push('uci delete %s.%s.<del>%s</del>'.format(config
, c
[1], c
[2]));
651 log
.push('uci rename %s.<ins>%s=<strong>%s</strong></ins>'.format(config
, c
[1], c
[2], c
[3]));
653 log
.push('uci rename %s.%s.<ins>%s=<strong>%s</strong></ins>'.format(config
, c
[1], c
[2], c
[3], c
[4]));
657 log
.push('uci add %s <ins>%s</ins> (= <ins><strong>%s</strong></ins>)'.format(config
, c
[2], c
[1]));
661 log
.push('uci add_list %s.%s.<ins>%s=<strong>%s</strong></ins>'.format(config
, c
[1], c
[2], c
[3], c
[4]));
665 log
.push('uci del_list %s.%s.<del>%s=<strong>%s</strong></del>'.format(config
, c
[1], c
[2], c
[3], c
[4]));
670 log
.push('uci set %s.<ins>%s=<strong>%s</strong></ins>'.format(config
, c
[1], c
[2]));
672 log
.push('uci set %s.%s.<ins>%s=<strong>%s</strong></ins>'.format(config
, c
[1], c
[2], c
[3], c
[4]));
677 html
+= '<code>/etc/config/%s</code><pre class="uci-changes">%s</pre>'.format(config
, log
.join('\n'));
678 n
+= changes
[config
].length
;
683 .click(function(ev
) {
684 L
.ui
.dialog(L
.tr('Staged configuration changes'), html
, {
686 confirm: function() {
688 function(code
) { alert('Success with code ' + code
); },
689 function(code
) { alert('Error with code ' + code
); }
697 .text(L
.trcp('Pending configuration changes', '1 change', '%d changes', n
).format(n
));
699 $('#changes').children('span').hide();
710 L
.session
.updateACLs(),
711 self
.updateHostname(),
712 self
.updateChanges(),
713 self
.renderMainMenu(),
716 self
.renderView(L
.globals
.defaultNode
).then(function() {
720 $(window
).on('hashchange', function() {
726 button: function(label
, style
, title
)
728 style
= style
|| 'default';
730 return $('<button />')
731 .attr('type', 'button')
732 .attr('title', title
? title
: '')
733 .addClass('btn btn-' + style
)
738 ui_class
.AbstractWidget
= Class
.extend({
739 i18n: function(text
) {
744 var key
= arguments
[0];
747 for (var i
= 1; i
< arguments
.length
; i
++)
748 args
.push(arguments
[i
]);
750 switch (typeof(this.options
[key
]))
756 return this.options
[key
].apply(this, args
);
759 return ''.format
.apply('' + this.options
[key
], args
);
763 toString: function() {
764 return $('<div />').append(this.render()).html();
767 insertInto: function(id
) {
768 return $(id
).empty().append(this.render());
771 appendTo: function(id
) {
772 return $(id
).append(this.render());
775 on: function(evname
, evfunc
)
777 var evnames
= L
.toArray(evname
);
782 for (var i
= 0; i
< evnames
.length
; i
++)
783 this.events
[evnames
[i
]] = evfunc
;
788 trigger: function(evname
, evdata
)
792 var evnames
= L
.toArray(evname
);
794 for (var i
= 0; i
< evnames
.length
; i
++)
795 if (this.events
[evnames
[i
]])
796 this.events
[evnames
[i
]].call(this, evdata
);
803 ui_class
.view
= ui_class
.AbstractWidget
.extend({
804 _fetch_template: function()
806 return $.ajax(L
.globals
.resource
+ '/template/' + this.options
.name
+ '.htm', {
810 success: function(data
) {
811 data
= data
.replace(/<%([#:=])?(.+?)%>/g, function(match
, p1
, p2
) {
812 p2
= p2
.replace(/^\s+/, '').replace(/\s+$/, '');
822 return L
.globals
[p2
] || '';
825 return '(?' + match
+ ')';
829 $('#maincontent').append(data
);
836 throw "Not implemented";
841 var container
= $('#maincontent');
846 container
.append($('<h2 />').append(this.title
));
848 if (this.description
)
849 container
.append($('<p />').append(this.description
));
854 for (var i
= 0; i
< arguments
.length
; i
++)
855 args
.push(arguments
[i
]);
857 return this._fetch_template().then(function() {
858 return L
.deferrable(self
.execute
.apply(self
, args
));
862 repeat: function(func
, interval
)
867 self
._timeouts
= [ ];
869 var index
= self
._timeouts
.length
;
871 if (typeof(interval
) != 'number')
874 var setTimer
, runTimer
;
876 setTimer = function() {
878 self
._timeouts
[index
] = window
.setTimeout(runTimer
, interval
);
881 runTimer = function() {
882 L
.deferrable(func
.call(self
)).then(setTimer
, setTimer
);
890 if ($.isArray(this._timeouts
))
892 for (var i
= 0; i
< this._timeouts
.length
; i
++)
893 window
.clearTimeout(this._timeouts
[i
]);
895 delete this._timeouts
;
900 ui_class
.menu
= ui_class
.AbstractWidget
.extend({
905 entries: function(entries
)
907 for (var entry
in entries
)
909 var path
= entry
.split(/\//);
910 var node
= this._nodes
;
912 for (i
= 0; i
< path
.length
; i
++)
917 if (!node
.childs
[path
[i
]])
918 node
.childs
[path
[i
]] = { };
920 node
= node
.childs
[path
[i
]];
923 $.extend(node
, entries
[entry
]);
927 sortNodesCallback: function(a
, b
)
929 var x
= a
.index
|| 0;
930 var y
= b
.index
|| 0;
934 firstChildView: function(node
)
940 for (var child
in (node
.childs
|| { }))
941 nodes
.push(node
.childs
[child
]);
943 nodes
.sort(this.sortNodesCallback
);
945 for (var i
= 0; i
< nodes
.length
; i
++)
947 var child
= this.firstChildView(nodes
[i
]);
950 for (var key
in child
)
951 if (!node
.hasOwnProperty(key
) && child
.hasOwnProperty(key
))
952 node
[key
] = child
[key
];
961 handleClick: function(ev
)
963 L
.setHash('view', ev
.data
);
969 renderNodes: function(childs
, level
, min
, max
)
972 for (var node
in childs
)
974 var child
= this.firstChildView(childs
[node
]);
976 nodes
.push(childs
[node
]);
979 nodes
.sort(this.sortNodesCallback
);
981 var list
= $('<ul />');
984 list
.addClass('nav').addClass('navbar-nav');
986 list
.addClass('dropdown-menu').addClass('navbar-inverse');
988 for (var i
= 0; i
< nodes
.length
; i
++)
990 if (!L
.globals
.defaultNode
)
992 var v
= L
.getHash('view');
993 if (!v
|| v
== nodes
[i
].view
)
994 L
.globals
.defaultNode
= nodes
[i
];
997 var item
= $('<li />')
1000 .text(L
.tr(nodes
[i
].title
)))
1003 if (nodes
[i
].childs
&& level
< max
)
1005 item
.addClass('dropdown');
1008 .addClass('dropdown-toggle')
1009 .attr('data-toggle', 'dropdown')
1010 .append('<b class="caret"></b>');
1012 item
.append(this.renderNodes(nodes
[i
].childs
, level
+ 1));
1016 item
.find('a').click(nodes
[i
].view
, this.handleClick
);
1023 render: function(min
, max
)
1025 var top
= min
? this.getNode(L
.globals
.defaultNode
.view
, min
) : this._nodes
;
1026 return this.renderNodes(top
.childs
, 0, min
, max
);
1029 getNode: function(path
, max
)
1031 var p
= path
.split(/\//);
1032 var n
= this._nodes
;
1034 if (typeof(max
) == 'undefined')
1037 for (var i
= 0; i
< max
; i
++)
1039 if (!n
.childs
[p
[i
]])
1049 ui_class
.table
= ui_class
.AbstractWidget
.extend({
1055 row: function(values
)
1057 if ($.isArray(values
))
1059 this._rows
.push(values
);
1061 else if ($.isPlainObject(values
))
1064 for (var i
= 0; i
< this.options
.columns
.length
; i
++)
1066 var col
= this.options
.columns
[i
];
1068 if (typeof col
.key
== 'string')
1069 v
.push(values
[col
.key
]);
1077 rows: function(rows
)
1079 for (var i
= 0; i
< rows
.length
; i
++)
1083 render: function(id
)
1085 var fieldset
= document
.createElement('fieldset');
1086 fieldset
.className
= 'cbi-section';
1088 if (this.options
.caption
)
1090 var legend
= document
.createElement('legend');
1091 $(legend
).append(this.options
.caption
);
1092 fieldset
.appendChild(legend
);
1095 var table
= document
.createElement('table');
1096 table
.className
= 'table table-condensed table-hover';
1098 var has_caption
= false;
1099 var has_description
= false;
1101 for (var i
= 0; i
< this.options
.columns
.length
; i
++)
1102 if (this.options
.columns
[i
].caption
)
1107 else if (this.options
.columns
[i
].description
)
1109 has_description
= true;
1115 var tr
= table
.insertRow(-1);
1116 tr
.className
= 'cbi-section-table-titles';
1118 for (var i
= 0; i
< this.options
.columns
.length
; i
++)
1120 var col
= this.options
.columns
[i
];
1121 var th
= document
.createElement('th');
1122 th
.className
= 'cbi-section-table-cell';
1127 th
.style
.width
= col
.width
;
1130 th
.style
.textAlign
= col
.align
;
1133 $(th
).append(col
.caption
);
1137 if (has_description
)
1139 var tr
= table
.insertRow(-1);
1140 tr
.className
= 'cbi-section-table-descr';
1142 for (var i
= 0; i
< this.options
.columns
.length
; i
++)
1144 var col
= this.options
.columns
[i
];
1145 var th
= document
.createElement('th');
1146 th
.className
= 'cbi-section-table-cell';
1151 th
.style
.width
= col
.width
;
1154 th
.style
.textAlign
= col
.align
;
1156 if (col
.description
)
1157 $(th
).append(col
.description
);
1161 if (this._rows
.length
== 0)
1163 if (this.options
.placeholder
)
1165 var tr
= table
.insertRow(-1);
1166 var td
= tr
.insertCell(-1);
1167 td
.className
= 'cbi-section-table-cell';
1169 td
.colSpan
= this.options
.columns
.length
;
1170 $(td
).append(this.options
.placeholder
);
1175 for (var i
= 0; i
< this._rows
.length
; i
++)
1177 var tr
= table
.insertRow(-1);
1179 for (var j
= 0; j
< this.options
.columns
.length
; j
++)
1181 var col
= this.options
.columns
[j
];
1182 var td
= tr
.insertCell(-1);
1184 var val
= this._rows
[i
][j
];
1186 if (typeof(val
) == 'undefined')
1187 val
= col
.placeholder
;
1189 if (typeof(val
) == 'undefined')
1193 td
.style
.width
= col
.width
;
1196 td
.style
.textAlign
= col
.align
;
1198 if (typeof col
.format
== 'string')
1199 $(td
).append(col
.format
.format(val
));
1200 else if (typeof col
.format
== 'function')
1201 $(td
).append(col
.format(val
, i
));
1209 fieldset
.appendChild(table
);
1215 ui_class
.progress
= ui_class
.AbstractWidget
.extend({
1218 var vn
= parseInt(this.options
.value
) || 0;
1219 var mn
= parseInt(this.options
.max
) || 100;
1220 var pc
= Math
.floor((100 / mn
) * vn
);
1224 if (typeof(this.options
.format
) == 'string')
1225 text
= this.options
.format
.format(this.options
.value
, this.options
.max
, pc
);
1226 else if (typeof(this.options
.format
) == 'function')
1227 text
= this.options
.format(pc
);
1229 text
= '%.2f%%'.format(pc
);
1232 .addClass('progress')
1233 .append($('<div />')
1234 .addClass('progress-bar')
1235 .addClass('progress-bar-info')
1236 .css('width', pc
+ '%'))
1237 .append($('<small />')
1242 ui_class
.devicebadge
= ui_class
.AbstractWidget
.extend({
1245 var l2dev
= this.options
.l2_device
|| this.options
.device
;
1246 var l3dev
= this.options
.l3_device
;
1247 var dev
= l3dev
|| l2dev
|| '?';
1249 var span
= document
.createElement('span');
1250 span
.className
= 'badge';
1252 if (typeof(this.options
.signal
) == 'number' ||
1253 typeof(this.options
.noise
) == 'number')
1256 if (typeof(this.options
.signal
) != 'undefined' &&
1257 typeof(this.options
.noise
) != 'undefined')
1259 var q
= (-1 * (this.options
.noise
- this.options
.signal
)) / 5;
1272 span
.appendChild(document
.createElement('img'));
1273 span
.lastChild
.src
= L
.globals
.resource
+ '/icons/signal-' + r
+ '.png';
1276 span
.title
= L
.tr('No signal');
1278 span
.title
= '%s: %d %s / %s: %d %s'.format(
1279 L
.tr('Signal'), this.options
.signal
, L
.tr('dBm'),
1280 L
.tr('Noise'), this.options
.noise
, L
.tr('dBm')
1285 var type
= 'ethernet';
1286 var desc
= L
.tr('Ethernet device');
1291 desc
= L
.tr('Tunnel interface');
1293 else if (dev
.indexOf('br-') == 0)
1296 desc
= L
.tr('Bridge');
1298 else if (dev
.indexOf('.') > 0)
1301 desc
= L
.tr('VLAN interface');
1303 else if (dev
.indexOf('wlan') == 0 ||
1304 dev
.indexOf('ath') == 0 ||
1305 dev
.indexOf('wl') == 0)
1308 desc
= L
.tr('Wireless Network');
1311 span
.appendChild(document
.createElement('img'));
1312 span
.lastChild
.src
= L
.globals
.resource
+ '/icons/' + type
+ (this.options
.up
? '' : '_disabled') + '.png';
1316 $(span
).append(' ');
1317 $(span
).append(dev
);
1323 return Class
.extend(ui_class
);