diff options
author | kondou <kondou@ts.unde.re> | 2013-07-29 11:34:38 +0200 |
---|---|---|
committer | kondou <kondou@ts.unde.re> | 2013-08-25 21:04:04 +0200 |
commit | fac671b14ed06233d37ad38194ebf9a99118644a (patch) | |
tree | db99cca8e2ee41b79b444b44f8a429bf8fe32b8a /settings | |
parent | 4a08f7d710ced1c564e05471e1f873ecfb9ca161 (diff) | |
download | nextcloud-server-fac671b14ed06233d37ad38194ebf9a99118644a.tar.gz nextcloud-server-fac671b14ed06233d37ad38194ebf9a99118644a.zip |
Modularize get(), async getAvatar, avatars @ usermgmt
And other small improvements
Diffstat (limited to 'settings')
-rw-r--r-- | settings/ajax/newavatar.php | 30 | ||||
-rw-r--r-- | settings/js/personal.js | 24 | ||||
-rw-r--r-- | settings/routes.php | 2 | ||||
-rw-r--r-- | settings/templates/admin.php | 3 | ||||
-rw-r--r-- | settings/templates/personal.php | 7 | ||||
-rw-r--r-- | settings/templates/users.php | 6 | ||||
-rw-r--r-- | settings/users.php | 1 |
7 files changed, 71 insertions, 2 deletions
diff --git a/settings/ajax/newavatar.php b/settings/ajax/newavatar.php new file mode 100644 index 00000000000..b52317c9678 --- /dev/null +++ b/settings/ajax/newavatar.php @@ -0,0 +1,30 @@ +<?php + +OC_JSON::checkLoggedIn(); +OC_JSON::callCheck(); +$user = OC_User::getUser(); + +if(isset($_POST['path'])) { + $path = $_POST['path']; + if ($path === "false") { // delete avatar + \OC_Avatar::setLocalAvatar($user, false, false); + } else { // select an image from own files + $view = new \OC\Files\View('/'.$user.'/files'); + $img = $view->file_get_contents($path); + + $type = substr($path, -3); + if ($type === 'peg') { $type = 'jpg'; } + + if ($type === 'jpg' or $type === 'png') { + \OC_Avatar::setLocalAvatar($user, $img, $type); + OC_JSON::success(); + } else { + OC_JSON::error(); + } + } +} elseif (isset($_POST['image'])) { // upload a new image + \OC_Avatar::setLocalAvatar($user, $_POST['image']); + OC_JSON::success(); +} else { + OC_JSON::error(); +} diff --git a/settings/js/personal.js b/settings/js/personal.js index 8ad26c086b5..fdaca07e98d 100644 --- a/settings/js/personal.js +++ b/settings/js/personal.js @@ -44,6 +44,17 @@ function changeDisplayName(){ } } +function selectAvatar (path) { + $.post(OC.filePath('settings', 'ajax', 'newavatar.php'), {path: path}); + updateAvatar(); +} + +function updateAvatar () { + $.post(OC.filePath('core', 'ajax', 'getavatar.php'), {user: OC.currentUser, size: 128}, function(data){ + $('#avatar img').attr('src', data.data); + }); +} + $(document).ready(function(){ $("#passwordbutton").click( function(){ if ($('#pass1').val() !== '' && $('#pass2').val() !== '') { @@ -128,6 +139,19 @@ $(document).ready(function(){ } }); + $('#uploadavatar').click(function(){ + alert('To be done'); + updateAvatar(); + }); + + $('#selectavatar').click(function(){ + OC.dialogs.filepicker(t('settings', "Select an avatar"), selectAvatar, false, "image"); + }); + + $('#removeavatar').click(function(){ + $.post(OC.filePath('settings', 'ajax', 'newavatar.php'), {path: false}); + updateAvatar(); + }); } ); OC.Encryption = { diff --git a/settings/routes.php b/settings/routes.php index 9a27c3e439b..7d323008419 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -72,3 +72,5 @@ $this->create('isadmin', '/settings/js/isadmin.js') ->actionInclude('settings/js/isadmin.php'); $this->create('settings_ajax_setavatarmode', '/settings/ajax/setavatarmode.php') ->actionInclude('settings/ajax/setavatarmode.php'); +$this->create('settings_ajax_newavatar', '/settings/ajax/newavatar.php') + ->actionInclude('settings/ajax/newavatar.php'); diff --git a/settings/templates/admin.php b/settings/templates/admin.php index a166aec7775..e5b941f2b2f 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -128,6 +128,9 @@ if (!$_['internetconnectionworking']) { <label for="avatar_gravatar">Gravatar</label><br> <em><?php print_unescaped($l->t('Use <a href="http://gravatar.com/">gravatar</a> for avatars')); ?></em><br> <em><?php p($l->t('This sends data to gravatar')); ?></em> + <?php if (!$_['internetconnectionworking']): ?> + <br><em><?php p($l->t('Gravatar needs an internet connection!')); ?></em> + <?php endif; ?> </td> </tr> <tr> diff --git a/settings/templates/personal.php b/settings/templates/personal.php index 55f626aa574..01415a6f9a1 100644 --- a/settings/templates/personal.php +++ b/settings/templates/personal.php @@ -87,8 +87,11 @@ if($_['passwordChangeSupported']) { <form id="avatar"> <fieldset class="personalblock"> <legend><strong><?php p($l->t('Avatar')); ?></strong></legend> - <img src="<?php print_unescaped(\OC_Avatar::get(\OC_User::getUser())); ?>"><br> - <button><?php p($l->t('Upload a new avatar')); ?></button> + <img src="<?php print_unescaped(\OC_Avatar::get(\OC_User::getUser(), 128)); ?>"><br> + <em><?php p($l->t('Your avatar has to be a square and either a PNG or JPG image')); ?></em><br> + <div class="inlineblock button" id="uploadavatar"><?php p($l->t('Upload a new avatar')); ?></div> + <div class="inlineblock button" id="selectavatar"><?php p($l->t('Select a new avatar from your files')); ?></div> + <div class="inlineblock button" id="removeavatar"><?php p($l->t('Remove my avatar')); ?></div> </fieldset> </form> <?php endif; ?> diff --git a/settings/templates/users.php b/settings/templates/users.php index 22450fdf25f..81d9a46d89d 100644 --- a/settings/templates/users.php +++ b/settings/templates/users.php @@ -81,6 +81,9 @@ $_['subadmingroups'] = array_flip($items); <table class="hascontrols" data-groups="<?php p(json_encode($allGroups));?>"> <thead> <tr> + <?php if(\OC_Avatar::getMode() !== "none"): ?> + <th id='headerAvatar'><?php p($l->t('Avatar')); ?></th> + <?php endif; ?> <th id='headerName'><?php p($l->t('Username'))?></th> <th id="headerDisplayName"><?php p($l->t( 'Display Name' )); ?></th> <th id="headerPassword"><?php p($l->t( 'Password' )); ?></th> @@ -96,6 +99,9 @@ $_['subadmingroups'] = array_flip($items); <?php foreach($_["users"] as $user): ?> <tr data-uid="<?php p($user["name"]) ?>" data-displayName="<?php p($user["displayName"]) ?>"> + <?php if(\OC_Avatar::getMode() !== "none"): ?> + <td class="avatar"><img src="<?php p($user["avatar"]); ?>"></td> + <?php endif; ?> <td class="name"><?php p($user["name"]); ?></td> <td class="displayName"><span><?php p($user["displayName"]); ?></span> <img class="svg action" src="<?php p(image_path('core', 'actions/rename.svg'))?>" diff --git a/settings/users.php b/settings/users.php index 213d1eecfda..7dba45e1284 100644 --- a/settings/users.php +++ b/settings/users.php @@ -58,6 +58,7 @@ foreach($accessibleusers as $uid => $displayName) { $users[] = array( "name" => $uid, + "avatar" => \OC_Avatar::get($uid, 32), "displayName" => $displayName, "groups" => OC_Group::getUserGroups($uid), 'quota' => $quota, |