hydra-editor 1.0.0.beta1 → 1.0.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a019714d3a9953d60b3ec89910581f30917d704
4
- data.tar.gz: 2ea18791705d16c26af05d51aafb692c5d1c99de
3
+ metadata.gz: bbbf4cde2792c9d9300d1fa47fade355fba8524f
4
+ data.tar.gz: 3a789723a0779f07cc15ea3679a47d14c93d6d91
5
5
  SHA512:
6
- metadata.gz: 0b51da1e6c2d35e090980d3540175ce8f39ff083a3d868beb63f45a0f88dcbbc6441ed5bdbbfc53b2f6c78a17c3c4196c6f8250fee8fae7cce32f216e224d019
7
- data.tar.gz: 775e159e509e65587cb2bd1d42f25e3a5f5d956be12aeb5521a53ed0ec18112cdc27b725daccb5a6c8fde3b635c9979ef65bf1466425b4cc19d7c23b10262a94
6
+ metadata.gz: 04413d824a3e627515d9cdb394c7df5078511e0f2c9696adfc15bd5d206448f11c63b87c4eaa30fcc24a30ac8ff36a3789095b2edf134168732d319a7d835a83
7
+ data.tar.gz: a13b247060e85a4e22f8fc2d2cfaa2323bed61f0d453b7178921efc4e9b6431f17149dcb60a2d04c7d4fc11a0c776cbffbe546d17ed1e4ff1697b45f3725eb2f
data/README.md CHANGED
@@ -39,9 +39,17 @@ en:
39
39
 
40
40
  ```
41
41
 
42
- Expects the following interface on your hydra models:
42
+ Create a form object for each of your models.
43
43
 
44
- ```terms_for_editing``` returns an array of model attributes to edit
44
+ ```ruby
45
+ # app/forms/recorded_audio_form.rb
46
+ class RecordedAudioForm
47
+ include HydraEditor::Form
48
+ self.model_class = RecordedAudio
49
+ self.terms = [] # Terms to be edited
50
+ self.required_fields = [] # Required fields
51
+ end
52
+ ```
45
53
 
46
54
  Add the javascript by adding this line to your app/assets/javascript/application.js:
47
55
 
@@ -55,6 +63,8 @@ Add the stylesheets by adding this line to your app/assets/stylesheets/applicati
55
63
  *= require hydra-editor/hydra-editor
56
64
  ```
57
65
 
66
+ (Note: The Javascript includes require Blacklight and must be put after that.)
67
+
58
68
  ## Other customizations
59
69
 
60
70
  By default hydra-editor provides a RecordsController with :new, :create, :edit, and :update actions implemented in the included RecordsControllerBehavior module, and a RecordsHelper module with methods implemented in RecordsHelperBehavior. If you are mounting the engine and using its routes, you can override the controller behaviors by creating your own RecordsController:
