]> source.dussan.org Git - nextcloud-server.git/commitdiff
show/hide navigation entries after enabling/disabling app
authorRobin Appelman <icewind@owncloud.com>
Fri, 26 Oct 2012 18:12:14 +0000 (20:12 +0200)
committerRobin Appelman <icewind@owncloud.com>
Fri, 26 Oct 2012 18:13:24 +0000 (20:13 +0200)
core/ajax/navigationdetect.php [new file with mode: 0644]
settings/js/apps.js

diff --git a/core/ajax/navigationdetect.php b/core/ajax/navigationdetect.php
new file mode 100644 (file)
index 0000000..c7d0bd3
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+
+$RUNTIME_NOAPPS = true;
+
+require_once '../../lib/base.php';
+
+OC_Util::checkAdminUser();
+OCP\JSON::callCheck();
+
+$app = $_GET['app'];
+
+//load the one app and see what it adds to the navigation
+OC_App::loadApp($app);
+
+$navigation = OC_App::getNavigation();
+
+$navIds = array();
+foreach ($navigation as $nav) {
+       $navIds[] = $nav['id'];
+}
+
+OCP\JSON::success(array('nav_ids' => array_values($navIds), 'nav_entries' => $navigation));
index 8de95100c4c59e9f912c43f1b5814ac1c56a474e..e45abf9b3dde4f6ee895dbabe24dfd367fc49ba1 100644 (file)
@@ -51,6 +51,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
                                }
                                else {
                                        element.data('active',false);
+                                       OC.Settings.Apps.removeNavigation(appid);
                                        element.val(t('settings','Enable'));
                                }
                        },'json');
@@ -61,6 +62,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
                                        OC.dialogs.alert('Error while enabling app','Error');
                                }
                                else {
+                                       OC.Settings.Apps.addNavigation(appid);
                                        element.data('active',true);
                                        element.val(t('settings','Disable'));
                                }
@@ -87,6 +89,38 @@ OC.Settings.Apps = OC.Settings.Apps || {
                        applist.last().after(app);
                }
                return app;
+       },
+       removeNavigation: function(appid){
+               $.getJSON(OC.filePath('core','ajax','navigationdetect.php'), {app: appid}).done(function(response){
+                       if(response.status === 'success'){
+                               var navIds=response.nav_ids;
+                               for(var i=0; i< navIds.length; i++){
+                                       $('#apps').children('li[data-id="'+navIds[i]+'"]').remove();
+                               }
+                       }
+               });
+       },
+       addNavigation: function(appid){
+               $.getJSON(OC.filePath('core','ajax','navigationdetect.php'), {app: appid}).done(function(response){
+                       if(response.status === 'success'){
+                               var navEntries=response.nav_entries;
+                               for(var i=0; i< navEntries.length; i++){
+                                       var entry = navEntries[i];
+                                       var container = $('#apps');
+
+                                       if(container.children('li[data-id="'+entry.id+'"]').length === 0){
+                                               var li=$('<li></li>');
+                                               li.attr('data-id', entry.id);
+                                               var a=$('<a></a>');
+                                               a.attr('style', 'background-image: url('+entry.icon+')');
+                                               a.text(entry.name);
+                                               a.attr('href', entry.href);
+                                               li.append(a);
+                                               container.append(li);
+                                       }
+                               }
+                       }
+               });
        }
 };