humdrum-rails 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/humdrum/version.rb +1 -1
- data/lib/rails/generators/humdrum/api/api_generator.rb +339 -0
- data/lib/rails/generators/humdrum/api/templates/controllers/resource_controller.rb +207 -0
- data/lib/rails/generators/humdrum/api/templates/javascripts/validations/tbr_untitled.js +114 -0
- data/lib/rails/generators/humdrum/api/templates/javascripts/validations/validator.js +85 -0
- data/lib/rails/generators/humdrum/api/templates/migrations/create_resources.rb +14 -0
- data/lib/rails/generators/humdrum/api/templates/models/resource.rb +32 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_edit.html.erb +7 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_field.html.erb +41 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_filters.html.erb +9 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_form.html.erb +81 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_index.html.erb +22 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_item.html.erb +21 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_nav_filters.html.erb +9 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_new.html.erb +9 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_show.html.erb +48 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/_summary.html.erb +10 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/create.js.erb +15 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/destroy.js.erb +14 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/edit.js.erb +2 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/index.html.erb +33 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/index.js.erb +15 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/new.js.erb +2 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/show.js.erb +2 -0
- data/lib/rails/generators/humdrum/api/templates/views/bootstrap/resource/update.js.erb +14 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_edit.html.erb +7 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_field.html.erb +41 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_filters.html.erb +18 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_form.html copy.erb +71 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_form.html.erb +49 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_index.html.erb +22 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_item.html.erb +21 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_nav_filters.html.erb +9 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_new.html.erb +9 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_show.html.erb +58 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/_summary.html.erb +10 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/create.js.erb +22 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/destroy.js.erb +14 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/edit.js.erb +3 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/index.html.erb +37 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/index.js.erb +15 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/new.js.erb +3 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/show.js.erb +2 -0
- data/lib/rails/generators/humdrum/api/templates/views/gumby/resource/update.js.erb +21 -0
- data/lib/rails/generators/humdrum/layout/layout_generator.rb +42 -29
- data/lib/rails/generators/humdrum/layout/templates/controllers/application_controller.rb +2 -9
- data/lib/rails/generators/humdrum/layout/templates/helpers/flash_helper.rb +13 -0
- data/lib/rails/generators/humdrum/layout/templates/helpers/params_parser_helper.rb +31 -0
- data/lib/rails/generators/humdrum/layout/templates/javascripts/application.js +5 -0
- data/lib/rails/generators/humdrum/layout/templates/javascripts/validations/main.js +15 -0
- data/lib/rails/generators/humdrum/layout/templates/stylesheets/application.css +2 -0
- data/lib/rails/generators/humdrum/layout/templates/stylesheets/bootstrap-responsive.css +1109 -0
- data/lib/rails/generators/humdrum/layout/templates/stylesheets/gumby-pagination.css +56 -0
- data/lib/rails/generators/humdrum/layout/templates/stylesheets/overrides-bootstrap.css +1 -1
- data/lib/rails/generators/humdrum/layout/templates/stylesheets/overrides-gumby.css +8 -0
- data/lib/rails/generators/humdrum/layout/templates/views/bootstrap/layouts/admin.html.erb +4 -4
- data/lib/rails/generators/humdrum/layout/templates/views/bootstrap/layouts/admin/_header.html.erb +1 -1
- data/lib/rails/generators/humdrum/layout/templates/views/bootstrap/layouts/public.html.erb +2 -2
- data/lib/rails/generators/humdrum/layout/templates/views/bootstrap/layouts/public/_header.html.erb +1 -1
- data/lib/rails/generators/humdrum/layout/templates/views/bootstrap/layouts/user.html.erb +2 -2
- data/lib/rails/generators/humdrum/layout/templates/views/bootstrap/layouts/user/_header.html.erb +1 -1
- data/lib/rails/generators/humdrum/resource/resource_generator.rb +60 -38
- data/lib/rails/generators/humdrum/resource/templates/controllers/resource_controller.rb +10 -2
- data/lib/rails/generators/humdrum/resource/templates/javascripts/validations/validator.js +78 -25
- data/lib/rails/generators/humdrum/resource/templates/migrations/create_resources.rb +1 -1
- data/lib/rails/generators/humdrum/resource/templates/models/resource.rb +28 -1
- data/lib/rails/generators/humdrum/resource/templates/views/bootstrap/resource/_edit.html.erb +1 -1
- data/lib/rails/generators/humdrum/resource/templates/views/bootstrap/resource/_field.html.erb +41 -0
- data/lib/rails/generators/humdrum/resource/templates/views/bootstrap/resource/_form.html.erb +59 -22
- data/lib/rails/generators/humdrum/resource/templates/views/bootstrap/resource/_item.html.erb +10 -10
- data/lib/rails/generators/humdrum/resource/templates/views/bootstrap/resource/_new.html.erb +1 -1
- data/lib/rails/generators/humdrum/resource/templates/views/bootstrap/resource/_show.html.erb +13 -3
- data/lib/rails/generators/humdrum/resource/templates/views/bootstrap/resource/_summary.html.erb +2 -2
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/_field.html.erb +41 -0
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/_form.html.erb +16 -38
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/_item.html.erb +10 -10
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/_new.html.erb +1 -1
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/_show.html.erb +15 -2
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/_summary.html.erb +1 -1
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/create.js.erb +8 -1
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/index.js.erb +3 -3
- data/lib/rails/generators/humdrum/resource/templates/views/gumby/resource/update.js.erb +8 -1
- data/lib/rails/generators/humdrum/setup/setup_generator.rb +57 -12
- data/lib/rails/generators/humdrum/setup/templates/config/initializers/config_center.rb +71 -0
- data/lib/rails/generators/humdrum/{resource → setup}/templates/config/locales/humdrum.en.yml +0 -0
- data/lib/rails/generators/humdrum/setup/templates/ruby-gemset +1 -1
- data/lib/rails/generators/humdrum/setup/templates/ruby-version +1 -1
- metadata +54 -3
@@ -0,0 +1,56 @@
|
|
1
|
+
/* pagination (base.css) */
|
2
|
+
|
3
|
+
.pagination { margin-top:10px;}
|
4
|
+
|
5
|
+
.pagination a,span {
|
6
|
+
float: left;
|
7
|
+
}
|
8
|
+
|
9
|
+
.pagination span.current {
|
10
|
+
padding: 2px 5px;
|
11
|
+
margin-right: 5px;
|
12
|
+
border-style: solid;
|
13
|
+
border-width: 1px;
|
14
|
+
background: #37a7d9;
|
15
|
+
color: white;
|
16
|
+
border: 1px solid #37a7d9;
|
17
|
+
min-width: 15px;
|
18
|
+
text-align: center;
|
19
|
+
-moz-border-radius: 2px;
|
20
|
+
-webkit-border-radius: 2px;
|
21
|
+
}
|
22
|
+
|
23
|
+
.pagination span.gap {
|
24
|
+
padding: 2px 5px;
|
25
|
+
margin-right: 5px;
|
26
|
+
text-align: center;
|
27
|
+
font-size:12px;
|
28
|
+
}
|
29
|
+
|
30
|
+
.pagination a {
|
31
|
+
text-decoration: none;
|
32
|
+
padding: 2px 5px;
|
33
|
+
margin-right: 5px;
|
34
|
+
display: block;
|
35
|
+
border-style: solid;
|
36
|
+
border-width: 1px;
|
37
|
+
border: 1px solid #c3c4ba;
|
38
|
+
-moz-border-radius: 2px;
|
39
|
+
-webkit-border-radius: 2px;
|
40
|
+
border-radius: 2px;
|
41
|
+
margin-right: 5px;
|
42
|
+
min-width: 15px;
|
43
|
+
text-align: center;
|
44
|
+
font-size:12px;
|
45
|
+
}
|
46
|
+
|
47
|
+
.pagination a:hover {
|
48
|
+
border: 1px solid #818171;
|
49
|
+
-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
|
50
|
+
-moz-box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
|
51
|
+
box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
|
52
|
+
}
|
53
|
+
|
54
|
+
.pagination a:active {
|
55
|
+
outline: none;
|
56
|
+
}
|
@@ -16,3 +16,11 @@ h4 { font-size: 20px; font-size: 1.50rem}
|
|
16
16
|
h5 { font-size: 16px; font-size: 1.40rem}
|
17
17
|
h6 { font-size: 14px; font-size: 1.30rem}
|
18
18
|
|
19
|
+
/* jQuery Validation error highlighting */
|
20
|
+
div.danger label.error {color: darkred; font-size:12px;}
|
21
|
+
div.danger textarea {background-color: #f0c5c5; }
|
22
|
+
|
23
|
+
/* textareas should stretch maximum with default border color to match with text boxes. Also the text style should match with text input fields*/
|
24
|
+
form textarea {width: 100%; border-color:#d8d8d8; color: #222; padding: 5px 10px; font-family: 'Open Sans'; font-weight: 300;}
|
25
|
+
|
26
|
+
|
@@ -11,13 +11,13 @@
|
|
11
11
|
|
12
12
|
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
|
13
13
|
<link rel="icon" href="/assets/favicon.ico" type="image/png">
|
14
|
-
|
14
|
+
|
15
15
|
<%%= stylesheet_link_tag "application", :media => "all" -%>
|
16
|
-
|
16
|
+
|
17
17
|
<%%= csrf_meta_tags -%>
|
18
18
|
|
19
|
-
<%%# Modernizr should be loaded first
|
20
|
-
<script src="/assets/
|
19
|
+
<%%# Modernizr should be loaded first %>
|
20
|
+
<script src="/assets/modernizr.2.6.2.js"></script>
|
21
21
|
|
22
22
|
</head>
|
23
23
|
|
@@ -18,10 +18,10 @@ module Humdrum
|
|
18
18
|
argument :resource_name, :type=>:string
|
19
19
|
argument :fields, :type=>:hash, :banner =>"Resource Fields."
|
20
20
|
|
21
|
-
class_option :
|
21
|
+
class_option :fixed, :type => :boolean, :default => false, :desc => "Create fixed layouts. Default is fluid (Gumby doesn't support fluid framework. Hence applicable only for bootstrap for the timebeing.)"
|
22
22
|
class_option :debug, :type => :boolean, :default => false, :desc => "This will print the arguments for debugging"
|
23
23
|
|
24
|
-
class_option :front_end_framework, :type => :string, :default => '
|
24
|
+
class_option :front_end_framework, :type => :string, :default => 'bootstrap', :desc => "Support Twitter Bootstrap (twitter.github.io/bootstrap/) and Gumpy (http://gumbyframework.com/). Default is bootstrap. Pass gumby for Gumby Framework"
|
25
25
|
|
26
26
|
def debug_args
|
27
27
|
print_args if options.debug?
|
@@ -34,6 +34,7 @@ module Humdrum
|
|
34
34
|
def generate_views
|
35
35
|
template "views/#{options.front_end_framework}/resource/_edit.html.erb", "app/views/#{controller_path}/_edit.html.erb"
|
36
36
|
template "views/#{options.front_end_framework}/resource/_filters.html.erb", "app/views/#{controller_path}/_filters.html.erb"
|
37
|
+
template "views/#{options.front_end_framework}/resource/_field.html.erb", "app/views/#{controller_path}/_field.html.erb"
|
37
38
|
template "views/#{options.front_end_framework}/resource/_form.html.erb", "app/views/#{controller_path}/_form.html.erb"
|
38
39
|
template "views/#{options.front_end_framework}/resource/_index.html.erb", "app/views/#{controller_path}/_index.html.erb"
|
39
40
|
template "views/#{options.front_end_framework}/resource/_item.html.erb", "app/views/#{controller_path}/_item.html.erb"
|
@@ -60,7 +61,14 @@ module Humdrum
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def generate_migrations
|
63
|
-
|
64
|
+
migration_dir = "db/migrate"
|
65
|
+
migration_file_name = "create_#{instances_name}.rb"
|
66
|
+
destination = self.class.migration_exists?(migration_dir, migration_file_name)
|
67
|
+
if destination
|
68
|
+
say_status("skipped", "Migration #{migration_file_name}.rb already exists")
|
69
|
+
else
|
70
|
+
migration_template "migrations/create_resources.rb", "db/migrate/create_#{instances_name}.rb"
|
71
|
+
end
|
64
72
|
end
|
65
73
|
|
66
74
|
def generate_routes
|
@@ -71,10 +79,6 @@ module Humdrum
|
|
71
79
|
}
|
72
80
|
end
|
73
81
|
|
74
|
-
def generate_locales
|
75
|
-
template "config/locales/humdrum.en.yml", "config/locales/humdrum.en.yml"
|
76
|
-
end
|
77
|
-
|
78
82
|
private
|
79
83
|
|
80
84
|
def print_args
|
@@ -152,6 +156,14 @@ module Humdrum
|
|
152
156
|
instance_name.pluralize
|
153
157
|
end
|
154
158
|
|
159
|
+
def instance_title
|
160
|
+
instance_name.titleize
|
161
|
+
end
|
162
|
+
|
163
|
+
def instances_title
|
164
|
+
instances_name.titleize
|
165
|
+
end
|
166
|
+
|
155
167
|
def table_name
|
156
168
|
instances_name
|
157
169
|
end
|
@@ -187,33 +199,6 @@ module Humdrum
|
|
187
199
|
end
|
188
200
|
end
|
189
201
|
|
190
|
-
def input_type(name, type)
|
191
|
-
if name.include?("email") && type == "string"
|
192
|
-
return "email"
|
193
|
-
elsif name.include?("password") && type == "string"
|
194
|
-
return "password"
|
195
|
-
elsif (name.include?("phone") || name.include?("mobile")) && type == "string"
|
196
|
-
return "tel"
|
197
|
-
else
|
198
|
-
case type
|
199
|
-
when "string"
|
200
|
-
"text"
|
201
|
-
when "text"
|
202
|
-
"textarea"
|
203
|
-
when "integer"
|
204
|
-
"number"
|
205
|
-
when "references"
|
206
|
-
"type"
|
207
|
-
when "date"
|
208
|
-
"date"
|
209
|
-
when "datetime"
|
210
|
-
"datetime-local"
|
211
|
-
when "timestamp", "time"
|
212
|
-
"time"
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
202
|
## List of all the string fields
|
218
203
|
def string_fields
|
219
204
|
main_field = main_string_field
|
@@ -231,6 +216,43 @@ module Humdrum
|
|
231
216
|
fields.map{|name, type| name if name.include?("name") && type == "string"}.uniq.compact || fields.keys.any? ? fields.keys.first : "id"
|
232
217
|
end
|
233
218
|
|
219
|
+
def guess_input_type(name, type)
|
220
|
+
case type
|
221
|
+
when "string"
|
222
|
+
if name.include?("url")
|
223
|
+
return "url"
|
224
|
+
elsif name.include?("email")
|
225
|
+
return "email"
|
226
|
+
elsif name.include?("phone") || name.include?("mobile") || name.include?("landline") || name.include?("contact number")
|
227
|
+
return "tel"
|
228
|
+
elsif name.include?("time")
|
229
|
+
return "time"
|
230
|
+
elsif name.include?("date")
|
231
|
+
return "date"
|
232
|
+
elsif name.include?("password")
|
233
|
+
return "password"
|
234
|
+
else
|
235
|
+
"text"
|
236
|
+
end
|
237
|
+
when "text"
|
238
|
+
"textarea"
|
239
|
+
when "integer"
|
240
|
+
"number"
|
241
|
+
when "references"
|
242
|
+
"type"
|
243
|
+
when "date"
|
244
|
+
"date"
|
245
|
+
when "datetime"
|
246
|
+
"datetime-local"
|
247
|
+
when "timestamp", "time"
|
248
|
+
"time"
|
249
|
+
when "boolean"
|
250
|
+
"checkbox"
|
251
|
+
else
|
252
|
+
"text"
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
234
256
|
## Text Fields like description or summary
|
235
257
|
def text_fields
|
236
258
|
fields.map{|name, type| name if type == "text"}.uniq.compact
|
@@ -238,21 +260,21 @@ module Humdrum
|
|
238
260
|
|
239
261
|
def container_class
|
240
262
|
if options.front_end_framework == "bootstrap"
|
241
|
-
options.
|
263
|
+
options.fixed? ? "container" : "container-fluid"
|
242
264
|
elsif options.front_end_framework == "gumby"
|
243
265
|
"container"
|
244
266
|
else
|
245
|
-
"container"
|
267
|
+
options.fixed? ? "container" : "container-fluid"
|
246
268
|
end
|
247
269
|
end
|
248
270
|
|
249
271
|
def row_class
|
250
272
|
if options.front_end_framework == "bootstrap"
|
251
|
-
options.
|
273
|
+
options.fixed? ? "row" : "row-fluid"
|
252
274
|
elsif options.front_end_framework == "gumby"
|
253
275
|
"row"
|
254
276
|
else
|
255
|
-
"row"
|
277
|
+
options.fixed? ? "row" : "row-fluid"
|
256
278
|
end
|
257
279
|
end
|
258
280
|
|
@@ -4,6 +4,8 @@ class <%= controller_class %> < ApplicationController
|
|
4
4
|
layout "public"
|
5
5
|
#authorize_actions_for Item, :actions => {:index => :delete}
|
6
6
|
|
7
|
+
before_filter :parse_pagination_params, :only=>:index
|
8
|
+
|
7
9
|
# GET /<%= instances_name %>
|
8
10
|
# GET /<%= instances_name %>.js
|
9
11
|
# GET /<%= instances_name %>.json
|
@@ -26,7 +28,7 @@ class <%= controller_class %> < ApplicationController
|
|
26
28
|
@<%= instance_name %> = <%= model_class %>.find(params[:id])
|
27
29
|
|
28
30
|
respond_to do |format|
|
29
|
-
format.html { get_collections and render :
|
31
|
+
format.html { get_collections and render :index }
|
30
32
|
format.json { render json: @<%= instance_name %> }
|
31
33
|
format.js {}
|
32
34
|
end
|
@@ -39,7 +41,7 @@ class <%= controller_class %> < ApplicationController
|
|
39
41
|
@<%= instance_name %> = <%= model_class %>.new
|
40
42
|
|
41
43
|
respond_to do |format|
|
42
|
-
format.html
|
44
|
+
format.html { get_collections and render :index }
|
43
45
|
format.json { render json: @<%= instance_name %> }
|
44
46
|
format.js {}
|
45
47
|
end
|
@@ -49,6 +51,12 @@ class <%= controller_class %> < ApplicationController
|
|
49
51
|
def edit
|
50
52
|
## Fetching the <%= instance_name %> object
|
51
53
|
@<%= instance_name %> = <%= model_class %>.find(params[:id])
|
54
|
+
|
55
|
+
respond_to do |format|
|
56
|
+
format.html { get_collections and render :index }
|
57
|
+
format.json { render json: @<%= instance_name %> }
|
58
|
+
format.js {}
|
59
|
+
end
|
52
60
|
end
|
53
61
|
|
54
62
|
# POST /<%= instances_name %>
|
@@ -1,32 +1,85 @@
|
|
1
1
|
function validate<%= model_class %>Form() {
|
2
2
|
|
3
|
-
$('#form_<%= instance_name %>').
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
return $el.val().match('@') !== null;
|
13
|
-
}
|
14
|
-
}
|
15
|
-
],
|
16
|
-
fail: function(failed) {
|
17
|
-
errorText = "Please fill out all the required fields and ensure the data entered is valid.";
|
18
|
-
$("#div_<%= instance_name %>_form_error").remove();
|
19
|
-
txtDiv = "<div id='div_<%= instance_name %>_form_error' class=\"alert danger\" data-alert=\"alert\" style=\"margin-bottom:5px;\">"+ errorText +"</div>"
|
20
|
-
$("#div_<%= instance_name %>_details").prepend(txtDiv);
|
3
|
+
$('#form_<%= instance_name %>').validate({
|
4
|
+
debug: true,
|
5
|
+
rules: {
|
6
|
+
<%- fields.each do |name, type| -%>
|
7
|
+
<%- input_type = guess_input_type(name, type) -%>
|
8
|
+
<%- if input_type == "email" -%>
|
9
|
+
"<%= instance_name %>[email]": {
|
10
|
+
required: true,
|
11
|
+
email: true
|
21
12
|
},
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
<%- elsif input_type == "text" -%>
|
14
|
+
"<%= instance_name %>[<%= name %>]": {
|
15
|
+
required: true,
|
16
|
+
minlength: 2,
|
17
|
+
maxlength: 50
|
18
|
+
},
|
19
|
+
<%- else -%>
|
20
|
+
"<%= instance_name %>[<%= name %>]": "required",
|
21
|
+
<%- end -%>
|
22
|
+
<%- end -%>
|
23
|
+
},
|
24
|
+
messages: {
|
25
|
+
<%- fields.each do |name, type| -%>
|
26
|
+
<%- input_type = guess_input_type(name, type) -%>
|
27
|
+
<%- if input_type == "email" -%>
|
28
|
+
"<%= instance_name %>[<%= name %>]": {
|
29
|
+
required: "We need your email address to contact you",
|
30
|
+
email: "Your email address must be in the format of name@domain.com"
|
31
|
+
},
|
32
|
+
<%- elsif input_type == "text" -%>
|
33
|
+
"<%= instance_name %>[<%= name %>]": "Please specify <%= name.titleize %>",
|
34
|
+
<%- else -%>
|
35
|
+
"<%= instance_name %>[<%= name %>]": "Please specify <%= name.titleize %>",
|
36
|
+
<%- end -%>
|
37
|
+
<%- end -%>
|
38
|
+
},
|
39
|
+
highlight: function(element) {
|
40
|
+
$(element).parent().addClass("danger");
|
41
|
+
},
|
42
|
+
unhighlight: function(element) {
|
43
|
+
$(element).parent().removeClass("danger");
|
44
|
+
},
|
45
|
+
invalidHandler: function(event, validator) {
|
46
|
+
// 'this' refers to the form
|
47
|
+
var errors = validator.numberOfInvalids();
|
48
|
+
if (errors) {
|
49
|
+
|
50
|
+
// Populating error message
|
51
|
+
var errorMessage = errors == 1
|
52
|
+
? 'You missed 1 field. It has been highlighted'
|
53
|
+
: 'You missed ' + errors + ' fields. They have been highlighted';
|
54
|
+
|
55
|
+
// Removing the form error if it already exists
|
56
|
+
$("#div_<%= instance_name %>_js_validation_error").remove();
|
57
|
+
|
58
|
+
errorHtml = "<div id='div_<%= instance_name %>_js_validation_error' class=\"alert danger\" data-alert=\"alert\" style=\"margin-bottom:5px;\">"+ errorMessage +"</div>"
|
59
|
+
$("#div_<%= instance_name %>_details").prepend(errorHtml);
|
60
|
+
|
61
|
+
// Show error labels
|
62
|
+
$("div.error").show();
|
63
|
+
|
64
|
+
} else {
|
65
|
+
// Hide error labels
|
66
|
+
$("div.error").hide();
|
67
|
+
// Removing the error message
|
68
|
+
$("#div_<%= instance_name %>_js_validation_error").remove();
|
29
69
|
}
|
70
|
+
},
|
71
|
+
submitHandler: function(form) {
|
72
|
+
// Submit the form via HTTP request
|
73
|
+
// form.submit();
|
74
|
+
|
75
|
+
// Submit the form via XMLHTTP request (Ajax)
|
76
|
+
$(form).ajaxSubmit({
|
77
|
+
url: $("#form_<%= instance_name %> input[name=faction]").val(),
|
78
|
+
type: $("#form_<%= instance_name %> input[name=fmethod]").val(),
|
79
|
+
dataType: 'script'
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
30
83
|
});
|
31
84
|
|
32
85
|
}
|