mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Merge branch 'master' into bugfix
Conflicts: app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee
This commit is contained in:
@@ -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, */*"
|
||||
|
||||
@@ -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 .
|
||||
|
||||
@@ -160,7 +160,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [
|
||||
|
||||
$scope.editWarn = (product, variant) ->
|
||||
if (DirtyProducts.count() > 0 and confirm("Unsaved changes will be lost. Continue anyway?")) or (DirtyProducts.count() == 0)
|
||||
window.open("/admin/products/" + product.permalink_live + ((if variant then "/variants/" + variant.id else "")) + "/edit")
|
||||
window.location = "/admin/products/" + product.permalink_live + ((if variant then "/variants/" + variant.id else "")) + "/edit"
|
||||
|
||||
|
||||
$scope.addVariant = (product) ->
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
angular.module("admin.enterprises")
|
||||
.controller "enterpriseCtrl", ($scope, $rootScope, 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
|
||||
$scope.$on "$routeChangeStart", (event, newUrl, oldUrl) ->
|
||||
event.preventDefault()
|
||||
|
||||
|
||||
@@ -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"])
|
||||
@@ -9,6 +9,7 @@
|
||||
*= require admin/spree_promo
|
||||
|
||||
*= require shared/jquery-ui-timepicker-addon
|
||||
*= require shared/textAngular.min
|
||||
|
||||
*= require_self
|
||||
*= require_tree .
|
||||
|
||||
@@ -213,3 +213,21 @@ table#listing_enterprise_groups {
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
app/assets/stylesheets/shared/textAngular.min.css
vendored
Normal file
1
app/assets/stylesheets/shared/textAngular.min.css
vendored
Normal 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}
|
||||
@@ -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
|
||||
|
||||
@@ -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("\"", """).gsub("'","'")
|
||||
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
|
||||
|
||||
@@ -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"}
|
||||
@@ -1,4 +0,0 @@
|
||||
/
|
||||
insert_before '[data-hook="admin_inside_head"]'
|
||||
|
||||
= render "layouts/bugherd_script"
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
= admin_inject_enterprise
|
||||
= admin_inject_enterprise_long_description
|
||||
= admin_inject_payment_methods
|
||||
= admin_inject_shipping_methods
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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', [])
|
||||
|
||||
@@ -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 ]
|
||||
|
||||
@@ -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{
|
||||
|
||||
1
vendor/assets/javascripts/textAngular-sanitize.min.js
vendored
Normal file
1
vendor/assets/javascripts/textAngular-sanitize.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
vendor/assets/javascripts/textAngular.min.js
vendored
Normal file
2
vendor/assets/javascripts/textAngular.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user