Adding properties tab to admin enterprise edit form

This commit is contained in:
Rob Harrington
2015-04-02 11:30:32 +11:00
parent 8926e3765e
commit 3aa5f6e023
6 changed files with 46 additions and 14 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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();
// }
// });

View File

@@ -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

View File

@@ -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)};