diff --git a/app/assets/javascripts/admin/enterprises/controllers/side_menu_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/side_menu_controller.js.coffee index a74c3005e0..d5d0e1681a 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/side_menu_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/side_menu_controller.js.coffee @@ -13,6 +13,7 @@ angular.module("admin.enterprises") { name: 'About', icon_class: "icon-pencil" } { name: 'Business Details', icon_class: "icon-briefcase" } { name: 'Images', icon_class: "icon-picture" } + { name: "Properties", icon_class: "icon-tags", show: "showProperties()" } { name: "Shipping Methods", icon_class: "icon-truck", show: "showShippingMethods()" } { name: "Payment Methods", icon_class: "icon-money", show: "showPaymentMethods()" } { name: "Enterprise Fees", icon_class: "icon-tasks", show: "showEnterpriseFees()" } @@ -28,6 +29,9 @@ angular.module("admin.enterprises") else true + $scope.showProperties = -> + !!$scope.Enterprise.is_primary_producer + $scope.showShippingMethods = -> enterprisePermissions.can_manage_shipping_methods && $scope.Enterprise.sells != "none" diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index c54f1f976f..e745d22909 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -12,6 +12,8 @@ module Admin before_filter :check_can_change_bulk_owner, only: :bulk_update before_filter :check_can_change_managers, only: :update before_filter :strip_new_properties, only: [:create, :update] + before_filter :load_properties, only: [:edit, :update] + before_filter :setup_property, only: [:edit] helper 'spree/products' @@ -172,6 +174,14 @@ module Admin end end + def load_properties + @properties = Spree::Property.pluck(:name) + end + + def setup_property + @enterprise.producer_properties.build + end + # Overriding method on Spree's resource controller def location_after_save if params[:enterprise].key? :producer_properties_attributes diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index aa2ae7f589..28f76d34d0 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -31,6 +31,10 @@ %legend Images = render 'admin/enterprises/form/images', f: f +%fieldset.alpha.no-border-bottom{ ng: { show: "menu.selected.name=='Properties'" } } + %legend Properties + = render 'admin/enterprises/form/properties', f: f + %fieldset.alpha.no-border-bottom{ ng: { show: "menu.selected.name=='Shipping Methods'" } } %legend Shipping Methods = render 'admin/enterprises/form/shipping_methods', f: f diff --git a/app/views/admin/enterprises/form/_properties.html.haml b/app/views/admin/enterprises/form/_properties.html.haml new file mode 100644 index 0000000000..795a104f1a --- /dev/null +++ b/app/views/admin/enterprises/form/_properties.html.haml @@ -0,0 +1,12 @@ += render 'admin/producer_properties/form', f: f + +// :javascript +// var properties = #{raw(@properties.to_json)}; +// +// $("#producer_properties input.autocomplete").live("keydown", function() { +// already_auto_completed = $(this).is('ac_input'); +// if (!already_auto_completed) { +// $(this).autocomplete({source: properties}); +// $(this).focus(); +// } +// }); diff --git a/app/views/admin/producer_properties/_form.html.haml b/app/views/admin/producer_properties/_form.html.haml new file mode 100644 index 0000000000..dcd83f8ec4 --- /dev/null +++ b/app/views/admin/producer_properties/_form.html.haml @@ -0,0 +1,12 @@ +%fieldset.no-border-top + .add_producer_properties{"data-hook" => "add_producer_properties"} + = image_tag 'spinner.gif', :plugin => 'spree', :style => 'display:none;', :id => 'busy_indicator' + %table.index.sortable{"data-hook" => "", "data-sortable-link" => main_app.update_positions_admin_enterprise_producer_properties_url(@enterprise)} + %thead + %tr{"data-hook" => "producer_properties_header"} + %th{colspan: "2"} Property + %th Value + %th.actions + %tbody#producer_properties{"data-hook" => ""} + = f.fields_for :producer_properties do |pp_form| + = render 'admin/producer_properties/producer_property_fields', f: pp_form diff --git a/app/views/admin/producer_properties/index.html.haml b/app/views/admin/producer_properties/index.html.haml index 2b4277b08d..d8eac9e816 100644 --- a/app/views/admin/producer_properties/index.html.haml +++ b/app/views/admin/producer_properties/index.html.haml @@ -13,20 +13,10 @@ = form_for @enterprise, url: main_app.admin_enterprise_path(@enterprise), method: :put do |f| - %fieldset.no-border-top - .add_producer_properties{"data-hook" => "add_producer_properties"} - = image_tag 'spinner.gif', :plugin => 'spree', :style => 'display:none;', :id => 'busy_indicator' - %table.index.sortable{"data-hook" => "", "data-sortable-link" => main_app.update_positions_admin_enterprise_producer_properties_url(@enterprise)} - %thead - %tr{"data-hook" => "producer_properties_header"} - %th{colspan: "2"} Property - %th Value - %th.actions - %tbody#producer_properties{"data-hook" => ""} - = f.fields_for :producer_properties do |pp_form| - = render 'producer_property_fields', f: pp_form - = render 'spree/admin/shared/edit_resource_links', collection_url: main_app.admin_enterprise_producer_properties_path(@enterprise) - = hidden_field_tag 'clear_producer_properties', 'true' + = render 'form', f: f + + = render 'spree/admin/shared/edit_resource_links', collection_url: main_app.admin_enterprise_producer_properties_path(@enterprise) + = hidden_field_tag 'clear_producer_properties', 'true' :javascript var properties = #{raw(@properties.to_json)};