@@ -1,4 +1,3 @@
1
- $(function() {
2
- $('form.editor').multiForm();
1
+ Blacklight.onLoad(function() {
2
+ $('.multi_value.form-group').manage_fields();
3
3
  });
4
-
@@ -1,2 +1,4 @@
1
- //= require hydra-editor/multiForm
1
+ //= require hydra-editor/manage_repeating_fields
2
+ //= require hydra-editor/keyboard_support
2
3
  //= require hydra-editor/editMetadata
4
+
@@ -0,0 +1,14 @@
1
+ Blacklight.onLoad(function() {
2
+ $('body').on('keypress', '.multi-text-field', function(event) {
3
+ var $activeField = $(event.target).parents('.field-wrapper'),
4
+ $activeFieldControls = $activeField.children('.field-controls'),
5
+ $addControl = $activeFieldControls.children('.add'),
6
+ $removeControl = $activeFieldControls.children('.remove');
7
+ if (event.keyCode == 13) {
8
+ event.preventDefault();
9
+ $addControl.click()
10
+ $removeControl.click()
11
+ }
12
+ });
13
+ });
14
+
@@ -0,0 +1,123 @@
1
+ // This widget manages the adding and removing of repeating fields.
2
+ // There are a lot of assumptions about the structure of the classes and elements.
3
+ // These assumptions are reflected in the MultiValueInput class.
4
+
5
+ (function($){
6
+
7
+ var FieldManager = function (element, options) {
8
+ this.element = $(element);
9
+ this.options = options;
10
+
11
+ this.controls = $("<span class=\"input-group-btn field-controls\">");
12
+ this.remover = $("<button class=\"btn btn-danger remove\"><i class=\"icon-white glyphicon-minus\"></i><span>Remove</span></button>");
13
+ this.adder = $("<button class=\"btn btn-success add\"><i class=\"icon-white glyphicon-plus\"></i><span>Add</span></button>");
14
+
15
+ this.fieldWrapperClass = '.field-wrapper';
16
+ this.warningClass = '.has-warning';
17
+ this.listClass = '.listing';
18
+
19
+ this.init();
20
+ }
21
+
22
+ FieldManager.prototype = {
23
+ init: function () {
24
+ this._addInitialClasses();
25
+ this._appendControls();
26
+ this._attachEvents();
27
+ this._addCallbacks();
28
+ },
29
+
30
+ _addInitialClasses: function () {
31
+ this.element.addClass("managed");
32
+ $(this.fieldWrapperClass, this.element).addClass("input-group input-append");
33
+ },
34
+
35
+ _appendControls: function() {
36
+ $(this.fieldWrapperClass, this.element).append(this.controls);
37
+ $(this.fieldWrapperClass+':not(:last-child) .field-controls', this.element).append(this.remover);
38
+ $('.field-controls:last', this.element).append(this.adder);
39
+ },
40
+
41
+ _attachEvents: function() {
42
+ var _this = this;
43
+ this.element.on('click', '.remove', function (e) {
44
+ _this.remove_from_list(e);
45
+ });
46
+ this.element.on('click', '.add', function (e) {
47
+ _this.add_to_list(e);
48
+ });
49
+ },
50
+
51
+ _addCallbacks: function() {
52
+ this.element.bind('managed_field:add', this.options.add);
53
+ this.element.bind('managed_field:remove', this.options.remove);
54
+ },
55
+
56
+ add_to_list: function( event ) {
57
+ event.preventDefault();
58
+ var $activeField = $(event.target).parents(this.fieldWrapperClass)
59
+
60
+ if ($activeField.children('input').val() === '') {
61
+ this.displayEmptyWarning();
62
+ } else {
63
+ var $listing = $(this.listClass, this.element);
64
+ this.clearEmptyWarning();
65
+ $listing.append(this._newField($activeField));
66
+ }
67
+ },
68
+
69
+ _newField: function($activeField) {
70
+ var $removeControl = this.remover.clone(),
71
+ $activeFieldControls = $activeField.children('.field-controls'),
72
+ $newField = $activeField.clone();
73
+ $('.add', $activeFieldControls).remove();
74
+ $activeFieldControls.prepend($removeControl);
75
+ $newChildren = $newField.children('input');
76
+ $newChildren.val('').removeProp('required');
77
+ $newChildren.first().focus();
78
+ this.element.trigger("managed_field:add", $newChildren.first());
79
+ return $newField;
80
+ },
81
+
82
+ clearEmptyWarning: function() {
83
+ $listing = $(this.listClass, this.element),
84
+ $listing.children(this.warningClass).remove();
85
+ },
86
+
87
+ displayEmptyWarning: function () {
88
+ $listing = $(this.listClass, this.element)
89
+ var $warningMessage = $("<div class=\'message has-warning\'>cannot add new empty field</div>");
90
+ $listing.children(this.warningClass).remove();
91
+ $listing.append($warningMessage);
92
+ },
93
+
94
+ remove_from_list: function( event ) {
95
+ event.preventDefault();
96
+
97
+ var field = $(event.target).parents(this.fieldWrapperClass)
98
+ field.remove();
99
+
100
+ this.element.trigger("managed_field:remove", field);
101
+ },
102
+
103
+ destroy: function() {
104
+ $(this.fieldWrapperClass, this.element).removeClass("input-append");
105
+ this.element.removeClass( "managed" );
106
+ }
107
+ }
108
+
109
+ FieldManager.DEFAULTS = {
110
+ add: null,
111
+ remove: null
112
+ }
113
+
114
+ $.fn.manage_fields = function(option) {
115
+ return this.each(function() {
116
+ var $this = $(this);
117
+ var data = $this.data('manage_fields');
118
+ var options = $.extend({}, FieldManager.DEFAULTS, $this.data(), typeof option == 'object' && option);
119
+
120
+ if (!data) $this.data('manage_fields', (data = new FieldManager(this, options)));
121
+ })
122
+ }
123
+ })(jQuery);
@@ -0,0 +1,52 @@
1
+ .multi_value {
2
+ .field-wrapper {
3
+ list-style-type:none;
4
+ }
5
+
6
+ .listing {
7
+ margin-left: 0;
8
+ max-width: 40em;
9
+ padding-left: 0px;
10
+ .input-group {
11
+ margin-bottom: 1px;
12
+ }
13
+ }
14
+
15
+ .field-controls span {
16
+ margin-left:.2em;
17
+ }
18
+
19
+ .field-controls {
20
+ margin-left: 2em;
21
+ }
22
+
23
+ .message{
24
+ background-size: 40px 40px;
25
+ background-image: linear-gradient(135deg, rgba(255, 255, 255, .05) 25%, transparent 25%,
26
+ transparent 50%, rgba(255, 255, 255, .05) 50%, rgba(255, 255, 255, .05) 75%,
27
+ transparent 75%, transparent);
28
+ box-shadow: inset 0 -1px 0 rgba(255,255,255,.4);
29
+ width: 100%;
30
+ border: 1px solid;
31
+ color: #fff;
32
+ padding: 10px;
33
+ text-shadow: 0 1px 0 rgba(0,0,0,.5);
34
+ animation: animate-bg 5s linear infinite;
35
+ border-radius: $border-radius-base;
36
+ }
37
+
38
+ .has-error{
39
+ background-color: #de4343;
40
+ border-color: #c43d3d;
41
+ }
42
+
43
+ .has-warning{
44
+ background-color: #eaaf51;
45
+ border-color: #d99a36;
46
+ }
47
+ }
48
+
49
+ // The contributor listing needs some normalization
50
+ #contributors .listing {
51
+ max-width:20em;
52
+ }
@@ -27,9 +27,7 @@ module HydraEditor
27
27
  def model_attributes(form_params)
28
28
  clean_params = sanitize_params(form_params)
29
29
  terms.each do |key|
30
- if clean_params[key] == ['']
31
- clean_params[key] = []
32
- end
30
+ clean_params[key].delete('') if clean_params[key]
33
31
  end
34
32
  clean_params
35
33
  end
@@ -1,13 +1,4 @@
1
1
  module RecordsHelperBehavior
2
-
3
- def metadata_help(key)
4
- I18n.t("hydra_editor.form.metadata_help.#{key}", default: key.to_s.humanize)
5
- end
6
-
7
- def field_label(key)
8
- I18n.t("hydra_editor.form.field_label.#{key}", default: key.to_s.humanize)
9
- end
10
-
11
2
  def model_label(key)
12
3
  I18n.t("hydra_editor.form.model_label.#{key}", default: key.to_s.humanize)
13
4
  end
@@ -25,14 +16,6 @@ module RecordsHelperBehavior
25
16
  render_edit_field_partial_with_action(collection, field_name, locals)
26
17
  end
27
18
 
28
- def add_field (key)
29
- more_or_less_button(key, 'adder', '+')
30
- end
31
-
32
- def subtract_field (key)
33
- more_or_less_button(key, 'remover', '-')
34
- end
35
-
36
19
  def record_form_action_url(record)
37
20
  router = respond_to?(:hydra_editor) ? hydra_editor : self
38
21
  record.persisted? ? router.record_path(record) : router.records_path
@@ -70,14 +53,4 @@ module RecordsHelperBehavior
70
53
  def partial_exists?(partial)
71
54
  lookup_context.find_all(partial).any?
72
55
  end
73
-
74
- def more_or_less_button(key, html_class, symbol)
75
- # TODO, there could be more than one element with this id on the page, but the fuctionality doesn't work without it.
76
- content_tag('button', class: "#{html_class} btn btn-default", id: "additional_#{key}_submit", name: "additional_#{key}") do
77
- (symbol +
78
- content_tag('span', class: 'sr-only') do
79
- "add another #{key.to_s}"
80
- end).html_safe
81
- end
82
- end
83
56
  end
@@ -0,0 +1,68 @@
1
+ class MultiValueInput < SimpleForm::Inputs::CollectionInput
2
+ def input(wrapper_options)
3
+ @rendered_first_element = false
4
+ input_html_classes.unshift("string")
5
+ input_html_options[:name] ||= "#{object_name}[#{attribute_name}][]"
6
+ markup = <<-HTML
7
+
8
+
9
+ <ul class="listing">
10
+ HTML
11
+
12
+ collection.each do |value|
13
+ unless value.to_s.strip.blank?
14
+ markup << <<-HTML
15
+ <li class="field-wrapper">
16
+ #{build_text_field(value)}
17
+ </li>
18
+ HTML
19
+ end
20
+ end
21
+
22
+ # One blank line at the end
23
+ markup << <<-HTML
24
+ <li class="field-wrapper">
25
+ #{build_text_field('')}
26
+ </li>
27
+ </ul>
28
+
29
+ HTML
30
+ end
31
+
32
+ private
33
+
34
+ def build_text_field(value)
35
+ options = input_html_options.dup
36
+
37
+ options[:value] = value
38
+ if @rendered_first_element
39
+ options[:id] = nil
40
+ options[:required] = nil
41
+ else
42
+ options[:id] ||= input_dom_id
43
+ end
44
+ options[:class] ||= []
45
+ options[:class] += ["#{input_dom_id} form-control multi-text-field"]
46
+ options[:'aria-labelledby'] = label_id
47
+ @rendered_first_element = true
48
+ if options.delete(:type) == 'textarea'.freeze
49
+ @builder.text_area(attribute_name, options)
50
+ else
51
+ @builder.text_field(attribute_name, options)
52
+ end
53
+ end
54
+
55
+ def label_id
56
+ input_dom_id + '_label'
57
+ end
58
+
59
+ def input_dom_id
60
+ input_html_options[:id] || "#{object_name}_#{attribute_name}"
61
+ end
62
+
63
+ def collection
64
+ @collection ||= Array.wrap(object[attribute_name])
65
+ end
66
+
67
+ def multiple?; true; end
68
+ end
@@ -1,9 +1,9 @@
1
- <%= bootstrap_form_for form, url: record_form_action_url(form), html: {class: 'form-inline editor'} do |f| %>
1
+ <%= simple_form_for form, url: record_form_action_url(form), html: {class: 'form-inline editor'} do |f| %>
2
2
  <div id="descriptions_display">
3
3
  <%= render 'records/form_header' %>
4
4
  <div class="well">
5
5
  <% f.object.terms.each do |term| %>
6
- <%= render "records/edit_field", f: f, render_req: true, key: term %>
6
+ <%= render_edit_field_partial(term, f: f) %>
7
7
  <% end %>
8
8
  </div> <!-- /well -->
9
9
  </div>
@@ -11,7 +11,7 @@
11
11
 
12
12
  <div class="form-actions">
13
13
  <div class="primary-actions">
14
- <%= f.primary 'Save' %>
14
+ <%= f.submit 'Save', class: 'btn btn-primary' %>
15
15
  <%= link_to t(:'helpers.action.cancel'), main_app.root_path, class: 'btn btn-link' %>
16
16
  </div>
17
17
  </div>
@@ -1,6 +1,6 @@
1
1
  <h1><%= t('hydra_editor.choose_type.title') %></h1>
2
- <%= bootstrap_form_tag url: hydra_editor.new_record_path, method: :get do |f| %>
2
+ <%= form_tag hydra_editor.new_record_path, method: :get do %>
3
3
  <label class="control-label" for="type">Select an object type</label>
4
4
  <%= select_tag :type, options_for_select(object_type_options) %>
5
- <%= f.primary t('hydra_editor.choose_type.next') %>
5
+ <%= submit_tag t('hydra_editor.choose_type.next'), class: 'btn btn-primary' %>
6
6
  <% end %>
@@ -1,10 +1,5 @@
1
- <div class="<%= 'input-group' if f.object.class.multiple?(key) %>" <% if index == 0 %> id="additional_<%= key.to_s %>_clone" <% end %>>
2
- <% required = render_req && index == 0 && f.object.required?(key) %>
3
- <%= text_field_tag "#{ActiveModel::Naming.singular(f.object)}[#{key.to_s}][]", v, id: "#{ActiveModel::Naming.singular(f.object)}_#{key.to_s}", class: "form-control", required: required %>
4
- <% if f.object.class.multiple?(key) %>
5
- <%= render "records/edit_fields/suffix", {key: key, index: index} %>
6
- <% end %>
7
- </div>
8
- <div id="additional_<%= key %>_elements"></div>
9
-
10
-
1
+ <% if f.object.class.multiple? key %>
2
+ <%= f.input key, as: :multi_value, input_html: { class: 'form-control' }, required: f.object.required?(key) %>
3
+ <% else %>
4
+ <%= f.input key, required: f.object.required?(key) %>
5
+ <% end %>
@@ -0,0 +1,31 @@
1
+ require 'simple_form'
2
+ # Use this setup block to configure all options available in SimpleForm.
3
+ SimpleForm.setup do |config|
4
+ config.wrappers :inline, tag: 'span', class: 'form-group inline', error_class: 'has-error' do |b|
5
+ b.use :html5
6
+ b.use :placeholder
7
+ b.use :label, class: 'control-label'
8
+ b.use :input, class: 'form-control'
9
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
10
+ end
11
+
12
+ config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
13
+ b.use :html5
14
+ b.use :placeholder
15
+ b.use :label, class: 'control-label'
16
+ b.wrapper tag: 'div' do |ba|
17
+ ba.use :input, class: 'form-control'
18
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
19
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
20
+ end
21
+ end
22
+
23
+ # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
24
+ # Check the Bootstrap docs (http://getbootstrap.com/css/)
25
+ # to learn about the different styles for forms and inputs,
26
+ # buttons and other elements.
27
+ config.default_wrapper = :vertical_form
28
+
29
+ config.error_notification_class = 'alert alert-danger'
30
+ config.button_class = 'btn btn-default'
31
+ end
data/lib/hydra-editor.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "hydra_editor/engine"
2
- require "bootstrap_form"
3
2
 
4
3
  module HydraEditor
5
4
 
@@ -1,3 +1,3 @@
1
1
  module HydraEditor
2
- VERSION = "1.0.0.beta1"
2
+ VERSION = "1.0.0.beta2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
4
+ version: 1.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-22 00:00:00.000000000 Z
12
+ date: 2015-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -26,47 +26,47 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '4.1'
28
28
  - !ruby/object:Gem::Dependency
29
- name: bootstrap_form
29
+ name: active-fedora
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.1.1
34
+ version: 9.0.0.beta8
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 2.1.1
41
+ version: 9.0.0.beta8
42
42
  - !ruby/object:Gem::Dependency
43
- name: active-fedora
43
+ name: cancancan
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 9.0.0.beta8
48
+ version: '0'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 9.0.0.beta8
55
+ version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: cancancan
57
+ name: simple_form
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: 3.1.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 3.1.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: sqlite3
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -191,23 +191,25 @@ files:
191
191
  - Rakefile
192
192
  - app/assets/javascripts/hydra-editor/editMetadata.js
193
193
  - app/assets/javascripts/hydra-editor/hydra-editor.js
194
- - app/assets/javascripts/hydra-editor/multiForm.js
194
+ - app/assets/javascripts/hydra-editor/keyboard_support.rb
195
+ - app/assets/javascripts/hydra-editor/manage_repeating_fields.js
195
196
  - app/assets/stylesheets/hydra-editor/application.css
196
197
  - app/assets/stylesheets/hydra-editor/hydra-editor.css
198
+ - app/assets/stylesheets/hydra-editor/multi_value_fields.scss
197
199
  - app/controllers/concerns/records_controller_behavior.rb
198
200
  - app/controllers/records_controller.rb
199
201
  - app/forms/hydra_editor/form.rb
200
202
  - app/helpers/concerns/records_helper_behavior.rb
201
203
  - app/helpers/records_helper.rb
204
+ - app/inputs/multi_value_input.rb
202
205
  - app/presenters/hydra/presenter.rb
203
- - app/views/records/_edit_field.html.erb
204
206
  - app/views/records/_form.html.erb
205
207
  - app/views/records/_form_header.html.erb
206
208
  - app/views/records/choose_type.html.erb
207
209
  - app/views/records/edit.html.erb
208
210
  - app/views/records/edit_fields/_default.html.erb
209
- - app/views/records/edit_fields/_suffix.html.erb
210
211
  - app/views/records/new.html.erb
212
+ - config/initializers/simple_form.rb
211
213
  - config/jetty.yml
212
214
  - config/locales/hydra_editor.yml
213
215
  - config/routes.rb
@@ -1,58 +0,0 @@
1
- (function( $ ){
2
-
3
- $.fn.multiForm = function( options ) {
4
-
5
- // Create some defaults, extending them with any options that were provided
6
- var settings = $.extend( { }, options);
7
-
8
- function addField() {
9
- var cloneId = this.id.replace("submit", "clone");
10
- var newId = this.id.replace("submit", "elements");
11
- var cloneElem = $('#'+cloneId).clone();
12
- // change the add button to a remove button
13
- var plusbttn = cloneElem.find('#'+this.id);
14
- plusbttn.html('-<span class="sr-only">remove this '+ this.name.replace("_", " ") +'</span>');
15
- plusbttn.on('click',removeField);
16
-
17
- // remove the help tag on subsequent added fields
18
- cloneElem.find('.formHelp').remove();
19
- cloneElem.find('i').remove();
20
- cloneElem.find('.modal-div').remove();
21
-
22
- //clear out the value for the element being appended
23
- //so the new element has a blank value
24
- cloneElem.find('input[type=text]').val("");
25
- cloneElem.find('input[type=text]').attr("required", false);
26
-
27
- if (settings.afterAdd) {
28
- settings.afterAdd(this, cloneElem);
29
- }
30
-
31
-
32
- $('#'+newId).append(cloneElem);
33
- cloneElem.find('input[type=text]').focus();
34
- return false;
35
- }
36
-
37
- function removeField () {
38
- // get parent and remove it
39
- $(this).parent().parent().remove();
40
- return false;
41
- }
42
-
43
- return this.each(function() {
44
-
45
- // Tooltip plugin code here
46
- /*
47
- * adds additional metadata elements
48
- */
49
- $('.adder', this).click(addField);
50
-
51
- $('.remover', this).click(removeField);
52
-
53
-
54
- });
55
-
56
- };
57
- })( jQuery );
58
-
@@ -1,14 +0,0 @@
1
- <% render_req ||= true # render_req is true for single file edit, false for batch edit%>
2
- <%= f.form_group key do %>
3
- <% vals = f.object[key] %>
4
- <% if render_req && f.object.required?(key) %>
5
- <% tmp = '<span class="error">*</span>' + field_label(key) %>
6
- <%= f.label key, tmp.html_safe, class: "control-label" %>
7
- <% else %>
8
- <%= f.label key, field_label(key), class: "control-label"%>
9
- <% end %>
10
-
11
- <% vals.to_ary.each_with_index do |v, index| %>
12
- <%= render_edit_field_partial(key, f: f, v: v, index: index, render_req: render_req) %>
13
- <% end %>
14
- <% end %>
@@ -1,7 +0,0 @@
1
- <span class="input-group-btn field-controls">
2
- <% if index == 0 %>
3
- <%= add_field(key) %>
4
- <% else %>
5
- <%= subtract_field(key) %>
6
- <% end %>
7
- </span>