diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 43580a51f7..9920d554e6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -38,6 +38,7 @@ phutil_register_library_map(array( 'AphrontFormDividerControl' => 'view/form/control/AphrontFormDividerControl.php', 'AphrontFormDragAndDropUploadControl' => 'view/form/control/AphrontFormDragAndDropUploadControl.php', 'AphrontFormFileControl' => 'view/form/control/AphrontFormFileControl.php', + 'AphrontFormImageControl' => 'view/form/control/AphrontFormImageControl.php', 'AphrontFormInsetView' => 'view/form/AphrontFormInsetView.php', 'AphrontFormLayoutView' => 'view/form/AphrontFormLayoutView.php', 'AphrontFormMarkupControl' => 'view/form/control/AphrontFormMarkupControl.php', @@ -1125,6 +1126,7 @@ phutil_register_library_map(array( 'AphrontFormDividerControl' => 'AphrontFormControl', 'AphrontFormDragAndDropUploadControl' => 'AphrontFormControl', 'AphrontFormFileControl' => 'AphrontFormControl', + 'AphrontFormImageControl' => 'AphrontFormControl', 'AphrontFormInsetView' => 'AphrontView', 'AphrontFormLayoutView' => 'AphrontView', 'AphrontFormMarkupControl' => 'AphrontFormControl', diff --git a/src/applications/people/controller/settings/panels/PhabricatorUserProfileSettingsPanelController.php b/src/applications/people/controller/settings/panels/PhabricatorUserProfileSettingsPanelController.php index c0f2807705..6cda66107c 100644 --- a/src/applications/people/controller/settings/panels/PhabricatorUserProfileSettingsPanelController.php +++ b/src/applications/people/controller/settings/panels/PhabricatorUserProfileSettingsPanelController.php @@ -51,7 +51,11 @@ final class PhabricatorUserProfileSettingsPanelController // Checked in runtime. $user->setTranslation($request->getStr('translation')); - if (!empty($_FILES['image'])) { + $default_image = $request->getExists('default_image'); + if ($default_image) { + $profile->setProfileImagePHID(null); + $user->setProfileImagePHID(null); + } else if (!empty($_FILES['image'])) { $err = idx($_FILES['image'], 'error'); if ($err != UPLOAD_ERR_NO_FILE) { $file = PhabricatorFile::newFromPHPUpload( @@ -188,7 +192,7 @@ final class PhabricatorUserProfileSettingsPanelController 'src' => $img_src, )))) ->appendChild( - id(new AphrontFormFileControl()) + id(new AphrontFormImageControl()) ->setLabel('Change Image') ->setName('image') ->setError($e_image) diff --git a/src/applications/project/controller/PhabricatorProjectProfileController.php b/src/applications/project/controller/PhabricatorProjectProfileController.php index f12a7d9f82..d0ec8d2988 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileController.php @@ -40,17 +40,7 @@ final class PhabricatorProjectProfileController $profile = new PhabricatorProjectProfile(); } - $src_phid = $profile->getProfileImagePHID(); - if (!$src_phid) { - $src_phid = $user->getProfileImagePHID(); - } - $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', - $src_phid); - if ($file) { - $picture = $file->getBestURI(); - } else { - $picture = PhabricatorUser::getDefaultProfileImageURI(); - } + $picture = $profile->loadProfileImageURI(); $members = mpull($project->loadAffiliations(), null, 'getUserPHID'); diff --git a/src/applications/project/controller/PhabricatorProjectProfileEditController.php b/src/applications/project/controller/PhabricatorProjectProfileEditController.php index 795d0c181c..b6e5e123b9 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileEditController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileEditController.php @@ -33,11 +33,12 @@ final class PhabricatorProjectProfileEditController return new Aphront404Response(); } $profile = $project->loadProfile(); - if (empty($profile)) { $profile = new PhabricatorProjectProfile(); } + $img_src = $profile->loadProfileImageURI(); + if ($project->getSubprojectPHIDs()) { $phids = $project->getSubprojectPHIDs(); $handles = id(new PhabricatorObjectHandleData($phids)) @@ -93,7 +94,10 @@ final class PhabricatorProjectProfileEditController $e_name = null; } - if (!empty($_FILES['image'])) { + $default_image = $request->getExists('default_image'); + if ($default_image) { + $profile->setProfileImagePHID(null); + } else if (!empty($_FILES['image'])) { $err = idx($_FILES['image'], 'error'); if ($err != UPLOAD_ERR_NO_FILE) { $file = PhabricatorFile::newFromPHPUpload( @@ -252,7 +256,16 @@ final class PhabricatorProjectProfileEditController ->setName('set_subprojects') ->setValue($subprojects)) ->appendChild( - id(new AphrontFormFileControl()) + id(new AphrontFormMarkupControl()) + ->setLabel('Profile Image') + ->setValue( + phutil_render_tag( + 'img', + array( + 'src' => $img_src, + )))) + ->appendChild( + id(new AphrontFormImageControl()) ->setLabel('Change Image') ->setName('image') ->setError($e_image) diff --git a/src/applications/project/storage/PhabricatorProjectProfile.php b/src/applications/project/storage/PhabricatorProjectProfile.php index 2fc6d0403c..edf9e80a71 100644 --- a/src/applications/project/storage/PhabricatorProjectProfile.php +++ b/src/applications/project/storage/PhabricatorProjectProfile.php @@ -22,4 +22,15 @@ final class PhabricatorProjectProfile extends PhabricatorProjectDAO { protected $blurb; protected $profileImagePHID; + public function loadProfileImageURI() { + $src_phid = $this->getProfileImagePHID(); + + $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid); + if ($file) { + return $file->getBestURI(); + } + + return PhabricatorUser::getDefaultProfileImageURI(); + } + } diff --git a/src/view/form/control/AphrontFormImageControl.php b/src/view/form/control/AphrontFormImageControl.php new file mode 100644 index 0000000000..0e68d10141 --- /dev/null +++ b/src/view/form/control/AphrontFormImageControl.php @@ -0,0 +1,53 @@ + 'file', + 'name' => $this->getName(), + 'class' => 'image', + )). + '-or-'. + phutil_render_tag( + 'input', + array( + 'type' => 'checkbox', + 'name' => 'default_image', + 'class' => 'default-image', + 'id' => $id, + )). + phutil_render_tag( + 'label', + array( + 'for' => $id, + ), + 'Use Default Image'); + } + +} diff --git a/webroot/rsrc/css/aphront/form-view.css b/webroot/rsrc/css/aphront/form-view.css index 72f7d98bf8..f173b680b0 100644 --- a/webroot/rsrc/css/aphront/form-view.css +++ b/webroot/rsrc/css/aphront/form-view.css @@ -139,6 +139,18 @@ table.aphront-form-control-checkbox-layout th { max-width: 400px; } +.aphront-form-control-image .image { + width: 164px; +} + +.aphront-form-control-image span { + margin: 0px 4px 0px 2px; +} + +.aphront-form-control-image .default-image { + width: 12px; +} + .aphront-form-input hr { border: none; background: #bbbbbb;