diff options
Diffstat (limited to 'settings/js/apps.js')
-rw-r--r-- | settings/js/apps.js | 221 |
1 files changed, 166 insertions, 55 deletions
diff --git a/settings/js/apps.js b/settings/js/apps.js index 3326886951f..6bad2cc842c 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -29,6 +29,7 @@ OC.Settings.Apps = OC.Settings.Apps || { State: { currentCategory: null, + currentCategoryElements: null, apps: null, $updateNotification: null, availableUpdates: 0 @@ -90,14 +91,15 @@ OC.Settings.Apps = OC.Settings.Apps || { }), { type:'GET', success: function (apps) { + OC.Settings.Apps.State.currentCategoryElements = apps.apps; var appListWithIndex = _.indexBy(apps.apps, 'id'); OC.Settings.Apps.State.apps = appListWithIndex; var appList = _.map(appListWithIndex, function(app) { // default values for missing fields return _.extend({level: 0}, app); }); - var source - if (categoryId === 'enabled' || categoryId === 'disabled' || categoryId === 'installed') { + var source; + if (categoryId === 'enabled' || categoryId === 'disabled' || categoryId === 'installed' || categoryId === 'app-bundles') { source = $("#app-template-installed").html(); $('#apps-list').addClass('installed'); } else { @@ -107,17 +109,19 @@ OC.Settings.Apps = OC.Settings.Apps || { var template = Handlebars.compile(source); if (appList.length) { - appList.sort(function(a,b) { - if (a.active !== b.active) { - return (a.active ? -1 : 1) - } else { - var levelDiff = b.level - a.level; - if (levelDiff === 0) { - return OC.Util.naturalSortCompare(a.name, b.name); + if(categoryId !== 'app-bundles') { + appList.sort(function (a, b) { + if (a.active !== b.active) { + return (a.active ? -1 : 1) + } else { + var levelDiff = b.level - a.level; + if (levelDiff === 0) { + return OC.Util.naturalSortCompare(a.name, b.name); + } + return levelDiff; } - return levelDiff; - } - }); + }); + } var firstExperimental = false; _.each(appList, function(app) { @@ -303,56 +307,126 @@ OC.Settings.Apps = OC.Settings.Apps || { return $.get(OC.generateUrl('apps/files')); }, - enableApp:function(appId, active, element, groups) { + enableAppBundle:function(bundleId, active, element, groups) { + if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { + OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableAppBundle, this, bundleId, active, element, groups)); + return; + } + + 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); + }, + + /** + * @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 …')); - $.post(OC.filePath('settings','ajax','enableapp.php'),{appid: appId, groups: groups},function(result) { + elements.forEach(function(element) { + element.val(t('settings', 'Enabling app …')); + }); + + var appIdArray = []; + if( typeof appId === 'string' ) { + appIdArray = [appId]; + } else { + appIdArray = appId; + } + $.post(OC.filePath('settings','ajax','enableapp.php'),{appIds: appIdArray, groups: groups},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 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) { @@ -364,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() { @@ -391,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')); + }); }); } }, @@ -774,10 +878,17 @@ 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'); - OC.Settings.Apps.enableApp(appId, active, element); + var category = $('#app-navigation').attr('data-category'); + if(bundleId) { + OC.Settings.Apps.enableAppBundle(bundleId, active, element); + element.val(t('settings', 'Enable all')); + } else { + OC.Settings.Apps.enableApp([appId], active); + } }); $(document).on('click', '#apps-list input.uninstall', function () { @@ -805,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; } }); |