Merge branch 'master' into reg

This commit is contained in:
Rob Harrington
2014-10-09 09:26:17 +11:00
30 changed files with 102 additions and 36 deletions

View File

@@ -1,3 +1,3 @@
angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown", "admin.products", "infinite-scroll"]).config ($httpProvider) ->
$httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"

View File

@@ -23,5 +23,7 @@
//= require ./products/products
//= require ./shipping_methods/shipping_methods
//= require ./users/users
//= require textAngular.min.js
//= require textAngular-sanitize.min.js
//= require_tree .

View File

@@ -1,8 +1,9 @@
angular.module("admin.enterprises")
.controller "enterpriseCtrl", ($scope, Enterprise, PaymentMethods, ShippingMethods) ->
.controller "enterpriseCtrl", ($scope, Enterprise, longDescription, PaymentMethods, ShippingMethods) ->
$scope.Enterprise = Enterprise.enterprise
$scope.PaymentMethods = PaymentMethods.paymentMethods
$scope.ShippingMethods = ShippingMethods.shippingMethods
$scope.htmlVariable = longDescription
for payment_method in $scope.PaymentMethods
payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids
@@ -32,4 +33,4 @@ angular.module("admin.enterprises")
$scope.ShippingMethods.reduce (count, shipping_method) ->
count++ if shipping_method.selected
count
, 0
, 0

View File

@@ -1 +1 @@
angular.module("admin.enterprises", ["admin.payment_methods", "admin.shipping_methods", "admin.users"])
angular.module("admin.enterprises", ["admin.payment_methods", "admin.shipping_methods", "admin.users", "textAngular"])

View File

@@ -9,6 +9,7 @@
*= require admin/spree_promo
*= require shared/jquery-ui-timepicker-addon
*= require shared/textAngular.min
*= require_self
*= require_tree .

View File

@@ -156,4 +156,4 @@ div.dashboard_item
background-color: #9fc820
&.bottom
border-radius: 0px 0px 6px 6px
padding: 15px 15px
padding: 15px 15px

View File

@@ -210,3 +210,24 @@ table#listing_enterprise_groups {
color: #575757;
}
.field_with_errors > input {
border-color: red;
}
// textAngular wysiwyg
text-angular {
.ta-scroll-window > .ta-bind {
max-height: 400px;
min-height: 100px;
}
.ta-scroll-window.form-control {
min-height: 100px;
}
.btn-group {
display: inline;
margin-right: 8px;
button {
padding: 5px 10px;
}
}
}

View File

@@ -33,6 +33,9 @@ div.sidebar_item
color: #DA5354
.list-item
.icon-arrow-right
padding-top: 6px
font-size: 20px
border: solid #5498da
border-width: 0px 1px 0px 1px
a.alpha, span.alpha
@@ -40,7 +43,6 @@ div.sidebar_item
margin-left: -1px
padding: 10px 2px 10px 5%
overflow: hidden
max-width: 160px
text-overflow: ellipsis
span.omega
padding: 8px 18px 8px 0px
@@ -72,4 +74,4 @@ div.sidebar_item
background-color: #DA5354
&:hover
background-color: #9fc820

View File

