pin carrier wave in web

This commit is contained in:
Seth Call 2017-01-06 06:43:38 -06:00
parent 19b2edcefa
commit 575abf01e5
8 changed files with 95 additions and 14 deletions

View File

@ -799,6 +799,11 @@ module JamRuby
lesson_booking.school = lesson_booking.teacher.teacher.school
end
# copy payment settings from retailer into lesson booking
if lesson_booking.teacher && lesson_booking.teacher.teacher.retailer
lesson_booking.payment = lesson_booking.teacher.teacher.retailer.payment_details.to_json
end
if user
lesson_booking.same_school = !!(lesson_booking.school && user.school && (lesson_booking.school.id == user.school.id))
if lesson_booking.same_school

View File

@ -220,16 +220,18 @@ module JamRuby
if success && lesson_booking.requires_teacher_distribution?(self)
is_education_school_on_school = lesson_booking.school_on_school_payment?
self.teacher_distributions << TeacherDistribution.create_for_lesson(self, false)
if is_education_school_on_school
self.teacher_distributions << TeacherDistribution.create_for_lesson(self, true)
if lesson_booking.payment
# if there is a payment object, it will describe how everything gets doled out
else
is_education_school_on_school = lesson_booking.school_on_school_payment?
self.teacher_distributions << TeacherDistribution.create_for_lesson(self, false)
if is_education_school_on_school
self.teacher_distributions << TeacherDistribution.create_for_lesson(self, true)
end
end
# this is a bit of a hack, in how the code is structured.
# but basically, the distributions calculated are too dynamic for the above code.
# if this is a retailer
end
if self.save

View File

@ -65,6 +65,13 @@ module JamRuby
self.city = params[:city]
self.state = params[:state]
self.slug = params[:slug] if params[:slug].present?
if params[:split]
split = params[:split]
if split[:teacher] && split[:teacher].is_a?(Number) && split[:retailer] && split[:retailer].is_a?(Number)
self.payment = split.to_json
end
end
if params[:password].present?
self.should_validate_password = true
@ -74,6 +81,15 @@ module JamRuby
self.save
end
# should be of form {teacher: 0-100, retailer: 0-100}
def payment_details
if self.payment
JSON.parse(self.payment)
else
{"teacher" => 75, "retailer" => 25}
end
end
def owner
user
end

View File

@ -72,7 +72,7 @@ gem 'filepicker-rails', '0.1.0'
gem 'aws-sdk', '~> 1'
gem 'aasm' #, '3.0.16'
gem 'carmen'
gem 'carrierwave' #, '0.9.0'
gem 'carrierwave', '0.11.2' #, '0.9.0'
gem 'carrierwave_direct'
gem 'fog'
#gem 'jquery-payment-rails', github: 'sethcall/jquery-payment-rails'

View File

@ -92,6 +92,7 @@ profileUtils = context.JK.ProfileUtils
selected: 'account',
updateErrors: null,
retailerName: null,
teacherSplit: null,
teacherInvitations: null,
updating: false
}
@ -121,18 +122,24 @@ profileUtils = context.JK.ProfileUtils
city = @root.find('select[name="cities"]').val()
password = @root.find('input[type="password"]').val()
teacherSplit = @teacherSplit()
retailerSplit = (100 - teacherSplit).toFixed(2)
@setState(updating: true)
rest.updateRetailer({
id: this.state.retailer.id,
name: name,
state: region,
city: city,
password:password
password:password,
split: {teacher: teacherSplit, retailer: retailerSplit}
}).done((response) => @onUpdateDone(response)).fail((jqXHR) => @onUpdateFail(jqXHR))
onUpdateDone: (response) ->
@setState({retailer: response, retailerName: null, updateErrors: null, updating: false})
@setState({retailer: response, retailerName: null, teacherSplit: null, updateErrors: null, updating: false})
@app.layout.notify({title: "update success", text: "Your retailer information has been successfully updated"})
@ -262,6 +269,40 @@ profileUtils = context.JK.ProfileUtils
logger.debug("handleLocationChange #{country} #{region} ${city}")
@setState({city: city, region: region})
teacherSplitCurrent: () ->
if this.state.teacherSplit?
this.state.teacherSplit
else
this.state.retailer.payment_details.teacherSplit
teacherSplitValue: () ->
@teacherSplitCurrent()
retailerSplitValue: () ->
teacherSplit = @teacherSplitCurrent()
return (100 - teacherSplit).toFixed(2)
onTeacherBlur: () ->
teacherSplit = @root.find('input[name="teacher-split"]').val()
teacherSplit = Number(teacherSplit)
if teacherSplit != teacherSplit #NaN?
@setState({teacherSplit: null})
teacherSplit: () ->
teacherSplit = @root.find('input[name="teacher-split"]').val()
if teacherSplit
teacherSplit = Number(teacherSplit)
if !teacherSplit
teacherSplit = 75
teacherSplit
onTeacherSplitChange: (e) ->
$target = $(e.target)
teacherSplit = @teacherSplit()
@setState({teacherSplit: teacherSplit})
account: () ->
nameErrors = context.JK.reactSingleFieldErrors('name', @state.updateErrors)
@ -313,6 +354,17 @@ profileUtils = context.JK.ProfileUtils
<StripeConnect purpose='retailer' user={this.state.user}/>
</div>
<div className="field split">
<div className="teacher-split">
<label>Teacher % of Each Lesson:</label>
<input name="teacher-split" className="split-input teacher" type="number" defaultValue="" placeholder="please enter a value 1-100" value={this.teacherSplitValue()} onChange={this.onTeacherSplitChange} onBlur={this.onTeacherBlur}/>
</div>
<div className="retailer-split">
<label>Retailer % of Each Lesson:</label>
<input name="retailer-split" className="split-input retailer" type="number" defaultValue="" value={this.retailerSplitValue()} readonly={true} disabled={true}/>
</div>
</div>
<div className="actions">
<a className={classNames(cancelClasses)} onClick={this.onCancel}>CANCEL</a>
<a className={classNames(updateClasses)} onClick={this.onUpdate}>UPDATE</a>

View File

@ -280,4 +280,10 @@
font-size:12px;
margin:0;
}
.split-input {
:after {
content: '%';
}
}
}

View File

@ -10,10 +10,10 @@ class ArtifactsController < ApiController
if is_jamblaster
# check and see if there is a build just for this JB
clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}%", params[:serialno]).order(:product)
clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}", params[:serialno]).order(:product)
if clients.count == 0
# if not, then fine, give back the default environment
clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}%", ArtifactUpdate::DEFAULT_ENVIRONMENT).order(:product)
clients = ArtifactUpdate.where('product ilike ? and environment = ?', "JamClient/#{params[:type]}", ArtifactUpdate::DEFAULT_ENVIRONMENT).order(:product)
end
else
clients = ArtifactUpdate.where("product like '%JamClient%' and environment = '#{ArtifactUpdate::DEFAULT_ENVIRONMENT}'").order(:product)

View File

@ -1,6 +1,6 @@
object @retailer
attributes :id, :user_id, :name, :enabled, :original_fpfile, :cropped_fpfile, :crop_selection, :photo_url, :slug, :state, :city
attributes :id, :user_id, :name, :enabled, :original_fpfile, :cropped_fpfile, :crop_selection, :photo_url, :slug, :state, :city, :payment_details
child :owner => :owner do
attributes :id, :email, :photo_url, :name, :first_name, :last_name