2 title
: L
.tr('Package management'),
4 updateDiskSpace: function()
6 return L
.system
.getDiskInfo().then(function(info
) {
7 $('#package_space').empty().append(
9 value
: info
.root
.used
/ 1024,
10 max
: info
.root
.total
/ 1024,
11 format
: '%d ' + L
.tr('kB') + ' / %d ' + L
.tr('kB') + ' ' + L
.trc('Used disk space', 'used') + ' (%d%%)'
16 installRemovePackage: function(pkgname
, installed
)
18 var dspname
= pkgname
.replace(/^.+\//, '');
19 var action
= installed
? L
.opkg
.removePackage
: L
.opkg
.installPackage
;
20 var title
= (installed
? L
.tr('Removing package "%s" …') : L
.tr('Installing package "%s" …')).format(dspname
);
21 var confirm
= (installed
? L
.tr('Really remove package "%h" ?') : L
.tr('Really install package "%h" ?')).format(dspname
);
25 L
.ui
.dialog(title
, confirm
, {
28 L
.ui
.dialog(title
, L
.tr('Waiting for package manager …'), { style
: 'wait' });
30 action(pkgname
).then(function(res
) {
31 self
.fetchInstalledList().then(function() { return self
.fetchPackageList(); }).then(function() {
35 output
.push($('<pre />').text(res
.stdout
));
38 output
.push($('<pre />').addClass('alert-message').text(res
.stderr
));
40 output
.push(res
.code
? L
.tr('Package manager failed with status %d.').format(res
.code
) : L
.tr('Package manager finished successfully.'));
42 L
.ui
.dialog(title
, output
, { style
: 'close' });
45 $('#package_url').val('');
52 fetchInstalledList: function()
55 return L
.opkg
.installedPackages(0, 0, '*').then(function(list
) {
56 self
.installedList
= { };
57 for (var i
= 0; i
< list
.length
; i
++)
58 self
.installedList
[list
[i
][0]] = true;
62 fetchPackageList: function(offset
, interactive
)
67 if (typeof(offset
) == 'undefined')
68 offset
= parseInt($('#package_filter').attr('offset')) || 0;
70 var pattern
= $('#package_filter').val() || '';
75 action
= $('#package_which').prop('checked') ? L
.opkg
.installedPackages
: L
.opkg
.findPackages
;
76 pattern
= '*' + pattern
+ '*';
78 $('#package_filter').next().attr('src', L
.globals
.resource
+ '/icons/cbi/remove.gif');
82 action
= $('#package_which').prop('checked') ? L
.opkg
.installedPackages
: L
.opkg
.listPackages
;
85 $('#package_filter').next().attr('src', L
.globals
.resource
+ '/icons/cbi/find.gif');
88 $('#package_filter').attr('offset', offset
);
90 var install_disabled
= $('#package_install').attr('disabled');
93 return action(offset
, 100, pattern
).then(function(list
) {
94 var packageTable
= new L
.ui
.table({
95 placeholder
: L
.tr('No matching packages found.'),
97 caption
: L
.trc('Package table header', 'Package'),
100 caption
: L
.trc('Package table header', 'Version'),
102 format: function(v
) {
103 return (v
.length
> 15 ? v
.substring(0, 14) + '…' : v
);
106 caption
: L
.trc('Package table header', 'Description'),
109 caption
: L
.trc('Package table header', 'Installation Status'),
112 format: function(v
, n
) {
113 var inst
= self
.installedList
[list
[n
][0]];
114 return L
.ui
.button(inst
? L
.trc('Package state', 'Installed') : L
.trc('Package state', 'Not installed'), inst
? 'success' : 'danger')
115 .css('width', '100%')
116 .attr('disabled', install_disabled
)
117 .attr('pkgname', list
[n
][0])
118 .attr('installed', inst
)
120 self
.installRemovePackage(this.getAttribute('pkgname'), this.getAttribute('installed') == 'true');
126 packageTable
.rows(list
);
127 packageTable
.insertInto('#package_table');
131 .attr('offset', offset
- 100)
132 .attr('disabled', false)
133 .text('« %d - %d'.format(offset
- 100 + 1, offset
));
136 .attr('disabled', true)
137 .text('« %d - %d'.format(1, Math
.min(100, list
.total
)));
139 if ((offset
+ 100) < list
.total
)
141 .attr('offset', offset
+ 100)
142 .attr('disabled', false)
143 .text('%d - %d »'.format(offset
+ 100 + 1, Math
.min(offset
+ 200, list
.total
)));
146 .attr('disabled', true)
147 .text('%d - %d »'.format(list
.total
- (list
.total
% 100) + 1, list
.total
));
151 }).then(self
.updateDiskSpace
);
158 $('textarea, input.cbi-button-save').attr('disabled', !this.options
.acls
.software
);
159 $('#package_update, #package_url, #package_install').attr('disabled', !this.options
.acls
.software
);
162 L
.opkg
.getConfig().then(function(config
) {
163 $('#config textarea')
164 .attr('rows', (config
.match(/\n/g) || [ ]).length
+ 1)
169 var data
= ($('#config textarea').val() || '').replace(/\r/g, '').replace(/\n?$/, '\n');
171 L
.opkg
.setConfig(data
).then(function() {
172 $('#config textarea')
173 .attr('rows', (data
.match(/\n/g) || [ ]).length
+ 1)
180 self
.fetchInstalledList(),
181 self
.updateDiskSpace()
183 $('#package_prev, #package_next').click(function(ev
) {
184 if (!this.getAttribute('disabled'))
186 self
.fetchPackageList(parseInt(this.getAttribute('offset')), true);
191 $('#package_filter').next().click(function(ev
) {
192 $('#package_filter').val('');
193 self
.fetchPackageList(0, true);
196 $('#package_filter').keyup(function(ev
) {
201 self
.fetchPackageList(0, true);
205 $('#package_which').click(function(ev
) {
207 self
.fetchPackageList(0, true);
210 $('#package_url').keyup(function(ev
) {
217 self
.installRemovePackage(this.value
, false);
220 $('#package_install').click(function(ev
) {
221 var name
= $('#package_url').val();
223 self
.installRemovePackage(name
, false);
226 $('#package_update').click(function(ev
) {
227 L
.ui
.dialog(L
.tr('Updating package lists'), L
.tr('Waiting for package manager …'), { style
: 'wait' });
228 L
.opkg
.updateLists().then(function(res
) {
232 output
.push($('<pre />').text(res
.stdout
));
235 output
.push($('<pre />').addClass('alert-message').text(res
.stderr
));
237 output
.push(res
.code
? L
.tr('Package manager failed with status %d.').format(res
.code
) : L
.tr('Package manager finished successfully.'));
239 L
.ui
.dialog(L
.tr('Updating package lists'), output
, { style
: 'close' });
243 return self
.fetchPackageList(0);