You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2017/06/11 20:25:35 UTC

[06/12] airavata-php-gateway git commit: AIRAVATA-2316 Adding multiple phone numbers

AIRAVATA-2316 Adding multiple phone numbers


Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/310ea4cb
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/310ea4cb
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/310ea4cb

Branch: refs/heads/keycloak-integration
Commit: 310ea4cbb75a6f58158217336a20c6dec3f91eee
Parents: 3bfc4e3
Author: Marcus Christie <ma...@iu.edu>
Authored: Thu Feb 23 13:50:36 2017 -0500
Committer: Marcus Christie <ma...@iu.edu>
Committed: Thu Feb 23 13:50:36 2017 -0500

----------------------------------------------------------------------
 app/controllers/UserSettingsController.php | 15 ++++++++++++++-
 app/libraries/UserProfileUtilities.php     | 10 +---------
 app/views/account/user-profile.blade.php   | 25 +++++++++++++++++++++++--
 3 files changed, 38 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/310ea4cb/app/controllers/UserSettingsController.php
----------------------------------------------------------------------
diff --git a/app/controllers/UserSettingsController.php b/app/controllers/UserSettingsController.php
index 054ea05..099d1e7 100644
--- a/app/controllers/UserSettingsController.php
+++ b/app/controllers/UserSettingsController.php
@@ -198,7 +198,20 @@ class UserSettingsController extends BaseController
     public function updateUserProfile() {
 
         // TODO: handle errors by redispaying input page
-        UserProfileUtilities::update_user_profile(Input::all());
+        $username = Session::get('username');
+        $userProfile = UserProfileUtilities::get_user_profile($username);
+
+        // Copy data from form to $userProfile object and update
+        $userProfile->userName = Input::get("userName");
+        $userProfile->homeOrganization = Input::get("homeOrganization");
+        $userProfile->country = Input::get("country");
+        $phones = Input::get("phones");
+        // Filter out empty phone numbers
+        $userProfile->phones = array_filter($phones, function($phone) {
+            return trim($phone) !== "";
+        });
+        Log::debug("userProfile", array($userProfile));
+        UserProfileUtilities::update_user_profile($userProfile);
         return Redirect::to("account/user-profile");
     }
 }

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/310ea4cb/app/libraries/UserProfileUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/UserProfileUtilities.php b/app/libraries/UserProfileUtilities.php
index 09f4e34..d4d52f7 100644
--- a/app/libraries/UserProfileUtilities.php
+++ b/app/libraries/UserProfileUtilities.php
@@ -27,16 +27,8 @@ class UserProfileUtilities
         return Airavata::getUserProfileById(Session::get('authz-token'), $userId, $gatewayId);
     }
 
-    public static function update_user_profile($userProfileData) {
+    public static function update_user_profile($userProfile) {
 
-        Log::debug("userProfileData", array($userProfileData));
-        $username = Session::get('username');
-        $userProfile = UserProfileUtilities::get_user_profile($username);
-
-        // Copy data from form to $userProfile object and update
-        $userProfile->userName = $userProfileData["userName"];
-        $userProfile->homeOrganization = $userProfileData["homeOrganization"];
-        $userProfile->country = $userProfileData["country"];
         return Airavata::updateUserProfile(Session::get('authz-token'), $userProfile);
     }
 }

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/310ea4cb/app/views/account/user-profile.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/user-profile.blade.php b/app/views/account/user-profile.blade.php
index e96b50c..e9ebeea 100644
--- a/app/views/account/user-profile.blade.php
+++ b/app/views/account/user-profile.blade.php
@@ -47,16 +47,37 @@
                         value="{{{ $userProfile->country }}}"/>
             </div>
         </div>
-
-        {{-- TODO: add phone numbers --}}
+        {{-- TODO: need to add delete as well --}}
+        <div class="form-group">
+            <label class="control-label">Phone Numbers</label>
+            @foreach ($userProfile->phones as $phone)
+            <input class="form-control" name="phones[]"
+                    placeholder="Phone number" type="text"
+                    value="{{{ $phone }}}"/>
+            @endforeach
+            <button id="add-phone-button" class="btn btn-default" type="button">Add Phone</button>
+        </div>
 
         <input name="update" type="submit" class="btn btn-primary btn-block" value="Update">
     </form>
 
 </div>
 
+<div id="new-phone-template" class="hidden">
+    <input class="form-control" name="phones[]"
+            placeholder="Phone number" type="text" />
+</div>
+
 @stop
 
 @section('scripts')
 @parent
+<script>
+
+    $('#add-phone-button').click(function(e){
+        $(this).before($('#new-phone-template').html());
+        e.preventDefault();
+        return false;
+    });
+</script>
 @stop