diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-04-25 21:06:24 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2017-04-26 20:07:50 +0200 |
commit | 732c92e93abfc200e4eee90a8e727ef562dc5604 (patch) | |
tree | 1ecd9e4f31efd62803c8693637fb4e845349e982 /settings | |
parent | da67264a238d0351029b5b452aa254caa652df1c (diff) | |
download | nextcloud-server-732c92e93abfc200e4eee90a8e727ef562dc5604.tar.gz nextcloud-server-732c92e93abfc200e4eee90a8e727ef562dc5604.zip |
Make disableapp.php accept arrays
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'settings')
-rw-r--r-- | settings/Controller/AppSettingsController.php | 2 | ||||
-rw-r--r-- | settings/ajax/disableapp.php | 9 | ||||
-rw-r--r-- | settings/js/apps.js | 177 |
3 files changed, 135 insertions, 53 deletions
diff --git a/settings/Controller/AppSettingsController.php b/settings/Controller/AppSettingsController.php index f3ef715a235..4cd4afd01dd 100644 --- a/settings/Controller/AppSettingsController.php +++ b/settings/Controller/AppSettingsController.php @@ -370,9 +370,9 @@ class AppSettingsController extends Controller { if($app['id'] === $identifier) { if($newCategory) { $app['newCategory'] = true; - $app['bundleId'] = $bundle->getIdentifier(); $app['categoryName'] = $bundle->getName(); } + $app['bundleId'] = $bundle->getIdentifier(); $newCategory = false; $apps[] = $app; continue; diff --git a/settings/ajax/disableapp.php b/settings/ajax/disableapp.php index 8edd1c1453e..9b76236a15b 100644 --- a/settings/ajax/disableapp.php +++ b/settings/ajax/disableapp.php @@ -36,8 +36,9 @@ if (!array_key_exists('appid', $_POST)) { exit; } -$appId = (string)$_POST['appid']; -$appId = OC_App::cleanAppId($appId); - -OC_App::disable($appId); +$appIds = (array)$_POST['appid']; +foreach($appIds as $appId) { + $appId = OC_App::cleanAppId($appId); + OC_App::disable($appId); +} OC_JSON::success(); diff --git a/settings/js/apps.js b/settings/js/apps.js index a8ef11c0856..79b6af287fd 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -313,53 +313,94 @@ OC.Settings.Apps = OC.Settings.Apps || { return; } - var bundles = OC.Settings.Apps.State.currentCategoryElements; - bundles.forEach(function(bundle) { - if(bundle['id'] === bundleId) { - OC.Settings.Apps.enableApp(bundle['apps'], active, element, groups); + var apps = OC.Settings.Apps.State.currentCategoryElements; + var appsToEnable = []; + apps.forEach(function(app) { + if(app['bundleId'] === bundleId) { + if(app['active'] === false) { + appsToEnable.push(app['id']); + } } }); + + OC.Settings.Apps.enableApp(appsToEnable, false, groups); }, - enableApp:function(appId, active, element, groups) { + /** + * @param {string[]} appId + * @param {boolean} active + * @param {array} groups + */ + enableApp:function(appId, active, groups) { if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { - OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableApp, this, appId, active, element, groups)); + OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableApp, this, appId, active, groups)); return; } + var elements = []; + appId.forEach(function(appId) { + elements.push($('#app-'+appId+' .enable')); + }); + var self = this; - OC.Settings.Apps.hideErrorMessage(appId); + appId.forEach(function(appId) { + OC.Settings.Apps.hideErrorMessage(appId); + }); groups = groups || []; - var appItem = $('div#app-'+appId+''); + var appItems = []; + appId.forEach(function(appId) { + appItems.push($('div#app-'+appId+'')); + }); + if(active && !groups.length) { - element.val(t('settings','Disabling app …')); + elements.forEach(function(element) { + element.val(t('settings','Disabling app …')); + }); $.post(OC.filePath('settings','ajax','disableapp.php'),{appid:appId},function(result) { if(!result || result.status !== 'success') { if (result.data && result.data.message) { OC.Settings.Apps.showErrorMessage(appId, result.data.message); - appItem.data('errormsg', result.data.message); + appItems.forEach(function(appItem) { + appItem.data('errormsg', result.data.message); + }) } else { OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while disabling app')); - appItem.data('errormsg', t('settings', 'Error while disabling app')); + appItems.forEach(function(appItem) { + appItem.data('errormsg', t('settings', 'Error while disabling app')); + }); } - element.val(t('settings','Disable')); - appItem.addClass('appwarning'); + elements.forEach(function(element) { + element.val(t('settings','Disable')); + }); + appItems.forEach(function(appItem) { + appItem.addClass('appwarning'); + }); } else { OC.Settings.Apps.rebuildNavigation(); - appItem.data('active',false); - appItem.data('groups', ''); - element.data('active',false); - appItem.removeClass('active'); - element.val(t('settings','Enable')); - element.parent().find(".groups-enable").hide(); - element.parent().find('#group_select').hide().val(null); + appItems.forEach(function(appItem) { + appItem.data('active', false); + appItem.data('groups', ''); + }); + elements.forEach(function(element) { + element.data('active', false); + }); + appItems.forEach(function(appItem) { + appItem.removeClass('active'); + }); + elements.forEach(function(element) { + element.val(t('settings', 'Enable')); + element.parent().find(".groups-enable").hide(); + element.parent().find('#group_select').hide().val(null); + }); OC.Settings.Apps.State.apps[appId].active = false; } },'json'); } else { // TODO: display message to admin to not refresh the page! // TODO: lock UI to prevent further operations - element.val(t('settings','Enabling app …')); + elements.forEach(function(element) { + element.val(t('settings', 'Enabling app …')); + }); var appIdArray = []; if( typeof appId === 'string' ) { @@ -371,13 +412,21 @@ OC.Settings.Apps = OC.Settings.Apps || { if(!result || result.status !== 'success') { if (result.data && result.data.message) { OC.Settings.Apps.showErrorMessage(appId, result.data.message); - appItem.data('errormsg', result.data.message); + appItems.forEach(function(appItem) { + appItem.data('errormsg', result.data.message); + }); } else { OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while enabling app')); - appItem.data('errormsg', t('settings', 'Error while disabling app')); + appItems.forEach(function(appItem) { + appItem.data('errormsg', t('settings', 'Error while disabling app')); + }); } - element.val(t('settings','Enable')); - appItem.addClass('appwarning'); + elements.forEach(function(element) { + element.val(t('settings', 'Enable')); + }); + appItems.forEach(function(appItem) { + appItem.addClass('appwarning'); + }); } else { self._checkServerHealth().done(function() { if (result.data.update_required) { @@ -389,24 +438,40 @@ OC.Settings.Apps = OC.Settings.Apps || { } OC.Settings.Apps.rebuildNavigation(); - appItem.data('active',true); - element.data('active',true); - appItem.addClass('active'); - element.val(t('settings','Disable')); + appItems.forEach(function(appItem) { + appItem.data('active', true); + }); + elements.forEach(function(element) { + element.data('active', true); + }); + appItems.forEach(function(appItem) { + appItem.addClass('active'); + }); + elements.forEach(function(element) { + element.val(t('settings', 'Disable')); + }); var app = OC.Settings.Apps.State.apps[appId]; app.active = true; if (OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') || OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging')) { - element.parent().find(".groups-enable").prop('checked', true); - element.parent().find(".groups-enable").hide(); - element.parent().find('#group_select').hide().val(null); + elements.forEach(function(element) { + element.parent().find(".groups-enable").prop('checked', true); + element.parent().find(".groups-enable").hide(); + element.parent().find('#group_select').hide().val(null); + }); } else { - element.parent().find("#groups-enable").show(); + elements.forEach(function(element) { + element.parent().find("#groups-enable").show(); + }); if (groups) { - appItem.data('groups', JSON.stringify(groups)); + appItems.forEach(function(appItem) { + appItem.data('groups', JSON.stringify(groups)); + }); } else { - appItem.data('groups', ''); + appItems.forEach(function(appItem) { + appItem.data('groups', ''); + }); } } }).fail(function() { @@ -416,26 +481,40 @@ OC.Settings.Apps = OC.Settings.Apps || { appId, t('settings', 'Error: this app cannot be enabled because it makes the server unstable') ); - appItem.data('errormsg', t('settings', 'Error while enabling app')); - element.val(t('settings','Enable')); - appItem.addClass('appwarning'); + appItems.forEach(function(appItem) { + appItem.data('errormsg', t('settings', 'Error while enabling app')); + }); + elements.forEach(function(element) { + element.val(t('settings', 'Enable')); + }); + appItems.forEach(function(appItem) { + appItem.addClass('appwarning'); + }); }).fail(function() { OC.Settings.Apps.showErrorMessage( appId, t('settings', 'Error: could not disable broken app') ); - appItem.data('errormsg', t('settings', 'Error while disabling broken app')); - element.val(t('settings','Enable')); + appItems.forEach(function(appItem) { + appItem.data('errormsg', t('settings', 'Error while disabling broken app')); + }); + elements.forEach(function(element) { + element.val(t('settings', 'Enable')); + }); }); }); } },'json') .fail(function() { OC.Settings.Apps.showErrorMessage(appId, t('settings', 'Error while enabling app')); - appItem.data('errormsg', t('settings', 'Error while enabling app')); - appItem.data('active',false); - appItem.addClass('appwarning'); - element.val(t('settings','Enable')); + appItems.forEach(function(appItem) { + appItem.data('errormsg', t('settings', 'Error while enabling app')); + appItem.data('active', false); + appItem.addClass('appwarning'); + }); + elements.forEach(function(element) { + element.val(t('settings', 'Enable')); + }); }); } }, @@ -799,14 +878,16 @@ OC.Settings.Apps = OC.Settings.Apps || { $(document).on('click', '#apps-list input.enable', function () { var appId = $(this).data('appid'); + var bundleId = $(this).data('bundleid'); var element = $(this); var active = $(this).data('active'); var category = $('#app-navigation').attr('data-category'); - if(category === 'app-bundles') { - OC.Settings.Apps.enableAppBundle(appId, active, element); + if(bundleId) { + OC.Settings.Apps.enableAppBundle(bundleId, active, element); + element.val(t('settings', 'Enable all')); } else { - OC.Settings.Apps.enableApp(appId, active, element); + OC.Settings.Apps.enableApp([appId], active); } }); @@ -835,7 +916,7 @@ OC.Settings.Apps = OC.Settings.Apps || { var appId = element.data('appid'); if (appId) { - OC.Settings.Apps.enableApp(appId, false, element, groups); + OC.Settings.Apps.enableApp([appId], false, groups); OC.Settings.Apps.State.apps[appId].groups = groups; } }); |