hydra-editor 1.0.0.rc2 → 1.0.0.rc3
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 +4 -4
- data/app/assets/javascripts/hydra-editor/manage_repeating_fields.js +122 -108
- data/app/assets/stylesheets/hydra-editor/hydra-editor.scss +1 -0
- data/app/controllers/concerns/records_controller_behavior.rb +1 -0
- data/app/forms/hydra_editor/form.rb +11 -8
- data/app/inputs/multi_value_input.rb +11 -14
- data/app/views/records/_form.html.erb +1 -1
- data/lib/hydra_editor/version.rb +1 -1
- metadata +4 -5
- data/app/assets/stylesheets/hydra-editor/application.css +0 -13
- data/app/assets/stylesheets/hydra-editor/hydra-editor.css +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00e027dc2628e668372a4fabc2e39c6c4671841f
|
4
|
+
data.tar.gz: bd836eccdefe6a6579048cd467062b9ce66c14b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c04346e9584534386b680b8040cd1d7e594a73d7169b1f489709d635399c15ae40471658ac0915732ff3bf2550efe33ed4c27692db315cb1a6d7abebf3ef500a
|
7
|
+
data.tar.gz: 940e53ec4b57c838b66255e80d87fe1092c1cae333a3d0cf322f91d9ba6c7a58f26aa648b7b4924cb4f33e15146c32ab077d2cd64d8205fb544f0a8cafed5225
|
@@ -2,122 +2,136 @@
|
|
2
2
|
// There are a lot of assumptions about the structure of the classes and elements.
|
3
3
|
// These assumptions are reflected in the MultiValueInput class.
|
4
4
|
|
5
|
-
(function($){
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
5
|
+
var HydraEditor = (function($) {
|
6
|
+
var FieldManager = function (element, options) {
|
7
|
+
this.element = $(element);
|
8
|
+
this.options = options;
|
9
|
+
|
10
|
+
this.controls = $("<span class=\"input-group-btn field-controls\">");
|
11
|
+
this.remover = $("<button class=\"btn btn-danger remove\"><i class=\"icon-white glyphicon-minus\"></i><span>Remove</span></button>");
|
12
|
+
this.adder = $("<button class=\"btn btn-success add\"><i class=\"icon-white glyphicon-plus\"></i><span>Add</span></button>");
|
13
|
+
|
14
|
+
this.fieldWrapperClass = '.field-wrapper';
|
15
|
+
this.warningClass = '.has-warning';
|
16
|
+
this.listClass = '.listing';
|
17
|
+
|
18
|
+
this.init();
|
19
|
+
}
|
20
|
+
|
21
|
+
FieldManager.prototype = {
|
22
|
+
init: function () {
|
23
|
+
this._addInitialClasses();
|
24
|
+
this._appendControls();
|
25
|
+
this._attachEvents();
|
26
|
+
this._addCallbacks();
|
27
|
+
},
|
28
|
+
|
29
|
+
_addInitialClasses: function () {
|
30
|
+
this.element.addClass("managed");
|
31
|
+
$(this.fieldWrapperClass, this.element).addClass("input-group input-append");
|
32
|
+
},
|
33
|
+
|
34
|
+
_appendControls: function() {
|
35
|
+
$(this.fieldWrapperClass, this.element).append(this.controls);
|
36
|
+
$(this.fieldWrapperClass+':not(:last-child) .field-controls', this.element).append(this.remover);
|
37
|
+
$('.field-controls:last', this.element).append(this.adder);
|
38
|
+
},
|
39
|
+
|
40
|
+
_attachEvents: function() {
|
41
|
+
var _this = this;
|
42
|
+
this.element.on('click', '.remove', function (e) {
|
43
|
+
_this.remove_from_list(e);
|
44
|
+
});
|
45
|
+
this.element.on('click', '.add', function (e) {
|
46
|
+
_this.add_to_list(e);
|
47
|
+
});
|
48
|
+
},
|
49
|
+
|
50
|
+
_addCallbacks: function() {
|
51
|
+
this.element.bind('managed_field:add', this.options.add);
|
52
|
+
this.element.bind('managed_field:remove', this.options.remove);
|
53
|
+
},
|
54
|
+
|
55
|
+
add_to_list: function( event ) {
|
56
|
+
event.preventDefault();
|
57
|
+
var $activeField = $(event.target).parents(this.fieldWrapperClass)
|
58
|
+
|
59
|
+
if ($activeField.children('input').val() === '') {
|
60
|
+
this.displayEmptyWarning();
|
61
|
+
} else {
|
62
|
+
var $listing = $(this.listClass, this.element);
|
63
|
+
this.clearEmptyWarning();
|
64
|
+
$listing.append(this._newField($activeField));
|
65
|
+
}
|
66
|
+
},
|
67
|
+
|
68
|
+
_newField: function ($activeField) {
|
69
|
+
var $newField = this.createNewField($activeField);
|
70
|
+
// _changeControlsToRemove must come after createNewField
|
71
|
+
// or the new field will not have an add button
|
72
|
+
this._changeControlsToRemove($activeField);
|
73
|
+
return $newField;
|
74
|
+
},
|
75
|
+
|
76
|
+
createNewField: function($activeField) {
|
77
|
+
$newField = $activeField.clone();
|
78
|
+
$newChildren = $newField.children('input');
|
79
|
+
$newChildren.val('').removeProp('required');
|
80
|
+
$newChildren.first().focus();
|
81
|
+
this.element.trigger("managed_field:add", $newChildren.first());
|
82
|
+
return $newField
|
83
|
+
},
|
84
|
+
|
85
|
+
_changeControlsToRemove: function($activeField) {
|
86
|
+
var $removeControl = this.remover.clone();
|
87
|
+
$activeFieldControls = $activeField.children('.field-controls');
|
88
|
+
$('.add', $activeFieldControls).remove();
|
89
|
+
$activeFieldControls.prepend($removeControl);
|
90
|
+
},
|
91
|
+
|
92
|
+
clearEmptyWarning: function() {
|
93
|
+
$listing = $(this.listClass, this.element),
|
94
|
+
$listing.children(this.warningClass).remove();
|
95
|
+
},
|
96
|
+
|
97
|
+
displayEmptyWarning: function () {
|
98
|
+
$listing = $(this.listClass, this.element)
|
99
|
+
var $warningMessage = $("<div class=\'message has-warning\'>cannot add new empty field</div>");
|
100
|
+
$listing.children(this.warningClass).remove();
|
101
|
+
$listing.append($warningMessage);
|
102
|
+
},
|
103
|
+
|
104
|
+
remove_from_list: function( event ) {
|
105
|
+
event.preventDefault();
|
106
|
+
|
107
|
+
var field = $(event.target).parents(this.fieldWrapperClass)
|
108
|
+
field.remove();
|
109
|
+
|
110
|
+
this.element.trigger("managed_field:remove", field);
|
111
|
+
},
|
112
|
+
|
113
|
+
destroy: function() {
|
114
|
+
$(this.fieldWrapperClass, this.element).removeClass("input-append");
|
115
|
+
this.element.removeClass( "managed" );
|
66
116
|
}
|
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
|
-
}
|
117
|
+
}
|
108
118
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
119
|
+
FieldManager.DEFAULTS = {
|
120
|
+
add: null,
|
121
|
+
remove: null
|
122
|
+
}
|
113
123
|
|
124
|
+
return { FieldManager: FieldManager };
|
125
|
+
})(jQuery);
|
126
|
+
|
127
|
+
(function($){
|
114
128
|
$.fn.manage_fields = function(option) {
|
115
129
|
return this.each(function() {
|
116
130
|
var $this = $(this);
|
117
131
|
var data = $this.data('manage_fields');
|
118
|
-
var options = $.extend({}, FieldManager.DEFAULTS, $this.data(), typeof option == 'object' && option);
|
132
|
+
var options = $.extend({}, HydraEditor.FieldManager.DEFAULTS, $this.data(), typeof option == 'object' && option);
|
119
133
|
|
120
|
-
if (!data) $this.data('manage_fields', (data = new FieldManager(this, options)));
|
134
|
+
if (!data) $this.data('manage_fields', (data = new HydraEditor.FieldManager(this, options)));
|
121
135
|
})
|
122
136
|
}
|
123
137
|
})(jQuery);
|
@@ -0,0 +1 @@
|
|
1
|
+
@import 'multi_value_fields';
|
@@ -2,6 +2,7 @@ module RecordsControllerBehavior
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
|
+
include Hydra::Controller::ControllerBehavior
|
5
6
|
load_and_authorize_resource only: [:new, :edit, :update, :create], instance_name: resource_instance_name
|
6
7
|
|
7
8
|
rescue_from HydraEditor::InvalidType do
|
@@ -56,16 +56,19 @@ module HydraEditor
|
|
56
56
|
end
|
57
57
|
|
58
58
|
protected
|
59
|
-
# override this method if you need to initialize more complex RDF assertions (b-nodes)
|
60
59
|
def initialize_fields
|
60
|
+
# we're making a local copy of the attributes that we can modify.
|
61
61
|
@attributes = model.attributes
|
62
|
-
terms.select { |key| self[key].blank? }.each
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
62
|
+
terms.select { |key| self[key].blank? }.each { |key| initialize_field(key) }
|
63
|
+
end
|
64
|
+
|
65
|
+
# override this method if you need to initialize more complex RDF assertions (b-nodes)
|
66
|
+
def initialize_field(key)
|
67
|
+
# if value is empty, we create an one element array to loop over for output
|
68
|
+
if self.class.multiple?(key)
|
69
|
+
self[key] = ['']
|
70
|
+
else
|
71
|
+
self[key] = ''
|
69
72
|
end
|
70
73
|
end
|
71
74
|
end
|
@@ -9,21 +9,15 @@ class MultiValueInput < SimpleForm::Inputs::CollectionInput
|
|
9
9
|
<ul class="listing">
|
10
10
|
HTML
|
11
11
|
|
12
|
-
collection.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
HTML
|
19
|
-
end
|
12
|
+
collection.each_with_index do |value, index|
|
13
|
+
markup << <<-HTML
|
14
|
+
<li class="field-wrapper">
|
15
|
+
#{build_field(value, index)}
|
16
|
+
</li>
|
17
|
+
HTML
|
20
18
|
end
|
21
19
|
|
22
|
-
# One blank line at the end
|
23
20
|
markup << <<-HTML
|
24
|
-
<li class="field-wrapper">
|
25
|
-
#{build_text_field('')}
|
26
|
-
</li>
|
27
21
|
</ul>
|
28
22
|
|
29
23
|
HTML
|
@@ -31,7 +25,10 @@ class MultiValueInput < SimpleForm::Inputs::CollectionInput
|
|
31
25
|
|
32
26
|
private
|
33
27
|
|
34
|
-
|
28
|
+
# Although the 'index' parameter is not used in this implementation it is useful in an
|
29
|
+
# an overridden version of this method, especially when the field is a complex object and
|
30
|
+
# the override defines nested fields.
|
31
|
+
def build_field(value, index)
|
35
32
|
options = input_html_options.dup
|
36
33
|
|
37
34
|
options[:value] = value
|
@@ -61,7 +58,7 @@ class MultiValueInput < SimpleForm::Inputs::CollectionInput
|
|
61
58
|
end
|
62
59
|
|
63
60
|
def collection
|
64
|
-
@collection ||= Array.wrap(object[attribute_name])
|
61
|
+
@collection ||= Array.wrap(object[attribute_name]).reject { |value| value.to_s.strip.blank? } + ['']
|
65
62
|
end
|
66
63
|
|
67
64
|
def multiple?; true; end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= simple_form_for form, url: record_form_action_url(form), html: {class: '
|
1
|
+
<%= simple_form_for form, url: record_form_action_url(form), html: { class: 'editor' } do |f| %>
|
2
2
|
<div id="descriptions_display">
|
3
3
|
<%= render 'records/form_header' %>
|
4
4
|
<div class="well">
|
data/lib/hydra_editor/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.0.rc3
|
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: 2015-01-
|
12
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -193,8 +193,7 @@ files:
|
|
193
193
|
- app/assets/javascripts/hydra-editor/hydra-editor.js
|
194
194
|
- app/assets/javascripts/hydra-editor/keyboard_support.js
|
195
195
|
- app/assets/javascripts/hydra-editor/manage_repeating_fields.js
|
196
|
-
- app/assets/stylesheets/hydra-editor/
|
197
|
-
- app/assets/stylesheets/hydra-editor/hydra-editor.css
|
196
|
+
- app/assets/stylesheets/hydra-editor/hydra-editor.scss
|
198
197
|
- app/assets/stylesheets/hydra-editor/multi_value_fields.scss
|
199
198
|
- app/controllers/concerns/records_controller_behavior.rb
|
200
199
|
- app/controllers/records_controller.rb
|
@@ -237,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
236
|
version: 1.3.1
|
238
237
|
requirements: []
|
239
238
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.
|
239
|
+
rubygems_version: 2.2.2
|
241
240
|
signing_key:
|
242
241
|
specification_version: 4
|
243
242
|
summary: A basic metadata editor for hydra-head
|
@@ -1,13 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
-
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
-
*
|
11
|
-
*= require_self
|
12
|
-
*= require_tree .
|
13
|
-
*/
|
File without changes
|