@@ -0,0 +1 @@
.ta-scroll-window.form-control{height:auto;min-height:300px;overflow:auto;font-family:inherit;font-size:100%;position:relative;padding:0}.ta-root.focussed .ta-scroll-window.form-control{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.ta-editor.ta-html{min-height:300px;height:auto;overflow:auto;font-family:inherit;font-size:100%}.ta-scroll-window>.ta-bind{height:auto;min-height:300px;padding:6px 12px}.ta-root .ta-resizer-handle-overlay{z-index:100;position:absolute;display:none}.ta-root .ta-resizer-handle-overlay>.ta-resizer-handle-info{position:absolute;bottom:16px;right:16px;border:1px solid #000;background-color:#FFF;padding:0 4px;opacity:.7}.ta-root .ta-resizer-handle-overlay>.ta-resizer-handle-background{position:absolute;bottom:5px;right:5px;left:5px;top:5px;border:1px solid #000;background-color:rgba(0,0,0,.2)}.ta-root .ta-resizer-handle-overlay>.ta-resizer-handle-corner{width:10px;height:10px;position:absolute}.ta-root .ta-resizer-handle-overlay>.ta-resizer-handle-corner-tl{top:0;left:0;border-left:1px solid #000;border-top:1px solid #000}.ta-root .ta-resizer-handle-overlay>.ta-resizer-handle-corner-tr{top:0;right:0;border-right:1px solid #000;border-top:1px solid #000}.ta-root .ta-resizer-handle-overlay>.ta-resizer-handle-corner-bl{bottom:0;left:0;border-left:1px solid #000;border-bottom:1px solid #000}.ta-root .ta-resizer-handle-overlay>.ta-resizer-handle-corner-br{bottom:0;right:0;border:1px solid #000;cursor:se-resize;background-color:#fff}

View File

@@ -2,14 +2,14 @@ require 'open_food_network/spree_api_key_loader'
Spree::Admin::ProductsController.class_eval do
include OpenFoodNetwork::SpreeApiKeyLoader
before_filter :load_form_data, :only => [:bulk_edit, :new, :edit]
before_filter :load_form_data, :only => [:bulk_edit, :new, :create, :edit, :update]
before_filter :load_spree_api_key, :only => :bulk_edit
alias_method :location_after_save_original, :location_after_save
respond_to :json, :only => :clone
respond_override create: { html: {
respond_override create: { html: {
success: lambda {
if params[:button] == "add_another"
redirect_to new_admin_product_path

View File

@@ -41,6 +41,12 @@ module Admin
render partial: "admin/json/injection_ams", locals: {ngModule: 'ofn.admin', name: 'SpreeApiKey', json: "'#{@spree_api_key.to_s}'"}
end
def admin_inject_enterprise_long_description
# Clean line breaks and quotes.
long_description = @enterprise.long_description.blank? ? "" : @enterprise.long_description.gsub("\r\n", "<br />").gsub("\"", "&#34;").gsub("'","&#39;")
render partial: "admin/json/injection_ams", locals: {ngModule: 'admin.enterprises', name: 'longDescription', json: "'#{long_description}'"}
end
def admin_inject_json_ams(ngModule, name, data, serializer, opts = {})
json = serializer.new(data).to_json

View File

@@ -49,10 +49,11 @@ class Enterprise < ActiveRecord::Base
validates :name, presence: true
validates :type, presence: true, inclusion: {in: TYPES}
validates :address, presence: true, associated: true
validates :email, presence: true
validates_presence_of :owner
validate :enforce_ownership_limit, if: lambda { owner_id_changed? }
validate :enforce_ownership_limit, if: lambda { owner_id_changed? && !owner_id.nil? }
before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? }
before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? }
before_validation :set_unused_address_fields
after_validation :geocode_address

View File

@@ -0,0 +1 @@
remove "code[erb-loud]:contains(\"render :partial => 'spree/admin/shared/configuration_menu'\")"

View File

@@ -0,0 +1,5 @@
/
insert_before '[data-hook="admin_inside_head"]'
= render "layouts/bugherd_script"
%link{'data-require' => "font-awesome@*", 'data-semver'=>"4.2.0", 'rel' => "stylesheet", 'href' => "//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.css"}

View File

@@ -1,4 +0,0 @@
/
insert_before '[data-hook="admin_inside_head"]'
= render "layouts/bugherd_script"

View File

@@ -1,3 +1,3 @@
class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
attributes :name, :id, :is_primary_producer, :is_distributor, :payment_method_ids, :shipping_method_ids
end
end

View File

@@ -182,7 +182,14 @@
.alpha.three.columns
= f.label :long_description, 'About Us'
.omega.eight.columns
= f.text_area :long_description, rows: 6, placeholder: 'Tell us about yourself. This information appears on your public profile (under "About Us")', class: 'fullwidth'
-# textAngular toolbar options, add to the ta-toolbar array below and separate into groups with extra ],[ if needed:
-# ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre', 'quote'],
-# ['bold', 'italics', 'underline', 'strikeThrough', 'ul', 'ol', 'redo', 'undo', 'clear'],
-# ['justifyLeft','justifyCenter','justifyRight','indent','outdent'],
-# ['html', 'insertImage', 'insertLink', 'insertVideo']
%text-angular{'ng-model' => 'htmlVariable', 'id' => 'enterprise_long_description', 'name' => 'enterprise[long_description]', 'class' => 'text-angular',
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
'placeholder' => 'Tell customers about yourself. This information appears on your public profile.'}
%fieldset.eleven.columns.alpha.no-border-bottom
%legend IMAGES
.row

View File

@@ -1,4 +1,5 @@
= admin_inject_enterprise
= admin_inject_enterprise_long_description
= admin_inject_payment_methods
= admin_inject_shipping_methods

View File

@@ -6,10 +6,13 @@
-# = hidden_field_tag "enterprise[payment_method_ids][]", []
- @payment_methods.each do |payment_method|
%span.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", ng: { controller: 'paymentMethodCtrl', init: "findPaymentMethodByID(#{payment_method.id})" } }
%a.three.columns.alpha{ href: "#{edit_admin_payment_method_path(payment_method)}" }
= payment_method.name
%span.one.column.omega
= f.check_box :payment_method_ids, { multiple: true, 'ng-model' => 'PaymentMethod.selected' }, payment_method.id, nil
%span.four.columns
%span.three.columns.alpha
%label
= f.check_box :payment_method_ids, { multiple: true, 'ng-model' => 'PaymentMethod.selected' }, payment_method.id, nil
= payment_method.name
%a.one.columns.omega{ href: "#{edit_admin_payment_method_path(payment_method)}" }
%span.icon-arrow-right
- else
.four.columns.alpha.list-item
%span.three.columns.alpha None Available

View File

@@ -5,10 +5,13 @@
- if @shipping_methods.count > 0
- @shipping_methods.each do |shipping_method|
%span.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", ng: { controller: 'shippingMethodCtrl', init: "findShippingMethodByID(#{shipping_method.id})" } }
%a.three.columns.alpha{ href: "#{edit_admin_shipping_method_path(shipping_method)}" }
= shipping_method.name
%span.one.column.omega
= f.check_box :shipping_method_ids, { :multiple => true, 'ng-model' => 'ShippingMethod.selected' }, shipping_method.id, nil
%span.four.columns
%span.three.columns.alpha
%label
= f.check_box :shipping_method_ids, { :multiple => true, 'ng-model' => 'ShippingMethod.selected' }, shipping_method.id, nil
= shipping_method.name
%a.one.columns.omega{ href: "#{edit_admin_shipping_method_path(shipping_method)}" }
%span.one.column.alpha.icon-arrow-right
- else
.four.columns.alpha.list-item
%span.three.columns.alpha None Available

View File

@@ -8,10 +8,13 @@
= hidden_field klass, :distributor_ids, :multiple => true, value: nil
- @hubs.each do |hub|
%span.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}" }
%a.three.columns.alpha{ href: "#{main_app.edit_admin_enterprise_path(hub)}" }
= hub.name
%span.one.column.omega
= check_box klass, :distributor_ids, { multiple: true }, hub.id, nil
%span.four.columns
%span.three.columns.alpha
%label
= check_box klass, :distributor_ids, { multiple: true }, hub.id, nil
= hub.name
%a.one.column.omega{ href: "#{main_app.edit_admin_enterprise_path(hub)}" }
%span.icon-arrow-right
- else
.four.columns.alpha.list-item
%span.three.columns.alpha None Available
@@ -19,4 +22,4 @@
%span.icon-remove-sign
%a.four.columns.alpha.button{ href: "#{main_app.admin_enterprises_path}", class: "#{hubs_color}" }
MANAGE
%span.icon-arrow-right
%span.icon-arrow-right

View File

@@ -53,7 +53,7 @@ Order Total: #{@order.display_total}
- if @order.special_instructions.present?
notes: #{@order.special_instructions}
\
Thanks for your support.
#{@order.distributor.contact},

View File

@@ -24,7 +24,7 @@ module Admin
describe "creating an enterprise" do
let(:country) { Spree::Country.find_by_name 'Australia' }
let(:state) { Spree::State.find_by_name 'Victoria' }
let(:enterprise_params) { {enterprise: {name: 'zzz', address_attributes: {address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id}}} }
let(:enterprise_params) { {enterprise: {name: 'zzz', email: "bob@example.com", address_attributes: {address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id}}} }
it "grants management permission if the current user is an enterprise user" do
controller.stub spree_current_user: user

View File

@@ -109,8 +109,8 @@ feature %q{
fill_in 'enterprise_address_attributes_zipcode', :with => '3072'
select2_search 'Australia', :from => 'Country'
select2_search 'Victoria', :from => 'State'
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
long_description = find :css, "text-angular div.ta-scroll-window div.ta-bind"
long_description.set 'Connecting farmers and eaters'
click_button 'Create'
flash_message.should == 'Enterprise "Eaterprises" has been successfully created!'
@@ -137,7 +137,8 @@ feature %q{
choose 'Single'
select2_search user.email, from: 'Owner'
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
long_description = find :css, "text-angular div.ta-scroll-window div.ta-bind"
long_description.set 'This is an interesting long description'
# Check Angularjs switching of sidebar elements
uncheck 'enterprise_is_primary_producer'
@@ -182,6 +183,7 @@ feature %q{
page.should have_checked_field "enterprise_payment_method_ids_#{payment_method.id}"
page.should have_checked_field "enterprise_shipping_method_ids_#{shipping_method.id}"
page.should have_selector "a.list-item", text: enterprise_fee.name
page.should have_content 'This is an interesting long description'
end
describe "producer properties" do
@@ -312,6 +314,7 @@ feature %q{
click_link 'Enterprises'
click_link 'New Enterprise'
fill_in 'enterprise_name', with: 'zzz'
fill_in 'enterprise_email', with: 'bob@example.com'
fill_in 'enterprise_address_attributes_address1', with: 'z'
fill_in 'enterprise_address_attributes_city', with: 'z'
fill_in 'enterprise_address_attributes_zipcode', with: 'z'

View File

@@ -1,7 +1,6 @@
//= require angular
//= require angular-resource
//= require angular-animate
//= require angular-sanitize
//= require angular-mocks
//= require angular-cookies
//= require angular-backstretch.js
@@ -9,6 +8,8 @@
//= require lodash.underscore.js
//= require angular-flash.min.js
//= require shared/mm-foundation-tpls-0.2.2.min.js
//= require textAngular.min.js
//= require textAngular-sanitize.min.js
//= require moment
angular.module('templates', [])

View File

@@ -4,9 +4,13 @@ describe "enterpriseCtrl", ->
Enterprise = null
PaymentMethods = null
ShippingMethods = null
longDescriptionMock = ["long description text"]
beforeEach ->
module('admin.enterprises')
module ($provide)->
$provide.value "longDescription", longDescriptionMock
null
Enterprise =
enterprise:
payment_method_ids: [ 1, 3 ]

View File

@@ -85,6 +85,7 @@ describe Enterprise do
describe "validations" do
subject { FactoryGirl.create(:distributor_enterprise, :address => FactoryGirl.create(:address)) }
it { should validate_presence_of(:name) }
it { should validate_presence_of(:email) }
it "requires an owner" do
expect{

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long