2 updateDiskSpace: function()
4 return L.system.getDiskInfo().then(function(info) {
5 $('#package_space').empty().append(
7 value: info.root.used / 1024,
8 max: info.root.total / 1024,
9 format: '%d ' + L.tr('kB') + ' / %d ' + L.tr('kB') + ' ' + L.trc('Used disk space', 'used') + ' (%d%%)'
14 installRemovePackage: function(name)
16 if (typeof(name) != 'string')
19 var pkgname = (name || this.getAttribute('name')).replace(/^.*\//, '');
20 var installed = name ? false : !!this.getAttribute('installed');
21 var action = installed ? L.opkg.removePackage : L.opkg.installPackage;
22 var title = (installed ? L.tr('Removing package "%s" …') : L.tr('Installing package "%s" …')).format(pkgname);
23 var confirm = (installed ? L.tr('Really remove package "%h" ?') : L.tr('Really install package "%h" ?')).format(pkgname);
27 L.ui.dialog(title, confirm, {
30 L.ui.dialog(title, L.tr('Waiting for package manager …'), { style: 'wait' });
32 action(name || pkgname).then(function(res) {
33 self.fetchInstalledList().then(function() { return self.fetchPackageList(); }).then(function() {
37 output.push($('<pre />').text(res.stdout));
40 output.push($('<pre />').addClass('alert-message').text(res.stderr));
42 output.push(res.code ? L.tr('Package manager failed with status %d.').format(res.code) : L.tr('Package manager finished successfully.'));
44 L.ui.dialog(title, output, { style: 'close' });
47 $('#package_url').val('');
54 fetchInstalledList: function()
57 return L.opkg.installedPackages(0, 0, '*').then(function(list) {
58 self.installedList = { };
59 for (var i = 0; i < list.length; i++)
60 self.installedList[list[i][0]] = true;
64 fetchPackageList: function(offset, interactive)
69 if (typeof(offset) == 'undefined')
70 offset = parseInt($('#package_filter').attr('offset')) || 0;
72 var pattern = $('#package_filter').val() || '';
77 action = $('#package_which').prop('checked') ? L.opkg.installedPackages : L.opkg.findPackages;
78 pattern = '*' + pattern + '*';
80 $('#package_filter').next().attr('src', L.globals.resource + '/icons/cbi/remove.gif');
84 action = $('#package_which').prop('checked') ? L.opkg.installedPackages : L.opkg.listPackages;
87 $('#package_filter').next().attr('src', L.globals.resource + '/icons/cbi/find.gif');
90 $('#package_filter').attr('offset', offset);
92 var install_disabled = $('#package_install').attr('disabled');
95 return action(offset, 100, pattern).then(function(list) {
96 var packageTable = new L.ui.table({
97 placeholder: L.tr('No matching packages found.'),
99 caption: L.trc('Package table header', 'Package'),
102 caption: L.trc('Package table header', 'Version'),
104 format: function(v) {
105 return (v.length > 15 ? v.substring(0, 14) + '…' : v);
108 caption: L.trc('Package table header', 'Description'),
111 caption: L.trc('Package table header', 'Installation Status'),
114 format: function(v, n) {
115 var inst = self.installedList[list[n][0]];
116 return $('<button />')
117 .css('width', '100%')
118 .attr('disabled', install_disabled)
119 .attr('name', list[n][0])
120 .attr('installed', inst)
121 .addClass('cbi-button')
122 .addClass(inst ? 'cbi-button-apply' : 'cbi-button-reset')
123 .text(inst ? L.trc('Package state', 'Installed') : L.trc('Package state', 'Not installed'))
124 .click(self.installRemovePackage);
129 packageTable.rows(list);
130 packageTable.insertInto('#package_table');
134 .attr('offset', offset - 100)
135 .attr('disabled', false)
136 .val('« %d - %d'.format(offset - 100 + 1, offset));
139 .attr('disabled', true)
140 .val('« %d - %d'.format(1, Math.min(100, list.total)));
142 if ((offset + 100) < list.total)
144 .attr('offset', offset + 100)
145 .attr('disabled', false)
146 .val('%d - %d »'.format(offset + 100 + 1, Math.min(offset + 200, list.total)));
149 .attr('disabled', true)
150 .val('%d - %d »'.format(list.total - (list.total % 100) + 1, list.total));
154 }).then(self.updateDiskSpace);
161 $('textarea, input.cbi-button-save').attr('disabled', !this.options.acls.software);
162 $('#package_update, #package_url, #package_install').attr('disabled', !this.options.acls.software);
165 L.opkg.getConfig().then(function(config) {
167 .attr('rows', (config.match(/\n/g) || [ ]).length + 1)
170 $('input.cbi-button-save')
172 var data = ($('textarea').val() || '').replace(/\r/g, '').replace(/\n?$/, '\n');
174 L.opkg.setConfig(data).then(function() {
176 .attr('rows', (data.match(/\n/g) || [ ]).length + 1)
183 self.fetchInstalledList(),
184 self.updateDiskSpace()
186 $('#tabs').show().tabs();
188 $('#package_prev, #package_next').click(function(ev) {
189 if (!this.getAttribute('disabled'))
191 self.fetchPackageList(parseInt(this.getAttribute('offset')), true);
196 $('#package_filter').next().click(function(ev) {
197 if (this.getAttribute('src').indexOf('remove.gif') > -1)
198 $('#package_filter').val('');
200 self.fetchPackageList(0, true);
203 $('#package_filter').keyup(function(ev) {
208 self.fetchPackageList(0, true);
212 $('#package_which').click(function(ev) {
214 self.fetchPackageList(0, true);
217 $('#package_url').keyup(function(ev) {
224 self.installRemovePackage(this.value);
227 $('#package_install').click(function(ev) {
228 var name = $('#package_url').val();
230 self.installRemovePackage(name);
233 $('#package_update').click(function(ev) {
234 L.ui.dialog(L.tr('Updating package lists'), L.tr('Waiting for package manager …'), { style: 'wait' });
235 L.opkg.updateLists().then(function(res) {
239 output.push($('<pre />').text(res.stdout));
242 output.push($('<pre />').addClass('alert-message').text(res.stderr));
244 output.push(res.code ? L.tr('Package manager failed with status %d.').format(res.code) : L.tr('Package manager finished successfully.'));
246 L.ui.dialog(L.tr('Updating package lists'), output, { style: 'close' });
250 return self.fetchPackageList(0);