mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Correctly index calculator fields. Adds ng-bind-html-unsafe-compiled.
This commit is contained in:
@@ -4,8 +4,14 @@ function AdminEnterpriseFeesCtrl($scope, $http) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
angular.module('enterprise_fees', [])
|
||||
.directive('ngBindHtmlUnsafeCompiled', function($compile) {
|
||||
return function(scope, element, attrs) {
|
||||
scope.$watch(attrs.ngBindHtmlUnsafeCompiled, function(value) {
|
||||
element.html($compile(value)(scope));
|
||||
});
|
||||
}
|
||||
})
|
||||
.directive('spreeDeleteResource', function() {
|
||||
return function(scope, element, attrs) {
|
||||
if(scope.enterprise_fee.id) {
|
||||
|
||||
@@ -6,7 +6,7 @@ module Admin
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { @presented_collection = @collection.map { |ef| EnterpriseFeePresenter.new(self, ef) } }
|
||||
format.json { @presented_collection = @collection.each_with_index.map { |ef, i| EnterpriseFeePresenter.new(self, ef, i) } }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ class ModelSet
|
||||
|
||||
attr_accessor :collection
|
||||
|
||||
|
||||
def initialize(klass, collection, reject_if, attributes={})
|
||||
def initialize(klass, collection, reject_if=nil, attributes={})
|
||||
@klass, @collection, @reject_if = klass, collection, reject_if
|
||||
|
||||
attributes.each do |name, value|
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class EnterpriseFeePresenter
|
||||
def initialize(controller, enterprise_fee)
|
||||
@controller = controller
|
||||
@enterprise_fee = enterprise_fee
|
||||
def initialize(controller, enterprise_fee, index)
|
||||
@controller, @enterprise_fee, @index = controller, enterprise_fee, index
|
||||
end
|
||||
|
||||
delegate :id, :enterprise_id, :fee_type, :name, :calculator_type, :to => :enterprise_fee
|
||||
@@ -23,10 +22,10 @@ class EnterpriseFeePresenter
|
||||
result = nil
|
||||
|
||||
@controller.send(:with_format, :html) do
|
||||
result = @controller.render_to_string :partial => 'admin/enterprise_fees/calculator_settings', :locals => {:enterprise_fee => @enterprise_fee}
|
||||
result = @controller.render_to_string :partial => 'admin/enterprise_fees/calculator_settings', :locals => {:enterprise_fee => @enterprise_fee, :index => @index}
|
||||
end
|
||||
|
||||
result
|
||||
result.gsub('[0]', '[{{ $index }}]').gsub('_0_', '_{{ $index }}_')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
-# Render only the calculator settings and not the surrounding form
|
||||
- enterprise_fee_set = ModelSet.new(EnterpriseFee, EnterpriseFee.where(:id => enterprise_fee.id))
|
||||
- form = nil
|
||||
- form_for enterprise_fee, :url => '' do |f|
|
||||
- form = capture do
|
||||
- if !enterprise_fee.new_record?
|
||||
.calculator-settings
|
||||
= f.fields_for :calculator do |calculator_form|
|
||||
= preference_fields(enterprise_fee.calculator, calculator_form)
|
||||
= form_for enterprise_fee_set, :as => :enterprise_fee_set, :url => '' do |form|
|
||||
= form.fields_for :collection do |f|
|
||||
- form = capture do
|
||||
- if !enterprise_fee.new_record?
|
||||
.calculator-settings
|
||||
= f.fields_for :calculator do |calculator_form|
|
||||
= preference_fields(enterprise_fee.calculator, calculator_form)
|
||||
= form
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
%th Calculator values
|
||||
%th
|
||||
%tbody
|
||||
/ -- Finished product
|
||||
= enterprise_fee_set_form.angular_fields_for :collection do |f|
|
||||
%tr{'ng-repeat' => 'enterprise_fee in enterprise_fees | filter:query'}
|
||||
%td
|
||||
@@ -26,7 +25,7 @@
|
||||
%td= f.angular_select :fee_type, enterprise_fee_type_options, 'enterprise_fee.fee_type'
|
||||
%td= f.angular_text_field :name
|
||||
%td= f.angular_collection_select :calculator_type, @calculators, :name, :description, 'enterprise_fee.calculator_type', {:class => 'calculator_type'}
|
||||
%td{'ng-bind-html-unsafe' => 'enterprise_fee.calculator_settings'}
|
||||
%td{'ng-bind-html-unsafe-compiled' => 'enterprise_fee.calculator_settings'}
|
||||
%td{'spree-delete-resource' => "1"}
|
||||
|
||||
= enterprise_fee_set_form.submit 'Update'
|
||||
|
||||
Reference in New Issue
Block a user