cambium 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4ea6803ff7b5699c765fd57eb79353db74645cc
4
- data.tar.gz: 92f9fee301ccb91d0bb9f9755343e39db07f1ff3
3
+ metadata.gz: dc213f76b0bfb1bc7f89557007412022d32f0c37
4
+ data.tar.gz: a02c79d2cbf1b519942703e3a57d246ca97f7cb0
5
5
  SHA512:
6
- metadata.gz: 5284b848c3a7d298fd978b9650f6b64c1ece775801ba615d84f6d2db5a07bff6a035a569f63464cf8b17906bf6cf5658c0fd61c3dd70f0807d1c6b3b7557a2d0
7
- data.tar.gz: 8bc1d2704a51bf91d44aa7fe06a63ed9a13a81413aa535100210541991fac0b0eac146d344a9d22c5a9bbbd50049414b5256bad677a75170314a875bb89c31e9
6
+ metadata.gz: 28daeea78d3becc708ed681e5e933fa6729980382df60d73a51c0d95ce0de5f18f88a42581e4be2fb55a877e42607abbffbca2d6a4dc1c76ce2a176a694cbc53
7
+ data.tar.gz: 431257c6a35b8f5c630c717697af2fc168f139c0215e0bd9d1db2c4a6d669253630c7c4ac4b04ac641d0fb441e03711ca57138ef6241728a866921c5969aac80
data/README.md CHANGED
@@ -224,6 +224,8 @@ export:
224
224
  email:
225
225
  label: Email
226
226
  form:
227
+ buttons:
228
+ delete: Delete User
227
229
  new: &new
228
230
  title: New User
229
231
  fields:
@@ -265,6 +267,9 @@ Every setting plays a role. Let's step through each one.
265
267
  * `export:columns:[column]:output`: An optional method you can pass to each
266
268
  object to help with display.
267
269
  * `form`: Settings for the form.
270
+ * `form:buttons:delete`: Label for the delete button. If you remove `delete`
271
+ entirely, then no delete button will exist (though you'd have to manually
272
+ remove the route from your routes file).
268
273
  * `form:[new/edit]`: New is the defaut, and most of the time Edit will inherit
269
274
  from new (the `<<: *new` is what handles that). But you can optionally
270
275
  override new values for your edit form.
@@ -1,6 +1,6 @@
1
1
  #= require jquery
2
2
  #= require jquery_ujs
3
- #= require mark_it_zero/mark_it_zero
3
+ #= require mark_it_zero
4
4
  #= require pickadate/picker
5
5
  #= require pickadate/picker.date
6
6
  #= require pickadate/picker.time
@@ -38,7 +38,7 @@ div.status{
38
38
  }
39
39
 
