luci2: implement LuCI2.session.updateACLs() and LuCI2.session.hasACL()
[project/luci2/ui.git] / luci2 / htdocs / luci2 / view / system.software.js
index 7526e01..65a86ea 100644 (file)
@@ -1,7 +1,9 @@
 L.ui.view.extend({
+       title: L.tr('Package management'),
+
        updateDiskSpace: function()
        {
-               return L.system.getInfo(function(info) {
+               return L.system.getDiskInfo().then(function(info) {
                        $('#package_space').empty().append(
                                new L.ui.progress({
                                        value:  info.root.used / 1024,
@@ -11,16 +13,12 @@ L.ui.view.extend({
                });
        },
 
-       installRemovePackage: function(name)
+       installRemovePackage: function(pkgname, installed)
        {
-               if (typeof(name) != 'string')
-                       name = undefined;
-
-               var pkgname   = (name || this.getAttribute('name')).replace(/^.*\//, '');
-               var installed = name ? false : !!this.getAttribute('installed');
+               var dspname   = pkgname.replace(/^.+\//, '');
                var action    = installed ? L.opkg.removePackage : L.opkg.installPackage;
-               var title     = (installed ? L.tr('Removing package "%s" …') : L.tr('Installing package "%s" …')).format(pkgname);
-               var confirm   = (installed ? L.tr('Really remove package "%h" ?') : L.tr('Really install package "%h" ?')).format(pkgname);
+               var title     = (installed ? L.tr('Removing package "%s" …') : L.tr('Installing package "%s" …')).format(dspname);
+               var confirm   = (installed ? L.tr('Really remove package "%h" ?') : L.tr('Really install package "%h" ?')).format(dspname);
 
                var self = this;
 
@@ -29,8 +27,8 @@ L.ui.view.extend({
                        confirm: function() {
                                L.ui.dialog(title, L.tr('Waiting for package manager …'), { style: 'wait' });
 
-                               action(name || pkgname).then(function(res) {
-                                       self.fetchInstalledList().then(function() { return fetchPackageList(); }).then(function() {
+                               action(pkgname).then(function(res) {
+                                       self.fetchInstalledList().then(function() { return self.fetchPackageList(); }).then(function() {
                                                var output = [ ];
 
                                                if (res.stdout)
@@ -54,11 +52,11 @@ L.ui.view.extend({
        fetchInstalledList: function()
        {
                var self = this;
-               return L.opkg.installedPackages(0, 0, '*'function(list) {
+               return L.opkg.installedPackages(0, 0, '*').then(function(list) {
                        self.installedList = { };
                        for (var i = 0; i < list.length; i++)
                                self.installedList[list[i][0]] = true;
-               })
+               });
        },
 
        fetchPackageList: function(offset, interactive)
@@ -92,7 +90,7 @@ L.ui.view.extend({
                var install_disabled = $('#package_install').attr('disabled');
                var self = this;
 
-               return action(offset, 100, patternfunction(list) {
+               return action(offset, 100, pattern).then(function(list) {
                        var packageTable = new L.ui.table({
                                placeholder: L.tr('No matching packages found.'),
                                columns: [ {
@@ -113,15 +111,14 @@ L.ui.view.extend({
                                        width:   '120px',
                                        format: function(v, n) {
                                                var inst = self.installedList[list[n][0]];
-                                               return $('<button />')
+                                               return L.ui.button(inst ? L.trc('Package state', 'Installed') : L.trc('Package state', 'Not installed'), inst ? 'success' : 'danger')
                                                        .css('width', '100%')
                                                        .attr('disabled', install_disabled)
-                                                       .attr('name', list[n][0])
+                                                       .attr('pkgname', list[n][0])
                                                        .attr('installed', inst)
-                                                       .addClass('cbi-button')
-                                                       .addClass(inst ? 'cbi-button-apply' : 'cbi-button-reset')
-                                                       .text(inst ? L.trc('Package state', 'Installed') : L.trc('Package state', 'Not installed'))
-                                                       .click(self.installRemovePackage);
+                                                       .click(function() {
+                                                               self.installRemovePackage(this.getAttribute('pkgname'), this.getAttribute('installed') == 'true');
+                                                       });
                                        }
                                } ]
                        });
@@ -133,21 +130,21 @@ L.ui.view.extend({
                                $('#package_prev')
                                        .attr('offset', offset - 100)
                                        .attr('disabled', false)
-                                       .val('« %d - %d'.format(offset - 100 + 1, offset));
+                                       .text('« %d - %d'.format(offset - 100 + 1, offset));
                        else
                                $('#package_prev')
                                        .attr('disabled', true)
-                                       .val('« %d - %d'.format(1, Math.min(100, list.total)));
+                                       .text('« %d - %d'.format(1, Math.min(100, list.total)));
 
                        if ((offset + 100) < list.total)
                                $('#package_next')
                                        .attr('offset', offset + 100)
                                        .attr('disabled', false)
-                                       .val('%d - %d »'.format(offset + 100 + 1, Math.min(offset + 200, list.total)));
+                                       .text('%d - %d »'.format(offset + 100 + 1, Math.min(offset + 200, list.total)));
                        else
                                $('#package_next')
                                        .attr('disabled', true)
-                                       .val('%d - %d »'.format(list.total - (list.total % 100) + 1, list.total));
+                                       .text('%d - %d »'.format(list.total - (list.total % 100) + 1, list.total));
 
                        if (interactive)
                                L.ui.loading(false);
@@ -162,17 +159,17 @@ L.ui.view.extend({
                $('#package_update, #package_url, #package_install').attr('disabled', !this.options.acls.software);
 
                return $.when(
-                       L.opkg.getConfig(function(config) {
-                               $('textarea')
+                       L.opkg.getConfig().then(function(config) {
+                               $('#config textarea')
                                        .attr('rows', (config.match(/\n/g) || [ ]).length + 1)
                                        .val(config);
 
-                               $('input.cbi-button-save')
+                               $('#config button')
                                        .click(function() {
-                                               var data = ($('textarea').val() || '').replace(/\r/g, '').replace(/\n?$/, '\n');
+                                               var data = ($('#config textarea').val() || '').replace(/\r/g, '').replace(/\n?$/, '\n');
                                                L.ui.loading(true);
-                                               L.opkg.setConfig(datafunction() {
-                                                       $('textarea')
+                                               L.opkg.setConfig(data).then(function() {
+                                                       $('#config textarea')
                                                                .attr('rows', (data.match(/\n/g) || [ ]).length + 1)
                                                                .val(data);
 
@@ -183,8 +180,6 @@ L.ui.view.extend({
                        self.fetchInstalledList(),
                        self.updateDiskSpace()
                ).then(function() {
-                       $('#tabs').show().tabs();
-
                        $('#package_prev, #package_next').click(function(ev) {
                                if (!this.getAttribute('disabled'))
                                {
@@ -194,9 +189,7 @@ L.ui.view.extend({
                        });
 
                        $('#package_filter').next().click(function(ev) {
-                               if (this.getAttribute('src').indexOf('remove.gif') > -1)
-                                       $('#package_filter').val('');
-
+                               $('#package_filter').val('');
                                self.fetchPackageList(0, true);
                        });
 
@@ -221,18 +214,18 @@ L.ui.view.extend({
                                ev.preventDefault();
 
                                if (this.value)
-                                       self.installRemovePackage(this.value);
+                                       self.installRemovePackage(this.value, false);
                        });
 
                        $('#package_install').click(function(ev) {
                                var name = $('#package_url').val();
                                if (name)
-                                       self.installRemovePackage(name);
+                                       self.installRemovePackage(name, false);
                        });
 
                        $('#package_update').click(function(ev) {
                                L.ui.dialog(L.tr('Updating package lists'), L.tr('Waiting for package manager …'), { style: 'wait' });
-                               L.opkg.updateLists(function(res) {
+                               L.opkg.updateLists().then(function(res) {
                                        var output = [ ];
 
                                        if (res.stdout)