godmin 0.9.5 → 0.9.6

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: 113b40103476fc56d7a936799d5750fecd7d3697
4
- data.tar.gz: ea1fd807681371728f6bb6e85645bb8cb3472faa
3
+ metadata.gz: 6c9bc1e136e1f026504ed65cd0199c7bed3b2ec4
4
+ data.tar.gz: 36d462277c7c058a619c2fb29afd86f42de87574
5
5
  SHA512:
6
- metadata.gz: 6e636dd69f663e11110d39a5583def41339daff335ca41b670bbcdbfb5871fc486ba231349327205ffafa7d3bd2d9e766ed8c3794c71d79c375e7fa29989b677
7
- data.tar.gz: c0e210a5a0ce0ad9d8a9338fe494fc8d9c0d056ba1ca499d4f2f29fad07579bd90caf1b20eabf452ada1ed6f9a3905fb11cb3ad8a3f26bec101b2f02c370ba8a
6
+ metadata.gz: e50bc8557f5bb7d677e75f6cc5e67f39221813f42d2e30539c8bc0d0bc874f6a52fe477fd3b4f9a84a34e911b7dab896c7a53d66f9d1fc4cf01c6d687ebaf042
7
+ data.tar.gz: 7185ab2665b695723c7422ee7007f6e11749ff9381ac5c51470342133dc220a2f482f29f3f7b885a2594964c12401db840481f3cac13359baf9aabcccd15671b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.9.6 - 2014-12-18
4
+ Features
5
+ - Bundled [datetimepicker](https://github.com/Eonasdan/bootstrap-datetimepicker/)
6
+ - Exposed JavaScript API
7
+
8
+ Notes
9
+ - You must now require godmin in application.js and application.css
10
+ - You can no longer use the `select-tag` class to initialize a select box
11
+
3
12
  ### 0.9.5 - 2014-12-15
4
13
  Bug fixes
5
14
  - Fixes Godmin::FormBuilder issue
@@ -29,4 +38,3 @@ Bug fixes
29
38
  - Removed rails executable from /bin folder.
30
39
 
31
40
  ### 0.9.0 - 2014-11-17
32
- Public release.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Godmin
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/godmin.svg)](https://rubygems.org/gems/godmin)
4
- [![Build Status](https://travis-ci.org/varvet/godmin.svg?branch=master)](https://travis-ci.org/varvet/godmin)
4
+ [![Build Status](https://img.shields.io/travis/varvet/godmin/master.svg)](https://travis-ci.org/varvet/godmin)
5
5
  [![Code Climate](https://codeclimate.com/github/varvet/godmin/badges/gpa.svg)](https://codeclimate.com/github/varvet/godmin)
6
6
 
7
7
  Godmin is an admin engine for Rails 4+.
@@ -25,6 +25,8 @@ Godmin is an admin engine for Rails 4+.
25
25
  - [Shared authentication](#shared-authentication)
26
26
  - [Authorization](#authorization)
27
27
  - [Localization](#localization)
28
+ - [JavaScript](#javascript)
29
+ - [Plugins](#plugins)
28
30
  - [Contributors](#contributors)
29
31
  - [License](#license)
30
32
 
@@ -110,6 +112,8 @@ class ApplicationController < ActionController::Base
110
112
  end
111
113
  ```
112
114
 
115
+ Require statements are placed in both `app/assets/javascripts/application.js` and `app/assets/stylesheets/application.css`.
116
+
113
117
  If Godmin was installed inside an engine, a `require "godmin"` statement is placed in `{namespace}/lib/{namespace}.rb`.
114
118
 
115
119
  And finally, the `app/views/layouts` folder is removed by default, so as not to interfere with the Godmin layouts. It can be added back in case you wish to override the built in layouts.
@@ -165,12 +169,7 @@ By now we have a basic admin interface for managing articles.
165
169
 
166
170
  ## Controllers
167
171
 
168
- We have already seen two controller methods at play: `attrs_for_index` and `attrs_for_form`. Now we will look at four additional controller concepts, namely:
169
-
170
- - Scopes
171
- - Filters
172
- - Batch actions
173
- - Resource fetching
172
+ We have already seen two controller methods at play: `attrs_for_index` and `attrs_for_form`. We will now look at some additional controller concepts.
174
173
 
175
174
  ### Scopes
176
175
 
@@ -195,9 +194,7 @@ end
195
194
 
196
195
  ### Filters
197
196
 
198
- Filters offer great flexibility when it comes to searching for resources.
199
-
200
- Filters can be created as follows:
197
+ Filters offer great flexibility when it comes to searching for resources, and can be created as follows:
201
198
 
202
199
  ```ruby
203
200
  class ArticlesController < ApplicationController
@@ -240,8 +237,6 @@ class ArticlesController < ApplicationController
240
237
  def batch_action_publish(resources)
241
238
  resources.each { |r| r.update_attributes(published: true) }
242
239
  end
243
-
244
- ...
245
240
  end
246
241
  ```
247
242
 
@@ -309,7 +304,7 @@ end
309
304
 
310
305
  ### Redirecting
311
306
 
312
- By default the user is redirected to the resource show page after create and update. To change this, there are four controller methods that can be overridden: `redirect_after_create`, `redirect_after_update`, `redirect_after_save`, and `redirect_after_destroy`.
307
+ By default the user is redirected to the resource show page after create and update, and to the index page after destroy. To change this, there are four controller methods that can be overridden: `redirect_after_create`, `redirect_after_update`, `redirect_after_save`, and `redirect_after_destroy`.
313
308
 
314
309
  For instance, to have the article controller redirect to the index page after both create and update:
315
310
 
@@ -345,6 +340,8 @@ If you wish to change the behaviour for every resource controller, consider crea
345
340
  class ResourceController < ApplicationController
346
341
  include Godmin::Resource
347
342
 
343
+ protected
344
+
348
345
  def redirect_after_save
349
346
  resource_class.model_name.route_key.to_sym
350
347
  end
@@ -585,6 +582,73 @@ Godmin comes with built in support for English and Swedish.
585
582
 
586
583
  There is a view helper available named `translate_scoped` that can be used in overridden views. Please see the source code for information on how to use it.
587
584
 
585
+ ## JavaScript
586
+
587
+ Godmin comes with a small set of JavaScript components and APIs.
588
+
589
+ ### Datetimepickers
590
+
591
+ Make a [bootstrap-datetimepicker](https://github.com/Eonasdan/bootstrap-datetimepicker) out of a text field:
592
+
593
+ ```ruby
594
+ f.text_field :date, data: { behavior: "datepicker" }
595
+ f.text_field :date, data: { behavior: "timepicker" }
596
+ f.text_field :date, data: { behavior: "datetimepicker" }
597
+ ```
598
+
599
+ If the field is added post page render, it can be initialized manually:
600
+
601
+ ```js
602
+ Godmin.Datetimepickers.initializeDatepicker($el);
603
+ Godmin.Datetimepickers.initializeTimepicker($el);
604
+ Godmin.Datetimepickers.initializeDatetimepicker($el);
605
+ ```
606
+
607
+ Additional options can be passed down to bootstrap-datetimepicker:
608
+
609
+ ```js
610
+ Godmin.Datetimepickers.initializeDatetimepicker($el, {
611
+ useMinutes: false,
612
+ useSeconds: false
613
+ });
614
+ ```
615
+
616
+ If you wish to translate the datetimepicker, add the following to your `app/assets/javascripts/application.js`:
617
+
618
+ ```js
619
+ //= require moment
620
+ //= require moment/{locale} // e.g. moment/sv
621
+ //= require godmin
622
+ ```
623
+
624
+ ### Select boxes
625
+
626
+ Make a [selectize.js](http://brianreavis.github.io/selectize.js/) select box out of a text field or select box:
627
+
628
+ ```ruby
629
+ f.text_field :tag_list, data: { behavior: "select-box" }
630
+ ```
631
+
632
+ If the field is added post page render, it can be initialized manually:
633
+
634
+ ```js
635
+ Godmin.SelectBoxes.initializeSelectBox($el);
636
+ ```
637
+
638
+ Additional options can be passed down to selectize:
639
+
640
+ ```js
641
+ Godmin.SelectBoxes.initializeSelectBox($el, {
642
+ create: true
643
+ });
644
+ ```
645
+
646
+ ## Plugins
647
+
648
+ Some additional features are available as plugins:
649
+
650
+ - [Godmin Uploads](https://github.com/varvet/godmin-uploads)
651
+
588
652
  ## Contributors
589
653
 
590
654
  https://github.com/varvet/godmin/graphs/contributors
@@ -0,0 +1,67 @@
1
+ window.Godmin = window.Godmin || {};
2
+
3
+ Godmin.BatchActions = (function() {
4
+ var $form;
5
+ var $selectAll;
6
+ var $selectNone;
7
+
8
+ function initialize() {
9
+ $form = $('form[data-behavior~=batch-actions-form]');
10
+ $selectAll = $form.find('[data-behavior~=batch-actions-select-all]');
11
+ $selectNone = $form.find('[data-behavior~=batch-actions-select-none]');
12
+
13
+ initializeEvents();
14
+ initializeState();
15
+ }
16
+
17
+ function initializeEvents() {
18
+ $form.find('[data-behavior~=batch-actions-select]').on('click', toggleCheckboxes);
19
+ $form.find('[data-behavior~=batch-actions-checkbox]').on('change', toggleActions);
20
+ $(document).delegate('[data-behavior~=batch-actions-action-link]', 'click', triggerAction);
21
+ }
22
+
23
+ function initializeState() {}
24
+
25
+ function setSelectToAll() {
26
+ $selectAll.removeClass('hidden');
27
+ $selectNone.addClass('hidden');
28
+ }
29
+
30
+ function setSelectToNone() {
31
+ $selectAll.addClass('hidden');
32
+ $selectNone.removeClass('hidden');
33
+ }
34
+
35
+ function toggleCheckboxes() {
36
+ if ($form.find('[data-behavior~=batch-actions-checkbox]:checked').length > 0) {
37
+ $form.find('[data-behavior~=batch-actions-checkbox]').prop('checked', false).trigger('change');
38
+ setSelectToAll();
39
+ } else {
40
+ $form.find('[data-behavior~=batch-actions-checkbox]').prop('checked', true).trigger('change');
41
+ setSelectToNone();
42
+ }
43
+ }
44
+
45
+ function toggleActions() {
46
+ if ($form.find('[data-behavior~=batch-actions-checkbox]:checked').length) {
47
+ $('[data-behavior~=batch-actions-action-link]').removeClass('hidden');
48
+ setSelectToNone();
49
+ } else {
50
+ $('[data-behavior~=batch-actions-action-link]').addClass('hidden');
51
+ setSelectToAll();
52
+ }
53
+ }
54
+
55
+ function triggerAction() {
56
+ $form.find('[data-behavior~=batch-actions-action]').val($(this).data('value'));
57
+ $form.submit();
58
+ }
59
+
60
+ return {
61
+ initialize: initialize
62
+ };
63
+ })();
64
+
65
+ $(function() {
66
+ Godmin.BatchActions.initialize();
67
+ });
@@ -0,0 +1,46 @@
1
+ window.Godmin = window.Godmin || {};
2
+
3
+ Godmin.Datetimepickers = (function() {
4
+ function initialize() {
5
+ initializeEvents();
6
+ initializeState();
7
+ }
8
+
9
+ function initializeEvents() {}
10
+
11
+ function initializeState() {
12
+ initializeDatepicker($('[data-behavior~=datepicker]'));
13
+ initializeTimepicker($('[data-behavior~=timepicker]'));
14
+ initializeDatetimepicker($('[data-behavior~=datetimepicker]'));
15
+ }
16
+
17
+ function initializeDatepicker($el, options) {
18
+ var defaults = {
19
+ pickTime: false
20
+ };
21
+ initializeDatetimepicker($el, $.extend(defaults, options));
22
+ }
23
+
24
+ function initializeTimepicker($el, options) {
25
+ var defaults = {
26
+ pickDate: false
27
+ };
28
+ initializeDatetimepicker($el, $.extend(defaults, options));
29
+ }
30
+
31
+ function initializeDatetimepicker($el, options) {
32
+ var defaults = {};
33
+ $el.datetimepicker($.extend(defaults, options));
34
+ }
35
+
36
+ return {
37
+ initialize: initialize,
38
+ initializeDatepicker: initializeDatepicker,
39
+ initializeTimepicker: initializeTimepicker,
40
+ initializeDatetimepicker: initializeDatetimepicker
41
+ };
42
+ })();
43
+
44
+ $(function() {
45
+ Godmin.Datetimepickers.initialize();
46
+ });
@@ -12,8 +12,11 @@
12
12
  //
13
13
  //= require jquery
14
14
  //= require jquery_ujs
15
+ //= require moment
15
16
  //= require bootstrap-sprockets
17
+ //= require bootstrap-datetimepicker
16
18
  //= require selectize
17
- //= require godmin/batch_actions
19
+ //= require godmin/batch-actions
20
+ //= require godmin/datetimepickers
18
21
  //= require godmin/navigation
19
- //= require godmin/select_tags
22
+ //= require godmin/select-boxes
@@ -1,9 +1,30 @@
1
- (function($) {
2
- $(function() {
1
+ window.Godmin = window.Godmin || {};
2
+
3
+ Godmin.Navigation = (function() {
4
+ function initialize() {
5
+ initializeEvents();
6
+ initializeState();
7
+ }
8
+
9
+ function initializeEvents() {}
10
+
11
+ function initializeState() {
12
+ removeEmptyDropdowns();
13
+ }
14
+
15
+ function removeEmptyDropdowns() {
3
16
  $('.navbar-nav .dropdown').each(function() {
4
17
  if ($(this).find('li').length === 0) {
5
18
  $(this).remove();
6
19
  }
7
20
  });
8
- });
9
- }(jQuery));
21
+ }
22
+
23
+ return {
24
+ initialize: initialize
25
+ };
26
+ })();
27
+
28
+ $(function() {
29
+ Godmin.Navigation.initialize();
30
+ });
@@ -0,0 +1,31 @@
1
+ window.Godmin = window.Godmin || {};
2
+
3
+ Godmin.SelectBoxes = (function() {
4
+ function initialize() {
5
+ initializeEvents();
6
+ initializeState();
7
+ }
8
+
9
+ function initializeEvents() {}
10
+
11
+ function initializeState() {
12
+ initializeSelectBox($('[data-behavior~=select-box]'));
13
+ }
14
+
15
+ function initializeSelectBox($el, options) {
16
+ var defaults = {
17
+ inputClass: 'form-control selectize-input'
18
+ };
19
+
20
+ $el.selectize($.extend(defaults, options));
21
+ }
22
+
23
+ return {
24
+ initialize: initialize,
25
+ initializeSelectBox: initializeSelectBox
26
+ };
27
+ })();
28
+
29
+ $(function() {
30
+ Godmin.SelectBoxes.initialize();
31
+ });
@@ -10,9 +10,9 @@
10
10
  *
11
11
  *= require_self
12
12
  */
13
-
14
13
  @import "bootstrap-sprockets";
15
14
  @import "bootstrap";
15
+ @import "bootstrap-datetimepicker";
16
16
  @import "selectize";
17
17
  @import "selectize.bootstrap3";
18
18
 
@@ -1,6 +1,8 @@
1
1
  <% if batch_action_map.present? %>
2
- <%= link_to translate_scoped("batch_actions.select_all"), "#", class: "btn btn-default batch-actions-select batch-actions-select-all" %>
3
- <%= link_to translate_scoped("batch_actions.deselect_all"), "#", class: "btn btn-default batch-actions-select batch-actions-select-none hidden" %>
2
+ <%= link_to translate_scoped("batch_actions.select_all"), "#", class: "btn btn-default",
3
+ data: { behavior: "batch-actions-select batch-actions-select-all" } %>
4
+ <%= link_to translate_scoped("batch_actions.deselect_all"), "#", class: "btn btn-default hidden",
5
+ data: { behavior: "batch-actions-select batch-actions-select-none" } %>
4
6
 
5
7
  <div class="btn-group">
6
8
  <% batch_action_map.each do |name, options| %>
@@ -8,5 +10,5 @@
8
10
  <% end %>
9
11
  </div>
10
12
 
11
- <%= hidden_field_tag "batch_action[action]", nil, id: "batch-actions-action" %>
13
+ <%= hidden_field_tag "batch_action[action]", nil, data: { behavior: "batch-actions-action" } %>
12
14
  <% end %>
@@ -2,7 +2,7 @@
2
2
  <% attrs_for_form.each do |attr| %>
3
3
  <div class="form-group">
4
4
  <% if @resource_class.reflect_on_association(attr) %>
5
- <%= f.association attr, error: false, input_html: { class: "form-control select-tag" } %>
5
+ <%= f.association attr, error: false, input_html: { class: "form-control", data: { behavior: "select-box" } } %>
6
6
  <% else %>
7
7
  <%= f.input attr, error: false, input_html: { class: "form-control" } %>
8
8
  <% end %>
@@ -19,7 +19,8 @@
19
19
  <% end %>
20
20
  <% if batch_action_map.present? %>
21
21
  <td align="center">
22
- <%= check_box_tag "batch_action[items][#{resource.id}]" %>
22
+ <%= check_box_tag "batch_action[items][#{resource.id}]", nil, nil,
23
+ data: { behavior: "batch-actions-checkbox" } %>
23
24
  </td>
24
25
  <% end %>
25
26
  <% attrs_for_index.each do |attr| %>
@@ -6,7 +6,7 @@
6
6
  <%= render partial: "filters" %>
7
7
  <% end %>
8
8
 
9
- <%= form_tag [:batch_action, @resource_class], id: "batch-actions-form" do %>
9
+ <%= form_tag [:batch_action, @resource_class], data: { behavior: "batch-actions-form" } do %>
10
10
 
11
11
  <%= render partial: "actions" %>
12
12
 
@@ -2,8 +2,8 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Godmin</title>
5
- <%= stylesheet_link_tag "godmin/application", [Godmin.namespace, "application"].compact.join("/"), media: "all" %>
6
- <%= javascript_include_tag "godmin/application", [Godmin.namespace, "application"].compact.join("/") %>
5
+ <%= stylesheet_link_tag [Godmin.namespace, "application"].compact.join("/"), media: "all" %>
6
+ <%= javascript_include_tag [Godmin.namespace, "application"].compact.join("/") %>
7
7
  <%= csrf_meta_tags %>
8
8
  <%= yield :head %>
9
9
  </head>