40
40
  a {
41
- &.new, &.export, &.file {
41
+ &.new, &.export, &.file, &.delete {
42
42
  &:before {
43
43
  font-family: 'icomoon';
44
44
  font-size: inherit;
@@ -48,6 +48,7 @@ a {
48
48
  }
49
49
  &.new:before { content: "\e702"; }
50
50
  &.export:before { content: "\e65e"; }
51
+ &.delete:before { content: "\e6a7"; }
51
52
  &.file:before { content: "\e622"; }
52
53
  }
53
54
 
@@ -112,6 +112,12 @@ section.form {
112
112
  color: $color-dark;
113
113
  }
114
114
  }
115
+ .error {
116
+ display: block;
117
+ font-weight: 600;
118
+ color: $color-danger;
119
+ text-transform: uppercase;
120
+ }
115
121
  }
116
122
 
117
123
  input[type=submit] {
@@ -24,7 +24,7 @@
24
24
  font-weight: 400;
25
25
  color: $color-dark;
26
26
  vertical-align: top;
27
- &.new, &.export {
27
+ &.new, &.export, &.delete {
28
28
  margin: 12px 0 0 10px;
29
29
  padding: 3px 8px;
30
30
  font-size: 13px;
@@ -35,7 +35,11 @@
35
35
  &.new {
36
36
  background: $color-2;
37
37
  }
38
- &.export {
38
+ &.delete {
39
+ background: $color-danger;
40
+ color: $color-light;
41
+ }
42
+ &.export, &.delete {
39
43
  float: right;
40
44
  }
41
45
  }
@@ -9,12 +9,19 @@ class Cambium::AdminController < Cambium::BaseController
9
9
 
10
10
  def index
11
11
  respond_to do |format|
12
- format.html do
12
+ scope = admin_table.scope
13
+ if scope.split('.').size > 1
14
+ @collection = admin_model
15
+ scope.split('.').each do |s|
16
+ @collection = @collection.send(s)
17
+ end
18
+ else
13
19
  @collection = admin_model.send(admin_table.scope)
14
- .page(params[:page] || 1).per(15)
20
+ end
21
+ format.html do
22
+ @collection = @collection.page(params[:page] || 1).per(15)
15
23
  end
16
24
  format.csv do
17
- @collection = admin_model.send(admin_table.scope)
18
25
  send_data admin.to_csv(@collection)
19
26
  end
20
27
  end
@@ -30,7 +37,6 @@ class Cambium::AdminController < Cambium::BaseController
30
37
  end
31
38
 
32
39
  def create
33
- set_object
34
40
  @object = admin_model.new(create_params)
35
41
  if @object.save
36
42
  redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} created!")
@@ -52,6 +58,12 @@ class Cambium::AdminController < Cambium::BaseController
52
58
  end
53
59
  end
54
60
 
61
+ def destroy
62
+ set_object
63
+ @object.destroy
64
+ redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} deleted!")
65
+ end
66
+
55
67
  private
56
68
 
57
69
  def set_object
@@ -62,6 +74,7 @@ class Cambium::AdminController < Cambium::BaseController
62
74
  id = params[:"#{admin_model.to_s.underscore}_id"] || params[:id]
63
75
  @object = admin_model.find_by_id(id.to_i)
64
76
  end
77
+ not_found if @object.nil?
65
78
  @obj = @object
66
79
  end
67
80
 
@@ -60,6 +60,15 @@ module Cambium
60
60
  :class => 'button export'
61
61
  )
62
62
  end
63
+ if is_edit? && can_delete?
64
+ o += link_to(
65
+ admin_view.form.buttons.delete,
66
+ admin_routes.delete,
67
+ :class => 'button delete',
68
+ :method => :delete,
69
+ :data => { :confirm => 'Are you sure?' }
70
+ )
71
+ end
63
72
  o.html_safe
64
73
  end
65
74
  end
@@ -131,10 +140,16 @@ module Cambium
131
140
  if options.type == 'heading'
132
141
  o += content_tag(:h2, options.label || attr.titleize)
133
142
  elsif ['select','check_boxes','radio_buttons'].include?(options.type)
143
+ parts = options.options.split('.')
144
+ if parts.size > 1
145
+ collection = parts[0].constantize.send(parts[1])
146
+ else
147
+ collection = options.options
148
+ end
134
149
  o += f.input(
135
150
  attr.to_sym,
136
151
  :as => options.type,
137
- :collection => options.options,
152
+ :collection => collection,
138
153
  :label => label,
139
154
  :readonly => readonly
140
155
  )
@@ -189,7 +204,7 @@ module Cambium
189
204
  end
190
205
  elsif options.type == 'markdown'
191
206
  o += content_tag(:div, :class => "input text optional #{attr}") do
192
- o2 = content_tag(:label, attr.titleize, :for => attr)
207
+ o2 = content_tag(:label, label, :for => attr)
193
208
  o2 += content_tag(
194
209
  :div,
195
210
  f.markdown(attr.to_sym),
@@ -250,9 +265,18 @@ module Cambium
250
265
  action_name == 'index'
251
266
  end
252
267
 
268
+ def is_edit?
269
+ ['edit','update'].include?(action_name)
270
+ end
271
+
253
272
  def has_new_form?
254
273
  admin_view.form.present? && admin_view.form.new.present?
255
274
  end
256
275
 
276
+ def can_delete?
277
+ admin_view.form.present? && admin_view.form.buttons.present? &&
278
+ admin_view.form.buttons.delete.present?
279
+ end
280
+
257
281
  end
258
282
  end
@@ -66,6 +66,7 @@ module Cambium
66
66
  "admin_#{@view.controller_name.singularize}_path",
67
67
  object
68
68
  )
69
+ r[:delete] = r[:show]
69
70
  end
70
71
  r.to_ostruct
71
72
  end
@@ -1,3 +1,3 @@
1
1
  module Cambium
2
- VERSION = "1.1.6"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -13,6 +13,8 @@ export:
13
13
  <%= "#{col.name}:" %>
14
14
  label: <%= "#{col.name.titleize}" %><% end %>
15
15
  form:
16
+ buttons:
17
+ delete: Delete <%= @model.to_s %>
16
18
  new: &new
17
19
  title: New <%= @model.to_s %>
18
20
  fields:<% @columns.each do |col| %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cambium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean C Davis