]> source.dussan.org Git - nextcloud-server.git/commitdiff
Improve app-management
authorkondou <kondou@ts.unde.re>
Tue, 6 Aug 2013 15:19:18 +0000 (17:19 +0200)
committerkondou <kondou@ts.unde.re>
Tue, 6 Aug 2013 15:19:18 +0000 (17:19 +0200)
- Better error messages

- Translate untranslated strings

Basically picks non-app-dependency related stuff from #4017

lib/app.php
settings/ajax/enableapp.php
settings/js/apps.js

index 2437896157ae5c272556cfa82c852f84f8d3f356..1ff18c799cb9e2b04913d5b1fff66333409ec359 100644 (file)
@@ -210,7 +210,8 @@ class OC_App{
        /**
         * @brief enables an app
         * @param mixed $app app
-        * @return bool
+        * @throws \Exception
+        * @return void
         *
         * This function set an app as enabled in appconfig.
         */
@@ -228,6 +229,7 @@ class OC_App{
                                }
                        }
                }
+               $l = OC_L10N::get('core');
                if($app!==false) {
                        // check if the app is compatible with this version of ownCloud
                        $info=OC_App::getAppInfo($app);
@@ -237,16 +239,15 @@ class OC_App{
                                        'App "'.$info['name'].'" can\'t be installed because it is'
                                        .' not compatible with this version of ownCloud',
                                        OC_Log::ERROR);
-                               return false;
+                               throw new \Exception($l->t("App can't be installed because it is not compatible with this version of ownCloud."));
                        }else{
                                OC_Appconfig::setValue( $app, 'enabled', 'yes' );
                                if(isset($appdata['id'])) {
                                        OC_Appconfig::setValue( $app, 'ocsid', $appdata['id'] );
                                }
-                               return true;
                        }
                }else{
-                       return false;
+                       throw new \Exception($l->t("No app name specified"));
                }
        }
 
index ab84aee516653c0fc14cf1e7ce538caae9b2723c..0784736a65530b82cb01dbeed5cfb781893469bb 100644 (file)
@@ -3,10 +3,9 @@
 OC_JSON::checkAdminUser();
 OCP\JSON::callCheck();
 
-$appid = OC_App::enable(OC_App::cleanAppId($_POST['appid']));
-if($appid !== false) {
-       OC_JSON::success(array('data' => array('appid' => $appid)));
-} else {
-       $l = OC_L10N::get('settings');  
-       OC_JSON::error(array("data" => array( "message" => $l->t("Could not enable app. ") )));
+try {
+       OC_App::enable(OC_App::cleanAppId($_POST['appid']));
+       OC_JSON::success();
+} catch (Exception $e) {
+       OC_JSON::error(array("data" => array("message" => $e->getMessage()) ));
 }
index 0540d9b1c58227d9d12e151766678101d93b0441..6b32686a693299813dedbba07b7e81a51bef5944 100644 (file)
@@ -61,7 +61,11 @@ OC.Settings.Apps = OC.Settings.Apps || {
                if(active) {
                        $.post(OC.filePath('settings','ajax','disableapp.php'),{appid:appid},function(result) {
                                if(!result || result.status !== 'success') {
-                                       OC.dialogs.alert('Error while disabling app', t('core', 'Error'));
+                                       if (result.data && result.data.message) {
+                                               OC.dialogs.alert(result.data.message, t('core', 'Error'));
+                                       } else {
+                                               OC.dialogs.alert(t('settings', 'Error while disabling app'), t('core', 'Error'));
+                                       }
                                }
                                else {
                                        element.data('active',false);
@@ -73,16 +77,20 @@ OC.Settings.Apps = OC.Settings.Apps || {
                } else {
                        $.post(OC.filePath('settings','ajax','enableapp.php'),{appid:appid},function(result) {
                                if(!result || result.status !== 'success') {
-                                       OC.dialogs.alert('Error while enabling app', t('core', 'Error'));
-                               }
-                               else {
+                                       if (result.data && result.data.message) {
+                                               OC.dialogs.alert(result.data.message, t('core', 'Error'));
+                                       } else {
+                                               OC.dialogs.alert(t('settings', 'Error while enabling app'), t('core', 'Error'));
+                                       }
+                                       element.val(t('settings','Enable'));
+                               } else {
                                        OC.Settings.Apps.addNavigation(appid);
                                        element.data('active',true);
                                        element.val(t('settings','Disable'));
                                }
                        },'json')
                        .fail(function() { 
-                               OC.dialogs.alert('Error while enabling app', t('core', 'Error'));
+                               OC.dialogs.alert(t('settings', 'Error while enabling app'), t('core', 'Error'));
                                element.data('active',false);
                                OC.Settings.Apps.removeNavigation(appid);
                                element.val(t('settings','Enable'));