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(pkgname, installed)
16 var dspname = pkgname.replace(/^.+\//, '');
17 var action = installed ? L.opkg.removePackage : L.opkg.installPackage;
18 var title = (installed ? L.tr('Removing package "%s" …') : L.tr('Installing package "%s" …')).format(dspname);
19 var confirm = (installed ? L.tr('Really remove package "%h" ?') : L.tr('Really install package "%h" ?')).format(dspname);
23 L.ui.dialog(title, confirm, {
26 L.ui.dialog(title, L.tr('Waiting for package manager …'), { style: 'wait' });
28 action(pkgname).then(function(res) {
29 self.fetchInstalledList().then(function() { return self.fetchPackageList(); }).then(function() {
33 output.push($('<pre />').text(res.stdout));
36 output.push($('<pre />').addClass('alert-message').text(res.stderr));
38 output.push(res.code ? L.tr('Package manager failed with status %d.').format(res.code) : L.tr('Package manager finished successfully.'));
40 L.ui.dialog(title, output, { style: 'close' });
43 $('#package_url').val('');
50 fetchInstalledList: function()
53 return L.opkg.installedPackages(0, 0, '*').then(function(list) {
54 self.installedList = { };
55 for (var i = 0; i < list.length; i++)
56 self.installedList[list[i][0]] = true;
60 fetchPackageList: function(offset, interactive)
65 if (typeof(offset) == 'undefined')
66 offset = parseInt($('#package_filter').attr('offset')) || 0;
68 var pattern = $('#package_filter').val() || '';
73 action = $('#package_which').prop('checked') ? L.opkg.installedPackages : L.opkg.findPackages;
74 pattern = '*' + pattern + '*';
76 $('#package_filter').next().attr('src', L.globals.resource + '/icons/cbi/remove.gif');
80 action = $('#package_which').prop('checked') ? L.opkg.installedPackages : L.opkg.listPackages;
83 $('#package_filter').next().attr('src', L.globals.resource + '/icons/cbi/find.gif');
86 $('#package_filter').attr('offset', offset);
88 var install_disabled = $('#package_install').attr('disabled');
91 return action(offset, 100, pattern).then(function(list) {
92 var packageTable = new L.ui.table({
93 placeholder: L.tr('No matching packages found.'),
95 caption: L.trc('Package table header', 'Package'),
98 caption: L.trc('Package table header', 'Version'),
100 format: function(v) {
101 return (v.length > 15 ? v.substring(0, 14) + '…' : v);
104 caption: L.trc('Package table header', 'Description'),
107 caption: L.trc('Package table header', 'Installation Status'),
110 format: function(v, n) {
111 var inst = self.installedList[list[n][0]];
112 return $('<button />')
113 .css('width', '100%')
114 .attr('disabled', install_disabled)
115 .attr('pkgname', list[n][0])
116 .attr('installed', inst)
117 .addClass('cbi-button')
118 .addClass(inst ? 'cbi-button-apply' : 'cbi-button-reset')
119 .text(inst ? L.trc('Package state', 'Installed') : L.trc('Package state', 'Not installed'))
121 self.installRemovePackage(this.getAttribute('pkgname'), this.getAttribute('installed') == 'true');
127 packageTable.rows(list);
128 packageTable.insertInto('#package_table');
132 .attr('offset', offset - 100)
133 .attr('disabled', false)
134 .val('« %d - %d'.format(offset - 100 + 1, offset));
137 .attr('disabled', true)
138 .val('« %d - %d'.format(1, Math.min(100, list.total)));
140 if ((offset + 100) < list.total)
142 .attr('offset', offset + 100)
143 .attr('disabled', false)
144 .val('%d - %d »'.format(offset + 100 + 1, Math.min(offset + 200, list.total)));
147 .attr('disabled', true)
148 .val('%d - %d »'.format(list.total - (list.total % 100) + 1, list.total));
152 }).then(self.updateDiskSpace);
159 $('textarea, input.cbi-button-save').attr('disabled', !this.options.acls.software);
160 $('#package_update, #package_url, #package_install').attr('disabled', !this.options.acls.software);
163 L.opkg.getConfig().then(function(config) {
165 .attr('rows', (config.match(/\n/g) || [ ]).length + 1)
168 $('input.cbi-button-save')
170 var data = ($('textarea').val() || '').replace(/\r/g, '').replace(/\n?$/, '\n');
172 L.opkg.setConfig(data).then(function() {
174 .attr('rows', (data.match(/\n/g) || [ ]).length + 1)
181 self.fetchInstalledList(),
182 self.updateDiskSpace()
184 $('#tabs').show().tabs();
186 $('#package_prev, #package_next').click(function(ev) {
187 if (!this.getAttribute('disabled'))
189 self.fetchPackageList(parseInt(this.getAttribute('offset')), true);
194 $('#package_filter').next().click(function(ev) {
195 if (this.getAttribute('src').indexOf('remove.gif') > -1)
196 $('#package_filter').val('');
198 self.fetchPackageList(0, true);
201 $('#package_filter').keyup(function(ev) {
206 self.fetchPackageList(0, true);
210 $('#package_which').click(function(ev) {
212 self.fetchPackageList(0, true);
215 $('#package_url').keyup(function(ev) {
222 self.installRemovePackage(this.value, false);
225 $('#package_install').click(function(ev) {
226 var name = $('#package_url').val();
228 self.installRemovePackage(name, false);
231 $('#package_update').click(function(ev) {
232 L.ui.dialog(L.tr('Updating package lists'), L.tr('Waiting for package manager …'), { style: 'wait' });
233 L.opkg.updateLists().then(function(res) {
237 output.push($('<pre />').text(res.stdout));
240 output.push($('<pre />').addClass('alert-message').text(res.stderr));
242 output.push(res.code ? L.tr('Package manager failed with status %d.').format(res.code) : L.tr('Package manager finished successfully.'));
244 L.ui.dialog(L.tr('Updating package lists'), output, { style: 'close' });
248 return self.fetchPackageList(0);