Class: Widgets::ManageProfile::Base
- Inherits:
-
ErpApp::Widgets::Base
- Object
- ErpApp::Widgets::Base
- Widgets::ManageProfile::Base
- Defined in:
- app/widgets/manage_profile/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_address ⇒ Object
- #add_email_address ⇒ Object
- #add_phone_number ⇒ Object
- #index ⇒ Object
-
#locate ⇒ Object
should not be modified modify at your own risk.
- #remove_address ⇒ Object
- #remove_email_address ⇒ Object
- #remove_phone_number ⇒ Object
- #update_password ⇒ Object
- #update_user_information ⇒ Object
Class Method Details
.base_layout ⇒ Object
239 240 241 242 243 244 245 246 |
# File 'app/widgets/manage_profile/base.rb', line 239 def base_layout begin file = File.join(File.dirname(__FILE__), "/views/layouts/base.html.erb") IO.read(file) rescue return nil end end |
.title ⇒ Object
231 232 233 |
# File 'app/widgets/manage_profile/base.rb', line 231 def title "Manage Profile" end |
.widget_name ⇒ Object
235 236 237 |
# File 'app/widgets/manage_profile/base.rb', line 235 def File.basename(File.dirname(__FILE__)) end |
Instance Method Details
#add_address ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'app/widgets/manage_profile/base.rb', line 174 def add_address begin address_line_1 = params[:address_line_1].strip address_line_2 = params[:address_line_2].strip city = params[:city].strip geo_zone_id = params[:state].strip postal_code = params[:postal_code].strip contact_purpose = params[:contact_purpose] postal_address = current_user.party.add_contact(PostalAddress, { address_line_1: address_line_1, address_line_2: address_line_2, city: city, geo_zone_id: geo_zone_id, state: GeoZone.find(geo_zone_id).zone_name, zip: postal_code, }, ContactPurpose.find_by_internal_identifier(contact_purpose)) {:json => {success: true, message: 'Address added', address: postal_address.to_hash(:only => [:id, :address_line_1, :address_line_2, :city, :state, :zip], :contact_purpose => postal_address.contact_purpose.description)}} rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") #TODO send out notification {:json => {success: false, message: 'Could not add address'}} end end |
#add_email_address ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/widgets/manage_profile/base.rb', line 102 def add_email_address begin email_address = params[:email_address].strip contact_purpose = params[:contact_purpose] email = current_user.party.add_contact(EmailAddress, {email_address: email_address}, ContactPurpose.find_by_internal_identifier(contact_purpose)) {:json => {success: true, message: 'Email added', email: email.to_hash(:only => [:id, :email_address], :contact_purpose => email.contact_purpose.description)}} rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") #TODO send out notification {:json => {success: false, message: 'Could not add email'}} end end |
#add_phone_number ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/widgets/manage_profile/base.rb', line 138 def add_phone_number begin phone_number = params[:phone_number].strip contact_purpose = params[:contact_purpose] phone_number = current_user.party.add_contact(PhoneNumber, {phone_number: phone_number}, ContactPurpose.find_by_internal_identifier(contact_purpose)) {:json => {success: true, message: 'Phone number added', phone: phone_number.to_hash(:only => [:id, :phone_number], :contact_purpose => phone_number.contact_purpose.description)}} rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") #TODO send out notification {:json => {success: false, message: 'Could not add phone number'}} end end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/widgets/manage_profile/base.rb', line 5 def index @user = User.find(current_user) @individual = @user.party.business_party @email_addresses = @user.party.find_all_contacts_by_contact_mechanism(EmailAddress) @phone_numbers = @user.party.find_all_contacts_by_contact_mechanism(PhoneNumber) @postal_addresses = @user.party.find_all_contacts_by_contact_mechanism(PostalAddress) contact_purposes = ContactPurpose.all @purpose_hash={} contact_purposes.each do |p| @purpose_hash[p.description]=p.internal_identifier end countries= GeoCountry.all @countries_id=[] @countries_id << ["Country", "default"] countries.each do |c| @countries_id << [c.name, c.id] end states= GeoZone.all @states_id=[] @states_id << ["State", "default"] states.each do |s| @states_id << [s.zone_name, s.id] end render end |
#locate ⇒ Object
should not be modified modify at your own risk
226 227 228 |
# File 'app/widgets/manage_profile/base.rb', line 226 def locate File.dirname(__FILE__) end |
#remove_address ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'app/widgets/manage_profile/base.rb', line 208 def remove_address begin address_id = params[:address_id].strip PostalAddress.find(address_id).destroy {:json => {success: true, message: 'address removed'}} rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") #TODO send out notification {:json => {success: false, message: 'Could not remove address'}} end end |
#remove_email_address ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/widgets/manage_profile/base.rb', line 122 def remove_email_address begin email_address_id = params[:email_address_id].strip EmailAddress.find(email_address_id).destroy {:json => {success: true, message: 'Email removed'}} rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") #TODO send out notification {:json => {success: false, message: 'Could not remove email'}} end end |
#remove_phone_number ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/widgets/manage_profile/base.rb', line 158 def remove_phone_number begin phone_number_id = params[:phone_number_id].strip PhoneNumber.find(phone_number_id).destroy {:json => {success: true, message: 'Phone number removed'}} rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") #TODO send out notification {:json => {success: false, message: 'Could not remove phone number'}} end end |
#update_password ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/widgets/manage_profile/base.rb', line 69 def update_password if @user = User.authenticate(current_user.username, params[:old_password]) if !params[:new_password].blank? && !params[:password_confirmation].blank? && params[:new_password] == params[:password_confirmation] @user.password_confirmation= params[:password_confirmation] if @user.change_password!(params[:new_password]) = "Password Updated" render :update => {:id => "#{@uuid}_result", :view => :success} else = "Error Updating Password" #### validation failed #### render :update => {:id => "#{@uuid}_result", :view => :error} end else #### password and password confirmation cant be blank or unequal #### = "Password Confirmation Must Match Password" render :update => {:id => "#{@uuid}_result", :view => :error} end else #### old password wrong #### = "Invalid Old Password" render :update => {:id => "#{@uuid}_result", :view => :error} end end |
#update_user_information ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/widgets/manage_profile/base.rb', line 35 def update_user_information #### Get appropriate models #### @user = User.find(current_user) @individual = @user.party.business_party @individual.current_first_name = params[:first_name] @individual.current_last_name = params[:last_name] @individual.current_middle_name = params[:middle_name] @individual.gender = params[:gender] @individual.birth_date = Date.strptime(params[:birth_date], '%m/%d/%Y') @user.email = params[:email] #### check validation then save and render message #### if @user.changed? || @individual.changed? if @user.valid? && @individual.valid? @user.save @individual.save = "User Information Updated" render :update => {:id => "#{@uuid}_result", :view => :success} else = 'sexyerror' = "Error Updating User Information" render :update => {:id => "#{@uuid}_result", :view => :error} end else = "User Information Updated" render :update => {:id => "#{@uuid}_result", :view => :success} end end |