Commits

xrd committed 586a0a9

Add invite via facebook

Comments (0)

Files changed (11)

app/assets/javascripts/app.js.coffee

         
         ]
 
-@app.controller 'FacebookCtrl', [ '$scope', 'Facebook', '$filter', '$timeout', '$location', 'Loans', ( $scope, fb, $filter, $timeout, $location, Loans ) ->
+@app.controller 'FacebookCtrl', [ '$scope', 'Facebook', '$filter', '$timeout', '$location', 'Loans', '$modal', ( $scope, fb, $filter, $timeout, $location, Loans, $modal ) ->
                 
         $scope.alphabetPagerSize = 6
         $scope.display = {}
                         $scope.selected[friend.id] = friend
                 else
                         delete $scope.selected[friend.id]
-                        
                 $scope.selectedCount = Object.keys($scope.selected).length
 
+        $scope.open = () ->
+
+                body = encodeURIComponent( "I am trying to eliminate payday loans.\n\nWill you join me in sponsoring a payday loan for someone in need?\n\nLearn more here: http://sharkbit.eqne.ws/payment/#{$scope.loan.code}\n\n" )
+                
+                subject = encodeURIComponent( "Help me eliminate payday loans" )
+                
+                modalInstance = $modal.open
+                        templateUrl: '/t/invite_modal',
+                        controller: 'ModalInstanceCtrl',
+                        resolve: 
+                                items: () -> $scope.selected
+                                body: () -> body
+                                subject: () -> subject
+                                
+                modalInstance.result.then () ->
+                        for item in Object.keys($scope.selected)
+                                $scope.selected[item].selected = false
+                        $scope.selected = {}
+                        $scope.selectedCount = 0
+                                                                
         $scope.inviteFriends = () ->
                 $scope.inviting = true
                 $scope.message = "Please wait, sending invites"
         
         ]
 
+@app.controller 'ModalInstanceCtrl', ['$scope', '$modalInstance', 'items', 'body', 'subject', ($scope, $modalInstance, items, body, subject ) ->
+        $scope.items = items
+        $scope.body = body
+        $scope.subject = subject
+
+        $scope.ok =  () ->
+                $modalInstance.close()
+
+        ]
+
+
 @app.controller 'LoginCtrl', [ '$scope', '$window', ($scope, $window) ->
         $window.location.href = "/auth/facebook"
         ]

app/assets/stylesheets/application.css.sass

   li
     list-style-type: none
 
+.login
+  padding-bottom: 2em
+
 
 .preview
   background-color: #eee

app/views/welcome/_navbar.html.haml

             %li 
               %a{ href: '/invite' } Invite
             %li
-              %a{ href: '/auth/signout' }== Logout #{@current_user.name}
+              %a{ href: '/auth/signout' } Logout
             %li
               %a== [ #{@current_user.name} ]
   
           %li 
             %a{ href: '/invite' } Invite
           %li
-            %a{ href: '/auth/signout' }== Logout
+            %a{ href: '/auth/signout' } Logout
           %li
             %a== [ #{@current_user.name} ]
   

app/views/welcome/index.html.haml

 
         = render partial: 'welcome/problem'
 
-        %a.active.btn.btn-large{ href: '/auth/facebook' } Login via Facebook to get started as a donor or sponsor
+        .login
+          %a.active.btn.btn-large.btn-block.btn-primary{ href: '/auth/facebook' } Get started by logging in
+        
 
 =# render partial: 'welcome/fb'

public/t/donate.html

     {{ loan.progress }}% of loan pledged.
     <progressbar value='loan.progress'></progressbar>
     <div ng-bind-html='loan.donate_button'></div>
-    {{ loan | json }}
   </div>
 </div>

public/t/invite.html

 <div class='alert alert-info' ng-show='message'>{{ message }}</div>
 <div class='toinvite' ng-hide='inviting &amp;&amp; !loading'>
   <div class='causeChosen' ng-show='loan'>
-    <a class='btn btn-large btn-default active' ng-click='inviteFriends()' ng-show='selectedCount'>Invite my {{ selectedCount }} friends to contribute</a>
+    <a class='btn btn-large btn-default active' ng-click='open()' ng-show='selectedCount'>Invite my {{ selectedCount }} friends to contribute</a>
     <div class='description'>Loan description: {{ loan.simple_description }}</div>
   </div>
   <div class='none' ng-hide='loans'>No loans available right now, try again later.</div>

public/t/invite_modal.html

+        <div class="modal-header">
+            <h3>Invite friends</h3>
+        </div>
+        <div class="modal-body">
+            Click each link to send an invitation. You may customize the message before sending or just send it
+            as-is.
+            <ul>
+                <li ng-repeat="item in items" ng-hide="item.hidden">
+                    <a target="_new" ng-click="item.hidden = true" ng-href="mailto:{{item.username}}@facebook.com?subject={{subject}}&body={{body}}">Invite {{item.name}} </a>
+                </li>
+            </ul>
+        </div>
+        <div class="modal-footer">
+            <button class="btn btn-primary"
+            ng-click="ok()">OK</button>
+        </div>

public/t/loans.html

       <span ng-show='type == "sponsor"'>How can we contact the loan recipient? This makes it easy to make successive loans once repayment has been made by verifying identity.</span>
     </p>
   </div>
-  <div class='form-group' ng-show='type == "sponsor"'>
-    <label for='loaneeName'>Your name</label>
-    <input class='form-control' id='sponsorName' ng-model='loan.sponsor' placeholder='Your name' type='text'>
-  </div>
   <div class='form-group'>
     <label for='loanDescription'>For purpose what will this loan be used?</label>
     <p class='help-block'>

templates/donate.haml

     {{ loan.progress }}% of loan pledged.
     %progressbar{ value: 'loan.progress' }
     %div{ 'ng-bind-html' => 'loan.donate_button' }
-    {{ loan | json }}

templates/invite.haml

 .toinvite{ 'ng-hide' => 'inviting && !loading' }
 
   .causeChosen{ 'ng-show' => 'loan' }
-    %a.btn.btn-large.btn-default.active{ 'ng-show' => 'selectedCount', 'ng-click' => 'inviteFriends()' } Invite my {{ selectedCount }} friends to contribute
+    %a.btn.btn-large.btn-default.active{ 'ng-show' => 'selectedCount', 'ng-click' => 'open()' } Invite my {{ selectedCount }} friends to contribute
     .description Loan description: {{ loan.simple_description }}
 
   .none{ 'ng-hide' => 'loans' } No loans available right now, try again later.

templates/loans.haml

       %span{ 'ng-show' => 'type == "inneed"' } We will contact you using this method when sponsors offer support
       %span{ 'ng-show' => 'type == "sponsor"' } How can we contact the loan recipient? This makes it easy to make successive loans once repayment has been made by verifying identity.
 
-  .form-group{ 'ng-show' => 'type == "sponsor"' }
-    %label{ for: 'loaneeName' } Your name
-    %input.form-control{ type: 'text', placeholder: 'Your name', id: 'sponsorName', 'ng-model' => 'loan.sponsor' }    
-
   .form-group
     %label{ for: 'loanDescription' } For purpose what will this loan be used?
     %p.help-block